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