Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
See license in Gwen.h
|
||||
*/
|
||||
|
||||
|
||||
#include "Gwen/InputHandler.h"
|
||||
#include "Gwen/Controls/Base.h"
|
||||
#include "Gwen/DragAndDrop.h"
|
||||
@@ -16,7 +15,6 @@
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
|
||||
struct Action
|
||||
{
|
||||
unsigned char type;
|
||||
@@ -32,7 +30,7 @@ struct t_KeyData
|
||||
{
|
||||
t_KeyData()
|
||||
{
|
||||
for ( int i=0; i<Gwen::Key::Count; i++ )
|
||||
for (int i = 0; i < Gwen::Key::Count; i++)
|
||||
{
|
||||
KeyState[i] = false;
|
||||
NextRepeat[i] = 0;
|
||||
@@ -43,18 +41,18 @@ struct t_KeyData
|
||||
RightMouseDown = false;
|
||||
}
|
||||
|
||||
bool KeyState[ Gwen::Key::Count ];
|
||||
float NextRepeat[ Gwen::Key::Count ];
|
||||
bool KeyState[Gwen::Key::Count];
|
||||
float NextRepeat[Gwen::Key::Count];
|
||||
Controls::Base* Target;
|
||||
bool LeftMouseDown;
|
||||
bool RightMouseDown;
|
||||
|
||||
} KeyData;
|
||||
|
||||
Gwen::Point MousePosition;
|
||||
Gwen::Point MousePosition;
|
||||
|
||||
static float g_fLastClickTime[MAX_MOUSE_BUTTONS];
|
||||
static Gwen::Point g_pntLastClickPos;
|
||||
static float g_fLastClickTime[MAX_MOUSE_BUTTONS];
|
||||
static Gwen::Point g_pntLastClickPos;
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -67,44 +65,43 @@ enum
|
||||
ACT_MESSAGE
|
||||
};
|
||||
|
||||
void UpdateHoveredControl( Controls::Base* pInCanvas )
|
||||
void UpdateHoveredControl(Controls::Base* pInCanvas)
|
||||
{
|
||||
Controls::Base* pHovered = pInCanvas->GetControlAt( MousePosition.x, MousePosition.y );
|
||||
Controls::Base* pHovered = pInCanvas->GetControlAt(MousePosition.x, MousePosition.y);
|
||||
|
||||
if ( Gwen::HoveredControl && pHovered != Gwen::HoveredControl )
|
||||
if (Gwen::HoveredControl && pHovered != Gwen::HoveredControl)
|
||||
{
|
||||
Gwen::HoveredControl->OnMouseLeave();
|
||||
|
||||
pInCanvas->Redraw();
|
||||
}
|
||||
|
||||
if ( pHovered != Gwen::HoveredControl )
|
||||
if (pHovered != Gwen::HoveredControl)
|
||||
{
|
||||
Gwen::HoveredControl = pHovered;
|
||||
|
||||
if ( Gwen::HoveredControl )
|
||||
if (Gwen::HoveredControl)
|
||||
Gwen::HoveredControl->OnMouseEnter();
|
||||
|
||||
pInCanvas->Redraw();
|
||||
}
|
||||
|
||||
if ( Gwen::MouseFocus && Gwen::MouseFocus->GetCanvas() == pInCanvas )
|
||||
if (Gwen::MouseFocus && Gwen::MouseFocus->GetCanvas() == pInCanvas)
|
||||
{
|
||||
Gwen::HoveredControl = Gwen::MouseFocus;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FindKeyboardFocus( Controls::Base* pControl )
|
||||
void FindKeyboardFocus(Controls::Base* pControl)
|
||||
{
|
||||
if ( !pControl ) return;
|
||||
if ( pControl->GetKeyboardInputEnabled() )
|
||||
if (!pControl) return;
|
||||
if (pControl->GetKeyboardInputEnabled())
|
||||
{
|
||||
//Make sure none of our children have keyboard focus first - todo recursive
|
||||
for (Controls::Base::List::iterator iter = pControl->Children.begin(); iter != pControl->Children.end(); ++iter)
|
||||
{
|
||||
Controls::Base* pChild = *iter;
|
||||
if ( pChild == Gwen::KeyboardFocus )
|
||||
if (pChild == Gwen::KeyboardFocus)
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,7 +109,7 @@ void FindKeyboardFocus( Controls::Base* pControl )
|
||||
return;
|
||||
}
|
||||
|
||||
return FindKeyboardFocus( pControl->GetParent() );
|
||||
return FindKeyboardFocus(pControl->GetParent());
|
||||
}
|
||||
|
||||
Gwen::Point Gwen::Input::GetMousePosition()
|
||||
@@ -120,51 +117,51 @@ Gwen::Point Gwen::Input::GetMousePosition()
|
||||
return MousePosition;
|
||||
}
|
||||
|
||||
void Gwen::Input::OnCanvasThink( Controls::Base* pControl )
|
||||
void Gwen::Input::OnCanvasThink(Controls::Base* pControl)
|
||||
{
|
||||
if ( Gwen::MouseFocus && !Gwen::MouseFocus->Visible() )
|
||||
if (Gwen::MouseFocus && !Gwen::MouseFocus->Visible())
|
||||
Gwen::MouseFocus = NULL;
|
||||
|
||||
if (Gwen::KeyboardFocus )
|
||||
|
||||
if (Gwen::KeyboardFocus)
|
||||
{
|
||||
bool isVisible = Gwen::KeyboardFocus->Visible();
|
||||
bool isEnabled = KeyboardFocus->GetKeyboardInputEnabled();
|
||||
|
||||
if ( !isVisible || !isEnabled )
|
||||
if (!isVisible || !isEnabled)
|
||||
Gwen::KeyboardFocus = NULL;
|
||||
}
|
||||
|
||||
if ( !KeyboardFocus ) return;
|
||||
if ( KeyboardFocus->GetCanvas() != pControl ) return;
|
||||
if (!KeyboardFocus) return;
|
||||
if (KeyboardFocus->GetCanvas() != pControl) return;
|
||||
|
||||
float fTime = Gwen::Platform::GetTimeInSeconds();
|
||||
|
||||
//
|
||||
// Simulate Key-Repeats
|
||||
//
|
||||
for ( int i=0; i<Gwen::Key::Count; i++ )
|
||||
for (int i = 0; i < Gwen::Key::Count; i++)
|
||||
{
|
||||
if ( KeyData.KeyState[i] && KeyData.Target != KeyboardFocus )
|
||||
if (KeyData.KeyState[i] && KeyData.Target != KeyboardFocus)
|
||||
{
|
||||
KeyData.KeyState[i] = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( KeyData.KeyState[i] && fTime > KeyData.NextRepeat[i] )
|
||||
if (KeyData.KeyState[i] && fTime > KeyData.NextRepeat[i])
|
||||
{
|
||||
KeyData.NextRepeat[i] = Gwen::Platform::GetTimeInSeconds() + KeyRepeatRate;
|
||||
|
||||
if ( KeyboardFocus )
|
||||
if (KeyboardFocus)
|
||||
{
|
||||
KeyboardFocus->OnKeyPress( i );
|
||||
KeyboardFocus->OnKeyPress(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Gwen::Input::IsKeyDown( int iKey )
|
||||
bool Gwen::Input::IsKeyDown(int iKey)
|
||||
{
|
||||
return KeyData.KeyState[ iKey ];
|
||||
return KeyData.KeyState[iKey];
|
||||
}
|
||||
|
||||
bool Gwen::Input::IsLeftMouseDown()
|
||||
@@ -177,55 +174,57 @@ bool Gwen::Input::IsRightMouseDown()
|
||||
return KeyData.RightMouseDown;
|
||||
}
|
||||
|
||||
void Gwen::Input::OnMouseMoved( Controls::Base* pCanvas, int x, int y, int /*deltaX*/, int /*deltaY*/ )
|
||||
void Gwen::Input::OnMouseMoved(Controls::Base* pCanvas, int x, int y, int /*deltaX*/, int /*deltaY*/)
|
||||
{
|
||||
MousePosition.x = x;
|
||||
MousePosition.y = y;
|
||||
|
||||
UpdateHoveredControl( pCanvas );
|
||||
UpdateHoveredControl(pCanvas);
|
||||
}
|
||||
|
||||
bool Gwen::Input::OnMouseClicked( Controls::Base* pCanvas, int iMouseButton, bool bDown )
|
||||
bool Gwen::Input::OnMouseClicked(Controls::Base* pCanvas, int iMouseButton, bool bDown)
|
||||
{
|
||||
// If we click on a control that isn't a menu we want to close
|
||||
// all the open menus. Menus are children of the canvas.
|
||||
if ( bDown && (!Gwen::HoveredControl || !Gwen::HoveredControl->IsMenuComponent()) )
|
||||
if (bDown && (!Gwen::HoveredControl || !Gwen::HoveredControl->IsMenuComponent()))
|
||||
{
|
||||
pCanvas->CloseMenus();
|
||||
}
|
||||
|
||||
if ( !Gwen::HoveredControl ) return false;
|
||||
if ( Gwen::HoveredControl->GetCanvas() != pCanvas ) return false;
|
||||
if ( !Gwen::HoveredControl->Visible() ) return false;
|
||||
if ( Gwen::HoveredControl == pCanvas ) return false;
|
||||
if (!Gwen::HoveredControl) return false;
|
||||
if (Gwen::HoveredControl->GetCanvas() != pCanvas) return false;
|
||||
if (!Gwen::HoveredControl->Visible()) return false;
|
||||
if (Gwen::HoveredControl == pCanvas) return false;
|
||||
|
||||
if ( iMouseButton > MAX_MOUSE_BUTTONS )
|
||||
if (iMouseButton > MAX_MOUSE_BUTTONS)
|
||||
return false;
|
||||
|
||||
if ( iMouseButton == 0 ) KeyData.LeftMouseDown = bDown;
|
||||
else if ( iMouseButton == 1 ) KeyData.RightMouseDown = bDown;
|
||||
if (iMouseButton == 0)
|
||||
KeyData.LeftMouseDown = bDown;
|
||||
else if (iMouseButton == 1)
|
||||
KeyData.RightMouseDown = bDown;
|
||||
|
||||
// Double click.
|
||||
// Todo: Shouldn't double click if mouse has moved significantly
|
||||
bool bIsDoubleClick = false;
|
||||
|
||||
if ( bDown &&
|
||||
g_pntLastClickPos.x == MousePosition.x &&
|
||||
if (bDown &&
|
||||
g_pntLastClickPos.x == MousePosition.x &&
|
||||
g_pntLastClickPos.y == MousePosition.y &&
|
||||
( Gwen::Platform::GetTimeInSeconds() - g_fLastClickTime[ iMouseButton ] ) < DOUBLE_CLICK_SPEED )
|
||||
(Gwen::Platform::GetTimeInSeconds() - g_fLastClickTime[iMouseButton]) < DOUBLE_CLICK_SPEED)
|
||||
{
|
||||
bIsDoubleClick = true;
|
||||
}
|
||||
|
||||
if ( bDown && !bIsDoubleClick )
|
||||
if (bDown && !bIsDoubleClick)
|
||||
{
|
||||
g_fLastClickTime[ iMouseButton ] = Gwen::Platform::GetTimeInSeconds();
|
||||
g_fLastClickTime[iMouseButton] = Gwen::Platform::GetTimeInSeconds();
|
||||
g_pntLastClickPos = MousePosition;
|
||||
}
|
||||
|
||||
if ( bDown )
|
||||
if (bDown)
|
||||
{
|
||||
FindKeyboardFocus( Gwen::HoveredControl );
|
||||
FindKeyboardFocus(Gwen::HoveredControl);
|
||||
}
|
||||
|
||||
Gwen::HoveredControl->UpdateCursor();
|
||||
@@ -234,129 +233,133 @@ bool Gwen::Input::OnMouseClicked( Controls::Base* pCanvas, int iMouseButton, boo
|
||||
// in turn tells its parents, who tell their parents.
|
||||
// This is basically so that Windows can pop themselves
|
||||
// to the top when one of their children have been clicked.
|
||||
if ( bDown )
|
||||
if (bDown)
|
||||
Gwen::HoveredControl->Touch();
|
||||
|
||||
#ifdef GWEN_HOOKSYSTEM
|
||||
if ( bDown )
|
||||
if (bDown)
|
||||
{
|
||||
if ( Hook::CallHook( &Hook::BaseHook::OnControlClicked, Gwen::HoveredControl, MousePosition.x, MousePosition.y ) )
|
||||
if (Hook::CallHook(&Hook::BaseHook::OnControlClicked, Gwen::HoveredControl, MousePosition.x, MousePosition.y))
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch ( iMouseButton )
|
||||
switch (iMouseButton)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if ( DragAndDrop::OnMouseButton( Gwen::HoveredControl, MousePosition.x, MousePosition.y, bDown ) )
|
||||
return true;
|
||||
|
||||
if ( bIsDoubleClick ) Gwen::HoveredControl->OnMouseDoubleClickLeft( MousePosition.x, MousePosition.y );
|
||||
else Gwen::HoveredControl->OnMouseClickLeft( MousePosition.x, MousePosition.y, bDown );
|
||||
{
|
||||
if (DragAndDrop::OnMouseButton(Gwen::HoveredControl, MousePosition.x, MousePosition.y, bDown))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (bIsDoubleClick)
|
||||
Gwen::HoveredControl->OnMouseDoubleClickLeft(MousePosition.x, MousePosition.y);
|
||||
else
|
||||
Gwen::HoveredControl->OnMouseClickLeft(MousePosition.x, MousePosition.y, bDown);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
if ( bIsDoubleClick ) Gwen::HoveredControl->OnMouseDoubleClickRight( MousePosition.x, MousePosition.y );
|
||||
else Gwen::HoveredControl->OnMouseClickRight( MousePosition.x, MousePosition.y, bDown );
|
||||
return true;
|
||||
}
|
||||
{
|
||||
if (bIsDoubleClick)
|
||||
Gwen::HoveredControl->OnMouseDoubleClickRight(MousePosition.x, MousePosition.y);
|
||||
else
|
||||
Gwen::HoveredControl->OnMouseClickRight(MousePosition.x, MousePosition.y, bDown);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Gwen::Input::HandleAccelerator( Controls::Base* pCanvas, Gwen::UnicodeChar chr )
|
||||
bool Gwen::Input::HandleAccelerator(Controls::Base* pCanvas, Gwen::UnicodeChar chr)
|
||||
{
|
||||
//Build the accelerator search string
|
||||
Gwen::UnicodeString accelString;
|
||||
if ( Gwen::Input::IsControlDown() )
|
||||
if (Gwen::Input::IsControlDown())
|
||||
accelString += L"Ctrl + ";
|
||||
if ( Gwen::Input::IsShiftDown() )
|
||||
if (Gwen::Input::IsShiftDown())
|
||||
accelString += L"Shift + ";
|
||||
|
||||
accelString += chr;
|
||||
|
||||
//Debug::Msg("Accelerator string :%S\n", accelString.c_str());
|
||||
|
||||
if ( Gwen::KeyboardFocus && Gwen::KeyboardFocus->HandleAccelerator( accelString ) )
|
||||
if (Gwen::KeyboardFocus && Gwen::KeyboardFocus->HandleAccelerator(accelString))
|
||||
return true;
|
||||
|
||||
if ( Gwen::MouseFocus && Gwen::MouseFocus->HandleAccelerator( accelString ) )
|
||||
if (Gwen::MouseFocus && Gwen::MouseFocus->HandleAccelerator(accelString))
|
||||
return true;
|
||||
|
||||
if ( pCanvas->HandleAccelerator( accelString ) )
|
||||
if (pCanvas->HandleAccelerator(accelString))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Gwen::Input::DoSpecialKeys( Controls::Base* pCanvas, Gwen::UnicodeChar chr )
|
||||
bool Gwen::Input::DoSpecialKeys(Controls::Base* pCanvas, Gwen::UnicodeChar chr)
|
||||
{
|
||||
if ( !Gwen::KeyboardFocus ) return false;
|
||||
if ( Gwen::KeyboardFocus->GetCanvas() != pCanvas ) return false;
|
||||
if ( !Gwen::KeyboardFocus->Visible() ) return false;
|
||||
if ( !Gwen::Input::IsControlDown() ) return false;
|
||||
if (!Gwen::KeyboardFocus) return false;
|
||||
if (Gwen::KeyboardFocus->GetCanvas() != pCanvas) return false;
|
||||
if (!Gwen::KeyboardFocus->Visible()) return false;
|
||||
if (!Gwen::Input::IsControlDown()) return false;
|
||||
|
||||
if ( chr == L'C' || chr == L'c' )
|
||||
if (chr == L'C' || chr == L'c')
|
||||
{
|
||||
Gwen::KeyboardFocus->OnCopy(NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( chr == L'V' || chr == L'v' )
|
||||
if (chr == L'V' || chr == L'v')
|
||||
{
|
||||
Gwen::KeyboardFocus->OnPaste(NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( chr == L'X' || chr == L'x' )
|
||||
if (chr == L'X' || chr == L'x')
|
||||
{
|
||||
Gwen::KeyboardFocus->OnCut(NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( chr == L'A' || chr == L'a' )
|
||||
if (chr == L'A' || chr == L'a')
|
||||
{
|
||||
Gwen::KeyboardFocus->OnSelectAll(NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Gwen::Input::OnKeyEvent( Controls::Base* pCanvas, int iKey, bool bDown )
|
||||
bool Gwen::Input::OnKeyEvent(Controls::Base* pCanvas, int iKey, bool bDown)
|
||||
{
|
||||
if ( !Gwen::KeyboardFocus ) return false;
|
||||
if ( Gwen::KeyboardFocus->GetCanvas() != pCanvas ) return false;
|
||||
if ( !Gwen::KeyboardFocus->Visible() ) return false;
|
||||
if (!Gwen::KeyboardFocus) return false;
|
||||
if (Gwen::KeyboardFocus->GetCanvas() != pCanvas) return false;
|
||||
if (!Gwen::KeyboardFocus->Visible()) return false;
|
||||
|
||||
if ( bDown )
|
||||
if (bDown)
|
||||
{
|
||||
if ( !KeyData.KeyState[ iKey ] )
|
||||
if (!KeyData.KeyState[iKey])
|
||||
{
|
||||
KeyData.KeyState[ iKey ] = true;
|
||||
KeyData.NextRepeat[ iKey ] = Gwen::Platform::GetTimeInSeconds() + KeyRepeatDelay;
|
||||
KeyData.KeyState[iKey] = true;
|
||||
KeyData.NextRepeat[iKey] = Gwen::Platform::GetTimeInSeconds() + KeyRepeatDelay;
|
||||
KeyData.Target = KeyboardFocus;
|
||||
|
||||
return KeyboardFocus->OnKeyPress( iKey );
|
||||
return KeyboardFocus->OnKeyPress(iKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( KeyData.KeyState[ iKey ] )
|
||||
if (KeyData.KeyState[iKey])
|
||||
{
|
||||
KeyData.KeyState[ iKey ] = false;
|
||||
KeyData.KeyState[iKey] = false;
|
||||
|
||||
// BUG BUG. This causes shift left arrow in textboxes
|
||||
// to not work. What is disabling it here breaking?
|
||||
//KeyData.Target = NULL;
|
||||
|
||||
return KeyboardFocus->OnKeyRelease( iKey );
|
||||
return KeyboardFocus->OnKeyRelease(iKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user