Skip to content

Commit 9856c1b

Browse files
committed
Separate selection handling from EditorApp and refactor
1 parent 5c5f69c commit 9856c1b

File tree

6 files changed

+411
-174
lines changed

6 files changed

+411
-174
lines changed

Editor/EditorApp.cpp

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -292,74 +292,6 @@ namespace RTEGUI {
292292
return (mousePosX >= xPos && mousePosX <= xPos + width && mousePosY >= yPos && mousePosY <= yPos + height) ? true : false;
293293
}
294294

295-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
296-
297-
void EditorApp::CalculateHandleResize(int mousePosX, int mousePosY, int *xPos, int *yPos, int *width, int *height) {
298-
int controlPosX;
299-
int controlPosY;
300-
int controlWidth;
301-
int controlHeight;
302-
m_SelectionInfo.Control->GetControlRect(&controlPosX, &controlPosY, &controlWidth, &controlHeight);
303-
GUIControl *parent = m_SelectionInfo.Control->GetParent();
304-
305-
int minSize = 5;
306-
307-
int parentPosX;
308-
int parentPosY;
309-
int parentWidth;
310-
int parentHeight;
311-
parent->GetControlRect(&parentPosX, &parentPosY, &parentWidth, &parentHeight);
312-
313-
// Left Move/Resize
314-
if (m_SelectionInfo.HandleIndex == 0 || m_SelectionInfo.HandleIndex == 3 || m_SelectionInfo.HandleIndex == 6) {
315-
int diff = mousePosX - m_SelectionInfo.GrabX;
316-
if (controlPosX + diff < parentPosX) { diff = parentPosX - controlPosX; }
317-
if (controlWidth - diff < minSize) { diff = controlWidth - minSize; }
318-
319-
diff = ProcessSnapCoord(diff);
320-
321-
controlPosX += diff;
322-
controlWidth -= diff;
323-
}
324-
// Top Move/Resize
325-
if (m_SelectionInfo.HandleIndex == 0 || m_SelectionInfo.HandleIndex == 1 || m_SelectionInfo.HandleIndex == 2) {
326-
int diff = mousePosY - m_SelectionInfo.GrabY;
327-
if (controlPosY + diff < parentPosY) { diff = parentPosY - controlPosY; }
328-
if (controlHeight - diff < minSize) { diff = controlHeight - minSize; }
329-
330-
diff = ProcessSnapCoord(diff);
331-
332-
controlPosY += diff;
333-
controlHeight -= diff;
334-
}
335-
// Right Resize
336-
if (m_SelectionInfo.HandleIndex == 2 || m_SelectionInfo.HandleIndex == 5 || m_SelectionInfo.HandleIndex == 8) {
337-
int diff = mousePosX - m_SelectionInfo.GrabX;
338-
if (controlPosX + controlWidth + diff > parentPosX + parentWidth) { diff = (parentPosX + parentWidth) - (controlPosX + controlWidth); }
339-
340-
diff = ProcessSnapCoord(diff);
341-
342-
controlWidth += diff;
343-
}
344-
// Bottom Resize
345-
if (m_SelectionInfo.HandleIndex == 6 || m_SelectionInfo.HandleIndex == 7 || m_SelectionInfo.HandleIndex == 8) {
346-
int diff = mousePosY - m_SelectionInfo.GrabY;
347-
if (controlPosY + controlHeight + diff > parentPosY + parentHeight) { diff = (parentPosY + parentHeight) - (controlPosY + controlHeight); }
348-
349-
diff = ProcessSnapCoord(diff);
350-
351-
controlHeight += diff;
352-
}
353-
354-
controlWidth = std::max(controlWidth, minSize);
355-
controlHeight = std::max(controlHeight, minSize);
356-
357-
*xPos = controlPosX;
358-
*yPos = controlPosY;
359-
*width = controlWidth;
360-
*height = controlHeight;
361-
}
362-
363295
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
364296

365297
int EditorApp::ProcessSnapCoord(int position) const {
@@ -696,52 +628,9 @@ namespace RTEGUI {
696628

697629
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
698630

699-
void EditorApp::DrawSelectionBox(GUIControl *control) {
700-
assert(control);
701-
702-
int mousePosX;
703-
int mousePosY;
704-
m_Input->GetMousePosition(&mousePosX, &mousePosY);
705-
706-
int controlPosX;
707-
int controlPosY;
708-
int controlWidth;
709-
int controlHeight;
710-
control->GetControlRect(&controlPosX, &controlPosY, &controlWidth, &controlHeight);
711-
712-
// If we've grabbed the control, draw the selection lines where the mouse is
713-
if (m_SelectionInfo.GrabbedControl && m_SelectionInfo.TriggerGrab) {
714-
controlPosX = mousePosX + m_SelectionInfo.GrabX;
715-
controlPosY = mousePosY + m_SelectionInfo.GrabY;
716-
717-
controlPosX = ProcessSnapCoord(controlPosX);
718-
controlPosY = ProcessSnapCoord(controlPosY);
719631
}
720632

721-
// Grabbed handles
722-
if (m_SelectionInfo.GrabbedHandle && m_SelectionInfo.TriggerGrab) { CalculateHandleResize(mousePosX, mousePosY, &controlPosX, &controlPosY, &controlWidth, &controlHeight); }
723-
724-
GUIRect rect;
725-
SetRect(&rect, controlPosX - 6, controlPosY - 6, controlPosX + controlWidth + 6, controlPosY + controlHeight + 6);
726-
m_Screen->GetBitmap()->SetClipRect(&rect);
727-
728-
m_Screen->GetBitmap()->DrawRectangle(controlPosX, controlPosY, controlWidth, controlHeight, 0xFFCCCCCC, false);
729-
730-
// Draw the handles
731-
for (int i = 0; i < 3; i++) {
732-
DrawSelectionResizeBox(controlPosX, controlPosY + i * (controlHeight / 2));
733-
if (i != 1) { DrawSelectionResizeBox(controlPosX + controlWidth / 2, controlPosY + i * (controlHeight / 2)); }
734-
DrawSelectionResizeBox(controlPosX + controlWidth, controlPosY + i * (controlHeight / 2));
735-
}
736-
m_Screen->GetBitmap()->SetClipRect(nullptr);
737-
}
738-
739-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
740633

741-
void EditorApp::DrawSelectionResizeBox(int xPos, int yPos) const {
742-
int boxSize = (m_Zoom) ? 5 : 7;
743-
m_Screen->GetBitmap()->DrawRectangle(xPos - boxSize / 2, yPos - boxSize / 2, boxSize, boxSize, 0x000000, true);
744-
m_Screen->GetBitmap()->DrawRectangle(xPos - boxSize / 2, yPos - boxSize / 2, boxSize, boxSize, 0xFFFFFF, false);
745634
}
746635

747636
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Editor/EditorApp.h

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -86,35 +86,6 @@ namespace RTEGUI {
8686

8787
private:
8888

89-
/// <summary>
90-
/// GUI element selection structure.
91-
/// </summary>
92-
struct Selection {
93-
bool GrabbedControl = false;
94-
bool GrabbedHandle = false;
95-
bool TriggerGrab = false;
96-
97-
GUIControl *Control = nullptr;
98-
int HandleIndex = 0;
99-
100-
int GrabX = 0;
101-
int GrabY = 0;
102-
int ClickX = 0;
103-
int ClickY = 0;
104-
105-
/// <summary>
106-
/// Clears selection info.
107-
/// </summary>
108-
void ClearSelection() {
109-
GrabbedControl = false;
110-
GrabbedHandle = false;
111-
TriggerGrab = false;
112-
Control = nullptr;
113-
HandleIndex = 0;
114-
GrabX = 0;
115-
GrabY = 0;
116-
}
117-
};
11889

11990
bool m_Quit = false;
12091
bool m_WindowResized = false;
@@ -143,9 +114,7 @@ namespace RTEGUI {
143114

144115
// Editor setup
145116
bool m_UnsavedChanges = false;
146-
bool m_SnapToGrid = true;
147117
bool m_Zoom = false;
148-
int m_GridSize = 5;
149118
int m_WorkspacePosX = 320;
150119
int m_WorkspacePosY = 60;
151120
int m_WorkspaceWidth = 640;
@@ -208,23 +177,6 @@ namespace RTEGUI {
208177
/// <returns>True/False.</returns>
209178
bool MouseInsideBox(int mousePosX, int mousePosY, int xPos, int yPos, int width, int height) const;
210179

211-
/// <summary>
212-
/// Calculates new position/size of a control given a handle movement.
213-
/// </summary>
214-
/// <param name="MouseX">Mouse.</param>
215-
/// <param name="MouseY"></param>
216-
/// <param name="X">Position.</param>
217-
/// <param name="Y"></param>
218-
/// <param name="Width">Size.</param>
219-
/// <param name="Height"></param>
220-
void CalculateHandleResize(int mousePosX, int mousePosY, int *xPos, int *yPos, int *width, int *height);
221-
222-
/// <summary>
223-
/// Calculates the nearest snap position (if snap is on).
224-
/// </summary>
225-
/// <param name="Position">Position.</param>
226-
/// <returns></returns>
227-
int ProcessSnapCoord(int position) const;
228180

229181
#pragma region GUI Element Creation
230182
/// <summary>
@@ -279,21 +231,6 @@ namespace RTEGUI {
279231
void ProcessKeyboardInput();
280232
#pragma endregion
281233

282-
#pragma region Drawing
283-
/// <summary>
284-
/// Draws the selection box around the selected control.
285-
/// </summary>
286-
/// <param name="Control">GUI element to draw selection box around.</param>
287-
void DrawSelectionBox(GUIControl *control);
288-
289-
/// <summary>
290-
/// Draws a selection box resize handle.
291-
/// </summary>
292-
/// <param name="X">X position of drawn box.</param>
293-
/// <param name="Y">Y position of drawn box.</param>
294-
void DrawSelectionResizeBox(int xPos, int yPos) const;
295-
#pragma endregion
296-
297234
// Disallow the use of some implicit methods.
298235
EditorApp(const EditorApp &reference) = delete;
299236
EditorApp &operator=(const EditorApp &rhs) = delete;

0 commit comments

Comments
 (0)