1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "ControlAnimation.h"
26 #include "Interface.h"
27 #include "ScriptEngine.h"
50 ControlType
= IE_GUI_INVALID
;
56 printMessage("Control","Destroying control inside event handler, crash may occur!\n", LIGHT_RED
);
58 core
->DisplayTooltip( 0, 0, NULL
);
63 core
->GetVideoDriver()->FreeSprite(AnimPicture
);
66 /** Sets the Tooltip text of the current control */
67 int Control::SetTooltip(const char* string
)
71 if ((string
== NULL
) || (string
[0] == 0)) {
74 Tooltip
= strdup (string
);
80 /** Sets the tooltip to be displayed on the screen now */
81 void Control::DisplayTooltip()
84 core
->DisplayTooltip( Owner
->XPos
+ XPos
+ Width
/ 2, Owner
->YPos
+ YPos
+ Height
/ 2, this );
86 core
->DisplayTooltip( 0, 0, NULL
);
89 void Control::ResetEventHandler(EventHandler handler
)
94 void Control::SetEventHandler(EventHandler handler
, const char* funcName
)
96 strncpy( handler
, funcName
, sizeof( EventHandler
) );
99 int Control::RunEventHandler(EventHandler handler
)
102 printMessage("Control","Nested event handlers are not supported!\n", YELLOW
);
110 unsigned short WID
= wnd
->WindowID
;
111 unsigned short ID
= (unsigned short) ControlID
;
113 core
->GetGUIScriptEngine()->RunFunction( (char*)handler
);
114 if (!core
->IsValidWindow(WID
,wnd
) ) {
115 printMessage ("Control","Owner window destructed!\n", LIGHT_RED
);
118 if (!wnd
->IsValidControl(ID
,this) ) {
119 printMessage ("Control","Control destructed!\n", LIGHT_RED
);
127 /** Key Press Event */
128 void Control::OnKeyPress(unsigned char /*Key*/, unsigned short /*Mod*/)
130 //printf("OnKeyPress: CtrlID = 0x%08X, Key = %c (0x%02hX)\n", (unsigned int) ControlID, Key, Key);
133 /** Key Release Event */
134 void Control::OnKeyRelease(unsigned char /*Key*/, unsigned short /*Mod*/)
136 //printf( "OnKeyRelease: CtrlID = 0x%08X, Key = %c (0x%02hX)\n", (unsigned int) ControlID, Key, Key );
139 /** Mouse Enter Event */
140 void Control::OnMouseEnter(unsigned short /*x*/, unsigned short /*y*/)
142 // printf("OnMouseEnter: CtrlID = 0x%08X, x = %hd, y = %hd\n", (unsigned int) ControlID, x, y);
145 /** Mouse Leave Event */
146 void Control::OnMouseLeave(unsigned short /*x*/, unsigned short /*y*/)
148 // printf("OnMouseLeave: CtrlID = 0x%08X, x = %hd, y = %hd\n", (unsigned int) ControlID, x, y);
151 /** Mouse Over Event */
152 void Control::OnMouseOver(unsigned short /*x*/, unsigned short /*y*/)
154 //printf("OnMouseOver: CtrlID = 0x%08X, x = %hd, y = %hd\n", (unsigned int) ControlID, x, y);
157 /** Mouse Button Down */
158 void Control::OnMouseDown(unsigned short x
, unsigned short y
,
159 unsigned short Button
, unsigned short Mod
)
161 if (Button
== GEM_MB_SCRLUP
|| Button
== GEM_MB_SCRLDOWN
) {
162 Control
*ctrl
= Owner
->GetScrollControl();
163 if (ctrl
&& (ctrl
!=this)) {
164 ctrl
->OnMouseDown(x
,y
,Button
,Mod
);
169 /** Mouse Button Up */
170 void Control::OnMouseUp(unsigned short /*x*/, unsigned short /*y*/,
171 unsigned short /*Button*/, unsigned short /*Mod*/)
173 //printf("OnMouseUp: CtrlID = 0x%08X, x = %hd, y = %hd, Button = %d, Mos = %hd\n", (unsigned int) ControlID, x, y, Button, Mod);
176 /** Special Key Press */
177 void Control::OnSpecialKeyPress(unsigned char Key
)
179 if (Key
== GEM_UP
|| Key
== GEM_DOWN
) {
180 Control
*ctrl
= Owner
->GetScrollControl();
181 if (ctrl
&& (ctrl
!=this)) {
182 ctrl
->OnSpecialKeyPress(Key
);
187 /** Sets the Display Flags */
188 int Control::SetFlags(int arg_flags
, int opcode
)
190 if ((arg_flags
>>24) != ControlType
)
194 Flags
= arg_flags
; //set
200 Flags
|= arg_flags
; //turn on
206 Flags
&= ~arg_flags
;//turn off
216 void Control::SetAnimPicture(Sprite2D
* newpic
)
218 core
->GetVideoDriver()->FreeSprite(AnimPicture
);
219 AnimPicture
= newpic
;
220 //apparently this is needed too, so the artifacts are not visible
221 if (Owner
->Visible
==WINDOW_VISIBLE
) {
223 Owner
->InvalidateForControl(this);
227 /** Sets the Scroll Bar Pointer. If 'ptr' is NULL no Scroll Bar will be linked
229 int Control::SetScrollBar(Control
* ptr
)
231 if (ptr
&& (ptr
->ControlType
!=IE_GUI_SCROLLBAR
)) {
233 printMessage("Control","Attached control is not a ScrollBar!\n",YELLOW
);