smp_dial.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/smp_dial.hh"
  9. #include "window/window.hh"
  10. #include "device/event.hh"
  11. #include "device/kernel.hh"
  12. #include "window/win_evt.hh"
  13. #include "image/image.hh"
  14. #include "window/style.hh"
  15. #include "gui/button.hh"
  16. #include "gui/text.hh"
  17. class i4_simple_dlg_class : public i4_parent_window_class
  18. {
  19. public:
  20. enum { YES, NO };
  21. char *name() { return "simple dlg"; }
  22. i4_event_handler_class *send_to;
  23. i4_event *yes_event, *no_event;
  24. i4_color bg_color;
  25. i4_graphical_style_class *style;
  26. i4_simple_dlg_class(w16 w, w16 h,
  27. i4_graphical_style_class *style,
  28. i4_event_handler_class *send_to,
  29. i4_event *yes_event, i4_event *no_event)
  30. : i4_parent_window_class(w,h),
  31. yes_event(yes_event), no_event(no_event),
  32. style(style),
  33. send_to(send_to),
  34. bg_color(style->color_hint->window.passive.medium)
  35. {}
  36. void receive_event(i4_event *ev)
  37. {
  38. if (ev->type()==i4_event::USER_MESSAGE)
  39. {
  40. CAST_PTR(uev, i4_user_message_event_class, ev);
  41. if (uev->sub_type==YES)
  42. {
  43. i4_kernel.send_event(send_to, yes_event);
  44. style->close_mp_window(parent);
  45. }
  46. else if (uev->sub_type==NO)
  47. {
  48. i4_kernel.send_event(send_to, no_event);
  49. style->close_mp_window(parent);
  50. }
  51. } else i4_parent_window_class::receive_event(ev);
  52. }
  53. void parent_draw(i4_draw_context_class &context)
  54. {
  55. local_image->clear(bg_color, context);
  56. }
  57. };
  58. static i4_button_class *i4_simple_create_button(const i4_const_str &name,
  59. i4_event_handler_class *send_to,
  60. i4_event *ev,
  61. i4_graphical_style_class *style)
  62. {
  63. i4_button_class *b=new i4_button_class(0,
  64. new i4_text_window_class(name, style),
  65. style,
  66. new i4_event_reaction_class(send_to, ev));
  67. b->set_popup(i4_T);
  68. return b;
  69. }
  70. i4_parent_window_class *i4_create_yes_no_dialog(i4_parent_window_class *parent,
  71. i4_graphical_style_class *style,
  72. const i4_const_str &title,
  73. const i4_const_str &message,
  74. const i4_const_str &yes, const i4_const_str &no,
  75. i4_event_handler_class *send_to,
  76. i4_event *yes_event, i4_event *no_event)
  77. {
  78. i4_parent_window_class *root=parent;
  79. i4_simple_dlg_class *sd=new i4_simple_dlg_class(0,0,
  80. style,
  81. send_to,
  82. yes_event, no_event);
  83. i4_button_class *y=i4_simple_create_button(yes, sd,
  84. new i4_user_message_event_class(0), style);
  85. i4_button_class *n=i4_simple_create_button(no, sd,
  86. new i4_user_message_event_class(1), style);
  87. i4_text_window_class *t=new i4_text_window_class(message, style);
  88. sw32 w=t->width(),h=t->height()+2+y->height();
  89. sw32 bw=y->width()+n->width();
  90. if (w<bw)
  91. w=bw;
  92. sd->resize(w,h);
  93. i4_parent_window_class *p;
  94. p=style->create_mp_window(parent->width()/2-w/2, parent->height()/2-h/2, w,h, title);
  95. sd->add_child(p->width()/2-bw/2, 0, y);
  96. sd->add_child(p->width()/2-bw/2+y->width(), 0, n);
  97. sd->add_child(p->width()/2-t->width()/2, y->height()+1, t);
  98. p->add_child(0,0,sd);
  99. return p;
  100. }