From c989b2d5854380b9d408371c37beca8655f7f648 Mon Sep 17 00:00:00 2001 From: ducphamhong Date: Wed, 28 Oct 2020 10:33:44 +0700 Subject: [PATCH] #6 Improve clipping, sub window --- Assets/Editor/GUI/draw_window.psd | Bin 35318 -> 36002 bytes Assets/Editor/GUI/draw_window_shadow.png | Bin 17306 -> 17309 bytes Projects/Editor/Source/Editor/CEditor.cpp | 1 + Projects/Editor/Source/GUI/Controls/CBase.cpp | 50 +++++++++++++----- Projects/Editor/Source/GUI/Controls/CBase.h | 36 +++++++++++-- .../Editor/Source/GUI/Controls/CDragger.cpp | 2 +- .../Source/GUI/Controls/CResizableControl.cpp | 2 +- .../Source/GUI/Controls/CResizableControl.h | 2 +- Projects/Editor/Source/GUI/Controls/CText.cpp | 1 + .../Source/GUI/Controls/CTextContainer.cpp | 1 + .../Editor/Source/GUI/Controls/CWindow.cpp | 22 +++++--- Projects/Editor/Source/GUI/Controls/CWindow.h | 2 +- .../Editor/Source/GUI/Renderer/CRenderer.h | 2 + .../Source/GUI/Renderer/CSkylichtRenderer.cpp | 28 ++++++++++ .../Source/GUI/Renderer/CSkylichtRenderer.h | 6 +++ .../Editor/Source/GUI/Theme/CSkylichtTheme.h | 10 ++++ .../Editor/Source/GUI/Theme/CThemeConfig.cpp | 1 + .../Editor/Source/GUI/Theme/CThemeConfig.h | 1 + .../Engine/Source/Graphics2D/CGraphics2D.cpp | 15 ++++-- .../Engine/Source/Graphics2D/CGraphics2D.h | 2 +- .../Engine/Source/Graphics2D/GUI/CGUIRect.cpp | 3 +- .../Graphics2D/SpriteFrame/CSpriteAtlas.h | 10 ++++ 22 files changed, 164 insertions(+), 33 deletions(-) diff --git a/Assets/Editor/GUI/draw_window.psd b/Assets/Editor/GUI/draw_window.psd index d6cd7cf2395bb5ddfa21ea02eda575e9626e940b..9ec4a852e90a54b3d979b5b812ac10d9b5f985cf 100644 GIT binary patch delta 3985 zcmeHJZ%|ZK6hHUAeednQ-DQzAAVfmgjnE;rl~};U42WG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?S;5m+v5OC%}gu{bK1c@>b!XZcG+mR$P79n9^Clsh(AaI;ukz|4d zB1;wl(;xwlE-=Cf5?}(0WL4TgRIHK(6NGW=WDq4D3onSW65j?=ydsMNPe^0|l*}+& zTmoVVad>LNK!)kDW9RVq&+($HCfHNCcCd1(_5@WHkr2H@_z#MT6!lID8+-#BfDK0` zE353O>2X{aC|q26s(qCrGpQ&m1fDGx3!xB`nv{~BndQ2=Ek|)>Wu~VjnQU?ebE!y> zZ1IW7X&DZu>sq$zayl~7k`v?E&`m}>;RVSWw;JU#9a&Ciw~IQ}EC;5sua2`yIQc93 I-s2wfJ4QuaHvj+t diff --git a/Assets/Editor/GUI/draw_window_shadow.png b/Assets/Editor/GUI/draw_window_shadow.png index 96f82d3f1d47a5bc45e5a03dad7c0323448c659a..a3827bb7e0e2bd1364a8664c8c7a01d320d2265f 100644 GIT binary patch delta 917 zcmbQ$&N#Q7aRUCpqxrJ_8l8L!) zQgX7HZc=KJk(s4YqM5OA+T`0TuDS+^2Byho#^$<)7Ri>nhK8w0x)x@ZX}U=!76u09 zNk+zL#)&ri6}bhzzE&=i7xIg2PGnufq>^lyW@ee3W~pmolxm@Co@$b)n`CI1sGDeE zW&pIn*u*f=VzMEJHQZf>#+wCr0vVN)Ow7zv3`|UQ%@UK$b&bqS40V%I43l+JP0|vL zEDe(_O^hZRa3K2!s84`#a~r236LG#mwiOsS0z9WDPvvVQ#^TME{5(c11@)W#CVM*S z*9&;MIEGZ*dUL1No7s?u?SuMP7qzbY|0kbPi~EzTTM`?8N%&aMJO|4{tC#tnuX~p+ zT9vTHS?*7Df0y(6D&5F!%>s{16qh|TJN)FRVpmAOmXCi|@(4cuI`iO`#>=~Bd97&+ zT&KD$1~j!D98Rqfh76)jH}6zFK=iW@Adwiz(q!dWBs(M2d~{ zMHdFenLF${u-9Xb^NTghofTdxtQBfEn|)0srzpTcvSnV zD81XPbI#Gdc@5vBUG<;i+u-mJQE7-djCQvs@}n;q>D;{{^q6U7n~Zyy8mbwLkyMTHE*B hyw9H`kYV?ajp5!+#%;$0^BNd{z|+;wWt~$(6977=S(*R< delta 914 zcmbQ+&N!=`aRULx40PsZ11>{m6$7(WpuB;ZuA!-!g|3l>iMg(Y5zw8MCMg!i ziHVj*<|c`l8U+|9EAToJ=PS6akiaqEIz4$RU!yV+F5Ya(&tt^0ae~~g$)1k-^}L=g zjv*Dd-rTwCci4c3HNpC=C`U`h|LadS8Jg?PIO8{2WSQk0kHDjKU7rfyT$`O4&$3);4c^^l>TYo3djGqvODF3uF=i^Y4cFc{^Z!xfm?Q}XCV>V9 z76k@Ij(P_qjswFX2ABjo`@(w$!{Uk~+SwVEk1w-0O2jqa3t0Z$?`5y-`ZH%-z9=eL zCKS!NSpk3@mr5&bC!(v1bZYOji9%DPC+-ps znRe;p4<61_dpWhf=e(MHeUj)>&+C_pyS9WqIbR_6_Z+v_Bni$}ySiSgq<-Ceb+Qtp zXMRzZ?TVaZfeBR$R)}(%n_tv7d$;fabH>HC=~JY8!xl_ad%pNy?0JLKP~?Nw#R7=Xaj)z4*}Q$iB}RG(O9 diff --git a/Projects/Editor/Source/Editor/CEditor.cpp b/Projects/Editor/Source/Editor/CEditor.cpp index 0797126f1..c83d06047 100644 --- a/Projects/Editor/Source/Editor/CEditor.cpp +++ b/Projects/Editor/Source/Editor/CEditor.cpp @@ -35,6 +35,7 @@ namespace Skylicht GUI::CWindow *window1 = new GUI::CWindow(canvas, 20.0f, 20.0f, 600.0f, 480.0f); GUI::CWindow *window2 = new GUI::CWindow(canvas, 400.0f, 20.0f, 600.0f, 480.0f); + GUI::CWindow *window3 = new GUI::CWindow(window2, 20.0f, 20.0f, 300.0f, 240.0f); } CEditor::~CEditor() diff --git a/Projects/Editor/Source/GUI/Controls/CBase.cpp b/Projects/Editor/Source/GUI/Controls/CBase.cpp index fe6fbdae3..345de8491 100644 --- a/Projects/Editor/Source/GUI/Controls/CBase.cpp +++ b/Projects/Editor/Source/GUI/Controls/CBase.cpp @@ -26,6 +26,7 @@ This file is part of the "Skylicht Engine". #include "CBase.h" #include "CCanvas.h" #include "GUI/CGUIContext.h" +#include "GUI/Theme/CThemeConfig.h" #include "GUI/Input/CInput.h" namespace Skylicht @@ -36,6 +37,7 @@ namespace Skylicht { CBase::CBase(CBase* parent, const std::string& name) : m_parent(NULL), + m_innerPanel(NULL), m_name(name), m_disabled(false), m_hidden(false), @@ -46,9 +48,13 @@ namespace Skylicht m_margin(0.0f, 0.0f, 0.0f, 0.0f), m_mouseInputEnabled(true), m_keyboardInputEnabled(true), - m_cursor(ECursorType::Normal) + m_shouldClip(false), + m_cursor(ECursorType::Normal), + m_renderFillRect(false), + m_fillRectColor(CThemeConfig::WindowInnerColor) { - setParent(parent); + if (parent != NULL) + setParent(parent->getInnerPanel()); } CBase::~CBase() @@ -325,10 +331,10 @@ namespace Skylicht m_renderBounds.Height = m_bounds.Height; } - void CBase::dragTo(float x, float y, float dragPosX, float dragPosY) + void CBase::dragTo(float x, float y, float dragPosX, float dragPosY, float paddingBottom) { float testX = x + dragPosX; - float testY = y + dragPosY; + float testY = y; if (m_parent) { @@ -341,12 +347,12 @@ namespace Skylicht if (testX + m_padding.Right > m_parent->width() - m_parent->m_margin.Right) testX = m_parent->width() - m_parent->m_margin.Right - m_padding.Right; - if (testY + m_padding.Bottom > m_parent->height() - m_parent->m_margin.Bottom) - testY = m_parent->height() - m_parent->m_margin.Bottom - m_padding.Bottom; + if (testY + m_padding.Bottom > m_parent->height() - m_parent->m_margin.Bottom - paddingBottom) + testY = m_parent->height() - m_parent->m_margin.Bottom - m_padding.Bottom - paddingBottom; } x = testX - dragPosX; - y = testY - dragPosY; + y = testY; setBounds(x, y, width(), height()); } @@ -404,7 +410,11 @@ namespace Skylicht } // Render this control and children controls - render->startClip(); + if (shouldClip()) + { + render->startClip(); + } + { this->render(); @@ -420,24 +430,40 @@ namespace Skylicht } } } - render->endClip(); + + if (shouldClip()) + { + render->endClip(); + } // Render overlay/focus { render->setClipRegion(oldRegion); - render->startClip(); + if (shouldClip()) + { + render->startClip(); + } + { renderOver(); renderFocus(); } - render->endClip(); + + if (shouldClip()) + { + render->endClip(); + } + render->setRenderOffset(oldRenderOffset); } } void CBase::render() { - + if (m_renderFillRect) + { + CRenderer::getRenderer()->drawFillRect(getRenderBounds(), m_fillRectColor); + } } void CBase::renderFocus() diff --git a/Projects/Editor/Source/GUI/Controls/CBase.h b/Projects/Editor/Source/GUI/Controls/CBase.h index 1335b7176..6490bc9ff 100644 --- a/Projects/Editor/Source/GUI/Controls/CBase.h +++ b/Projects/Editor/Source/GUI/Controls/CBase.h @@ -111,11 +111,20 @@ namespace Skylicht virtual CBase* getChild(u32 i); virtual void setParent(CBase* parent); - virtual CBase* getParent() const + + virtual CBase* getParent() { return m_parent; } + virtual CBase* getInnerPanel() + { + if (m_innerPanel == NULL) + return this; + + return m_innerPanel; + } + virtual const List& getChildren() { return Children; @@ -177,7 +186,7 @@ namespace Skylicht inline void setMargin(const SMargin& margin) { m_margin = margin; } virtual void moveTo(float x, float y); - virtual void dragTo(float x, float y, float dragPosX, float dragPosY); + virtual void dragTo(float x, float y, float dragPosX, float dragPosY, float paddingBottom); inline void moveBy(float x, float y) { moveTo(X() + x, Y() + y); } inline const SRect& getBounds() const { return m_bounds; } @@ -196,7 +205,22 @@ namespace Skylicht virtual void doRender(); virtual void renderRecursive(const SRect& cliprect); - virtual bool shouldClip() { return true; } + bool shouldClip() { return m_shouldClip; } + + inline void enableClip(bool b) + { + m_shouldClip = b; + } + + inline void enableRenderFillRect(bool b) + { + m_renderFillRect = b; + } + + inline void setFillRectColor(const SGUIColor& c) + { + m_fillRectColor = c; + } protected: @@ -301,6 +325,7 @@ namespace Skylicht protected: CBase *m_parent; + CBase *m_innerPanel; std::string m_name; @@ -315,9 +340,14 @@ namespace Skylicht bool m_hidden; bool m_needsLayout; + bool m_shouldClip; + bool m_mouseInputEnabled; bool m_keyboardInputEnabled; + bool m_renderFillRect; + SGUIColor m_fillRectColor; + EPosition m_dock; ECursorType m_cursor; diff --git a/Projects/Editor/Source/GUI/Controls/CDragger.cpp b/Projects/Editor/Source/GUI/Controls/CDragger.cpp index 945a357fa..f9234aa22 100644 --- a/Projects/Editor/Source/GUI/Controls/CDragger.cpp +++ b/Projects/Editor/Source/GUI/Controls/CDragger.cpp @@ -58,7 +58,7 @@ namespace Skylicht if (m_target->getParent() != NULL) p = m_target->getParent()->canvasPosToLocal(p); - m_target->dragTo(p.X, p.Y, m_holdPosition.X, m_holdPosition.Y); + m_target->dragTo(p.X, p.Y, m_holdPosition.X, m_holdPosition.Y, height()); m_target->onMoved(); } diff --git a/Projects/Editor/Source/GUI/Controls/CResizableControl.cpp b/Projects/Editor/Source/GUI/Controls/CResizableControl.cpp index fcea3d0e2..f8cb0ed4c 100644 --- a/Projects/Editor/Source/GUI/Controls/CResizableControl.cpp +++ b/Projects/Editor/Source/GUI/Controls/CResizableControl.cpp @@ -31,7 +31,7 @@ namespace Skylicht { namespace GUI { - CResizableControl::CResizableControl(CCanvas* parent, float x, float y, float w, float h) : + CResizableControl::CResizableControl(CBase* parent, float x, float y, float w, float h) : CBase(parent) { setBounds(x, y, w, h); diff --git a/Projects/Editor/Source/GUI/Controls/CResizableControl.h b/Projects/Editor/Source/GUI/Controls/CResizableControl.h index 10c860d7c..4a4eedd65 100644 --- a/Projects/Editor/Source/GUI/Controls/CResizableControl.h +++ b/Projects/Editor/Source/GUI/Controls/CResizableControl.h @@ -39,7 +39,7 @@ namespace Skylicht CResizer *m_resizers[8]; public: - CResizableControl(CCanvas* parent, float x, float y, float w, float h); + CResizableControl(CBase* parent, float x, float y, float w, float h); virtual ~CResizableControl(); diff --git a/Projects/Editor/Source/GUI/Controls/CText.cpp b/Projects/Editor/Source/GUI/Controls/CText.cpp index 5f46d1d38..966cfa1b9 100644 --- a/Projects/Editor/Source/GUI/Controls/CText.cpp +++ b/Projects/Editor/Source/GUI/Controls/CText.cpp @@ -38,6 +38,7 @@ namespace Skylicht m_color(CThemeConfig::DefaultTextColor) { setMouseInputEnabled(false); + enableClip(true); } CText::~CText() diff --git a/Projects/Editor/Source/GUI/Controls/CTextContainer.cpp b/Projects/Editor/Source/GUI/Controls/CTextContainer.cpp index 59ff2608d..b812dba05 100644 --- a/Projects/Editor/Source/GUI/Controls/CTextContainer.cpp +++ b/Projects/Editor/Source/GUI/Controls/CTextContainer.cpp @@ -39,6 +39,7 @@ namespace Skylicht m_fontSize(EFontSize::SizeNormal) { setMouseInputEnabled(false); + enableClip(true); } CTextContainer::~CTextContainer() diff --git a/Projects/Editor/Source/GUI/Controls/CWindow.cpp b/Projects/Editor/Source/GUI/Controls/CWindow.cpp index 5afbfde6d..9b980ccd6 100644 --- a/Projects/Editor/Source/GUI/Controls/CWindow.cpp +++ b/Projects/Editor/Source/GUI/Controls/CWindow.cpp @@ -34,32 +34,38 @@ namespace Skylicht { namespace GUI { - CWindow::CWindow(CCanvas* parent, float x, float y, float w, float h) : + CWindow::CWindow(CBase* parent, float x, float y, float w, float h) : CResizableControl(parent, x, y, w, h) { + enableClip(true); + m_titleBar = new CDragger(this); - m_titleBar->setHeight(28.0f); + m_titleBar->setHeight(22.0f); m_titleBar->setPadding(SPadding(0.0f, 0.0f, 0.0f, 0.0f)); m_titleBar->setMargin(SMargin(0.0f, 0.0f, 0.0f, 4.0f)); m_titleBar->dock(EPosition::Top); m_icon = new CIcon(m_titleBar, ESystemIcon::Window, false); m_icon->dock(EPosition::Left); - m_icon->setMargin(SPadding(0.0f, -2.0f, 0.0f, 0.0f)); + m_icon->setMargin(SPadding(0.0f, 0.0f, 0.0f, 0.0f)); m_title = new CLabel(m_titleBar); m_title->setString(L"Window title"); m_title->dock(EPosition::Fill); - m_title->setPadding(SPadding(4.0f, 2.0f, 0.0f, 0.0f)); + m_title->setPadding(SPadding(4.0f, 4.0f, 0.0f, 0.0f)); m_close = new CButton(m_titleBar); - m_close->setSize(18.0f, 18.0f); + m_close->setSize(20.0f, 20.0f); m_close->dock(EPosition::Right); m_close->setIcon(ESystemIcon::Close); - m_close->setMargin(SMargin(0.0f, 0.0f, 0.0f, 10.0f)); - m_close->setIconMargin(SMargin(-1.0f, -1.0f, 0.0f, 0.0f)); + m_close->setMargin(SMargin(0.0f, 0.0f, 0.0f, 2.0f)); m_close->showIcon(true); m_close->OnPress = BIND_LISTENER(&CWindow::onCloseButtonPress, this); + + m_innerPanel = new CBase(this); + m_innerPanel->dock(EPosition::Fill); + m_innerPanel->enableClip(true); + m_innerPanel->enableRenderFillRect(true); } CWindow::~CWindow() @@ -78,11 +84,13 @@ namespace Skylicht void CWindow::touch() { bringToFront(); + CBase::touch(); } void CWindow::onChildTouched(CBase* child) { bringToFront(); + CBase::onChildTouched(child); } void CWindow::onCloseButtonPress(CBase *sender) diff --git a/Projects/Editor/Source/GUI/Controls/CWindow.h b/Projects/Editor/Source/GUI/Controls/CWindow.h index 8134a9092..47cbdf968 100644 --- a/Projects/Editor/Source/GUI/Controls/CWindow.h +++ b/Projects/Editor/Source/GUI/Controls/CWindow.h @@ -44,7 +44,7 @@ namespace Skylicht CButton *m_close; public: - CWindow(CCanvas* parent, float x, float y, float w, float h); + CWindow(CBase* parent, float x, float y, float w, float h); virtual ~CWindow(); diff --git a/Projects/Editor/Source/GUI/Renderer/CRenderer.h b/Projects/Editor/Source/GUI/Renderer/CRenderer.h index 741b21f66..a347956e7 100644 --- a/Projects/Editor/Source/GUI/Renderer/CRenderer.h +++ b/Projects/Editor/Source/GUI/Renderer/CRenderer.h @@ -59,6 +59,8 @@ namespace Skylicht virtual void endClip() {} + virtual void drawFillRect(const SRect &r, const SGUIColor& color) {} + virtual void renderText(const SRect &r, EFontSize fontSize, const SGUIColor& textColor, const std::wstring& string) {} virtual SDimension measureText(EFontSize fontSize, const std::wstring& string) = 0; diff --git a/Projects/Editor/Source/GUI/Renderer/CSkylichtRenderer.cpp b/Projects/Editor/Source/GUI/Renderer/CSkylichtRenderer.cpp index ef6c6e612..a90656820 100644 --- a/Projects/Editor/Source/GUI/Renderer/CSkylichtRenderer.cpp +++ b/Projects/Editor/Source/GUI/Renderer/CSkylichtRenderer.cpp @@ -25,6 +25,7 @@ This file is part of the "Skylicht Engine". #include "pch.h" #include "CSkylichtRenderer.h" #include "GUI/Theme/CThemeConfig.h" +#include "GUI/Theme/CSkylichtTheme.h" #include "Graphics2D/Glyph/CGlyphFreetype.h" namespace Skylicht @@ -113,6 +114,23 @@ namespace Skylicht } } + void CSkylichtRenderer::drawFillRect(const SRect &r, const SGUIColor& color) + { + CGraphics2D *g = CGraphics2D::getInstance(); + CSkylichtTheme *theme = (CSkylichtTheme*)CTheme::getTheme(); + + float invW = 1.0f / (float)theme->getAtlasWidth(); + float invH = 1.0f / (float)theme->getAtlasHeight(); + + const core::matrix4 &world = getWorldTransform(); + + float offsetX = 2.0f; + float offsetY = 2.0f; + core::rectf uv(offsetX * invW, offsetY * invH, offsetX * invW, offsetY * invH); + + g->addRectangleBatch(getRect(r), uv, getColor(color), world, m_materialID, NULL); + } + void CSkylichtRenderer::renderText(const SRect &r, EFontSize fontSize, const SGUIColor& textColor, const std::wstring& string) { CGlyphFont *font = m_fontNormal; @@ -247,6 +265,16 @@ namespace Skylicht m_fontLarge = new CGlyphFont(CThemeConfig::FontName.c_str(), fontSmall); m_fontNormal = new CGlyphFont(CThemeConfig::FontName.c_str(), fontNormal); } + + core::rectf CSkylichtRenderer::getRect(const SRect& rect) + { + return core::rectf(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); + } + + video::SColor CSkylichtRenderer::getColor(const SGUIColor& color) + { + return SColor(color.A, color.R, color.G, color.B); + } } } } \ No newline at end of file diff --git a/Projects/Editor/Source/GUI/Renderer/CSkylichtRenderer.h b/Projects/Editor/Source/GUI/Renderer/CSkylichtRenderer.h index ee3435fa4..d212bd2af 100644 --- a/Projects/Editor/Source/GUI/Renderer/CSkylichtRenderer.h +++ b/Projects/Editor/Source/GUI/Renderer/CSkylichtRenderer.h @@ -69,6 +69,8 @@ namespace Skylicht virtual void endClip(); + virtual void drawFillRect(const SRect &r, const SGUIColor& color); + virtual void renderText(const SRect &r, EFontSize fontSize, const SGUIColor& textColor, const std::wstring& string); virtual SDimension measureText(EFontSize fontSize, const std::wstring& string); @@ -80,6 +82,10 @@ namespace Skylicht m_world.setTranslation(core::vector3df(m_renderOffset.X, m_renderOffset.Y, 0.0f)); return m_world; } + + core::rectf getRect(const SRect& rect); + + video::SColor getColor(const SGUIColor& color); }; } } diff --git a/Projects/Editor/Source/GUI/Theme/CSkylichtTheme.h b/Projects/Editor/Source/GUI/Theme/CSkylichtTheme.h index b89f4fac3..3abb936ec 100644 --- a/Projects/Editor/Source/GUI/Theme/CSkylichtTheme.h +++ b/Projects/Editor/Source/GUI/Theme/CSkylichtTheme.h @@ -85,6 +85,16 @@ namespace Skylicht return m_systemIcon32[icon]; } + inline int getAtlasWidth() + { + return m_sprite->getWidth(); + } + + inline int getAtlasHeight() + { + return m_sprite->getHeight(); + } + private: void initSystemIcon(); diff --git a/Projects/Editor/Source/GUI/Theme/CThemeConfig.cpp b/Projects/Editor/Source/GUI/Theme/CThemeConfig.cpp index 6c226cf6f..b30df8460 100644 --- a/Projects/Editor/Source/GUI/Theme/CThemeConfig.cpp +++ b/Projects/Editor/Source/GUI/Theme/CThemeConfig.cpp @@ -38,6 +38,7 @@ namespace Skylicht SGUIColor CThemeConfig::Black = SGUIColor(255, 0, 0, 0); SGUIColor CThemeConfig::WindowBackgroundColor = SGUIColor(252, 35, 35, 35); + SGUIColor CThemeConfig::WindowInnerColor = SGUIColor(255, 55, 55, 55); SGUIColor CThemeConfig::DefaultTextColor = SGUIColor(255, 165, 165, 165); SGUIColor CThemeConfig::DefaultIconColor = SGUIColor(255, 215, 215, 215); SGUIColor CThemeConfig::IconPressColor = SGUIColor(255, 255, 255, 255); diff --git a/Projects/Editor/Source/GUI/Theme/CThemeConfig.h b/Projects/Editor/Source/GUI/Theme/CThemeConfig.h index b604a976e..6186b1c0a 100644 --- a/Projects/Editor/Source/GUI/Theme/CThemeConfig.h +++ b/Projects/Editor/Source/GUI/Theme/CThemeConfig.h @@ -42,6 +42,7 @@ namespace Skylicht static SGUIColor Black; static SGUIColor WindowBackgroundColor; + static SGUIColor WindowInnerColor; static SGUIColor DefaultTextColor; static SGUIColor DefaultIconColor; static SGUIColor IconPressColor; diff --git a/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.cpp b/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.cpp index ce7a76b58..c39e37cac 100644 --- a/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.cpp +++ b/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.cpp @@ -1294,7 +1294,7 @@ namespace Skylicht flushWithMaterial(material); } - void CGraphics2D::addRectangleBatch(const core::rectf& pos, const SColor& color, const core::matrix4& absoluteTransform, int shaderID, CMaterial *material) + void CGraphics2D::addRectangleBatch(const core::rectf& pos, const core::rectf& uv, const SColor& color, const core::matrix4& absoluteTransform, int shaderID, CMaterial *material) { if (m_2dMaterial.MaterialType != shaderID || material != NULL) flush(); @@ -1314,12 +1314,17 @@ namespace Skylicht index[numIndices + 4] = numVertices + 2; index[numIndices + 5] = numVertices + 3; + float u1 = uv.UpperLeftCorner.X; + float v1 = uv.UpperLeftCorner.Y; + float u2 = uv.LowerRightCorner.X; + float v2 = uv.LowerRightCorner.Y; + m_vertices->set_used(vertexUse); S3DVertex *vertices = (S3DVertex*)m_vertices->getVertices(); - vertices[numVertices + 0] = S3DVertex(pos.UpperLeftCorner.X, pos.UpperLeftCorner.Y, 0.0f, 0.0f, 0.0f, 1.0f, color, 0.0f, 0.0f); - vertices[numVertices + 1] = S3DVertex(pos.LowerRightCorner.X, pos.UpperLeftCorner.Y, 0.0f, 0.0f, 0.0f, 1.0f, color, 1.0f, 0.0f); - vertices[numVertices + 2] = S3DVertex(pos.LowerRightCorner.X, pos.LowerRightCorner.Y, 0.0f, 0.0f, 0.0f, 1.0f, color, 1.0f, 1.0f); - vertices[numVertices + 3] = S3DVertex(pos.UpperLeftCorner.X, pos.LowerRightCorner.Y, 0.0f, 0.0f, 0.0f, 1.0f, color, 0.0f, 1.0f); + vertices[numVertices + 0] = S3DVertex(pos.UpperLeftCorner.X, pos.UpperLeftCorner.Y, 0.0f, 0.0f, 0.0f, 1.0f, color, u1, v1); + vertices[numVertices + 1] = S3DVertex(pos.LowerRightCorner.X, pos.UpperLeftCorner.Y, 0.0f, 0.0f, 0.0f, 1.0f, color, u2, v1); + vertices[numVertices + 2] = S3DVertex(pos.LowerRightCorner.X, pos.LowerRightCorner.Y, 0.0f, 0.0f, 0.0f, 1.0f, color, u2, v2); + vertices[numVertices + 3] = S3DVertex(pos.UpperLeftCorner.X, pos.LowerRightCorner.Y, 0.0f, 0.0f, 0.0f, 1.0f, color, u1, v2); // transform for (int i = 0; i < 4; i++) diff --git a/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.h b/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.h index 640586976..7377741b0 100644 --- a/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.h +++ b/Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.h @@ -144,7 +144,7 @@ namespace Skylicht void addFrameBatch(SFrame *frame, const SColor& color, const core::matrix4& absoluteMatrix, int materialID, CMaterial *material = NULL); - void addRectangleBatch(const core::rectf& pos, const SColor& color, const core::matrix4& absoluteTransform, int shaderID, CMaterial *material = NULL); + void addRectangleBatch(const core::rectf& pos, const core::rectf& uv, const SColor& color, const core::matrix4& absoluteTransform, int shaderID, CMaterial *material = NULL); void beginDrawDepth(); diff --git a/Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIRect.cpp b/Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIRect.cpp index 59cfa6df9..217c100e7 100644 --- a/Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIRect.cpp +++ b/Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIRect.cpp @@ -48,6 +48,7 @@ namespace Skylicht void CGUIRect::render(CCamera *camera) { - CGraphics2D::getInstance()->addRectangleBatch(m_rect, m_color, m_absoluteTransform, m_shaderID, m_material); + core::rectf uv(0.0f, 0.0f, 1.0f, 1.0f); + CGraphics2D::getInstance()->addRectangleBatch(m_rect, uv, m_color, m_absoluteTransform, m_shaderID, m_material); } } \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/Graphics2D/SpriteFrame/CSpriteAtlas.h b/Projects/Skylicht/Engine/Source/Graphics2D/SpriteFrame/CSpriteAtlas.h index 1b5b7f79d..2175d2a6a 100644 --- a/Projects/Skylicht/Engine/Source/Graphics2D/SpriteFrame/CSpriteAtlas.h +++ b/Projects/Skylicht/Engine/Source/Graphics2D/SpriteFrame/CSpriteAtlas.h @@ -56,5 +56,15 @@ namespace Skylicht SImage* createAtlasRect(int w, int h, core::recti& outRegion); void updateTexture(); + + inline int getWidth() + { + return m_width; + } + + inline int getHeight() + { + return m_height; + } }; } \ No newline at end of file