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:
erwincoumans
2018-09-23 14:17:31 -07:00
parent b73b05e9fb
commit ab8f16961e
1773 changed files with 1081087 additions and 474249 deletions

View File

@@ -18,100 +18,143 @@
namespace Gwen
{
namespace Input
namespace Input
{
class SDL13
{
public:
SDL13()
{
class SDL13
{
public:
SDL13()
{
m_Canvas = NULL;
}
void Initialize( Gwen::Controls::Canvas* c )
{
m_Canvas = c;
}
bool ProcessEvent( SDL_Event* Event )
{
if (!m_Canvas) return false;
switch(Event->type)
{
case SDL_KEYUP:
case SDL_KEYDOWN:
{
SDL_KeyboardEvent* E = &Event->key;
int iKey = -1;
SDL_scancode scancode = E->keysym.scancode;
switch (scancode) {
case SDL_SCANCODE_RETURN: iKey = Gwen::Key::Return; break;
case SDL_SCANCODE_BACKSPACE: iKey = Gwen::Key::Backspace; break;
case SDL_SCANCODE_DELETE: iKey = Gwen::Key::Delete; break;
case SDL_SCANCODE_LEFT: iKey = Gwen::Key::Left; break;
case SDL_SCANCODE_RIGHT: iKey = Gwen::Key::Right; break;
case SDL_SCANCODE_LSHIFT: iKey = Gwen::Key::Shift; break;
case SDL_SCANCODE_RSHIFT: iKey = Gwen::Key::Shift; break;
case SDL_SCANCODE_TAB: iKey = Gwen::Key::Tab; break;
case SDL_SCANCODE_SPACE: iKey = Gwen::Key::Space; break;
case SDL_SCANCODE_HOME: iKey = Gwen::Key::Home; break;
case SDL_SCANCODE_END: iKey = Gwen::Key::End; break;
case SDL_SCANCODE_LCTRL: iKey = Gwen::Key::Control; break;
case SDL_SCANCODE_RCTRL: iKey = Gwen::Key::Control; break;
case SDL_SCANCODE_UP: iKey = Gwen::Key::Up; break;
case SDL_SCANCODE_DOWN: iKey = Gwen::Key::Down; break;
case SDL_SCANCODE_ESCAPE: iKey = Gwen::Key::Escape; break;
case SDL_SCANCODE_LALT: iKey = Gwen::Key::Alt; break;
case SDL_SCANCODE_RALT: iKey = Gwen::Key::Alt; break;
default: return false;
}
return m_Canvas->InputKey(iKey, E->state);
}
case SDL_TEXTINPUT:
{
SDL_TextInputEvent* E = &Event->text;
wchar_t* widechar = (wchar_t*)SDL_iconv_string(UCS_STRING, "UTF-8", E->text, SDL_strlen(E->text)+1);
bool ret = m_Canvas->InputCharacter(*widechar);
SDL_free(widechar);
return ret;
}
case SDL_MOUSEMOTION:
{
SDL_MouseMotionEvent* E = &Event->motion;
return m_Canvas->InputMouseMoved(E->x, E->y, E->xrel, E->yrel);
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
SDL_MouseButtonEvent* E = &Event->button;
int Button = -1;
switch (E->button) {
case SDL_BUTTON_LEFT: Button = 0; break;
case SDL_BUTTON_MIDDLE: Button = 2; break;
case SDL_BUTTON_RIGHT: Button = 1; break;
default: return false;
}
return m_Canvas->InputMouseButton(Button, E->state);
}
case SDL_MOUSEWHEEL:
{
SDL_MouseWheelEvent* E = &Event->wheel;
return m_Canvas->InputMouseWheel(E->y);
}
default:
{
return false;
}
}
}
protected:
Gwen::Controls::Canvas* m_Canvas;
};
m_Canvas = NULL;
}
}
void Initialize(Gwen::Controls::Canvas* c)
{
m_Canvas = c;
}
bool ProcessEvent(SDL_Event* Event)
{
if (!m_Canvas) return false;
switch (Event->type)
{
case SDL_KEYUP:
case SDL_KEYDOWN:
{
SDL_KeyboardEvent* E = &Event->key;
int iKey = -1;
SDL_scancode scancode = E->keysym.scancode;
switch (scancode)
{
case SDL_SCANCODE_RETURN:
iKey = Gwen::Key::Return;
break;
case SDL_SCANCODE_BACKSPACE:
iKey = Gwen::Key::Backspace;
break;
case SDL_SCANCODE_DELETE:
iKey = Gwen::Key::Delete;
break;
case SDL_SCANCODE_LEFT:
iKey = Gwen::Key::Left;
break;
case SDL_SCANCODE_RIGHT:
iKey = Gwen::Key::Right;
break;
case SDL_SCANCODE_LSHIFT:
iKey = Gwen::Key::Shift;
break;
case SDL_SCANCODE_RSHIFT:
iKey = Gwen::Key::Shift;
break;
case SDL_SCANCODE_TAB:
iKey = Gwen::Key::Tab;
break;
case SDL_SCANCODE_SPACE:
iKey = Gwen::Key::Space;
break;
case SDL_SCANCODE_HOME:
iKey = Gwen::Key::Home;
break;
case SDL_SCANCODE_END:
iKey = Gwen::Key::End;
break;
case SDL_SCANCODE_LCTRL:
iKey = Gwen::Key::Control;
break;
case SDL_SCANCODE_RCTRL:
iKey = Gwen::Key::Control;
break;
case SDL_SCANCODE_UP:
iKey = Gwen::Key::Up;
break;
case SDL_SCANCODE_DOWN:
iKey = Gwen::Key::Down;
break;
case SDL_SCANCODE_ESCAPE:
iKey = Gwen::Key::Escape;
break;
case SDL_SCANCODE_LALT:
iKey = Gwen::Key::Alt;
break;
case SDL_SCANCODE_RALT:
iKey = Gwen::Key::Alt;
break;
default:
return false;
}
return m_Canvas->InputKey(iKey, E->state);
}
case SDL_TEXTINPUT:
{
SDL_TextInputEvent* E = &Event->text;
wchar_t* widechar = (wchar_t*)SDL_iconv_string(UCS_STRING, "UTF-8", E->text, SDL_strlen(E->text) + 1);
bool ret = m_Canvas->InputCharacter(*widechar);
SDL_free(widechar);
return ret;
}
case SDL_MOUSEMOTION:
{
SDL_MouseMotionEvent* E = &Event->motion;
return m_Canvas->InputMouseMoved(E->x, E->y, E->xrel, E->yrel);
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
SDL_MouseButtonEvent* E = &Event->button;
int Button = -1;
switch (E->button)
{
case SDL_BUTTON_LEFT:
Button = 0;
break;
case SDL_BUTTON_MIDDLE:
Button = 2;
break;
case SDL_BUTTON_RIGHT:
Button = 1;
break;
default:
return false;
}
return m_Canvas->InputMouseButton(Button, E->state);
}
case SDL_MOUSEWHEEL:
{
SDL_MouseWheelEvent* E = &Event->wheel;
return m_Canvas->InputMouseWheel(E->y);
}
default:
{
return false;
}
}
}
protected:
Gwen::Controls::Canvas* m_Canvas;
};
} // namespace Input
} // namespace Gwen
#endif

View File

@@ -16,133 +16,164 @@
namespace Gwen
{
namespace Input
namespace Input
{
class SFML
{
public:
SFML()
{
class SFML
{
public:
SFML()
{
m_Canvas = NULL;
m_MouseX = 0;
m_MouseY = 0;
}
void Initialize( Gwen::Controls::Canvas* c )
{
m_Canvas = c;
}
unsigned char TranslateKeyCode( int iKeyCode )
{
switch ( iKeyCode )
{
#if SFML_VERSION_MAJOR == 2
case sf::Keyboard::Back: return Gwen::Key::Backspace;
case sf::Keyboard::Return: return Gwen::Key::Return;
case sf::Keyboard::Escape: return Gwen::Key::Escape;
case sf::Keyboard::Tab: return Gwen::Key::Tab;
case sf::Keyboard::Space: return Gwen::Key::Space;
case sf::Keyboard::Up: return Gwen::Key::Up;
case sf::Keyboard::Down: return Gwen::Key::Down;
case sf::Keyboard::Left: return Gwen::Key::Left;
case sf::Keyboard::Right: return Gwen::Key::Right;
case sf::Keyboard::Home: return Gwen::Key::Home;
case sf::Keyboard::End: return Gwen::Key::End;
case sf::Keyboard::Delete: return Gwen::Key::Delete;
case sf::Keyboard::LControl: return Gwen::Key::Control;
case sf::Keyboard::LAlt: return Gwen::Key::Alt;
case sf::Keyboard::LShift: return Gwen::Key::Shift;
case sf::Keyboard::RControl: return Gwen::Key::Control;
case sf::Keyboard::RAlt: return Gwen::Key::Alt;
case sf::Keyboard::RShift: return Gwen::Key::Shift;
#else
case sf::Key::Back: return Gwen::Key::Backspace;
case sf::Key::Return: return Gwen::Key::Return;
case sf::Key::Escape: return Gwen::Key::Escape;
case sf::Key::Tab: return Gwen::Key::Tab;
case sf::Key::Space: return Gwen::Key::Space;
case sf::Key::Up: return Gwen::Key::Up;
case sf::Key::Down: return Gwen::Key::Down;
case sf::Key::Left: return Gwen::Key::Left;
case sf::Key::Right: return Gwen::Key::Right;
case sf::Key::Home: return Gwen::Key::Home;
case sf::Key::End: return Gwen::Key::End;
case sf::Key::Delete: return Gwen::Key::Delete;
case sf::Key::LControl: return Gwen::Key::Control;
case sf::Key::LAlt: return Gwen::Key::Alt;
case sf::Key::LShift: return Gwen::Key::Shift;
case sf::Key::RControl: return Gwen::Key::Control;
case sf::Key::RAlt: return Gwen::Key::Alt;
case sf::Key::RShift: return Gwen::Key::Shift;
#endif
}
return Gwen::Key::Invalid;
}
bool ProcessMessage( sf::Event& event )
{
if ( !m_Canvas ) return false;
switch(event.Type)
{
case sf::Event::MouseMoved:
{
int dx = event.MouseMove.X - m_MouseX;
int dy = event.MouseMove.Y - m_MouseY;
m_MouseX = event.MouseMove.X;
m_MouseY = event.MouseMove.Y;
return m_Canvas->InputMouseMoved( m_MouseX, m_MouseY, dx, dy );
}
case sf::Event::MouseButtonPressed:
case sf::Event::MouseButtonReleased:
{
return m_Canvas->InputMouseButton( event.MouseButton.Button, event.Type == sf::Event::MouseButtonPressed );
}
case sf::Event::MouseWheelMoved:
{
return m_Canvas->InputMouseWheel( event.MouseWheel.Delta * 60 );
}
case sf::Event::TextEntered:
{
return m_Canvas->InputCharacter( event.Text.Unicode );
}
case sf::Event::KeyPressed:
case sf::Event::KeyReleased:
{
bool bPressed = (event.Type == sf::Event::KeyPressed);
if ( event.Key.Control && bPressed && event.Key.Code >= 'a' && event.Key.Code <= 'z' )
{
return m_Canvas->InputCharacter( event.Key.Code );
}
unsigned char iKey = TranslateKeyCode( event.Key.Code );
return m_Canvas->InputKey( iKey, bPressed );
}
}
return false;
}
protected:
Gwen::Controls::Canvas* m_Canvas;
int m_MouseX;
int m_MouseY;
};
m_Canvas = NULL;
m_MouseX = 0;
m_MouseY = 0;
}
}
void Initialize(Gwen::Controls::Canvas* c)
{
m_Canvas = c;
}
unsigned char TranslateKeyCode(int iKeyCode)
{
switch (iKeyCode)
{
#if SFML_VERSION_MAJOR == 2
case sf::Keyboard::Back:
return Gwen::Key::Backspace;
case sf::Keyboard::Return:
return Gwen::Key::Return;
case sf::Keyboard::Escape:
return Gwen::Key::Escape;
case sf::Keyboard::Tab:
return Gwen::Key::Tab;
case sf::Keyboard::Space:
return Gwen::Key::Space;
case sf::Keyboard::Up:
return Gwen::Key::Up;
case sf::Keyboard::Down:
return Gwen::Key::Down;
case sf::Keyboard::Left:
return Gwen::Key::Left;
case sf::Keyboard::Right:
return Gwen::Key::Right;
case sf::Keyboard::Home:
return Gwen::Key::Home;
case sf::Keyboard::End:
return Gwen::Key::End;
case sf::Keyboard::Delete:
return Gwen::Key::Delete;
case sf::Keyboard::LControl:
return Gwen::Key::Control;
case sf::Keyboard::LAlt:
return Gwen::Key::Alt;
case sf::Keyboard::LShift:
return Gwen::Key::Shift;
case sf::Keyboard::RControl:
return Gwen::Key::Control;
case sf::Keyboard::RAlt:
return Gwen::Key::Alt;
case sf::Keyboard::RShift:
return Gwen::Key::Shift;
#else
case sf::Key::Back:
return Gwen::Key::Backspace;
case sf::Key::Return:
return Gwen::Key::Return;
case sf::Key::Escape:
return Gwen::Key::Escape;
case sf::Key::Tab:
return Gwen::Key::Tab;
case sf::Key::Space:
return Gwen::Key::Space;
case sf::Key::Up:
return Gwen::Key::Up;
case sf::Key::Down:
return Gwen::Key::Down;
case sf::Key::Left:
return Gwen::Key::Left;
case sf::Key::Right:
return Gwen::Key::Right;
case sf::Key::Home:
return Gwen::Key::Home;
case sf::Key::End:
return Gwen::Key::End;
case sf::Key::Delete:
return Gwen::Key::Delete;
case sf::Key::LControl:
return Gwen::Key::Control;
case sf::Key::LAlt:
return Gwen::Key::Alt;
case sf::Key::LShift:
return Gwen::Key::Shift;
case sf::Key::RControl:
return Gwen::Key::Control;
case sf::Key::RAlt:
return Gwen::Key::Alt;
case sf::Key::RShift:
return Gwen::Key::Shift;
#endif
}
return Gwen::Key::Invalid;
}
bool ProcessMessage(sf::Event& event)
{
if (!m_Canvas) return false;
switch (event.Type)
{
case sf::Event::MouseMoved:
{
int dx = event.MouseMove.X - m_MouseX;
int dy = event.MouseMove.Y - m_MouseY;
m_MouseX = event.MouseMove.X;
m_MouseY = event.MouseMove.Y;
return m_Canvas->InputMouseMoved(m_MouseX, m_MouseY, dx, dy);
}
case sf::Event::MouseButtonPressed:
case sf::Event::MouseButtonReleased:
{
return m_Canvas->InputMouseButton(event.MouseButton.Button, event.Type == sf::Event::MouseButtonPressed);
}
case sf::Event::MouseWheelMoved:
{
return m_Canvas->InputMouseWheel(event.MouseWheel.Delta * 60);
}
case sf::Event::TextEntered:
{
return m_Canvas->InputCharacter(event.Text.Unicode);
}
case sf::Event::KeyPressed:
case sf::Event::KeyReleased:
{
bool bPressed = (event.Type == sf::Event::KeyPressed);
if (event.Key.Control && bPressed && event.Key.Code >= 'a' && event.Key.Code <= 'z')
{
return m_Canvas->InputCharacter(event.Key.Code);
}
unsigned char iKey = TranslateKeyCode(event.Key.Code);
return m_Canvas->InputKey(iKey, bPressed);
}
}
return false;
}
protected:
Gwen::Controls::Canvas* m_Canvas;
int m_MouseX;
int m_MouseY;
};
} // namespace Input
} // namespace Gwen
#endif

View File

@@ -14,151 +14,162 @@
namespace Gwen
{
namespace Input
namespace Input
{
class Windows
{
public:
Windows()
{
class Windows
{
public:
Windows()
{
m_Canvas = NULL;
m_MouseX = 0;
m_MouseY = 0;
}
void Initialize( Gwen::Controls::Canvas* c )
{
m_Canvas = c;
}
bool ProcessMessage( MSG msg )
{
if ( !m_Canvas ) return false;
switch ( msg.message )
{
case WM_MOUSEMOVE:
{
int x = (signed short)LOWORD( msg.lParam );
int y = (signed short)HIWORD( msg.lParam );
int dx = x - m_MouseX;
int dy = y - m_MouseY;
m_MouseX = x;
m_MouseY = y;
return m_Canvas->InputMouseMoved( x, y, dx, dy );
}
case WM_CHAR:
{
Gwen::UnicodeChar chr = (Gwen::UnicodeChar)msg.wParam;
return m_Canvas->InputCharacter( chr );
}
case WM_MOUSEWHEEL:
{
return m_Canvas->InputMouseWheel( (short)HIWORD( msg.wParam ) );
}
case WM_LBUTTONDOWN:
{
SetCapture( msg.hwnd );
return m_Canvas->InputMouseButton( 0, true );
}
case WM_LBUTTONUP:
{
ReleaseCapture();
return m_Canvas->InputMouseButton( 0, false );
}
case WM_RBUTTONDOWN:
{
SetCapture( msg.hwnd );
return m_Canvas->InputMouseButton( 1, true );
}
case WM_RBUTTONUP:
{
ReleaseCapture();
return m_Canvas->InputMouseButton( 1, false );
}
case WM_MBUTTONDOWN:
{
SetCapture( msg.hwnd );
return m_Canvas->InputMouseButton( 2, true );
}
case WM_MBUTTONUP:
{
ReleaseCapture();
return m_Canvas->InputMouseButton( 2, true );
}
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
{
// Filter out those events from the application
return true;
}
case WM_KEYDOWN:
case WM_KEYUP:
{
bool bDown = msg.message == WM_KEYDOWN;
int iKey = -1;
// These aren't sent by WM_CHAR when CTRL is down - but we need
// them internally for copy and paste etc..
if ( bDown && GetKeyState( VK_CONTROL ) & 0x80 && msg.wParam >= 'A' && msg.wParam <= 'Z' )
{
Gwen::UnicodeChar chr = (Gwen::UnicodeChar)msg.wParam;
return m_Canvas->InputCharacter( chr );
}
if ( msg.wParam == VK_SHIFT ) iKey = Gwen::Key::Shift;
else if ( msg.wParam == VK_RETURN ) iKey = Gwen::Key::Return;
else if ( msg.wParam == VK_BACK ) iKey = Gwen::Key::Backspace;
else if ( msg.wParam == VK_DELETE ) iKey = Gwen::Key::Delete;
else if ( msg.wParam == VK_LEFT ) iKey = Gwen::Key::Left;
else if ( msg.wParam == VK_RIGHT ) iKey = Gwen::Key::Right;
else if ( msg.wParam == VK_TAB ) iKey = Gwen::Key::Tab;
else if ( msg.wParam == VK_SPACE ) iKey = Gwen::Key::Space;
else if ( msg.wParam == VK_HOME ) iKey = Gwen::Key::Home;
else if ( msg.wParam == VK_END ) iKey = Gwen::Key::End;
else if ( msg.wParam == VK_CONTROL ) iKey = Gwen::Key::Control;
else if ( msg.wParam == VK_SPACE ) iKey = Gwen::Key::Space;
else if ( msg.wParam == VK_UP ) iKey = Gwen::Key::Up;
else if ( msg.wParam == VK_DOWN ) iKey = Gwen::Key::Down;
if ( iKey != -1 )
{
return m_Canvas->InputKey( iKey, bDown );
}
break;
}
default:
{
break;
}
}
return false;
}
protected:
Gwen::Controls::Canvas* m_Canvas;
int m_MouseX;
int m_MouseY;
};
m_Canvas = NULL;
m_MouseX = 0;
m_MouseY = 0;
}
}
void Initialize(Gwen::Controls::Canvas* c)
{
m_Canvas = c;
}
bool ProcessMessage(MSG msg)
{
if (!m_Canvas) return false;
switch (msg.message)
{
case WM_MOUSEMOVE:
{
int x = (signed short)LOWORD(msg.lParam);
int y = (signed short)HIWORD(msg.lParam);
int dx = x - m_MouseX;
int dy = y - m_MouseY;
m_MouseX = x;
m_MouseY = y;
return m_Canvas->InputMouseMoved(x, y, dx, dy);
}
case WM_CHAR:
{
Gwen::UnicodeChar chr = (Gwen::UnicodeChar)msg.wParam;
return m_Canvas->InputCharacter(chr);
}
case WM_MOUSEWHEEL:
{
return m_Canvas->InputMouseWheel((short)HIWORD(msg.wParam));
}
case WM_LBUTTONDOWN:
{
SetCapture(msg.hwnd);
return m_Canvas->InputMouseButton(0, true);
}
case WM_LBUTTONUP:
{
ReleaseCapture();
return m_Canvas->InputMouseButton(0, false);
}
case WM_RBUTTONDOWN:
{
SetCapture(msg.hwnd);
return m_Canvas->InputMouseButton(1, true);
}
case WM_RBUTTONUP:
{
ReleaseCapture();
return m_Canvas->InputMouseButton(1, false);
}
case WM_MBUTTONDOWN:
{
SetCapture(msg.hwnd);
return m_Canvas->InputMouseButton(2, true);
}
case WM_MBUTTONUP:
{
ReleaseCapture();
return m_Canvas->InputMouseButton(2, true);
}
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
{
// Filter out those events from the application
return true;
}
case WM_KEYDOWN:
case WM_KEYUP:
{
bool bDown = msg.message == WM_KEYDOWN;
int iKey = -1;
// These aren't sent by WM_CHAR when CTRL is down - but we need
// them internally for copy and paste etc..
if (bDown && GetKeyState(VK_CONTROL) & 0x80 && msg.wParam >= 'A' && msg.wParam <= 'Z')
{
Gwen::UnicodeChar chr = (Gwen::UnicodeChar)msg.wParam;
return m_Canvas->InputCharacter(chr);
}
if (msg.wParam == VK_SHIFT)
iKey = Gwen::Key::Shift;
else if (msg.wParam == VK_RETURN)
iKey = Gwen::Key::Return;
else if (msg.wParam == VK_BACK)
iKey = Gwen::Key::Backspace;
else if (msg.wParam == VK_DELETE)
iKey = Gwen::Key::Delete;
else if (msg.wParam == VK_LEFT)
iKey = Gwen::Key::Left;
else if (msg.wParam == VK_RIGHT)
iKey = Gwen::Key::Right;
else if (msg.wParam == VK_TAB)
iKey = Gwen::Key::Tab;
else if (msg.wParam == VK_SPACE)
iKey = Gwen::Key::Space;
else if (msg.wParam == VK_HOME)
iKey = Gwen::Key::Home;
else if (msg.wParam == VK_END)
iKey = Gwen::Key::End;
else if (msg.wParam == VK_CONTROL)
iKey = Gwen::Key::Control;
else if (msg.wParam == VK_SPACE)
iKey = Gwen::Key::Space;
else if (msg.wParam == VK_UP)
iKey = Gwen::Key::Up;
else if (msg.wParam == VK_DOWN)
iKey = Gwen::Key::Down;
if (iKey != -1)
{
return m_Canvas->InputKey(iKey, bDown);
}
break;
}
default:
{
break;
}
}
return false;
}
protected:
Gwen::Controls::Canvas* m_Canvas;
int m_MouseX;
int m_MouseY;
};
} // namespace Input
} // namespace Gwen
#endif