News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GtkApplication

Started by mabdelouahab, August 08, 2024, 01:42:55 AM

Previous topic - Next topic

mabdelouahab

GtkApplication is the cornerstone for building robust and flexible desktop applications using the GTK library. It provides a comprehensive infrastructure for managing the application lifecycle, handling events, and window management. With GtkApplication, developers can focus on designing the user interface and implementing the application logic, rather than dealing with complex technical details. In short, GtkApplication is a powerful tool that helps accelerate application development and deliver a better user experience

Hello World GTK application:
main.asm:
   GtkApplication                TYPEDEF QWORD
   GtkWidget                     TYPEDEF QWORD
   gpointer                     TYPEDEF QWORD 

   g_signal_connect_data          PROTO :QWORD,:QWORD, :QWORD, :QWORD, :QWORD, :QWORD
   gtk_window_set_default_size     PROTO :QWORD, :QWORD, :QWORD
   g_application_run              PROTO :QWORD,:QWORD, :QWORD
   gtk_application_window_new      PROTO :QWORD
   gtk_application_new            PROTO :QWORD,:QWORD
   gtk_window_set_title           PROTO :QWORD,:QWORD
   gtk_widget_show_all            PROTO :QWORD
   g_object_unref                PROTO :QWORD

   G_APPLICATION_FLAGS_NONE      EQU      0

.code
   main  PROC  argc:QWORD, argv:QWORD
         LOCAL app:GtkApplication, status:DWORD
      
         mov app, RV(gtk_application_new , CStr("uasm.gtk.example"), G_APPLICATION_FLAGS_NONE) 
         invoke g_signal_connect_data, app, CStr("activate"), ADDR activate, 0, 0, 0
         invoke g_application_run , app, 0 , 0
         mov status, eax
         invoke g_object_unref, app
         mov eax, status
         ret
   main  ENDP

   activate PROC  app:GtkApplication, user_data:gpointer
       LOCAL window:GtkWidget

       mov window , RV(gtk_application_window_new, app)
       invoke gtk_window_set_title, window, CStr("Window")
       invoke gtk_window_set_default_size, window, 640, 480
       invoke gtk_widget_show_all, window
       ret
   activate ENDP               
end 


build.sh:
    #!/bin/bash
    uasm -elf64 hwgtkapp.asm
    gcc -o hwgtkapplication hwgtkapp.o -lgio-2.0  -lgtk-3 -lgobject-2.0
    ./hwgtkapplication




Biterider

Hi mabdelouahab
Thanks for the demo code.
After installing UASM and GTK on my Mint (v.22) OS, I was able to compile and link the asm file.



I had some fun tweaking the build.sh file, but finally got it to work.

    #!/bin/bash
    uasm -elf64 hwgtkapp.asm
    gcc -o hwgtkapplication hwgtkapp.o -z noexecstack -lgio-2.0 -lgtk-3 -lgobject-2.0 -fno-pie -no-pie
    ./hwgtkapplication


This is very exciting as it opens up a huge opportunity for macro frameworks such as ObjAsm.

Regards, Biterider