2 /****************************************************************************
3 * Copyright (C) 2002 by Leo Khramov
4 * email: leo@xnc.dubna.su
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 ****************************************************************************/
16 // $Id: wellkey.cxx,v 1.1.1.1 2003/01/04 11:37:22 leo Exp $
18 /// module description
19 /// WellKey class implements key (or button) GUI element. It draw key with
20 /// given images (uses geometry module) then catches mouse events and calls
21 /// ObjectCaller on press.
25 #include "wellengine.h"
27 //////////////////////////////WellKey class///////////////////////////////
29 //===========================================================================
30 /// global WellKey(char*)
31 /// constructor - fill name and get geometry
33 WellKey::WellKey(char* iname
) : WellObject()
35 strncpy(object_name
,iname
,GEO_NAME
);
36 object_name
[GEO_NAME
]=0;
37 geo
=get_geo_by_name(object_name
);
41 //===========================================================================
42 /// global process_event(wEvent)
43 /// stub that process events
45 bool WellKey::process_event(wEvent ev
)
51 dbgprintf(("WellKey - pressed\n"));
52 object_on_press
.call(wEvent(aKeyPressed
,this));
56 pmev
=(MouseEvent
*)ev
.data
;
57 return !press(pmev
->mx
,pmev
->my
);
60 pmev
=(MouseEvent
*)ev
.data
;
61 return !highlight(pmev
->mx
,pmev
->my
);
67 //===========================================================================
68 /// global highlight(int mx, int my)
71 bool WellKey::highlight(int mx
, int my
)
73 if(mx
>=geo
[1].tox
&& my
>=geo
[1].toy
&&
74 mx
<geo
[1].tox
+geo
[1].l
&& my
<geo
[1].toy
+geo
[1].h
)
78 dbgprintf(("WellKey highlighted via mouse\n"));
80 default_well_engine
->screen_copy(&geo
[1]); //highlighted state
88 dbgprintf(("WellKey DEhighlighted via mouse\n"));
89 default_well_engine
->screen_copy(&geo
[0]); //normal state
96 //===========================================================================
97 /// global press(int mx, int my)
98 /// press key and call object
100 bool WellKey::press(int mx
, int my
)
102 if(mx
>=geo
[2].tox
&& my
>=geo
[2].toy
&&
103 mx
<geo
[2].tox
+geo
[2].l
&& my
<geo
[2].toy
+geo
[2].h
)
105 dbgprintf(("WellKey pressed via mouse\n"));
106 default_well_engine
->screen_copy(&geo
[2]); //highlighted state
107 object_on_press
.call(wEvent(aKeyPressed
,this));
113 //===========================================================================
121 default_well_engine
->add_object(this);
124 //===========================================================================
128 void WellKey::redraw()
131 default_well_engine
->screen_copy(&geo
[0]);
134 //===========================================================================
141 default_well_engine
->screen_clear(&geo
[0]);
142 default_well_engine
->del_object(this);