Add gtk85

This commit is contained in:
daleclack 2021-06-12 22:10:22 +08:00
parent 68172e1f51
commit e00533f0e3
6 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,19 @@
set(CMAKE_CXX_STANDARD 17)
cmake_minimum_required(VERSION 3.0.0)
project(gtk85 VERSION 0.1.0)
include(CTest)
enable_testing()
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
find_package (PkgConfig REQUIRED)
pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0)
include_directories (${GTKMM3_INCLUDE_DIRS})
link_directories (${GTKMM3_LIBRARY_DIRS})
add_executable(gtk85 src/main.cc src/MyWin.cc)
add_definitions (${GTKMM3_CFLAGS_OTHER})
target_link_libraries (${PROJECT_NAME} ${GTKMM3_LIBRARIES})

View File

@ -0,0 +1,3 @@
cd build_mingw
mingw32-make
gtk85

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="app-menu">
<section>
<item>
<attribute name='label'>Change background</attribute>
<attribute name='action'>app.back</attribute>
</item>
<item>
<attribute name='label'>Default background</attribute>
<attribute name='action'>app.default</attribute>
</item>
<item>
<attribute name='label'>About</attribute>
<attribute name="action">app.about</attribute>
</item>
<item>
<attribute name='label'>Exit</attribute>
<attribute name='action'>app.quit</attribute>
</item>
</section>
</menu>
</interface>

View File

@ -0,0 +1,30 @@
#include "MyWin.hh"
MyWin::MyWin(){
//Initalize Window
set_icon_name("org.gtk.daleclack");
set_default_size(800,450);
overlay.add_overlay(draw_area);
//Initalize menu
menu_builder=Gtk::Builder::create_from_file("../res/appmenu.xml");
auto object=menu_builder->get_object("app-menu");
auto gmenu=Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
//Set Popover Menu
popover.bind_model(gmenu);
popover.set_relative_to(draw_area);
//Set Gesture
gesture=Gtk::GestureMultiPress::create(draw_area);
gesture->set_button(3);
gesture->signal_pressed().connect(sigc::mem_fun(*this,&MyWin::btn_pressed));
add(overlay);
show_all();
}
void MyWin::btn_pressed(int n_press,double x,double y){
Gdk::Rectangle point{(int)x,(int)y,1,1};
popover.set_pointing_to(point);
popover.popup();
}
MyWin::~MyWin(){
}

View File

@ -0,0 +1,18 @@
#pragma once
#include <gtkmm.h>
class MyWin : public Gtk::Window{
public:
MyWin();
virtual ~MyWin();
private:
//Child widgets
Glib::RefPtr<Gtk::Builder> menu_builder;
Gtk::Overlay overlay;
Gtk::DrawingArea draw_area;
Gtk::PopoverMenu popover;
//Gesture Widgets
Glib::RefPtr<Gtk::GestureMultiPress> gesture;
void btn_pressed(int n_press,double x,double y);
};

View File

@ -0,0 +1,7 @@
#include "MyWin.hh"
int main(int argc,char **argv){
auto app=Gtk::Application::create(argc,argv,"org.gtk.daleclack");
MyWin window;
return app->run(window);
}