source: golgotha/src/i4/window/dragwin.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 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: 5.0 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 "arch.hh"
10#include "window/dragwin.hh"
11#include "device/kernel.hh"
12#include "error/error.hh"
13#include "window/win_evt.hh"
14#include "area/rectlist.hh"
15#include "image/image.hh"
16
17class i4_drag_frame_class : public i4_window_class
18{
19  i4_coord ghost_x,ghost_y;
20
21  public :
22  i4_bool need_remove_ghost,
23    draw_self;
24
25  char *name() { return "drag_frame"; }
26
27  i4_drag_frame_class(w16 w, w16 h) :
28    i4_window_class(w,h)
29  {
30    need_remove_ghost=i4_F;
31    draw_self=i4_T;
32  }
33
34  virtual void draw(i4_draw_context_class &context)
35  {
36    // this draw is special in that it should not be subject to clipping and
37    // window coordinate transformations
38
39    i4_rect_list_class no_clip(0,0,local_image->width()-1,local_image->height()-1);
40    context.clip.swap(&no_clip);
41    i4_coord old_xoff=context.xoff,old_yoff=context.yoff;
42    context.xoff=0;
43    context.yoff=0;
44
45    if (need_remove_ghost)
46    {
47      i4_coord x1=ghost_x,y1=ghost_y;
48      i4_coord x2=x1+width()-1,y2=y1+height()-1;
49
50      i4_color c=0xffffffff;
51
52      local_image->xor_bar(x1,y1,x2,y1,c,context);
53      local_image->xor_bar(x2,y1,x2,y2,c,context);
54      local_image->xor_bar(x1,y1,x1,y2,c,context);
55      local_image->xor_bar(x1,y2,x2,y2,c,context);     
56    }
57
58    if (draw_self)
59    {
60      i4_coord x1=x(),y1=y();
61      i4_coord x2=x1+width()-1,y2=y1+height()-1;
62      i4_color c=0xffffffff;
63
64      local_image->xor_bar(x1,y1,x2,y1,c,context);
65      local_image->xor_bar(x2,y1,x2,y2,c,context);
66      local_image->xor_bar(x1,y1,x1,y2,c,context);
67      local_image->xor_bar(x1,y2,x2,y2,c,context);
68      ghost_x=x();
69      ghost_y=y();
70    }
71    draw_self=i4_T;
72    need_remove_ghost=i4_T;
73
74    context.xoff=old_xoff;
75    context.yoff=old_yoff;
76    context.clip.swap(&no_clip);
77  }
78
79  virtual void show_self(w32 indent)
80  {   
81    char fmt[50];
82    sprintf(fmt,"%%%ds drag_window",indent);
83    i4_warning(fmt," ");
84  }
85
86} ;
87
88
89i4_draggable_window_class::i4_draggable_window_class(w16 w, w16 h) : i4_parent_window_class(w,h)
90{
91  drag_frame=0;
92  last_mouse_x=0;
93  last_mouse_y=0;
94}
95
96void i4_draggable_window_class::receive_event(i4_event *ev)
97{
98  if (ev->type()==i4_event::WINDOW_MESSAGE)
99  {
100    CAST_PTR(message,i4_window_request_drag_start_class,ev);
101    // must have a parent in order to move/be dragged
102    if (message->sub_type==i4_window_message_class::REQUEST_DRAG_START && parent) 
103    {
104      // see if we can grab the mouse     
105      i4_window_request_mouse_grab_class grab(message->from());
106
107      // ask ourself, we will check with our parent..
108      i4_kernel.send_event(this,&grab);
109
110      if (grab.return_result)
111      {
112        drag_frame=new i4_drag_frame_class(width(),height());
113        parent->add_child(x(),y(),drag_frame);
114       
115        message->return_result=i4_T;     
116      }
117      else
118      {
119        message->return_result=i4_F;
120        i4_warning("draggable window:: unable to grab mouse");
121      }
122    }
123    // must have a parent in order to move/be dragged
124    else if (message->sub_type==i4_window_message_class::REQUEST_DRAG_END && parent) 
125    {
126      if (!drag_frame)
127        i4_error("got drag end message and not dragging");
128
129      i4_window_request_mouse_ungrab_class ungrab(this);
130      i4_kernel.send_event(this,&ungrab);
131
132      // move ourself to the final position of the drag frame
133      move(drag_frame->x()-x(),drag_frame->y()-y());
134      request_redraw();
135
136      // tell ourselves to delete the dragger next tick,
137      // so it gets a chance to clear itself off the screen
138      i4_kernel.delete_handler(drag_frame);
139
140      drag_frame->need_remove_ghost=i4_T;
141      drag_frame->draw_self=i4_F;
142      drag_frame=0;   // assume it is deleted now
143    }
144    else i4_parent_window_class::receive_event(ev);
145  } else if (ev->type()==i4_event::MOUSE_MOVE)
146  {
147    CAST_PTR(move,i4_mouse_move_event_class,ev);
148    current_mouse_x=move->x+x();
149    current_mouse_y=move->y+y();
150    if (drag_frame &&
151        ((current_mouse_x!=last_mouse_x ||
152          current_mouse_y!=last_mouse_y)))
153    {
154      if (current_mouse_x<0)
155        current_mouse_x=0;
156      if (current_mouse_y<0)
157        current_mouse_y=0;
158      i4_coord xo=current_mouse_x-last_mouse_x,yo=current_mouse_y-last_mouse_y;
159      drag_frame->move(xo,yo,i4_F);
160      drag_frame->request_redraw();
161    }
162
163    last_mouse_x=current_mouse_x;
164    last_mouse_y=current_mouse_y;
165    i4_parent_window_class::receive_event(ev);
166  } else i4_parent_window_class::receive_event(ev);
167}
168
169
170
171
172
173
Note: See TracBrowser for help on using the repository browser.