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

Signal Connect

parent bace32a4
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/app",
"program": "${workspaceFolder}/bin/app",
"args": ["800","800"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
......@@ -24,6 +24,7 @@
}
],
"preLaunchTask": "Build using Make",
}
]
}
\ No newline at end of file
......@@ -15,7 +15,13 @@
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
"detail": "Task generated by Debugger.",
"dependsOn" : "Unset GTK Path"
},
{
"type": "shell",
"label": "Unset GTK Path",
"command": "unset GTK_PATH"
}
],
"version": "2.0.0"
......
......@@ -9,7 +9,6 @@ Written in C using Gtk 3
Build Environment: Linux Ubuntu 22.04
# Dependencies
- GTK+ 3.0
- GNU Make
# Building
Run ```make``` in the src Directory
......
No preview for this file type
......@@ -27,6 +27,11 @@ gboolean on_button_clicked(GtkWidget *button, gpointer user_data)
g_print("Button clicked!\n");
}
gboolean on_shape_choice(GtkWidget *button, gpointer user_data)
{
}
gboolean draw(GtkWidget *widget, cairo_t *c, gpointer data)
{
set_source_color(c, &red);
......@@ -116,15 +121,17 @@ int create_window_layout(int argc, char **argv)
gtk_widget_set_size_request(drawing_area, width, height);
t_custom_toolbar *toolbar = create_toolbar();
GtkToolItem *test1_btn = create_and_bind_toolbutton(toolbar,"test with callback");
GtkToolItem *test2_btn = create_and_bind_toolbutton(toolbar,"test 3");
GtkToolItem *test3_btn = create_and_bind_toolbutton(toolbar,"test 4");
GtkToolItem *triangle_btn = create_and_bind_toolbutton(toolbar,"Triangle");
GtkToolItem *rectangle_btn = create_and_bind_toolbutton(toolbar,"Rectangle");
GtkToolItem *circle_btn = create_and_bind_toolbutton(toolbar,"Circle");
bind_click_signal(test1_btn,on_button_clicked);
bind_click_signal(triangle_btn,on_shape_choice, TRIANGLE);
bind_click_signal(rectangle_btn,on_shape_choice, RECTANGLE);
bind_click_signal(circle_btn,on_shape_choice, CIRCLE);
gtk_container_add(GTK_CONTAINER(hbox), GTK_WIDGET(drawing_area));
gtk_container_add(GTK_CONTAINER(hbox), GTK_WIDGET(toolbar->widget));
gtk_container_add(GTK_CONTAINER(vbox), button);
gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(toolbar->widget));
gtk_container_add(GTK_CONTAINER(vbox), hbox);
gtk_container_add(GTK_CONTAINER(window), vbox);
......
......@@ -5,9 +5,8 @@
#define UNDEFINED 0
#define TRIANGLE 1
#define SQUARE 2
#define RECT 3
enum SHAPETYPE { TRIANGLE,CIRCLE,RECTANGLE };
typedef gboolean (*SignalHandlerPointer)(GtkWidget *widget, gpointer user_data);
......@@ -40,6 +39,6 @@ t_shape NULL_SHAPE();
t_custom_toolbar *create_toolbar();
GtkToolItem *create_and_bind_toolbutton(t_custom_toolbar *toolbar,const gchar *name);
void bind_click_signal(GtkToolItem *item, SignalHandlerPointer sp);
void bind_click_signal(GtkToolItem *item, SignalHandlerPointer sp, int data);
#endif
\ No newline at end of file
......@@ -26,7 +26,7 @@ t_shape create_square(int x1,int y1,int x2, int y2)
t_shape shape;
shape.vertexCount = 4;
shape.vertices = malloc(sizeof(t_vertex)*4);
shape.type = SQUARE;
shape.type = RECTANGLE;
shape.flag = 1;
t_vertex* v = shape.vertices;
v[0] = point(x1,y1);
......
......@@ -23,8 +23,8 @@ GtkToolItem *create_and_bind_toolbutton(t_custom_toolbar *toolbar,const gchar *n
return b;
}
void bind_click_signal(GtkToolItem *item, SignalHandlerPointer sp)
void bind_click_signal(GtkToolItem *item, SignalHandlerPointer sp, int data)
{
g_signal_connect(G_OBJECT(item), "clicked", G_CALLBACK(sp), NULL);
g_signal_connect(G_OBJECT(item), "clicked", G_CALLBACK(sp),data);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment