source: golgotha/src/i4/gui/butbox.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
10#include "gui/butbox.hh"
11#include "error/error.hh"
12#include "device/kernel.hh"
13#include "device/event.hh"
14#include "app/app.hh"
15
16void i4_button_box_class::parent_draw(i4_draw_context_class &context)
17{
18  // this code swiped from color_window
19  i4_rect_list_class child_clip(&context.clip,0,0);
20  child_clip.intersect_list(&undrawn_area);
21
22  child_clip.swap(&context.clip);
23 
24  i4_graphical_style_class *style=i4_current_app->get_style();
25
26  for (i4_rect_list_class::area_iter c=context.clip.list.begin();c!=context.clip.list.end();++c)
27    style->deco_neutral_fill(local_image, c->x1, c->y1, c->x2, c->y2, context);
28
29  child_clip.swap(&context.clip);
30  i4_parent_window_class::parent_draw(context);
31}
32
33i4_button_box_class::i4_button_box_class(i4_event_handler_class *receiver,
34                                         i4_bool require_one_down)
35  : receiver(receiver),
36    require_one_down(require_one_down)
37{
38  current_down=0;
39}
40
41void i4_button_box_class::add_child(i4_coord x, i4_coord y, i4_window_class *child)
42{
43  i4_error("You must use add_button");
44}
45
46void i4_button_box_class::expand_if_needed()
47{
48  win_iter c=children.begin();
49  w32 w=width(),h=height();
50  for (;c!=children.end(); ++c)
51  {
52    if (c->x()+c->width()-x()>w)
53      w=c->x()+c->width()-x();
54    if (c->y()+c->height()-y()>h)
55      h=c->y()+c->height()-y();
56  }
57  if ((w!=width() || h!=height()))
58    resize(w,h);
59}
60
61// when adding a child, enlarge the button box window if nessary to encompass it
62void i4_button_box_class::add_button(i4_coord _x, i4_coord _y, i4_button_class *child)
63{
64  i4_parent_window_class::add_child(_x,_y,child);
65  child->set_menu_parent(this);
66  expand_if_needed();
67}
68
69void i4_button_box_class::arrange_right_down()
70{
71  i4_parent_window_class::arrange_right_down();
72  expand_if_needed();
73}
74 
75void i4_button_box_class::arrange_down_right()
76{
77  i4_parent_window_class::arrange_down_right();
78  expand_if_needed();
79}
80
81
82void i4_button_box_class::note_reaction_sent(i4_menu_item_class *who,       // this is who sent it
83                                             i4_event_reaction_class *ev,   // who it was to
84                                             i4_menu_item_class::reaction_type type)
85{
86  i4_button_class *but=(i4_button_class *)who;
87
88  if (type==i4_menu_item_class::PRESSED)
89  {
90    if (current_down)
91    {
92      if (current_down!=but)  // see if we need to depress the current button
93      {
94        i4_button_class *old_down=current_down;
95        current_down=but;
96        old_down->do_depress();
97      } 
98    } else current_down=but;
99  }
100  else if (type==i4_menu_item_class::DEPRESSED)
101  {
102    if (but==current_down && require_one_down)
103      current_down->do_press();         // sorry we need you to stay down
104  }
105}
106
107
108void i4_button_box_class::push_button(i4_button_class *which, i4_bool send_event)
109{
110  if (!which) return;
111
112  if (current_down)
113  {
114    if (current_down!=which)
115    {
116      current_down->do_depress();
117      current_down=which;   
118      current_down->do_press();
119    }
120  } else
121  {
122    current_down=which;
123    current_down->do_press();
124  }
125
126  if (send_event)
127    current_down->send_event(current_down->send.press, i4_menu_item_class::PRESSED);
128}
Note: See TracBrowser for help on using the repository browser.