Skip to content

Commit

Permalink
Add a border around the grid to improve visibility and match keynav
Browse files Browse the repository at this point in the history
  • Loading branch information
lesderid committed Jan 25, 2021
1 parent 492b467 commit 236a20a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/keynavish/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import core.sys.windows.windows;
enum windowClassName = "keynavish-grid"w;
enum windowColourKey = RGB(255, 0, 255);

enum penColour = RGB(30, 64, 64);
enum penWidth = 1;
enum mainPenColour = RGB(30, 64, 64);
enum mainPenWidth = 1;
enum borderPenColour = RGB(255, 255, 255);
enum borderPenWidth = 1;

static assert(windowColourKey != penColour, "Colour key and pen colour can't be the same");
static assert(windowColourKey != mainPenColour, "Colour key and main pen colour can't be the same");
static assert(windowColourKey != borderPenColour, "Colour key and border pen colour can't be the same");

enum programName = "keynavish"w;
enum programInfo = programName ~ q"EOS
Expand Down
10 changes: 7 additions & 3 deletions src/keynavish/grid.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ struct Grid
private Grid grid_;
private SList!Grid gridStack;

HPEN pen;
HPEN mainPen;
HPEN borderPen;

@property
Tuple!(int, "width", int, "height") deviceResolution()
Expand Down Expand Up @@ -83,8 +84,6 @@ void paintGrid(HDC deviceContext)
import std.algorithm : map;
import std.range : repeat, join, array;

SelectObject(deviceContext, pen);

auto pointArrays = splitGrid.map!(r => [
POINT(r.left, r.top),
POINT(r.right, r.top),
Expand All @@ -94,5 +93,10 @@ void paintGrid(HDC deviceContext)
]).join;

DWORD[] sizes = uint(5).repeat(pointArrays.length).array;

SelectObject(deviceContext, borderPen);
PolyPolyline(deviceContext, pointArrays.ptr, sizes.ptr, grid.columns * grid.rows);

SelectObject(deviceContext, mainPen);
PolyPolyline(deviceContext, pointArrays.ptr, sizes.ptr, grid.columns * grid.rows);
}
3 changes: 2 additions & 1 deletion src/keynavish/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ static this()
registerWindowClass();
registerKeyboardHook();

pen = CreatePen(PS_SOLID, penWidth, penColour);
mainPen = CreatePen(PS_SOLID, mainPenWidth, mainPenColour);
borderPen = CreatePen(PS_SOLID, borderPenWidth * 2 + mainPenWidth, borderPenColour);
}

extern(C)
Expand Down

0 comments on commit 236a20a

Please sign in to comment.