Add gtk28

This commit is contained in:
daleclack 2020-12-20 11:22:22 +08:00
parent fcfdf1839d
commit d11f4cb65b
8 changed files with 165 additions and 0 deletions

36
Gtk3/gtk28/gtk28.cbp Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="gtk28" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/gtk28" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/gtk28" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Extensions />
</Project>
</CodeBlocks_project_file>

21
Gtk3/gtk28/gtk28.depend Normal file
View File

@ -0,0 +1,21 @@
# depslib dependency file v1.0
1608374440 source:/root/cpp50/gtkclass.cpp
"gtkclass.h"
1608375016 /root/cpp50/gtkclass.h
<gtk/gtk.h>
1608431207 source:/root/cpp50/gtkwin.cpp
1608433745 /root/cpp50/gtkwin.h
<gtk/gtk.h>
1608432192 source:/root/cpp50/main.cpp
"gtkwin.h"
1608433787 source:/root/cpp50/test.cpp
"test.h"
1608433607 /root/cpp50/test.h
<gtk/gtk.h>

5
Gtk3/gtk28/gtk28.layout Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
</CodeBlocks_layout_file>

49
Gtk3/gtk28/gtkwin.cpp Normal file
View File

@ -0,0 +1,49 @@
#include "gtkwin.h"
#include "test.h"
//Initalize GtkButton
void GtkBtn::init(const gchar *str,int width,int height){
button=gtk_button_new_with_label(str);
gtk_widget_set_size_request(button,width,height);
}
//Link "clicked" signal
void GtkBtn::signal_clicked(pfun func,gpointer data){
g_signal_connect(button,"clicked",G_CALLBACK(func),data);
}
//put widget int layout
void Winlayout::put(GtkWidget *child,int x,int y){
gtk_layout_put(GTK_LAYOUT(layout),child,x,y);
}
//Initalize Gtklayout
void Winlayout::init(){
GtkBtn button1;
button1.init("Test",100,50);
button1.signal_clicked(print,NULL);
put(button1.button,150,100);
}
//Add widget to window
void GtkWin::add(GtkWidget *widget){
gtk_container_add(GTK_CONTAINER(window),widget);
}
void GtkWin::win_init(GtkApplication *app,int width,int height){
//Create a window and set window proprites
window=gtk_application_window_new(app);
_window=GTK_WINDOW(window);
gtk_window_set_default_size(_window,width,height);
gtk_window_set_position(_window,GTK_WIN_POS_CENTER);
//Put a layout
Winlayout layout1;
layout1.init();
add(layout1.layout);
}
//Show everything
void GtkWin::show_all(){
gtk_widget_show_all(window);
}

30
Gtk3/gtk28/gtkwin.h Normal file
View File

@ -0,0 +1,30 @@
#include <gtk/gtk.h>
typedef void(*pfun)(GtkWidget *,gpointer);//define a pointer to function
//GtkButton class
class GtkBtn{
public:
GtkWidget *button;
void init(const gchar *str,int width,int height);
void signal_clicked(pfun func,gpointer data);
};
//GtkLayout class
class Winlayout{
void put(GtkWidget *child,int x,int y);
public:
GtkWidget *layout=gtk_layout_new(NULL,NULL);
void init();
};
//GtkWindow class
class GtkWin{
GtkWidget *window;
GtkWindow *_window;
void add(GtkWidget *widget);
public:
void win_init(GtkApplication *app,int width,int height);
void show_all();
};

16
Gtk3/gtk28/main.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "gtkwin.h"
static void gtkmain(GtkApplication *app,gpointer user_data){
//initalize gtk window
GtkWin mainwin;
mainwin.win_init(app,400,300);
mainwin.show_all();
}
int main(int argc,char *argv[]){
//Start a gtk application
GtkApplication *app;
app=gtk_application_new("com.github.daleclack.gtk28",G_APPLICATION_FLAGS_NONE);
g_signal_connect(app,"activate",G_CALLBACK(gtkmain),NULL);
return g_application_run(G_APPLICATION(app),argc,argv);
}

5
Gtk3/gtk28/test.cpp Normal file
View File

@ -0,0 +1,5 @@
#include "test.h"
void print(GtkWidget *widget,gpointer data){
g_print("hello");
}

3
Gtk3/gtk28/test.h Normal file
View File

@ -0,0 +1,3 @@
#include <gtk/gtk.h>
void print(GtkWidget *widget,gpointer data);