feat(gui): added gtk flags/boilerplate
authorametama <ametama@wafflesoft.org>
Wed, 17 Dec 2025 16:02:51 +0000 (17:02 +0100)
committerametama <ametama@wafflesoft.org>
Wed, 17 Dec 2025 16:02:51 +0000 (17:02 +0100)
.gitignore [new file with mode: 0644]
Makefile
src/particle_swarm.c

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..240b3f9
--- /dev/null
@@ -0,0 +1,2 @@
+opt
+compile_flags.txt
index a806caf7e52c20d1c152dc8834e74857c96419a1..d93f90f1775380b15862f46f591cb3989d87444a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,2 +1,2 @@
 opt: src/particle_swarm.c src/vector.c
-       gcc -Iinclude -lm -fopenmp src/vector.c src/particle_swarm.c -o opt
+       gcc -Iinclude `pkg-config --cflags gtk4` -lm -fopenmp src/vector.c src/particle_swarm.c -o opt `pkg-config --libs gtk4`
index f1e2b412b4489363b41caa2f6d54149fc8eb08a5..1d574c1e5611882bd52ef6edf0779e6400b366ae 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include "particle_swarm.h"
 #include "vector.h"
+#include <gtk/gtk.h>
 
 double c = 2.05;
 double s = 2.05;
@@ -73,7 +74,15 @@ void swarm_velocity_update(swarm *sw, const int dim) {
   }
 }
 
-int main() {
+static void on_activate(GtkApplication *app) {
+  GtkWidget *window = gtk_application_window_new(app);
+  GtkWidget *button = gtk_button_new_with_label("Hello, World!");
+  g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_window_close), window);
+  gtk_window_set_child(GTK_WINDOW(window), button);
+  gtk_window_present(GTK_WINDOW(window));
+}
+
+int main(int argc, char *argv[]) {
   double eps = pow(2, 40);
   int dim = 2;
   int particlec = 100;
@@ -98,5 +107,8 @@ int main() {
   printf("PSO: converged in x=");
   vec_print(dim, sw.global_best->current.x);
   printf(" with fitness f(x)=%f\n", sw.global_best->current.fitness);
-  return 0;
+
+  GtkApplication *app = gtk_application_new("org.wafflesoft.NCPSO", G_APPLICATION_DEFAULT_FLAGS);
+  g_signal_connect(app, "activate", G_CALLBACK(on_activate), NULL);
+  return g_application_run(G_APPLICATION(app), argc, argv);
 }