Skip to content

Commit

Permalink
#6 Add basic window, theme for editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 21, 2020
1 parent 9d0787c commit 847581c
Show file tree
Hide file tree
Showing 22 changed files with 608 additions and 22 deletions.
Binary file added Assets/Editor/GUI/draw_window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Editor/GUI/draw_window.psd
Binary file not shown.
Binary file added Assets/Editor/GUI/draw_window_shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Editor/GUI/empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions Projects/Editor/Source/Editor/CEditor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
!@
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 "CEditor.h"

namespace Skylicht
{
namespace Editor
{
CEditor::CEditor()
{
GUI::CCanvas *canvas = GUI::CGUIContext::getRoot();

GUI::CWindow *window = new GUI::CWindow(canvas, 20.0f, 20.0f, 600.0f, 480.0f);
}

CEditor::~CEditor()
{

}
}
}
42 changes: 42 additions & 0 deletions Projects/Editor/Source/Editor/CEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
!@
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/CGUIContext.h"
#include "GUI/Controls/CWindow.h"

namespace Skylicht
{
namespace Editor
{
class CEditor
{
public:
CEditor();

virtual ~CEditor();
};
}
}
48 changes: 46 additions & 2 deletions Projects/Editor/Source/GUI/CGUIContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ 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"

namespace Skylicht
{
Expand All @@ -32,10 +35,51 @@ namespace Skylicht
namespace GUI
{
CBase* CGUIContext::HoveredControl = NULL;

CBase* CGUIContext::MouseFocus = NULL;

CBase* CGUIContext::KeyboardFocus = NULL;

CCanvas* g_rootCanvas = NULL;

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

void CGUIContext::initGUI(float width, float height)
{
g_rootCanvas = new CCanvas(width, height);

g_renderer = new CSkylichtRenderer();
CRenderer::setRenderer(g_renderer);

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

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

void CGUIContext::update()
{
g_rootCanvas->update();
}

void CGUIContext::render()
{
g_rootCanvas->doRender();
}

void CGUIContext::resize(float width, float height)
{
g_rootCanvas->setBounds(0.0f, 0.0f, width, height);
}

CCanvas* CGUIContext::getRoot()
{
return g_rootCanvas;
}
}
}
}
18 changes: 16 additions & 2 deletions Projects/Editor/Source/GUI/CGUIContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,28 @@ namespace Skylicht
{
namespace GUI
{
class CCanvas;

class CGUIContext
{
public:
static CBase* HoveredControl;

static CBase* MouseFocus;

static CBase* KeyboardFocus;

public:

static void initGUI(float width, float height);

static void destroyGUI();

static void update();

static void render();

static void resize(float width, float height);

static CCanvas* getRoot();
};
}
}
Expand Down
31 changes: 26 additions & 5 deletions Projects/Editor/Source/GUI/Controls/CBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ This file is part of the "Skylicht Engine".
#include "pch.h"
#include "CBase.h"
#include "CCanvas.h"
#include "GUI/Renderer/CRenderer.h"
#include "GUI/CGUIContext.h"

namespace Skylicht
Expand All @@ -35,7 +34,7 @@ namespace Skylicht
namespace GUI
{
CBase::CBase(CBase* parent, const std::string& name) :
m_parent(parent),
m_parent(NULL),
m_name(name),
m_disabled(false),
m_hidden(false),
Expand All @@ -47,12 +46,28 @@ namespace Skylicht
m_mouseInputEnabled(true),
m_keyboardInputEnabled(true)
{

setParent(parent);
}

CBase::~CBase()
{
CCanvas *canvas = getCanvas();

if (canvas != NULL)
canvas->removeDelayDelete(this);

setParent(NULL);

releaseChildren();

if (CGUIContext::HoveredControl == this)
CGUIContext::HoveredControl = NULL;

if (CGUIContext::KeyboardFocus == this)
CGUIContext::KeyboardFocus = NULL;

if (CGUIContext::MouseFocus == this)
CGUIContext::MouseFocus = NULL;
}

void CBase::setHidden(bool hidden)
Expand All @@ -65,6 +80,12 @@ namespace Skylicht
reDraw();
}

void CBase::remove()
{
CCanvas* canvas = getCanvas();
canvas->addDelayedDelete(this);
}

bool CBase::isHidden() const
{
return m_hidden;
Expand Down Expand Up @@ -285,8 +306,8 @@ namespace Skylicht
{
m_renderBounds.X = 0;
m_renderBounds.Y = 0;
m_renderBounds.X = m_bounds.Width;
m_renderBounds.Y = m_bounds.Height;
m_renderBounds.Width = m_bounds.Width;
m_renderBounds.Height = m_bounds.Height;
}

void CBase::moveTo(float x, float y)
Expand Down
6 changes: 6 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ This file is part of the "Skylicht Engine".
#pragma once

#include <functional>
#include <set>

#include "GUI/Type.h"
#include "GUI/Theme/CTheme.h"
#include "GUI/Renderer/CRenderer.h"

namespace Skylicht
{
Expand All @@ -44,6 +48,8 @@ namespace Skylicht
virtual ~CBase();

public:
virtual void remove();

virtual void setHidden(bool hidden);

//!< Returns true only if this control is hidden.
Expand Down
53 changes: 47 additions & 6 deletions Projects/Editor/Source/GUI/Controls/CCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ This file is part of the "Skylicht Engine".

#include "pch.h"
#include "CCanvas.h"
#include "GUI/Renderer/CRenderer.h"

namespace Skylicht
{
namespace Editor
{
namespace GUI
{
CCanvas::CCanvas() :
CCanvas::CCanvas(float width, float height) :
CBase(NULL),
FirstTab(NULL),
NextTab(NULL)
{
setBounds(0.0, 0.0f, width, height);
initialize();
}

Expand All @@ -47,25 +47,66 @@ namespace Skylicht

void CCanvas::initialize()
{
}

CCanvas* CCanvas::getCanvas()
{
return this;
}

void CCanvas::addDelayedDelete(CBase* control)
{
if (m_deleteSet.find(control) == m_deleteSet.end())
{
m_deleteSet.insert(control);
m_deleteList.push_back(control);
}
}

void CCanvas::removeDelayDelete(CBase *control)
{
std::set<CBase*>::iterator itFind;

if ((itFind = m_deleteSet.find(control)) != m_deleteSet.end())
{
m_deleteList.remove(control);
m_deleteSet.erase(control);
}
}

void CCanvas::processDelayedDeletes()
{
CBase::List deleteList = m_deleteList;
m_deleteList.clear();
m_deleteSet.clear();

for (auto&& control : deleteList)
{
delete control;
}

reDraw();
}

void CCanvas::update()
{
processDelayedDeletes();

if (isHidden())
return;

recurseLayout();

if (NextTab == NULL)
NextTab = FirstTab;
}

void CCanvas::doRender()
{
update();

CRenderer *render = CRenderer::getRenderer();

render->begin();

recurseLayout();

render->setClipRegion(m_bounds);

render->setRenderOffset(SPoint(0.0f, 0.0f));
Expand Down
Loading

0 comments on commit 847581c

Please sign in to comment.