butbox.cc 3.7 KB

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