From a12422b51ca6d8a13f891a1e7acde409a52272b4 Mon Sep 17 00:00:00 2001 From: Tom Prince Date: Wed, 2 Jun 2010 14:00:28 -0400 Subject: [PATCH] Button: Add separate event handler for dropping portraits. Use separate event, rather than magic names. Signed-off-by: Tom Prince --- gemrb/GUIScripts/GUIDefines.py | 5 +++-- gemrb/GUIScripts/bg1/GUICommonWindows.py | 5 +++-- gemrb/GUIScripts/bg2/GUICommonWindows.py | 5 +++-- gemrb/core/Button.cpp | 16 ++++------------ gemrb/core/Button.h | 6 ++++-- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/gemrb/GUIScripts/GUIDefines.py b/gemrb/GUIScripts/GUIDefines.py index 9074690a7..d3fdd3541 100644 --- a/gemrb/GUIScripts/GUIDefines.py +++ b/gemrb/GUIScripts/GUIDefines.py @@ -71,8 +71,9 @@ IE_GUI_MOUSE_LEAVE_BUTTON = 0x00000003 IE_GUI_BUTTON_ON_SHIFT_PRESS= 0x00000004 IE_GUI_BUTTON_ON_RIGHT_PRESS= 0x00000005 IE_GUI_BUTTON_ON_DRAG_DROP = 0x00000006 -IE_GUI_BUTTON_ON_DRAG = 0x00000007 -IE_GUI_BUTTON_ON_DOUBLE_PRESS = 0x00000008 +IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT = 0x00000007 +IE_GUI_BUTTON_ON_DRAG = 0x00000008 +IE_GUI_BUTTON_ON_DOUBLE_PRESS = 0x00000009 IE_GUI_PROGRESS_END_REACHED = 0x01000000 IE_GUI_SLIDER_ON_CHANGE = 0x02000000 IE_GUI_EDIT_ON_CHANGE = 0x03000000 diff --git a/gemrb/GUIScripts/bg1/GUICommonWindows.py b/gemrb/GUIScripts/bg1/GUICommonWindows.py index 975cf74c5..68d935b4e 100644 --- a/gemrb/GUIScripts/bg1/GUICommonWindows.py +++ b/gemrb/GUIScripts/bg1/GUICommonWindows.py @@ -472,6 +472,7 @@ def OpenPortraitWindow (needcontrols): Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "PortraitButtonOnPress") Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, "PortraitButtonOnShiftPress") Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, "OnDropItemToPC") + Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT, "OnDropPortraitToPC") Button.SetEvent (IE_GUI_BUTTON_ON_DRAG, "PortraitButtonOnDrag") Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, "PortraitButtonOnMouseEnter") Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, "PortraitButtonOnMouseLeave") @@ -623,7 +624,7 @@ def PortraitButtonOnMouseEnter (): DraggedPortrait = i GemRB.SetTimedEvent ("CheckDragging",1) else: - OnDropItemToPC2() + OnDropPortraitToPC() return if GemRB.IsDraggingItem (): @@ -631,7 +632,7 @@ def PortraitButtonOnMouseEnter (): Button.EnableBorder (FRAME_PC_TARGET, 1) return -def OnDropItemToPC2 (): +def OnDropPortraitToPC (): GemRB.SetVar ("PressedPortrait",0) GemRB.DragItem (0, -1, "") DraggedPortrait = None diff --git a/gemrb/GUIScripts/bg2/GUICommonWindows.py b/gemrb/GUIScripts/bg2/GUICommonWindows.py index 0ed6c0aae..c39da7a34 100644 --- a/gemrb/GUIScripts/bg2/GUICommonWindows.py +++ b/gemrb/GUIScripts/bg2/GUICommonWindows.py @@ -511,6 +511,7 @@ def OpenPortraitWindow (needcontrols): Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "PortraitButtonOnPress") Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, "PortraitButtonOnShiftPress") Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP, "OnDropItemToPC") + Button.SetEvent (IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT, "OnDropPortraitToPC") Button.SetEvent (IE_GUI_BUTTON_ON_DRAG, "PortraitButtonOnDrag") Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, "PortraitButtonOnMouseEnter") Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, "PortraitButtonOnMouseLeave") @@ -677,7 +678,7 @@ def PortraitButtonOnMouseEnter (): DraggedPortrait = i GemRB.SetTimedEvent ("CheckDragging",1) else: - OnDropItemToPC2() + OnDropPortraitToPC() return if GemRB.IsDraggingItem (): @@ -685,7 +686,7 @@ def PortraitButtonOnMouseEnter (): Button.EnableBorder (FRAME_PC_TARGET, 1) return -def OnDropItemToPC2 (): +def OnDropPortraitToPC (): GemRB.SetVar ("PressedPortrait",0) GemRB.DragItem (0, -1, "") DraggedPortrait = None diff --git a/gemrb/core/Button.cpp b/gemrb/core/Button.cpp index cf04c1f2d..65fc6340d 100644 --- a/gemrb/core/Button.cpp +++ b/gemrb/core/Button.cpp @@ -477,23 +477,12 @@ void Button::OnMouseUp(unsigned short x, unsigned short y, } } - //FIXME: you may want to clean this mess up - //normally there is only one handler allowed, but the portraits need - //another, i didn't want to have another 64 bytes allocated for every - //button control, so this hack calls a different function in case - //a portrait was dropped - //If the original was: DropItemToPC, then it calls DropItemToPC2 switch (dragtype) { case 1: RunEventHandler( ButtonOnDragDrop ); return; case 2: - //very ugly hack - EventHandler tmp; - - memcpy(tmp, ButtonOnDragDrop, sizeof(tmp)); - strncat(tmp,"2", sizeof(EventHandler) ); - RunEventHandler( tmp ); + RunEventHandler( ButtonOnDragDropPortrait ); return; } @@ -615,6 +604,9 @@ bool Button::SetEvent(int eventType, const char *handler) case IE_GUI_BUTTON_ON_DRAG_DROP: SetEventHandler( ButtonOnDragDrop, handler ); break; + case IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT: + SetEventHandler( ButtonOnDragDropPortrait, handler ); + break; case IE_GUI_BUTTON_ON_DRAG: SetEventHandler( ButtonOnDrag, handler ); break; diff --git a/gemrb/core/Button.h b/gemrb/core/Button.h index c63712fec..1bf6e28c0 100644 --- a/gemrb/core/Button.h +++ b/gemrb/core/Button.h @@ -88,8 +88,9 @@ class Palette; #define IE_GUI_BUTTON_ON_SHIFT_PRESS 0x00000004 #define IE_GUI_BUTTON_ON_RIGHT_PRESS 0x00000005 #define IE_GUI_BUTTON_ON_DRAG_DROP 0x00000006 -#define IE_GUI_BUTTON_ON_DRAG 0x00000007 -#define IE_GUI_BUTTON_ON_DOUBLE_PRESS 0x00000008 +#define IE_GUI_BUTTON_ON_DRAG_DROP_PORTRAIT 0x00000007 +#define IE_GUI_BUTTON_ON_DRAG 0x00000008 +#define IE_GUI_BUTTON_ON_DOUBLE_PRESS 0x00000009 /** Border/frame settings for a button */ struct ButtonBorder { @@ -165,6 +166,7 @@ public: // Public Events EventHandler ButtonOnRightPress; EventHandler ButtonOnDoublePress; EventHandler ButtonOnDragDrop; + EventHandler ButtonOnDragDropPortrait; EventHandler ButtonOnDrag; EventHandler MouseEnterButton; EventHandler MouseLeaveButton; -- 2.11.4.GIT