Skip to content

Commit

Permalink
Merge pull request #8 from Limero/display-dimensions
Browse files Browse the repository at this point in the history
Display dimensions of selection
  • Loading branch information
emersion authored Jul 3, 2018
2 parents 70b6a14 + 22112a6 commit a94273e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct slurp_state {
} colors;

uint32_t border_weight;
bool display_dimensions;

struct slurp_box result;
};
Expand Down
7 changes: 6 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ static const char usage[] =
"Usage: slurp [options...]\n"
"\n"
" -h Show help message and quit.\n"
" -d Display dimensions of selection.\n"
" -b #rrggbb Set background color.\n"
" -c #rrggbb Set border color.\n"
" -s #rrggbb Set selection color.\n"
Expand Down Expand Up @@ -363,14 +364,18 @@ int main(int argc, char *argv[]) {
.selection = 0x00000000,
},
.border_weight = 2,
.display_dimensions = false,
};

int opt;
while ((opt = getopt(argc, argv, "hb:c:s:w:")) != -1) {
while ((opt = getopt(argc, argv, "hdb:c:s:w:")) != -1) {
switch (opt) {
case 'h':
printf("%s", usage);
return EXIT_SUCCESS;
case 'd':
state.display_dimensions = true;
break;
case 'b':
state.colors.background = parse_color(optarg);
break;
Expand Down
11 changes: 11 additions & 0 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,16 @@ void render(struct slurp_output *output) {
cairo_rectangle(cairo, x * scale, y * scale,
width * scale, height * scale);
cairo_stroke(cairo);

if (state->display_dimensions) {
cairo_select_font_face(cairo, "Sans", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cairo, 14 * scale);
// buffer of 12 can hold selections up to 99999x99999
char dimensions[12];
snprintf(dimensions, sizeof(dimensions), "%ix%i", width, height);
cairo_move_to(cairo, (x + width + 10) * scale, (y + height + 20) * scale);
cairo_show_text(cairo, dimensions);
}
}
}
3 changes: 3 additions & 0 deletions slurp.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ select, or click to cancel the selection.
*-h*
Show help message and quit.

*-d*
Display dimensions of selection.

*-b* _color_
Set background color. See *COLORS* for more detail.

Expand Down

0 comments on commit a94273e

Please sign in to comment.