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 "loaders/load.hh"
|
---|
11 | #include "menu.hh"
|
---|
12 | #include "image/image.hh"
|
---|
13 | #include "window/style.hh"
|
---|
14 | #include "device/event.hh"
|
---|
15 | #include "menu/textitem.hh"
|
---|
16 | #include "window/win_evt.hh"
|
---|
17 | #include "error/alert.hh"
|
---|
18 |
|
---|
19 | class g1_menu_item_class : public i4_window_class
|
---|
20 | {
|
---|
21 | public:
|
---|
22 | i4_bool active;
|
---|
23 | i4_image_class *act_im;
|
---|
24 | i4_event_reaction_class *press;
|
---|
25 | g1_menu_item_class(i4_image_class *act_im,
|
---|
26 | i4_event_reaction_class *press)
|
---|
27 | : i4_window_class(act_im->width(), act_im->height()),
|
---|
28 | act_im(act_im),
|
---|
29 | press(press)
|
---|
30 | {
|
---|
31 | active=i4_F;
|
---|
32 | }
|
---|
33 |
|
---|
34 | char *name() { return "g1_menu_item"; }
|
---|
35 |
|
---|
36 | virtual i4_bool transparent() { return !active; }
|
---|
37 | virtual void draw(i4_draw_context_class &context)
|
---|
38 | {
|
---|
39 | if (active)
|
---|
40 | act_im->put_image(local_image, 0,0, context);
|
---|
41 | i4_window_class::draw(context);
|
---|
42 | }
|
---|
43 |
|
---|
44 | virtual void receive_event(i4_event *ev)
|
---|
45 | {
|
---|
46 | if (ev->type()==i4_event::WINDOW_MESSAGE)
|
---|
47 | {
|
---|
48 | CAST_PTR(wev, i4_window_message_class, ev);
|
---|
49 | if (wev->sub_type==i4_window_message_class::GOT_MOUSE_FOCUS)
|
---|
50 | {
|
---|
51 | active=i4_T;
|
---|
52 | request_redraw();
|
---|
53 | }
|
---|
54 | else if (wev->sub_type==i4_window_message_class::LOST_MOUSE_FOCUS)
|
---|
55 | {
|
---|
56 | active=i4_F;
|
---|
57 | request_redraw();
|
---|
58 | }
|
---|
59 | }
|
---|
60 | else if (ev->type()==i4_event::MOUSE_BUTTON_DOWN)
|
---|
61 | {
|
---|
62 | if (active)
|
---|
63 | i4_kernel.send(press);
|
---|
64 | }
|
---|
65 | else i4_window_class::receive_event(ev);
|
---|
66 | }
|
---|
67 |
|
---|
68 | ~g1_menu_item_class()
|
---|
69 | {
|
---|
70 | delete act_im;
|
---|
71 | delete press;
|
---|
72 | }
|
---|
73 | };
|
---|
74 |
|
---|
75 | g1_main_menu_class::g1_main_menu_class(w16 w, w16 h,
|
---|
76 | i4_event_handler_class *notify,
|
---|
77 | sw32 *ids,
|
---|
78 | i4_graphical_style_class *style)
|
---|
79 | : i4_parent_window_class(w,h),
|
---|
80 | notify(notify),
|
---|
81 | style(style)
|
---|
82 | {
|
---|
83 | deco=i4_load_image(i4gets("title_screen"));
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 | i4_const_str *tb=i4_string_man.get_array("title_buts");
|
---|
89 | int on=0;
|
---|
90 | for (int i=0; !tb[i].null();)
|
---|
91 | {
|
---|
92 | i4_image_class *im=i4_load_image(tb[i]);
|
---|
93 | if (!im)
|
---|
94 | {
|
---|
95 | i4_alert(i4gets("file_missing"),100,&tb[i]);
|
---|
96 | i4_error("could load image");
|
---|
97 | }
|
---|
98 | i++;
|
---|
99 | i4_const_str::iterator it=tb[i].begin();
|
---|
100 | int x=it.read_number();
|
---|
101 | i++;
|
---|
102 | it=tb[i].begin();
|
---|
103 | int y=it.read_number();
|
---|
104 | i++;
|
---|
105 |
|
---|
106 | i4_event_reaction_class *re;
|
---|
107 | re=new i4_event_reaction_class(notify, new i4_user_message_event_class(ids[on]));
|
---|
108 | on++;
|
---|
109 |
|
---|
110 | g1_menu_item_class *gi=new g1_menu_item_class(im,re);
|
---|
111 | add_child(x,y, gi);
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 | i4_free(tb);
|
---|
116 | }
|
---|
117 |
|
---|
118 | void g1_main_menu_class::parent_draw(i4_draw_context_class &context)
|
---|
119 | {
|
---|
120 | i4_rect_list_class child_clip(&context.clip,0,0);
|
---|
121 | child_clip.intersect_list(&undrawn_area);
|
---|
122 | child_clip.swap(&context.clip);
|
---|
123 |
|
---|
124 | if (deco)
|
---|
125 | {
|
---|
126 | i4_coord xp,yp;
|
---|
127 |
|
---|
128 | xp=width()/2-deco->width()/2;
|
---|
129 | yp=height()/2-deco->height()/2;
|
---|
130 | if (!undrawn_area.empty())
|
---|
131 | local_image->clear(0,context);
|
---|
132 |
|
---|
133 |
|
---|
134 | deco->put_image(local_image,xp,yp,context);
|
---|
135 | }
|
---|
136 | else
|
---|
137 | {
|
---|
138 | if (!undrawn_area.empty())
|
---|
139 | local_image->clear(0,context);
|
---|
140 | request_redraw();
|
---|
141 | }
|
---|
142 |
|
---|
143 | child_clip.swap(&context.clip);
|
---|
144 | i4_parent_window_class::parent_draw(context);
|
---|
145 |
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | g1_main_menu_class::~g1_main_menu_class()
|
---|
150 | {
|
---|
151 |
|
---|
152 | delete deco;
|
---|
153 | }
|
---|