Skip to content

Commit 58927f5

Browse files
committed
#158 Update ruler bar, calc mouse position, fix build error on MacOS
1 parent 85be60a commit 58927f5

File tree

7 files changed

+80
-15
lines changed

7 files changed

+80
-15
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ endif()
7676
if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
7777
set(BUILD_MACOS ON)
7878
set(XCODE ON)
79+
set(USE_OPENMP OFF)
80+
7981
add_definitions(-DMACOS)
8082

8183
set(CMAKE_CXX_STANDARD 14)

Projects/Editor/Source/Editor/Space/GUIDesign/CSpaceGUIDesign.cpp

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace Skylicht
3131
{
3232
namespace Editor
3333
{
34-
const float LeftOffset = 40.0f;
34+
const float LeftOffset = 40.0f;// == size the height TOP Ruler
3535

3636
CSpaceGUIDesign::CSpaceGUIDesign(GUI::CWindow* window, CEditor* editor) :
3737
CSpace(window, editor),
@@ -42,6 +42,8 @@ namespace Skylicht
4242
m_viewY(0.0f),
4343
m_pressX(0.0f),
4444
m_pressY(0.0f),
45+
m_mouseGUIX(0.0f),
46+
m_mouseGUIY(0.0f),
4547
m_middleDrag(false),
4648
m_scene(NULL),
4749
m_guiCamera(NULL)
@@ -62,30 +64,35 @@ namespace Skylicht
6264
m_toolBar->addButton(GUI::ESystemIcon::Copy);
6365
m_toolBar->addButton(GUI::ESystemIcon::Paste);
6466

67+
m_textMousePos = new GUI::CLabel(m_toolBar);
68+
m_toolBar->addControl(m_textMousePos, true);
69+
m_textMousePos->setPadding(GUI::SPadding(0.0f, 3.0f, 0.0f, 0.0f));
70+
m_textMousePos->setString(L"(0, 0)");
71+
m_textMousePos->setTextAlignment(GUI::TextCenter);
72+
m_textMousePos->setWidth(90.0f);
73+
6574
m_textZoom = new GUI::CLabel(m_toolBar);
6675
m_toolBar->addControl(m_textZoom, true);
6776
m_textZoom->setPadding(GUI::SPadding(0.0f, 3.0f, 0.0f, 0.0f));
6877
m_textZoom->setString(L"Zoom: 100%");
6978
m_textZoom->sizeToContents();
7079

7180
m_leftRuler = new GUI::CRulerBar(window, false);
72-
m_leftRuler->setHeight(100.0f);
73-
m_leftRuler->setBeginOffset(LeftOffset);
81+
m_leftRuler->setWidth(60.0f);
7482
m_leftRuler->setPixelPerUnit(10.0f);
7583

7684
m_topRuler = new GUI::CRulerBar(window, true);
77-
m_topRuler->setWidth(200.0f);
7885
m_topRuler->setPixelPerUnit(10.0f);
7986

8087
m_leftRuler->setUnitScale(10.0f);
8188
m_topRuler->setUnitScale(10.0f);
8289

83-
m_leftRuler->setPosition(0.0f);
84-
m_topRuler->setPosition(0.0f);
85-
8690
m_topRuler->setBeginOffset(0.0f);
8791
m_leftRuler->setBeginOffset(LeftOffset);
8892

93+
m_topRuler->enableDrawCursorline(true);
94+
m_leftRuler->enableDrawCursorline(true);
95+
8996
m_view = new GUI::CBase(window);
9097
m_view->dock(GUI::EPosition::Fill);
9198
m_view->enableRenderFillRect(true);
@@ -149,8 +156,8 @@ namespace Skylicht
149156
float dx = x - m_pressX;
150157
float dy = y - m_pressY;
151158

152-
m_topRuler->setBeginOffset(0.0f + m_viewX * m_guiScale + dx);
153-
m_leftRuler->setBeginOffset(LeftOffset + m_viewY * m_guiScale + dy);
159+
m_topRuler->setPosition(-(m_viewX * m_guiScale + dx));
160+
m_leftRuler->setPosition(-(m_viewY * m_guiScale + dy));
154161

155162
if (m_scene)
156163
{
@@ -164,6 +171,26 @@ namespace Skylicht
164171
);
165172
}
166173
}
174+
175+
// check the mouse position
176+
GUI::SPoint localPos = view->canvasPosToLocal(GUI::SPoint(x, y));
177+
wchar_t mouseText[512];
178+
179+
float mx = localPos.X - m_viewX * m_guiScale;
180+
float my = localPos.Y - m_viewY * m_guiScale;
181+
m_mouseGUIX = mx / m_guiScale;
182+
m_mouseGUIY = my / m_guiScale;
183+
184+
swprintf(
185+
mouseText, 512,
186+
L"(%d, %d)",
187+
(int)m_mouseGUIX,
188+
(int)m_mouseGUIY
189+
);
190+
m_textMousePos->setString(std::wstring(mouseText));
191+
192+
m_topRuler->setCursorPosition(mx);
193+
m_leftRuler->setCursorPosition(my);
167194
}
168195

169196
void CSpaceGUIDesign::onMouseWheel(GUI::CBase* scroll, int delta)
@@ -228,8 +255,8 @@ namespace Skylicht
228255
m_viewX = m_viewX - dx;
229256
m_viewY = m_viewY - dy;
230257

231-
m_topRuler->setBeginOffset(0.0f + m_viewX * m_guiScale);
232-
m_leftRuler->setBeginOffset(LeftOffset + m_viewY * m_guiScale);
258+
m_topRuler->setPosition(-m_viewX * m_guiScale);
259+
m_leftRuler->setPosition(-m_viewY * m_guiScale);
233260
}
234261

235262
if (m_scene)
@@ -266,8 +293,8 @@ namespace Skylicht
266293
m_viewX = m_viewX - dx;
267294
m_viewY = m_viewY - dy;
268295

269-
m_topRuler->setBeginOffset(0.0f + m_viewX * m_guiScale);
270-
m_leftRuler->setBeginOffset(LeftOffset + m_viewY * m_guiScale);
296+
m_topRuler->setPosition(-m_viewX * m_guiScale);
297+
m_leftRuler->setPosition(-m_viewY * m_guiScale);
271298
}
272299

273300
if (m_scene)

Projects/Editor/Source/Editor/Space/GUIDesign/CSpaceGUIDesign.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace Skylicht
4040
GUI::CBase* m_view;
4141

4242
GUI::CLabel* m_textZoom;
43+
GUI::CLabel* m_textMousePos;
4344

4445
float m_guiWidth;
4546
float m_guiHeight;
@@ -50,6 +51,9 @@ namespace Skylicht
5051
float m_viewX;
5152
float m_viewY;
5253

54+
float m_mouseGUIX;
55+
float m_mouseGUIY;
56+
5357
bool m_middleDrag;
5458

5559
CScene* m_scene;

Projects/Editor/Source/GUI/Controls/CRulerBar.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ namespace Skylicht
3939
m_position(0.0f),
4040
m_pixelPerUnit(5.0f),
4141
m_unitScale(1.0f),
42-
m_textPerUnit(10)
42+
m_textPerUnit(10),
43+
m_cursorPosition(0.0f),
44+
m_drawCursorLine(false)
4345
{
4446
if (m_isHorizontal)
4547
{
@@ -74,7 +76,10 @@ namespace Skylicht
7476
float size3 = 15.0f; // 5
7577
float size4 = 30.0f; // 10
7678

79+
// convert the position to unity
7780
int unit = (int)(m_position / m_pixelPerUnit);
81+
82+
// begin unit from m_position (round)
7883
float offset = m_position - unit * m_pixelPerUnit;
7984

8085
SGUIColor& lineColor = CThemeConfig::RulerLine1;
@@ -122,6 +127,12 @@ namespace Skylicht
122127
x = x + m_pixelPerUnit;
123128
unit++;
124129
}
130+
131+
if (m_drawCursorLine)
132+
{
133+
float x = m_beginOffset - m_position + m_cursorPosition;
134+
renderer->drawLineY(x, 0.0f, size4, CThemeConfig::RulerCursor);
135+
}
125136
}
126137
else
127138
{
@@ -158,13 +169,19 @@ namespace Skylicht
158169
r.Y = y;
159170
r.Width = 20.0f;
160171
r.Height = 20.0f;
161-
swprintf(textValue, 64, L"%d", unit);
172+
swprintf(textValue, 64, L"%d", (int)(unit * m_unitScale));
162173
renderer->renderText(r, SizeNormal, CThemeConfig::DefaultTextColor, std::wstring(textValue));
163174
}
164175

165176
y = y + m_pixelPerUnit;
166177
unit++;
167178
}
179+
180+
if (m_drawCursorLine)
181+
{
182+
float y = m_beginOffset - m_position + m_cursorPosition;
183+
renderer->drawLineX(0.0f, y, size4, CThemeConfig::RulerCursor);
184+
}
168185
}
169186
}
170187

Projects/Editor/Source/GUI/Controls/CRulerBar.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ namespace Skylicht
4242
float m_unitScale;
4343
int m_textPerUnit;
4444

45+
float m_cursorPosition;
46+
bool m_drawCursorLine;
47+
4548
public:
4649
std::function<void(float x, float y, bool down, float value)> OnMouseClickLeftValue;
4750
std::function<void(float x, float y, bool down, float value)> OnMouseClickRightValue;
@@ -101,6 +104,16 @@ namespace Skylicht
101104
{
102105
return m_pixelPerUnit;
103106
}
107+
108+
inline void enableDrawCursorline(bool b)
109+
{
110+
m_drawCursorLine = b;
111+
}
112+
113+
inline void setCursorPosition(float p)
114+
{
115+
m_cursorPosition = p;
116+
}
104117
};
105118
}
106119
}

Projects/Editor/Source/GUI/Theme/CThemeConfig.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ namespace Skylicht
103103
SGUIColor CThemeConfig::RulerLine1 = SGUIColor(255, 70, 70, 70);
104104
SGUIColor CThemeConfig::RulerLine2 = SGUIColor(255, 100, 100, 100);
105105
SGUIColor CThemeConfig::RulerLine3 = SGUIColor(255, 140, 140, 140);
106+
SGUIColor CThemeConfig::RulerCursor = SGUIColor(255, 80, 120, 180);
106107

107108
SGUIColor CThemeConfig::Timeline = SGUIColor(255, 60, 60, 60);
108109
SGUIColor CThemeConfig::TimelineItemBG = SGUIColor(255, 35, 35, 35);

Projects/Editor/Source/GUI/Theme/CThemeConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ namespace Skylicht
107107
static SGUIColor RulerLine1;
108108
static SGUIColor RulerLine2;
109109
static SGUIColor RulerLine3;
110+
static SGUIColor RulerCursor;
110111
static SGUIColor Timeline;
111112
static SGUIColor TimelineItemBG;
112113
static SGUIColor TimelineItemBorder;

0 commit comments

Comments
 (0)