Skip to content

Commit

Permalink
DRY-ed the cursor drawing to use a common function (#187)
Browse files Browse the repository at this point in the history
DRY-ed the cursor drawing to use a common function
  • Loading branch information
realSquidCoder authored Feb 10, 2025
1 parent 9f5aa0f commit 9bc4002
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 9bc4002

Please sign in to comment.