source: golgotha/src/i4/gui/slider.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.7 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "gui/slider.hh"
10#include "window/style.hh"
11#include "window/win_evt.hh"
12
13i4_slider_class::i4_slider_class(sw32 width,
14                                 sw32 initial_start,
15                                 i4_event_handler_class *notify,
16                                 w32 milli_delay,
17                                 i4_graphical_style_class *style)
18  : i4_window_class(width,style->font_hint->normal_font->largest_height()+2),
19    style(style),
20    notify(notify),
21    milli_delay(milli_delay)
22{   
23  off=initial_start;
24  grab=i4_F;
25  active=i4_F;
26  w32 ol,or,ot,ob;
27  style->get_out_deco_size(ol,ot,or,ob);
28  bw=ol+or+2;
29  need_cancel=i4_F;
30}
31
32void i4_slider_class::draw(i4_draw_context_class &context)
33{
34  w32 il,ir,it,ib;
35  w32 med=style->color_hint->window.passive.medium;
36  local_image->clear(med, context);
37
38  style->get_in_deco_size(il,it,ir,ib);
39  style->draw_in_deco(local_image, 0,height()/2-it,width()-1,height()/2+ib, active, context);
40
41  w32 ol,or,ot,ob;
42  style->get_out_deco_size(ol,ot,or,ob);
43  style->draw_out_deco(local_image, off,0,off+bw-1,height()-1, active, context); 
44  local_image->bar(off+ol, ot, off+bw-or, height()-ob, med, context);
45}
46
47
48void i4_slider_class::send_change()
49{
50  if (notify)
51  {
52    if (need_cancel)
53    {
54      i4_time_dev.cancel_event(t_event);
55      need_cancel=i4_F;
56    }
57
58    i4_slider_event ev(this, off, width()-bw);
59
60    if (milli_delay)
61    {
62      t_event=i4_time_dev.request_event(notify, &ev, milli_delay);
63      need_cancel=i4_T;
64    } else i4_kernel.send_event(notify, &ev);
65  }
66}
67
68
69i4_slider_class::~i4_slider_class()
70{
71  if (need_cancel)
72  {
73    milli_delay=0;
74    send_change();
75  }
76}
77
78
79void i4_slider_class::set_off_from_mouse()
80{
81  w32 ol,or,ot,ob;
82  sw32 loff=off;
83
84  style->get_out_deco_size(ol,ot,or,ob);
85  off=lx-bw/2;
86  if (off<0) off=0;
87  if (off+bw>=width())
88    off=width()-bw;
89
90  if (loff!=off)
91  {
92    send_change();
93    request_redraw();
94  }
95}
96
97void i4_slider_class::receive_event(i4_event *ev)
98{
99  switch (ev->type())
100  {
101    case i4_event::WINDOW_MESSAGE :
102    {
103      CAST_PTR(wev, i4_window_message_class, ev);
104      if (wev->sub_type==i4_window_message_class::GOT_MOUSE_FOCUS)
105      {
106        active=i4_T;
107        request_redraw();
108      }
109      else if (wev->sub_type==i4_window_message_class::LOST_MOUSE_FOCUS)
110      {
111        active=i4_F;
112        request_redraw();
113      }
114    } break;
115
116    case i4_event::MOUSE_MOVE :
117    {
118      CAST_PTR(mev, i4_mouse_move_event_class, ev);
119      lx=mev->x;
120      ly=mev->y;
121       
122      if (grab)
123        set_off_from_mouse();               
124
125    } break;
126
127    case i4_event::MOUSE_BUTTON_DOWN :
128    {
129      CAST_PTR(bev, i4_mouse_button_down_event_class, ev);
130      if (bev->left() && !grab)
131      {
132        grab=i4_T;
133        i4_window_request_mouse_grab_class grab(this);
134        i4_kernel.send_event(parent,&grab);
135        set_off_from_mouse();
136      }       
137
138    } break;
139    case i4_event::MOUSE_BUTTON_UP :
140    {
141      CAST_PTR(bev, i4_mouse_button_up_event_class, ev);
142      if (grab && bev->left())
143      {
144        i4_window_request_mouse_ungrab_class ungrab(this);
145        i4_kernel.send_event(parent,&ungrab);
146        grab=i4_F;
147      }
148    } break;
149  }
150}
Note: See TracBrowser for help on using the repository browser.