Skip to content

Commit

Permalink
#6 Implement base input gui
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 22, 2020
1 parent f2f7f6f commit 4cd1b14
Show file tree
Hide file tree
Showing 18 changed files with 736 additions and 42 deletions.
17 changes: 16 additions & 1 deletion Projects/Editor/Source/GUI/CGUIContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ This file is part of the "Skylicht Engine".
#include "pch.h"
#include "CGUIContext.h"
#include "GUI/Controls/CCanvas.h"

#include "GUI/Renderer/CSkylichtRenderer.h"
#include "GUI/Theme/CSkylichtTheme.h"
#include "GUI/Input/CSkylichtInput.h"

namespace Skylicht
{
Expand All @@ -39,10 +41,13 @@ namespace Skylicht
CBase* CGUIContext::KeyboardFocus = NULL;

CCanvas* g_rootCanvas = NULL;
CInput* g_input = NULL;

CSkylichtRenderer *g_renderer = NULL;
CSkylichtTheme *g_theme = NULL;

float g_guiUpdateTime = 0.0f;

void CGUIContext::initGUI(float width, float height)
{
g_rootCanvas = new CCanvas(width, height);
Expand All @@ -52,18 +57,28 @@ namespace Skylicht

g_theme = new CSkylichtTheme();
CTheme::setTheme(g_theme);

g_input = new CSkylichtInput();
CInput::setInput(g_input);
}

void CGUIContext::destroyGUI()
{
delete g_rootCanvas;
delete g_renderer;
delete g_theme;
delete g_input;
}

void CGUIContext::update()
void CGUIContext::update(float time)
{
g_rootCanvas->update();
g_guiUpdateTime = time;
}

float CGUIContext::getTime()
{
return g_guiUpdateTime;
}

void CGUIContext::render()
Expand Down
4 changes: 3 additions & 1 deletion Projects/Editor/Source/GUI/CGUIContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ namespace Skylicht

static void destroyGUI();

static void update();
static void update(float time);

static float getTime();

static void render();

Expand Down
6 changes: 4 additions & 2 deletions Projects/Editor/Source/GUI/Controls/CBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,16 @@ namespace Skylicht

void CBase::onMouseEnter()
{
OnHoverEnter(this);
if (OnHoverEnter != nullptr)
OnHoverEnter(this);

reDraw();
}

void CBase::onMouseLeave()
{
OnHoverLeave(this);
if (OnHoverLeave != nullptr)
OnHoverLeave(this);

reDraw();
}
Expand Down
14 changes: 8 additions & 6 deletions Projects/Editor/Source/GUI/Controls/CBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace Skylicht
inline void setWidth(float w) { setSize(w, height()); }
inline void setHeight(float h) { setSize(width(), h); }

inline bool setSize(float w, float h) { setBounds(X(), Y(), w, h); }
inline bool setSize(float w, float h) { return setBounds(X(), Y(), w, h); }
inline bool setSize(const SDimension& p) { setSize(p.Width, p.Height); }
inline SDimension GetSize() const { return SDimension(width(), height()); }

Expand Down Expand Up @@ -195,18 +195,20 @@ namespace Skylicht

public:

virtual void onMouseMoved(int x, int y, int deltaX, int deltaY) {}
virtual void updateCursor() {}

virtual void onMouseMoved(float x, float y, float deltaX, float deltaY) {}
virtual bool onMouseWheeled(int iDelta);

virtual void onMouseClickLeft(int x, int y, bool bDown) {}
virtual void onMouseClickRight(int x, int y, bool bDown) {}
virtual void onMouseClickLeft(float x, float y, bool bDown) {}
virtual void onMouseClickRight(float x, float y, bool bDown) {}

virtual void onMouseDoubleClickLeft(int x, int y)
virtual void onMouseDoubleClickLeft(float x, float y)
{
onMouseClickLeft(x, y, true);
}

virtual void onMouseDoubleClickRight(int x, int y)
virtual void onMouseDoubleClickRight(float x, float y)
{
onMouseClickRight(x, y, true);
}
Expand Down
4 changes: 4 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ namespace Skylicht

virtual void removeDelayDelete(CBase *control);

public:



public:

CBase* FirstTab;
Expand Down
76 changes: 76 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CDragger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "CDragger.h"

namespace Skylicht
{
namespace Editor
{
namespace GUI
{
CDragger::CDragger(CBase* parent, float x, float y, float w, float h) :
CBase(parent),
m_pressed(false)
{
setBounds(x, y, w, h);
}

CDragger::~CDragger()
{

}

void CDragger::onMouseMoved(float x, float y, float deltaX, float deltaY)
{
if (m_disabled)
return;

if (!m_pressed)
return;

SPoint p = SPoint(x - m_holdPosition.X, y - m_holdPosition.Y);

if (m_parent->getParent() != NULL)
p = m_parent->getParent()->canvasPosToLocal(p);

m_parent->moveTo(p.X, p.Y);
}

void CDragger::onMouseClickLeft(float x, float y, bool bDown)
{
if (m_disabled)
return;

m_pressed = bDown;

if (m_pressed == true)
{
m_holdPosition = m_parent->canvasPosToLocal(SPoint(x, y));
}
}
}
}
}
52 changes: 52 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CDragger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/
#pragma once

#include "GUI/Controls/CBase.h"

namespace Skylicht
{
namespace Editor
{
namespace GUI
{
class CDragger : public CBase
{
protected:
bool m_pressed;

SPoint m_holdPosition;

public:
CDragger(CBase* parent, float x, float y, float w, float h);

virtual ~CDragger();

virtual void onMouseMoved(float x, float y, float deltaX, float deltaY);

virtual void onMouseClickLeft(float x, float y, bool bDown);
};
}
}
}
8 changes: 8 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This file is part of the "Skylicht Engine".
*/

#include "pch.h"
#include "CDragger.h"
#include "CWindow.h"

namespace Skylicht
Expand All @@ -35,6 +36,13 @@ namespace Skylicht
CBase(parent)
{
setBounds(x, y, w, h);

CDragger *titleBar = new CDragger(this, 0.0f, 0.0f, 0.0f, 0.0f);
titleBar->setHeight(24);
titleBar->setPadding(SPadding(0, 0, 0, 0));
titleBar->setMargin(SMargin(0, 0, 0, 4));
titleBar->dock(EPosition::Top);

}

CWindow::~CWindow()
Expand Down
Loading

0 comments on commit 4cd1b14

Please sign in to comment.