original 1.0.1 release
[xwelltris.git] / src / wellswitch.cxx
blobb5b0d6d9637aab7019139108996c612809a73c53
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: wellswitch.cxx,v 1.1.1.1 2003/01/04 11:37:22 leo Exp $
18 /// module description
19 /// WellSwitch class implements Switch GUI element, it can be set or reset,
20 /// uses for switching options
22 #include "globals.h"
23 #include "wellswitch.h"
24 #include "wellengine.h"
26 //////////////////////////////WellSwitch class///////////////////////////////
28 //===========================================================================
29 /// global WellSwitch(char*)
30 /// constructor - fill name and get geometry
31 /// tags WellSwitch
32 WellSwitch::WellSwitch(char* iname) : WellObject()
34 strncpy(object_name,iname,GEO_NAME);
35 object_name[GEO_NAME]=0;
36 geo=get_geo_by_name(object_name);
37 value=false;
38 mode=SetReset;
42 //===========================================================================
43 /// global process_event(wEvent)
44 /// stub that process events
45 /// tags WellSwitch
46 bool WellSwitch::process_event(wEvent ev)
48 MouseEvent *pmev;
49 switch(ev.type)
51 case eMousePress:
52 pmev=(MouseEvent*)ev.data;
53 return !press(pmev->mx,pmev->my);
55 case eMouseMove:
56 pmev=(MouseEvent*)ev.data;
57 return !highlight(pmev->mx,pmev->my);
60 return true;
63 //===========================================================================
64 /// global highlight(int mx, int my)
65 /// highlights key
66 /// tags WellSwitch
67 bool WellSwitch::highlight(int mx, int my)
69 if(mx>=geo[1].tox && my>=geo[1].toy &&
70 mx<geo[1].tox+geo[1].l && my<geo[1].toy+geo[1].h)
72 if(!highlighted)
74 dbgprintf(("WellSwitch highlighted via mouse\n"));
75 highlighted=true;
76 default_well_engine->screen_copy(&geo[1]); //highlighted state
77 return true;
79 } else
81 if(highlighted)
83 highlighted=false;
84 dbgprintf(("WellSwitch DEhighlighted via mouse\n"));
85 redraw();
86 return true;
89 return false;
92 //===========================================================================
93 /// global press(int mx, int my)
94 /// press key and call object
95 /// tags WellSwitch
96 bool WellSwitch::press(int mx, int my)
98 if(mx>=geo[1].tox && my>=geo[1].toy &&
99 mx<geo[1].tox+geo[1].l && my<geo[1].toy+geo[1].h)
101 dbgprintf(("WellSwitch pressed via mouse\n"));
102 value= value ? false : true;
103 switch(mode)
105 case OnlySet:
106 value=true;
107 break;
108 case OnlyReset:
109 value=false;
110 break;
112 redraw();
113 object_on_switch.call(wEvent(aSwitchChanged,this));
114 return true;
116 return false;
119 //===========================================================================
120 /// global show()
121 /// show object
122 /// tags WellSwitch
123 void WellSwitch::show()
125 shown=true;
126 redraw();
127 default_well_engine->add_object(this);
130 //===========================================================================
131 /// global redraw()
132 /// redraw object
133 /// tags WellSwitch
134 void WellSwitch::redraw()
136 if(shown)
138 default_well_engine->screen_copy(&geo[0]); //normal state
139 if(value)
140 default_well_engine->screen_copy(&geo[2]); //value state
141 else
142 default_well_engine->screen_clear(&geo[2]); //value state
146 //===========================================================================
147 /// global hide()
148 /// hide object
149 /// tags WellSwitch
150 void WellSwitch::hide()
152 shown=false;
153 default_well_engine->screen_clear(&geo[0]);
154 default_well_engine->del_object(this);