Skip to content
Snippets Groups Projects
Commit 453c7c0c authored by Younes Oubkis's avatar Younes Oubkis
Browse files

setup for clickable shapes

parent 4ce958c9
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -7,6 +7,7 @@ GtkWidget *window;
GtkWidget *drawing_area;
enum INPUTTYPE current_input;
t_shape shapes[MAX_SHAPES + 1];
t_shape selected_shape;
int shape_type;
int click_count;
t_vertex click_positions[4];
......
......@@ -17,6 +17,7 @@ extern int shape_type;
extern int click_count;
extern t_vertex click_positions[4];
extern t_shape shapes[MAX_SHAPES + 1];
extern t_shape selected_shape;
gboolean on_clear(GtkWidget *button, gpointer user_data);
gboolean drawing_area_click(GtkWidget *widget, GdkEventButton *event, gpointer data);
......
......@@ -6,11 +6,24 @@ GdkRGBA yellow = {1.0, 1.0, 0.0, 0.6};
GdkRGBA blue = {0.0, 0.5, 1.0, 0.4};
GdkRGBA black = {0.0, 0.0, 0.0, 1.0};
int selection_flag = 0;
float selectionX, selectionY;
gboolean drawing_area_click(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
if (!event->button == GDK_BUTTON_PRIMARY) // Left Click
if (event->button != GDK_BUTTON_SECONDARY && event->button != GDK_BUTTON_PRIMARY) // Left Click
return FALSE;
if (event->button == GDK_BUTTON_SECONDARY) // Left Click
{
selection_flag = 1;
selectionX = event->x;
selectionY = event->y;
gtk_widget_queue_draw(drawing_area);
return TRUE;
}
double clickX = event->x;
double clickY = event->y;
......@@ -75,7 +88,6 @@ void handle_shape_click(float x, float y)
}
void handle_freehand_click(float x, float y)
{
}
void add_shape(t_shape new_shape)
{
......@@ -130,11 +142,18 @@ gboolean draw(GtkWidget *widget, cairo_t *c, gpointer data)
}
cairo_close_path(c);
}
cairo_fill(c);
cairo_close_path(c);
}
if (selection_flag)
{
gboolean isInside = cairo_in_fill(c, selectionX, selectionY);
if (isInside)
g_print("HIT!");
else
g_print("MISS!");
selection_flag = 0;
}
cairo_fill(c);
for (int i = 0; i < click_count; i++)
{
set_source_color(c, &black);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment