original 1.0.1 release
[xwelltris.git] / src / wellkey.cxx
blob5e6074b113af82810b23987d64a5cf3669768d47
1 // docm_prefix(///)
2 /****************************************************************************
3 * Copyright (C) 2002 by Leo Khramov
4 * email: leo@xnc.dubna.su
5 *
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.
23 #include "globals.h"
24 #include "wellkey.h"
25 #include "wellengine.h"
27 //////////////////////////////WellKey class///////////////////////////////
29 //===========================================================================
30 /// global WellKey(char*)
31 /// constructor - fill name and get geometry
32 /// tags WellKey
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
44 /// tags WellKey
45 bool WellKey::process_event(wEvent ev)
47 MouseEvent *pmev;
48 switch(ev.type)
50 case eKeyPress:
51 dbgprintf(("WellKey - pressed\n"));
52 object_on_press.call(wEvent(aKeyPressed,this));
53 return false;
55 case eMousePress:
56 pmev=(MouseEvent*)ev.data;
57 return !press(pmev->mx,pmev->my);
59 case eMouseMove:
60 pmev=(MouseEvent*)ev.data;
61 return !highlight(pmev->mx,pmev->my);
64 return true;
67 //===========================================================================
68 /// global highlight(int mx, int my)
69 /// highlights key
70 /// tags WellKey
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)
76 if(!highlighted)
78 dbgprintf(("WellKey highlighted via mouse\n"));
79 highlighted=true;
80 default_well_engine->screen_copy(&geo[1]); //highlighted state
81 return true;
83 } else
85 if(highlighted)
87 highlighted=false;
88 dbgprintf(("WellKey DEhighlighted via mouse\n"));
89 default_well_engine->screen_copy(&geo[0]); //normal state
90 return true;
93 return false;
96 //===========================================================================
97 /// global press(int mx, int my)
98 /// press key and call object
99 /// tags WellKey
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));
108 return true;
110 return false;
113 //===========================================================================
114 /// global show()
115 /// show object
116 /// tags WellKey
117 void WellKey::show()
119 shown=true;
120 redraw();
121 default_well_engine->add_object(this);
124 //===========================================================================
125 /// global redraw()
126 /// redraw object
127 /// tags WellKey
128 void WellKey::redraw()
130 if(shown)
131 default_well_engine->screen_copy(&geo[0]);
134 //===========================================================================
135 /// global hide()
136 /// hide object
137 /// tags WellKey
138 void WellKey::hide()
140 shown=false;
141 default_well_engine->screen_clear(&geo[0]);
142 default_well_engine->del_object(this);