From 9bc40021b3673f59393e4c718949b5575599f01f Mon Sep 17 00:00:00 2001 From: Squid Coder <92821989+realSquidCoder@users.noreply.github.com> Date: Sun, 9 Feb 2025 19:45:42 -0600 Subject: [PATCH] DRY-ed the cursor drawing to use a common function (#187) DRY-ed the cursor drawing to use a common function --- GUI.cpp | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/GUI.cpp b/GUI.cpp index 74726878..6610d762 100644 --- a/GUI.cpp +++ b/GUI.cpp @@ -484,24 +484,18 @@ void DrawCurrentLevelOutline(bool backPart) namespace { - void drawSelectionCursor(WorldSegment* segment) + void drawCursorAt(WorldSegment* segment, Crd3D& cursor, const ALLEGRO_COLOR& color) { auto& ssConfig = stonesenseState.ssConfig; + segment->CorrectTileForSegmentOffset(cursor.x, cursor.y, cursor.z); + segment->CorrectTileForSegmentRotation(cursor.x, cursor.y, cursor.z); - Crd3D selection = segment->segState.dfSelection; - if ((selection.x != -30000 && ssConfig.config.follow_DFcursor)) { - segment->CorrectTileForSegmentOffset(selection.x, selection.y, selection.z); - segment->CorrectTileForSegmentRotation(selection.x, selection.y, selection.z); - } - else { - return; - } - Crd2D point = LocalTileToScreen(selection.x, selection.y, selection.z); + Crd2D point = LocalTileToScreen(cursor.x, cursor.y, cursor.z); int sheetx = SPRITEOBJECT_CURSOR % SHEET_OBJECTSWIDE; int sheety = SPRITEOBJECT_CURSOR / SHEET_OBJECTSWIDE; al_draw_tinted_scaled_bitmap( stonesenseState.IMGObjectSheet, - uiColor(3), + color, sheetx * SPRITEWIDTH, sheety * SPRITEHEIGHT, SPRITEWIDTH, @@ -513,29 +507,22 @@ namespace 0); } - void drawDebugCursor(WorldSegment* segment) + void drawSelectionCursor(WorldSegment* segment) { auto& ssConfig = stonesenseState.ssConfig; + Crd3D& selection = segment->segState.dfSelection; + if ((selection.x != -30000 && ssConfig.config.follow_DFcursor)) { + drawCursorAt(segment, selection, uiColor(3)); + } + else { + return; + } + } - Crd3D cursor = segment->segState.dfCursor; - segment->CorrectTileForSegmentOffset(cursor.x, cursor.y, cursor.z); - segment->CorrectTileForSegmentRotation(cursor.x, cursor.y, cursor.z); - - Crd2D point = LocalTileToScreen(cursor.x, cursor.y, cursor.z); - int sheetx = SPRITEOBJECT_CURSOR % SHEET_OBJECTSWIDE; - int sheety = SPRITEOBJECT_CURSOR / SHEET_OBJECTSWIDE; - al_draw_tinted_scaled_bitmap( - stonesenseState.IMGObjectSheet, - uiColor(2), - sheetx * SPRITEWIDTH, - sheety * SPRITEHEIGHT, - SPRITEWIDTH, - SPRITEHEIGHT, - point.x - ((SPRITEWIDTH / 2) * ssConfig.scale), - point.y - (WALLHEIGHT)*ssConfig.scale, - SPRITEWIDTH * ssConfig.scale, - SPRITEHEIGHT * ssConfig.scale, - 0); + void drawDebugCursor(WorldSegment* segment) + { + Crd3D& cursor = segment->segState.dfCursor; + drawCursorAt(segment, cursor, uiColor(2)); } void drawAdvmodeMenuTalk(const ALLEGRO_FONT* font, int x, int y)