Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ arcs with a certain `radius`, if these segments exceed a length of

"ortho line" = ORTHOGONAL (color="red" size=5 simplify=15 radius=20 minlen=50 snap=40);

A `FRAME`-tool that draws predefined frames centered around the clicked location. Border width is taken from `size`. `color` is defined as usual. `xlength` (width) and `ylength` (height) are mandatory, `fill` color and corner `radius` are optional.
It allows for drawing rectangles (with slightly rounded corners) as well as circles/dots:

![FRAME tool](data/tool-frame.gif)

"magenta square empty" = FRAME (size=10 color="magenta" xlength=100 ylength=100 radius=0);
"yellow circle filled" = FRAME (size=5 color="yellow" fillcolor="rgba(255, 255, 0, 0.5)" xlength=50 ylength=50 radius=25);

If you define a tool with the same name as an input-device
(see the output of `xinput --list`) this input-device uses this tool:

Expand Down
Binary file added data/tool-frame.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 20 additions & 6 deletions src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ void on_monitors_changed ( GdkScreen *screen,
parse_config(data); // also calls paint_context_new() :-(


data->default_pen = paint_context_new (data, GROMIT_PEN, data->red, 7, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 1, 0, G_MAXUINT);
data->default_eraser = paint_context_new (data, GROMIT_ERASER, data->red, 75, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 1, 0, G_MAXUINT);
data->default_pen = paint_context_new (data, GROMIT_PEN, data->red, NULL, 7, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 1, 0, 0, 0, G_MAXUINT);
data->default_eraser = paint_context_new (data, GROMIT_ERASER, data->red, NULL, 75, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 1, 0, 0, 0, G_MAXUINT);

if(!data->composited) // set shape
{
Expand Down Expand Up @@ -301,6 +301,14 @@ gboolean on_buttonpress (GtkWidget *win,
if(data->maxwidth > devdata->cur_context->maxwidth)
data->maxwidth = devdata->cur_context->maxwidth;


if (type == GROMIT_FRAME)
{
GromitPaintContext *ctx = devdata->cur_context;
draw_frame(data, ev->device, ev->x, ev->y, ctx->xlength, ctx->ylength, ctx->radius, ctx->width, ctx->fill_color);
return TRUE;
}

if (ev->button <= 5)
draw_line (data, ev->device, ev->x, ev->y, ev->x, ev->y);

Expand Down Expand Up @@ -334,6 +342,9 @@ gboolean on_motion (GtkWidget *win,

GromitPaintType type = devdata->cur_context->type;

if(type == GROMIT_FRAME)
return FALSE;

gdk_device_get_history (ev->device, ev->window,
devdata->motion_time, ev->time,
&coords, &nevents);
Expand Down Expand Up @@ -461,6 +472,9 @@ gboolean on_buttonrelease (GtkWidget *win,

GromitPaintType type = ctx->type;

if(type == GROMIT_FRAME)
return FALSE;

if (type == GROMIT_SMOOTH || type == GROMIT_ORTHOGONAL)
{
gboolean joined = FALSE;
Expand Down Expand Up @@ -644,8 +658,8 @@ void on_mainapp_selection_received (GtkWidget *widget,
"Keeping default.\n");
}
GromitPaintContext* line_ctx =
paint_context_new(data, GROMIT_PEN, fg_color, thickness, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 0, thickness, thickness);
paint_context_new(data, GROMIT_PEN, fg_color, NULL, thickness, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 0, 0, 0, thickness, thickness);

GdkRectangle rect;
rect.x = MIN (startX,endX) - thickness / 2;
Expand Down
61 changes: 58 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ enum tool_arguments {
SYM_RADIUS,
SYM_SIMPLIFY,
SYM_SNAP,
SYM_XLENGTH,
SYM_YLENGTH,
SYM_FILLCOLOR,
};

/*
Expand Down Expand Up @@ -162,10 +165,11 @@ gboolean parse_config (GromitData *data)
gchar *name, *copy;

GromitPaintType type;
GdkRGBA *fg_color=NULL;
GdkRGBA *fg_color=NULL, *fill_color=NULL;
guint width, minwidth, maxwidth;
gfloat arrowsize;
guint minlen, maxangle, radius, simplify, snapdist;
guint xlength, ylength;
GromitArrowType arrowtype;

/* try user config location */
Expand Down Expand Up @@ -212,6 +216,7 @@ gboolean parse_config (GromitData *data)
g_scanner_scope_add_symbol (scanner, 0, "PEN", (gpointer) GROMIT_PEN);
g_scanner_scope_add_symbol (scanner, 0, "LINE", (gpointer) GROMIT_LINE);
g_scanner_scope_add_symbol (scanner, 0, "RECT", (gpointer) GROMIT_RECT);
g_scanner_scope_add_symbol (scanner, 0, "FRAME", (gpointer) GROMIT_FRAME);
g_scanner_scope_add_symbol (scanner, 0, "SMOOTH", (gpointer) GROMIT_SMOOTH);
g_scanner_scope_add_symbol (scanner, 0, "ORTHOGONAL",(gpointer) GROMIT_ORTHOGONAL);
g_scanner_scope_add_symbol (scanner, 0, "ERASER", (gpointer) GROMIT_ERASER);
Expand Down Expand Up @@ -240,6 +245,9 @@ gboolean parse_config (GromitData *data)
g_scanner_scope_add_symbol (scanner, 2, "minlen", (gpointer) SYM_MINLEN);
g_scanner_scope_add_symbol (scanner, 2, "simplify", (gpointer) SYM_SIMPLIFY);
g_scanner_scope_add_symbol (scanner, 2, "snap", (gpointer) SYM_SNAP);
g_scanner_scope_add_symbol (scanner, 2, "xlength", (gpointer) SYM_XLENGTH);
g_scanner_scope_add_symbol (scanner, 2, "ylength", (gpointer) SYM_YLENGTH);
g_scanner_scope_add_symbol (scanner, 2, "fillcolor", (gpointer) SYM_FILLCOLOR);

g_scanner_set_scope (scanner, 0);
scanner->config->scope_0_fallback = 0;
Expand Down Expand Up @@ -283,7 +291,10 @@ gboolean parse_config (GromitData *data)
maxangle = 15;
simplify = 10;
snapdist = 0;
xlength = 0;
ylength = 0;
fg_color = data->red;
fill_color = data->transparent;

if (token == G_TOKEN_SYMBOL)
{
Expand All @@ -310,7 +321,10 @@ gboolean parse_config (GromitData *data)
snapdist = context_template->snapdist;
minwidth = context_template->minwidth;
maxwidth = context_template->maxwidth;
xlength = context_template->xlength;
ylength = context_template->ylength;
fg_color = context_template->paint_color;
fill_color = context_template->fill_color;
}
else
{
Expand Down Expand Up @@ -449,7 +463,47 @@ gboolean parse_config (GromitData *data)
if (isnan(v)) goto cleanup;
snapdist = v;
}
else
else if ((intptr_t) scanner->value.v_symbol == SYM_XLENGTH)
{
gfloat v = parse_get_float(scanner, "Missing xlength (float)");
if (isnan(v)) goto cleanup;
xlength = v;
}
else if ((intptr_t) scanner->value.v_symbol == SYM_YLENGTH)
{
gfloat v = parse_get_float(scanner, "Missing ylength (float)");
if (isnan(v)) goto cleanup;
ylength = v;
}
else if ((intptr_t) scanner->value.v_symbol == SYM_FILLCOLOR)
{
token = g_scanner_get_next_token (scanner);
if (token != G_TOKEN_EQUAL_SIGN)
{
g_printerr ("Missing \"=\"... aborting\n");
goto cleanup;
}
token = g_scanner_get_next_token (scanner);
if (token != G_TOKEN_STRING)
{
g_printerr ("Missing fillcolor (string)... "
"aborting\n");
goto cleanup;
}
color = g_malloc (sizeof (GdkRGBA));
if (gdk_rgba_parse (color, scanner->value.v_string))
{
fill_color = color;
}
else
{
g_printerr ("Unable to parse fillcolor. "
"Keeping default.\n");
g_free (color);
}
color = NULL;
}
else
{
g_printerr ("Unknown tool type?????\n");
}
Expand All @@ -474,9 +528,10 @@ gboolean parse_config (GromitData *data)
goto cleanup;
}

context = paint_context_new (data, type, fg_color, width,
context = paint_context_new (data, type, fg_color, fill_color, width,
arrowsize, arrowtype,
simplify, radius, maxangle, minlen, snapdist,
xlength, ylength,
minwidth, maxwidth);
g_hash_table_insert (data->tool_config, name, context);
}
Expand Down
48 changes: 48 additions & 0 deletions src/drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,51 @@ void draw_arrow (GromitData *data,
data->painted = 1;
}

void draw_frame (GromitData *data,
GdkDevice *dev,
gint x, gint y,
gint xlength, gint ylength,
gint radius, gint strokewidth,
GdkRGBA *fill_color)
{
GdkRectangle rect;
GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev);

x = x - xlength/2 + 1;
y = y - ylength/2 + 1;

rect.x = x - strokewidth;
rect.y = y - strokewidth;
rect.width = xlength + strokewidth*2;
rect.height = ylength + strokewidth*2;

if (radius > MIN (xlength, ylength) / 2)
radius = MIN (xlength, ylength) / 2;

if(data->debug)
g_printerr("DEBUG: draw frame with center %d, %d, width %d, height %d, corner radius %d and fill color %s\n", x, y, xlength, ylength, radius, gdk_rgba_to_string(fill_color));

if (devdata->cur_context->paint_ctx)
{
double degrees = M_PI / 180.0;
cairo_new_sub_path(devdata->cur_context->paint_ctx);
cairo_arc(devdata->cur_context->paint_ctx, x + xlength - radius, y + radius, radius, -90 * degrees, 0 * degrees);
cairo_arc(devdata->cur_context->paint_ctx, x + xlength - radius, y + ylength - radius, radius, 0 * degrees, 90 * degrees);
cairo_arc(devdata->cur_context->paint_ctx, x + radius, y + ylength - radius, radius, 90 * degrees, 180 * degrees);
cairo_arc(devdata->cur_context->paint_ctx, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
cairo_close_path(devdata->cur_context->paint_ctx);
if (fill_color)
{
gdk_cairo_set_source_rgba(devdata->cur_context->paint_ctx, devdata->cur_context->fill_color);
cairo_fill_preserve(devdata->cur_context->paint_ctx);
gdk_cairo_set_source_rgba(devdata->cur_context->paint_ctx, devdata->cur_context->paint_color);
}
cairo_stroke(devdata->cur_context->paint_ctx);

data->modified = 1;

gdk_window_invalidate_rect(gtk_widget_get_window(data->win), &rect, 0);
}

data->painted = 1;
}
1 change: 1 addition & 0 deletions src/drawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ typedef struct

void draw_line (GromitData *data, GdkDevice *dev, gint x1, gint y1, gint x2, gint y2);
void draw_arrow (GromitData *data, GdkDevice *dev, gint x1, gint y1, gfloat width, gfloat direction);
void draw_frame (GromitData *data, GdkDevice *dev, gint x, gint y, gint xlength, gint ylength, gint radius, gint strokewidth, GdkRGBA *fill_color);

#endif
29 changes: 22 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@
GromitPaintContext *paint_context_new (GromitData *data,
GromitPaintType type,
GdkRGBA *paint_color,
GdkRGBA *fill_color,
guint width,
gfloat arrowsize,
GromitArrowType arrowtype,
guint simpilfy,
guint simplify,
guint radius,
guint maxangle,
guint minlen,
guint snapdist,
guint xlength,
guint ylength,
guint minwidth,
guint maxwidth)
{
Expand All @@ -62,11 +65,14 @@ GromitPaintContext *paint_context_new (GromitData *data,
context->minwidth = minwidth;
context->maxwidth = maxwidth;
context->paint_color = paint_color;
context->fill_color = fill_color;
context->radius = radius;
context->maxangle = maxangle;
context->simplify = simpilfy;
context->simplify = simplify;
context->minlen = minlen;
context->snapdist = snapdist;
context->xlength = xlength;
context->ylength = ylength;

context->paint_ctx = cairo_create (data->backbuffer);

Expand Down Expand Up @@ -101,6 +107,8 @@ void paint_context_print (gchar *name,
g_printerr ("Line, "); break;
case GROMIT_RECT:
g_printerr ("Rect, "); break;
case GROMIT_FRAME:
g_printerr ("Frame, "); break;
case GROMIT_SMOOTH:
g_printerr ("Smooth, "); break;
case GROMIT_ORTHOGONAL:
Expand Down Expand Up @@ -142,6 +150,11 @@ void paint_context_print (gchar *name,
g_printerr(" radius: %u, minlen: %u, maxangle: %u ",
context->radius, context->minlen, context->maxangle);
}
if (context->type == GROMIT_FRAME)
{
g_printerr("xlength: %u, ylength: %u, radius: %u, ", context->xlength, context->ylength, context->radius);
g_printerr("fillcolor: %s, ", gdk_rgba_to_string(context->fill_color));
}
g_printerr ("color: %s\n", gdk_rgba_to_string(context->paint_color));
}

Expand Down Expand Up @@ -642,13 +655,15 @@ void setup_main_app (GromitData *data, int argc, char ** argv)
g_free(data->white);
g_free(data->black);
g_free(data->red);
g_free(data->transparent);
data->white = g_malloc (sizeof (GdkRGBA));
data->black = g_malloc (sizeof (GdkRGBA));
data->red = g_malloc (sizeof (GdkRGBA));
data->transparent = g_malloc (sizeof (GdkRGBA));
gdk_rgba_parse(data->white, "#FFFFFF");
gdk_rgba_parse(data->black, "#000000");
gdk_rgba_parse(data->red, "#FF0000");

gdk_rgba_parse(data->transparent, "rgba(0, 0, 0, 0.0)");

/*
CURSORS
Expand Down Expand Up @@ -852,11 +867,11 @@ void setup_main_app (GromitData *data, int argc, char ** argv)
data->modified = 0;

data->default_pen =
paint_context_new (data, GROMIT_PEN, data->red, 7, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 0, 1, G_MAXUINT);
paint_context_new (data, GROMIT_PEN, data->red, data->transparent, 7, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 0, 0, 0, 1, G_MAXUINT);
data->default_eraser =
paint_context_new (data, GROMIT_ERASER, data->red, 75, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 0, 1, G_MAXUINT);
paint_context_new (data, GROMIT_ERASER, data->red, data->transparent, 75, 0, GROMIT_ARROW_END,
5, 10, 15, 25, 0, 0, 0, 1, G_MAXUINT);

gdk_event_handler_set ((GdkEventFunc) main_do_event, data, NULL);
gtk_key_snooper_install (snoop_key_press, data);
Expand Down
10 changes: 8 additions & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef enum
GROMIT_PEN,
GROMIT_LINE,
GROMIT_RECT,
GROMIT_FRAME,
GROMIT_SMOOTH,
GROMIT_ORTHOGONAL,
GROMIT_ERASER,
Expand All @@ -92,7 +93,10 @@ typedef struct
guint maxangle;
guint simplify;
guint snapdist;
guint xlength;
guint ylength;
GdkRGBA *paint_color;
GdkRGBA *fill_color;
cairo_t *paint_ctx;
gdouble pressure;
} GromitPaintContext;
Expand Down Expand Up @@ -135,6 +139,7 @@ typedef struct
GdkRGBA *white;
GdkRGBA *black;
GdkRGBA *red;
GdkRGBA *transparent;

GromitPaintContext *default_pen;
GromitPaintContext *default_eraser;
Expand Down Expand Up @@ -193,9 +198,10 @@ void undo_decompress(GromitData *data, gint undo_slot, cairo_surface_t *surface)
void clear_screen (GromitData *data);

GromitPaintContext *paint_context_new (GromitData *data, GromitPaintType type,
GdkRGBA *fg_color, guint width,
GdkRGBA *fg_color, GdkRGBA *fill_color, guint width,
gfloat arrowsize, GromitArrowType arrowtype,
guint simpilfy, guint radius, guint maxangle, guint minlen, guint snapdist,
guint simplify, guint radius, guint maxangle, guint minlen, guint snapdist,
guint xlength, guint ylength,
guint minwidth, guint maxwidth);
void paint_context_free (GromitPaintContext *context);

Expand Down