Skip to content

Commit 57dcd27

Browse files
jpcanoc3d
authored andcommitted
Paint navigation arrows in SHOW
This improves the UX in the SHOW command as it indicates to the user that there are more grob to paint in the corresponding direction pointed by the arrows. Authored-by: Jesus Cano <[email protected]> Reviewed-by: Christophe de Dinechin <[email protected]>
1 parent 25b2aaf commit 57dcd27

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

src/graphics.cc

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,88 @@ static coord show_x = 0;
11521152
static coord show_y = 0;
11531153
static coord show_delta = 8;
11541154

1155+
static void draw_show_horizontal_arrow(coord tipx, coord tipy,
1156+
coord size, coord padding,
1157+
bool right, pattern fc, pattern bc)
1158+
// ----------------------------------------------------------------------------
1159+
// Draw a left/right pointing arrow with tip at (tipx, tipy)
1160+
// ----------------------------------------------------------------------------
1161+
// tipx, tipy: Arrow tip coordinates on screen (assuming the padding is 0)
1162+
// size: Arrow size in pixels
1163+
// padding: Extra pixels around the arrow body
1164+
// right: true for a right arrow, false for a left arrow
1165+
// fc: Foreground pattern for the arrow
1166+
// bc: Background pattern behind the arrow
1167+
{
1168+
Screen.fill(right ? tipx - size - 2*padding: tipx,
1169+
tipy - size - padding,
1170+
right ? tipx : tipx + size + 2*padding,
1171+
tipy + size + padding,
1172+
bc);
1173+
for (coord offset = 0; offset < size; offset++)
1174+
{
1175+
coord span = offset + 1;
1176+
coord x = right ? tipx - offset - padding : tipx + offset + padding;
1177+
Screen.fill(x, tipy - span + 1, x, tipy + span - 1, fc);
1178+
}
1179+
}
1180+
1181+
1182+
1183+
static void draw_show_vertical_arrow(coord tipx, coord tipy,
1184+
coord size, coord padding,
1185+
bool down, pattern fc, pattern bc)
1186+
// ----------------------------------------------------------------------------
1187+
// Draw an up/down pointing arrow with tip at (tipx, tipy)
1188+
// ----------------------------------------------------------------------------
1189+
// tipx, tipy: Arrow tip coordinates on screen (assuming padding is 0)
1190+
// size: Arrow size in pixels
1191+
// padding: Extra pixels around the arrow body
1192+
// down: true for a down arrow, false for an up arrow
1193+
// fc: Foreground pattern for the arrow
1194+
// bc: Background pattern behind the arrow
1195+
{
1196+
Screen.fill(tipx - size - padding,
1197+
down ? tipy - size - 2*padding : tipy,
1198+
tipx + size + padding,
1199+
down ? tipy : tipy + size + 2*padding,
1200+
bc);
1201+
for (coord offset = 0; offset < size; offset++)
1202+
{
1203+
coord span = offset + 1;
1204+
coord y = down ? tipy - offset - padding : tipy + offset + padding;
1205+
Screen.fill(tipx - span + 1, y, tipx + span - 1, y, fc);
1206+
}
1207+
}
1208+
1209+
1210+
static void draw_show_arrows(grob::pixsize width, grob::pixsize height)
1211+
// ----------------------------------------------------------------------------
1212+
// Render navigation arrows if the grob object is bigger than the display
1213+
// ----------------------------------------------------------------------------
1214+
// width, height: Size of the full grob being shown
1215+
{
1216+
auto fc = Settings.Foreground();
1217+
auto bc = pattern::gray90;
1218+
const coord arrow_size = 6;
1219+
const coord arrow_padding = 2;
1220+
coord midx = LCD_W / 2;
1221+
coord midy = LCD_H / 2;
1222+
1223+
if (show_x > 0)
1224+
draw_show_horizontal_arrow(0, midy, arrow_size, arrow_padding,
1225+
false, fc, bc);
1226+
if (show_x + LCD_W < coord(width))
1227+
draw_show_horizontal_arrow(LCD_W - 1, midy, arrow_size, arrow_padding,
1228+
true, fc, bc);
1229+
if (show_y > 0)
1230+
draw_show_vertical_arrow(midx, 0, arrow_size, arrow_padding,
1231+
false, fc, bc);
1232+
if (show_y + LCD_H < coord(height))
1233+
draw_show_vertical_arrow(midx, LCD_H - 1, arrow_size, arrow_padding,
1234+
true, fc, bc);
1235+
}
1236+
11551237

11561238
void show_grob(grob_p graph)
11571239
// ----------------------------------------------------------------------------
@@ -1179,6 +1261,7 @@ void show_grob(grob_p graph)
11791261
grob::surface s = graph->pixels();
11801262
Screen.copy(s, r, point(show_x,show_y));
11811263
}
1264+
draw_show_arrows(width, height);
11821265
mark_dirty(0, 0, LCD_W-1, LCD_H-1);
11831266
refresh_dirty();
11841267
}

0 commit comments

Comments
 (0)