mirror of https://github.com/daleclack/My_GtkUi
Update to v2.2
This commit is contained in:
parent
62f1509fc0
commit
3ae57c6a89
|
@ -1,6 +1,6 @@
|
|||
set(CMAKE_CXX_STANDARD 17)
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(My_GtkUi VERSION 2.1.0)
|
||||
project(My_GtkUi VERSION 2.2.0)
|
||||
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
|
@ -14,7 +14,7 @@ find_package (PkgConfig REQUIRED)
|
|||
pkg_check_modules (GTK3 REQUIRED gtk+-3.0)
|
||||
include_directories (${GTK3_INCLUDE_DIRS})
|
||||
link_directories (${GTK3_LIBRARY_DIRS})
|
||||
add_executable(My_GtkUi src/main.cpp src/background.cpp src/game.cpp
|
||||
add_executable(My_GtkUi src/main.cpp src/background.cpp src/game.cpp src/TextEditor.cpp
|
||||
src/panel1.cpp src/panel2.cpp src/win1.cpp src/winconf.cpp src/resources.cpp)
|
||||
add_definitions (${GTK3_CFLAGS_OTHER})
|
||||
target_link_libraries (${PROJECT_NAME} ${GTK3_LIBRARIES} -lpthread -lm)
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="image3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
<object class="GtkPopover" id="popover1">
|
||||
<property name="width-request">300</property>
|
||||
<property name="height-request">400</property>
|
||||
|
@ -170,6 +175,20 @@
|
|||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="btneditor">
|
||||
<property name="label" translatable="yes">Simple Text Editor</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
<property name="relief">none</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="btnabout">
|
||||
<property name="label" translatable="yes">About</property>
|
||||
|
@ -182,7 +201,7 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -191,9 +210,6 @@
|
|||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
|
@ -250,9 +266,4 @@
|
|||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkImage" id="image3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="stock">gtk-about</property>
|
||||
</object>
|
||||
</interface>
|
||||
|
|
|
@ -170,6 +170,19 @@
|
|||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="btneditor">
|
||||
<property name="label" translatable="yes">Simple Text Editor</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="btnabout">
|
||||
<property name="label" translatable="yes">About</property>
|
||||
|
@ -182,7 +195,7 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -191,9 +204,6 @@
|
|||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
#include "TextEditor.h"
|
||||
|
||||
static GtkWidget *infobar;
|
||||
static GtkTextBuffer *textbuffer;
|
||||
static int filemode;
|
||||
|
||||
static void dialog_response(GtkWidget *widget,int response,gpointer data){
|
||||
char *contents,*filename;
|
||||
gsize length;
|
||||
if(response==GTK_RESPONSE_OK){
|
||||
GFile *file=gtk_file_chooser_get_file((GtkFileChooser*)widget);
|
||||
filename=g_file_get_path(file);
|
||||
if(filemode==0){
|
||||
//Get File contents and show
|
||||
if(g_file_get_contents(filename,&contents,&length,NULL)){
|
||||
gtk_text_buffer_set_text(textbuffer,contents,length);
|
||||
}
|
||||
}else{
|
||||
//Get Start and End char of Text
|
||||
GtkTextIter start,end;
|
||||
gtk_text_buffer_get_start_iter(textbuffer,&start);
|
||||
gtk_text_buffer_get_end_iter(textbuffer,&end);
|
||||
//Get Contents
|
||||
contents=gtk_text_buffer_get_text(textbuffer,&start,&end,TRUE);
|
||||
//Create a file and write
|
||||
FILE *fp;
|
||||
fp=fopen(filename,"wt+");
|
||||
if(fp!=NULL){
|
||||
fputs(contents,fp);
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
g_object_unref(file);
|
||||
g_free(contents);
|
||||
g_free(filename);
|
||||
}
|
||||
gtk_widget_destroy(widget);
|
||||
}
|
||||
|
||||
static void openfile_dialog(GtkWidget *widget,GtkWindow *parent){
|
||||
filemode=0;
|
||||
GtkFileChooserAction action=GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||
GtkWidget *dialog=gtk_file_chooser_dialog_new("Open a text file",parent,
|
||||
action,"OK",GTK_RESPONSE_OK,"Cancel",GTK_RESPONSE_CANCEL,NULL);
|
||||
|
||||
GtkFileFilter *filter=gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(filter,"Text Files");
|
||||
gtk_file_filter_add_mime_type(filter,"text/*");
|
||||
gtk_file_chooser_add_filter((GtkFileChooser*)dialog,filter);
|
||||
//g_object_unref(filter);
|
||||
|
||||
filter=gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(filter,"Any Files");
|
||||
gtk_file_filter_add_pattern(filter,"*");
|
||||
gtk_file_chooser_add_filter((GtkFileChooser*)dialog,filter);
|
||||
//g_object_unref(filter);
|
||||
|
||||
g_signal_connect(dialog,"response",G_CALLBACK(dialog_response),NULL);
|
||||
gtk_widget_show_all(dialog);
|
||||
}
|
||||
|
||||
static void savefile_dialog(GtkWidget *widget,GtkWindow *parent){
|
||||
filemode=1;
|
||||
GtkFileChooserAction action=GTK_FILE_CHOOSER_ACTION_SAVE;
|
||||
GtkWidget *dialog=gtk_file_chooser_dialog_new("Open a text file",parent,
|
||||
action,"OK",GTK_RESPONSE_OK,"Cancel",GTK_RESPONSE_CANCEL,NULL);
|
||||
|
||||
GtkFileFilter *filter=gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(filter,"Text Files");
|
||||
gtk_file_filter_add_mime_type(filter,"text/*");
|
||||
gtk_file_chooser_add_filter((GtkFileChooser*)dialog,filter);
|
||||
//g_object_unref(filter);
|
||||
|
||||
filter=gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(filter,"Any Files");
|
||||
gtk_file_filter_add_pattern(filter,"*");
|
||||
gtk_file_chooser_add_filter((GtkFileChooser*)dialog,filter);
|
||||
//g_object_unref(filter);
|
||||
|
||||
g_signal_connect(dialog,"response",G_CALLBACK(dialog_response),NULL);
|
||||
gtk_widget_show_all(dialog);
|
||||
}
|
||||
|
||||
static void textbuffer_clear(GtkWidget *widget,GtkTextBuffer *buffer){
|
||||
gtk_text_buffer_set_text(buffer,"",-1);
|
||||
gtk_widget_show(infobar);
|
||||
}
|
||||
|
||||
static void infobar_response(GtkWidget *widget,gpointer data){
|
||||
gtk_widget_hide(widget);
|
||||
}
|
||||
|
||||
void text_editor(GtkWidget *widget,GtkWindow *parent){
|
||||
//Initalize window
|
||||
GtkWidget *window,*vbox;
|
||||
//window=gtk_application_window_new(app);
|
||||
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_transient_for((GtkWindow*)window,parent);
|
||||
gtk_window_set_title((GtkWindow*)window,"Simple Text Editor");
|
||||
gtk_window_set_icon_name((GtkWindow*)window,"org.gtk.daleclack");
|
||||
gtk_window_set_default_size((GtkWindow*)window,800,450);
|
||||
vbox=gtk_box_new(GTK_ORIENTATION_VERTICAL,5);
|
||||
|
||||
//Initalize infobar
|
||||
infobar=gtk_info_bar_new_with_buttons("OK",GTK_RESPONSE_OK,NULL);
|
||||
GtkWidget *content_area=gtk_info_bar_get_content_area((GtkInfoBar*)infobar);
|
||||
GtkWidget *label=gtk_label_new("Cleared the text");
|
||||
g_signal_connect(infobar,"response",G_CALLBACK(infobar_response),NULL);
|
||||
gtk_container_add((GtkContainer*)content_area,label);
|
||||
gtk_box_pack_start((GtkBox*)vbox,infobar,TRUE,FALSE,0);
|
||||
|
||||
//Ininalize TextView
|
||||
GtkWidget *scrolled;
|
||||
GtkWidget *textview;
|
||||
//GtkTextBuffer *textbuffer;
|
||||
scrolled=gtk_scrolled_window_new(NULL,NULL);
|
||||
gtk_scrolled_window_set_policy((GtkScrolledWindow*)scrolled,
|
||||
GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
|
||||
textview=gtk_text_view_new();
|
||||
textbuffer=gtk_text_view_get_buffer((GtkTextView*)textview);
|
||||
gtk_widget_set_size_request(scrolled,800,440);
|
||||
gtk_container_add((GtkContainer*)scrolled,textview);
|
||||
gtk_box_pack_start((GtkBox*)vbox,scrolled,TRUE,TRUE,0);
|
||||
|
||||
//Add Buttons
|
||||
GtkWidget *btn_box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
|
||||
GtkWidget *btnopen,*btnsave,*btnclear,*btnexit;
|
||||
btnopen=gtk_button_new_with_label("Open File");
|
||||
g_signal_connect(btnopen,"clicked",G_CALLBACK(openfile_dialog),window);
|
||||
btnsave=gtk_button_new_with_label("Save File");
|
||||
g_signal_connect(btnsave,"clicked",G_CALLBACK(savefile_dialog),window);
|
||||
btnclear=gtk_button_new_with_label("Clear");
|
||||
g_signal_connect(btnclear,"clicked",G_CALLBACK(textbuffer_clear),textbuffer);
|
||||
btnexit=gtk_button_new_with_label("Exit");
|
||||
g_signal_connect_swapped(btnexit,"clicked",G_CALLBACK(gtk_widget_destroy),window);
|
||||
gtk_box_pack_end((GtkBox*)btn_box,btnexit,FALSE,FALSE,0);
|
||||
gtk_box_pack_end((GtkBox*)btn_box,btnclear,FALSE,FALSE,0);
|
||||
gtk_box_pack_end((GtkBox*)btn_box,btnsave,FALSE,FALSE,0);
|
||||
gtk_box_pack_end((GtkBox*)btn_box,btnopen,FALSE,FALSE,0);
|
||||
gtk_box_pack_end((GtkBox*)vbox,btn_box,TRUE,FALSE,0);
|
||||
|
||||
//Add widgets and show everything
|
||||
gtk_container_add((GtkContainer*)window,vbox);
|
||||
gtk_widget_show_all(window);
|
||||
gtk_widget_hide(infobar);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef __TEXTEDITOR_H_
|
||||
#define __TEXTEDITOR_H_
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <cstdio>
|
||||
|
||||
void text_editor(GtkWidget *widget,GtkWindow *parent);
|
||||
|
||||
#endif
|
|
@ -3,6 +3,7 @@
|
|||
#include "panel2.h"
|
||||
#include "win1.h"
|
||||
#include "game.h"
|
||||
#include "TextEditor.h"
|
||||
|
||||
void add_leftpanel(GtkBuilder *builder,GtkFixed *fixed){
|
||||
//Get Left panel
|
||||
|
@ -52,6 +53,10 @@ void add_leftpanel(GtkBuilder *builder,GtkFixed *fixed){
|
|||
GObject *btngame=gtk_builder_get_object(panel2,"btngame");
|
||||
g_signal_connect(btngame,"clicked",G_CALLBACK(gamemain),window);
|
||||
g_signal_connect_swapped(btngame,"clicked",G_CALLBACK(gtk_widget_hide),popover);
|
||||
//Text Editor(Gtk86)
|
||||
GObject *btnedit=gtk_builder_get_object(panel2,"btneditor");
|
||||
g_signal_connect(btnedit,"clicked",G_CALLBACK(text_editor),window);
|
||||
g_signal_connect_swapped(btnedit,"clicked",G_CALLBACK(gtk_widget_hide),popover);
|
||||
//About window
|
||||
GObject *btn_about=gtk_builder_get_object(panel2,"btnabout");
|
||||
g_signal_connect(btn_about,"clicked",G_CALLBACK(win1_init),window);
|
||||
|
|
|
@ -11,7 +11,7 @@ void win1_init(GtkWidget *widget,GtkWindow *parent){
|
|||
gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(window1),logo_sized);
|
||||
//Add version information
|
||||
char *version;
|
||||
version=g_strdup_printf("2.1\nRunning Against Gtk %d.%d.%d",
|
||||
version=g_strdup_printf("2.2\nRunning Against Gtk %d.%d.%d",
|
||||
gtk_get_major_version(),
|
||||
gtk_get_minor_version(),
|
||||
gtk_get_micro_version());
|
||||
|
|
Loading…
Reference in New Issue