Debian Codegraph @

examples/others/window/wheelbarrow.cc

raw
1 // A wheelbarrow on a transparent background
2
3 #include <gdkmm.h>
4 #include <gtkmm/image.h>
5 #include <gtkmm/application.h>
6 #include <gtkmm/window.h>
7 #include <gtkmm/cssprovider.h>
8 #include <gtkmm/stylecontext.h>
9 #include <gtkmm/gestureclick.h>
10 #include <gtkmm/version.h>
11 #include <iostream>
12
13 #define HAS_STYLE_PROVIDER_ADD_PROVIDER_FOR_DISPLAY GTKMM_CHECK_VERSION(4,9,1)
14
15 namespace
16 {
17
18 const char *const wheelbarrow_xpm[] =
19 {
20 "48 48 64 1",
21 " c None",
22 ". c #DF7DCF3CC71B",
23 "X c #965875D669A6",
24 "o c #71C671C671C6",
25 "O c #A699A289A699",
26 "+ c #965892489658",
27 "@ c #8E38410330C2",
28 "# c #D75C7DF769A6",
29 "$ c #F7DECF3CC71B",
30 "% c #96588A288E38",
31 "& c #A69992489E79",
32 "* c #8E3886178E38",
33 "= c #104008200820",
34 "- c #596510401040",
35 "; c #C71B30C230C2",
36 ": c #C71B9A699658",
37 "> c #618561856185",
38 ", c #20811C712081",
39 "< c #104000000000",
40 "1 c #861720812081",
41 "2 c #DF7D4D344103",
42 "3 c #79E769A671C6",
43 "4 c #861782078617",
44 "5 c #41033CF34103",
45 "6 c #000000000000",
46 "7 c #49241C711040",
47 "8 c #492445144924",
48 "9 c #082008200820",
49 "0 c #69A618611861",
50 "q c #B6DA71C65144",
51 "w c #410330C238E3",
52 "e c #CF3CBAEAB6DA",
53 "r c #71C6451430C2",
54 "t c #EFBEDB6CD75C",
55 "y c #28A208200820",
56 "u c #186110401040",
57 "i c #596528A21861",
58 "p c #71C661855965",
59 "a c #A69996589658",
60 "s c #30C228A230C2",
61 "d c #BEFBA289AEBA",
62 "f c #596545145144",
63 "g c #30C230C230C2",
64 "h c #8E3882078617",
65 "j c #208118612081",
66 "k c #38E30C300820",
67 "l c #30C2208128A2",
68 "z c #38E328A238E3",
69 "x c #514438E34924",
70 "c c #618555555965",
71 "v c #30C2208130C2",
72 "b c #38E328A230C2",
73 "n c #28A228A228A2",
74 "m c #41032CB228A2",
75 "M c #104010401040",
76 "N c #492438E34103",
77 "B c #28A2208128A2",
78 "V c #A699596538E3",
79 "C c #30C21C711040",
80 "Z c #30C218611040",
81 "A c #965865955965",
82 "S c #618534D32081",
83 "D c #38E31C711040",
84 "F c #082000000820",
85 " ",
86 " .XoO ",
87 " +@#$%o& ",
88 " *=-;#::o+ ",
89 " >,<12#:34 ",
90 " 45671#:X3 ",
91 " +89<02qwo ",
92 "e* >,67;ro ",
93 "ty> 459@>+&& ",
94 "$2u+ ><ipas8* ",
95 "%$;=* *3:.Xa.dfg> ",
96 "Oh$;ya *3d.a8j,Xe.d3g8+ ",
97 " Oh$;ka *3d$a8lz,,xxc:.e3g54 ",
98 " Oh$;kO *pd$%svbzz,sxxxxfX..&wn> ",
99 " Oh$@mO *3dthwlsslszjzxxxxxxx3:td8M4 ",
100 " Oh$@g& *3d$XNlvvvlllm,mNwxxxxxxxfa.:,B* ",
101 " Oh$@,Od.czlllllzlmmqV@V#V@fxxxxxxxf:%j5& ",
102 " Oh$1hd5lllslllCCZrV#r#:#2AxxxxxxxxxcdwM* ",
103 " OXq6c.%8vvvllZZiqqApA:mq:Xxcpcxxxxxfdc9* ",
104 " 2r<6gde3bllZZrVi7S@SV77A::qApxxxxxxfdcM ",
105 " :,q-6MN.dfmZZrrSS:#riirDSAX@Af5xxxxxfevo",
106 " +A26jguXtAZZZC7iDiCCrVVii7Cmmmxxxxxx%3g",
107 " *#16jszN..3DZZZZrCVSA2rZrV7Dmmwxxxx&en",
108 " p2yFvzssXe:fCZZCiiD7iiZDiDSSZwwxx8e*>",
109 " OA1<jzxwwc:$d%NDZZZZCCCZCCZZCmxxfd.B ",
110 " 3206Bwxxszx%et.eaAp77m77mmmf3&eeeg* ",
111 " @26MvzxNzvlbwfpdettttttttttt.c,n& ",
112 " *;16=lsNwwNwgsvslbwwvccc3pcfu<o ",
113 " p;<69BvwwsszslllbBlllllllu<5+ ",
114 " OS0y6FBlvvvzvzss,u=Blllj=54 ",
115 " c1-699Blvlllllu7k96MMMg4 ",
116 " *10y8n6FjvllllB<166668 ",
117 " S-kg+>666<M<996-y6n<8* ",
118 " p71=4 m69996kD8Z-66698&& ",
119 " &i0ycm6n4 ogk17,0<6666g ",
120 " N-k-<> >=01-kuu666> ",
121 " ,6ky& &46-10ul,66, ",
122 " Ou0<> o66y<ulw<66& ",
123 " *kk5 >66By7=xu664 ",
124 " <<M4 466lj<Mxu66o ",
125 " *>> +66uv,zN666* ",
126 " 566,xxj669 ",
127 " 4666FF666> ",
128 " >966666M ",
129 " oM6668+ ",
130 " *4 ",
131 " ",
132 " "
133 };
134
135 const char *const transparent_background_css =
136 "#wheelbarrow-window { background-color: rgba(0,0,0,0.0); }";
137
138 class Wheelbarrow : public Gtk::Window
139 {
140 public:
141 Wheelbarrow();
142 ~Wheelbarrow() override;
143
144 protected:
145 void on_button_pressed(int n_press, double x, double y);
146 static void on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section,
147 const Glib::Error& error);
148
149 Glib::RefPtr<Gtk::GestureClick> m_gesture_click;
150 };
151
152
153 Wheelbarrow::Wheelbarrow()
154 {
155 set_resizable(false);
156 set_decorated(false);
157
158 set_name("wheelbarrow-window"); // CSS name, which must be used in the CSS file.
159
160 // Load extra CSS data.
161 auto css_provider = Gtk::CssProvider::create();
162 #if HAS_STYLE_PROVIDER_ADD_PROVIDER_FOR_DISPLAY
163 Gtk::StyleProvider::add_provider_for_display(get_display(), css_provider,
164 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
165 #else
166 Gtk::StyleContext::add_provider_for_display(get_display(), css_provider,
167 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
168 #endif
169 css_provider->signal_parsing_error().connect(
170 [](const auto& section, const auto& error)
171 { on_parsing_error(section, error); }
172 );
173 css_provider->load_from_data(transparent_background_css);
174
175 const auto pixbuf = Gdk::Pixbuf::create_from_xpm_data(wheelbarrow_xpm);
176 Gtk::Image *const image = Gtk::make_managed<Gtk::Image>(pixbuf);
177 image->set_size_request(48, 48);
178 set_child(*image);
179
180 m_gesture_click = Gtk::GestureClick::create();
181 m_gesture_click->set_button(0); // All mouse buttons
182 m_gesture_click->signal_pressed().connect(sigc::mem_fun(*this, &Wheelbarrow::on_button_pressed));
183 add_controller(m_gesture_click);
184 }
185
186 Wheelbarrow::~Wheelbarrow()
187 {}
188
189 void Wheelbarrow::on_button_pressed(int /* n_press */, double x, double y)
190 {
191 const auto current_button = m_gesture_click->get_current_button();
192 switch (current_button)
193 {
194 case 1:
195 {
196 auto toplevel = std::dynamic_pointer_cast<Gdk::ToplevelSurfaceImpl>(get_surface());
197 if (toplevel)
198 toplevel->begin_move(m_gesture_click->get_current_event_device(),
199 current_button, x, y, m_gesture_click->get_current_event_time());
200 break;
201 }
202 case 3:
203 close();
204 break;
205 }
206 }
207
208 void Wheelbarrow::on_parsing_error(const Glib::RefPtr<const Gtk::CssSection>& section,
209 const Glib::Error& error)
210 {
211 std::cerr << "on_parsing_error(): " << error.what() << std::endl;
212 if (section)
213 {
214 const auto file = section->get_file();
215 if (file)
216 {
217 std::cerr << " URI = " << file->get_uri() << std::endl;
218 }
219
220 auto start_location = section->get_start_location();
221 auto end_location = section->get_end_location();
222 std::cerr << " start_line = " << start_location.get_lines()+1
223 << ", end_line = " << end_location.get_lines()+1 << std::endl;
224 std::cerr << " start_position = " << start_location.get_line_chars()
225 << ", end_position = " << end_location.get_line_chars() << std::endl;
226 }
227 }
228
229 } // anonymous namespace
230
231
232 int main(int argc, char** argv)
233 {
234 auto app = Gtk::Application::create("org.gtkmm.example");
235
236 return app->make_window_and_run<Wheelbarrow>(argc, argv);
237 }