Skip to content

Commit

Permalink
ortho and smooth rebased on current master
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-niklaus committed Mar 15, 2024
1 parent 7d171ac commit 4d58439
Show file tree
Hide file tree
Showing 9 changed files with 1,020 additions and 52 deletions.
33 changes: 31 additions & 2 deletions src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "config.h"
#include "drawing.h"
#include "build-config.h"

#include "smooth.h"

gboolean on_expose (GtkWidget *widget,
cairo_t* cr,
Expand Down Expand Up @@ -281,7 +281,7 @@ gboolean on_buttonpress (GtkWidget *win,
GromitPaintType type = devdata->cur_context->type;

// store original state to have dynamic update of line and rect
if (type == GROMIT_LINE || type == GROMIT_RECT)
if (type == GROMIT_LINE || type == GROMIT_RECT || type == GROMIT_SMOOTH)
{
copy_surface(data->aux_backbuffer, data->backbuffer);
}
Expand Down Expand Up @@ -398,6 +398,7 @@ gboolean on_motion (GtkWidget *win,
}
if (type == GROMIT_LINE)
{
GromitArrowType atype = devdata->cur_context->arrow_type;
draw_line (data, ev->device, devdata->lastx, devdata->lasty, ev->x, ev->y);
if (devdata->cur_context->arrowsize > 0)
{
Expand Down Expand Up @@ -460,6 +461,34 @@ gboolean on_buttonrelease (GtkWidget *win,

GromitPaintType type = devdata->cur_context->type;

if (type == GROMIT_SMOOTH)
{
if (0) {
// smooth pen
douglas_peucker(devdata->coordlist, 10); // was 15
add_points(devdata->coordlist, 200);
devdata->coordlist = catmull_rom(devdata->coordlist, 5);
} else {
// smart rect pen
douglas_peucker(devdata->coordlist, 15); // was 15
orthogonalize(devdata->coordlist, 20, 40);
round_corners(devdata->coordlist, 20, 6);
}

copy_surface(data->backbuffer, data->aux_backbuffer);
GdkRectangle rect = {0, 0, data->width, data->height};
gdk_window_invalidate_rect(gtk_widget_get_window(data->win), &rect, 0);

GList *ptr = devdata->coordlist;
while (ptr->next)
{
GromitStrokeCoordinate *c1 = ptr->data;
GromitStrokeCoordinate *c2 = ptr->next->data;
ptr = ptr->next;
draw_line (data, ev->device, c1->x, c1->y, c2->x, c2->y);
}
}

if (devdata->cur_context->arrowsize != 0)
{
GromitArrowType atype = devdata->cur_context->arrow_type;
Expand Down
4 changes: 3 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,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, "SMOOTH", (gpointer) GROMIT_SMOOTH);
g_scanner_scope_add_symbol (scanner, 0, "ERASER", (gpointer) GROMIT_ERASER);
g_scanner_scope_add_symbol (scanner, 0, "RECOLOR",(gpointer) GROMIT_RECOLOR);
g_scanner_scope_add_symbol (scanner, 0, "HOTKEY", HOTKEY_SYMBOL_VALUE);
Expand Down Expand Up @@ -340,6 +341,7 @@ gboolean parse_config (GromitData *data)
goto cleanup;
}
arrowsize = scanner->value.v_float;
arrowtype = GROMIT_ARROW_END;
}
else if ((intptr_t) scanner->value.v_symbol == 4)
{
Expand Down Expand Up @@ -567,7 +569,7 @@ int parse_args (int argc, char **argv, GromitData *data)
wrong_arg = TRUE;
}
}
else if (strcmp (arg, "-o") == 0 ||
else if (strcmp (arg, "-o") == 0 ||
strcmp (arg, "--opacity") == 0)
{
if (i+1 < argc && strtod (argv[i+1], NULL) >= 0.0 && strtod (argv[i+1], NULL) <= 1.0)
Expand Down
8 changes: 0 additions & 8 deletions src/drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
#include "drawing.h"
#include "main.h"

typedef struct
{
gint x;
gint y;
gint width;
} GromitStrokeCoordinate;


void draw_line (GromitData *data,
GdkDevice *dev,
gint x1, gint y1,
Expand Down
8 changes: 8 additions & 0 deletions src/drawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

#include "main.h"

typedef struct
{
gint x;
gint y;
gint width;
} GromitStrokeCoordinate;


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, gint width, gfloat direction);

Expand Down
Loading

0 comments on commit 4d58439

Please sign in to comment.