diff --git a/Gtkmm3/gtk98_curves/meson.build b/Gtkmm3/gtk98_curves/meson.build new file mode 100644 index 0000000..a7a060c --- /dev/null +++ b/Gtkmm3/gtk98_curves/meson.build @@ -0,0 +1,30 @@ +#A Simple Project Test +project('gtk98', 'cpp', + default_options : ['c_std=c17', 'cpp_std=c++17']) + +#Initalize variants +# gnome=import('gnome') + +#Compile Resource +# gresources = gnome.compile_resources( +# 'resources', 'res/gtk91.resource.xml', +# source_dir: 'res', +# c_name: 'resources' +# ) + +#The Gtkmm Library as a dependency +gtkdep = dependency('gtkmm-3.0') + +#Additional include dirs +dir_include = include_directories('..') + +#Use Different Build Opinions in windows and Linux +if host_machine.system() == 'windows' + win=import('windows') + icon_res=win.compile_resources('../icon.rc') + executable('gtk98', icon_res, 'src/main.cc', 'src/MyArea.cc', dependencies : gtkdep, + win_subsystem : 'windows', include_directories : dir_include) +else + executable('gtk98', 'src/main.cc', 'src/MyArea.cc', dependencies : gtkdep, + include_directories : dir_include) +endif diff --git a/Gtkmm3/gtk98_curves/src/MyArea.cc b/Gtkmm3/gtk98_curves/src/MyArea.cc new file mode 100644 index 0000000..d5ace59 --- /dev/null +++ b/Gtkmm3/gtk98_curves/src/MyArea.cc @@ -0,0 +1,31 @@ +#include "MyArea.hh" + +bool MyArea::on_draw(const Cairo::RefPtr &cr) +{ + Gtk::Allocation allocation = get_allocation(); + const int width = allocation.get_width(); + const int height = allocation.get_height(); + + double x0 = 0.1, y0 = 0.5, // start point + x1 = 0.4, y1 = 0.9, // control point #1 + x2 = 0.6, y2 = 0.1, // control point #2 + x3 = 0.9, y3 = 0.5; // end point + + // scale to unit square (0 to 1 width and height) + cr->scale(width, height); + + cr->set_line_width(0.05); + // draw curve + cr->move_to(x0, y0); + cr->curve_to(x1, y1, x2, y2, x3, y3); + cr->stroke(); + // show control points + cr->set_source_rgba(1, 0.2, 0.2, 0.6); + cr->move_to(x0, y0); + cr->line_to(x1, y1); + cr->move_to(x2, y2); + cr->line_to(x3, y3); + cr->stroke(); + + return true; +} diff --git a/Gtkmm3/gtk98_curves/src/MyArea.hh b/Gtkmm3/gtk98_curves/src/MyArea.hh new file mode 100644 index 0000000..3e22cad --- /dev/null +++ b/Gtkmm3/gtk98_curves/src/MyArea.hh @@ -0,0 +1,9 @@ +#pragma once + +#include + +class MyArea : public Gtk::DrawingArea{ +protected: + //Override default signal handler: + bool on_draw(const Cairo::RefPtr& cr) override; +}; diff --git a/Gtkmm3/gtk98_curves/src/main.cc b/Gtkmm3/gtk98_curves/src/main.cc new file mode 100644 index 0000000..9282ae0 --- /dev/null +++ b/Gtkmm3/gtk98_curves/src/main.cc @@ -0,0 +1,14 @@ +#include +#include +#include "MyArea.hh" + +int main(int argc,char **argv){ + auto app=Gtk::Application::create(argc,argv,"org.gtk.daleclack"); + //Create a window + Gtk::Window window; + MyArea area1; + window.add(area1); + window.show_all(); + + return app->run(window); +}