Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
ImageView.hh
Go to the documentation of this file.
1
2#pragma once
3
4#include "GtkCompat.hh"
5
6#include <gtkmm/box.h>
7#include <gtkmm/image.h>
8#ifndef USE_GTK4
9#include <gtkmm/eventbox.h>
10#endif
11#include <gtkmm/drawingarea.h>
12#ifdef USE_GTK4
13#include <gtkmm/eventcontrollermotion.h>
14#endif
15
16namespace cadabra {
17
18 class ImageView;
19
22
23 class ImageArea : public Gtk::DrawingArea {
24 public:
27 const std::string& filename, bool raster);
28
29 void set_image_from_base64(const std::string& b64);
30 void set_image_from_svg(const std::string& svg);
31
32 // Re-render the image from the raw bytes at the indicated
33 // width (in logical pixels, which may be multiple display pixels).
34 void rerender(int width);
35
36 friend ImageView;
37 protected:
41 void draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
42#ifndef USE_GTK4
43 virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
44#endif
45
46 private:
47 Glib::RefPtr<Gdk::Pixbuf> pixbuf;
48
49 std::string decoded; // raw byte content of image
53 };
54
55
59
60#ifdef USE_GTK4
61 class ImageView : public Gtk::Box {
62#else
63 class ImageView : public Gtk::EventBox {
64#endif
65 public:
66 ImageView(double display_scale, int logical_width);
67 virtual ~ImageView();
68
69 void on_save_as() const;
70
72 void on_pointer_motion(double x, double y);
73#ifndef USE_GTK4
74 virtual bool on_motion_notify_event(GdkEventMotion *event) override;
75#endif
76
80 void on_button_pressed(int n_press, double x, double y);
81 void on_button_released(int n_press, double x, double y);
82
83 void set_image_from_base64(const std::string& b64);
84 void set_image_from_svg(const std::string& svg);
85
86 private:
88
89 bool sizing;
90 double prev_x, prev_y;
92
94
95 Glib::RefPtr<cdb::ClickGesture> click_gesture;
96#ifdef USE_GTK4
97 Glib::RefPtr<Gtk::EventControllerMotion> motion_controller;
98#endif
99 };
100
101};
Compatibility helpers that let the gtkmm frontend build against both gtkmm-3 and gtkmm-4 from a singl...
Widget which behaves as Gtk::Image, but instead uses the full device resolution (so images come out s...
Definition ImageView.hh:23
void set_image_from_svg(const std::string &svg)
Definition ImageView.cc:157
friend ImageView
Definition ImageView.hh:36
void draw(const Cairo::RefPtr< Cairo::Context > &cr, int width, int height)
The actual painting.
Definition ImageView.cc:213
void set_image_from_base64(const std::string &b64)
Definition ImageView.cc:140
double display_scale
Definition ImageView.hh:51
void rerender(int width)
Definition ImageView.cc:164
int logical_width
Definition ImageView.hh:52
bool is_raster
Definition ImageView.hh:50
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &cr) override
Definition ImageView.cc:221
std::string decoded
Definition ImageView.hh:49
Glib::RefPtr< Gdk::Pixbuf > pixbuf
Definition ImageView.hh:47
An image viewing widget.
Definition ImageView.hh:63
void set_image_from_svg(const std::string &svg)
Definition ImageView.cc:152
void on_button_released(int n_press, double x, double y)
Definition ImageView.cc:129
cdb::ContextMenu context_menu
Definition ImageView.hh:93
ImageArea area
Definition ImageView.hh:87
void set_image_from_base64(const std::string &b64)
Definition ImageView.cc:135
int height_at_press
Definition ImageView.hh:91
virtual bool on_motion_notify_event(GdkEventMotion *event) override
Definition ImageView.cc:101
int width_at_press
Definition ImageView.hh:91
virtual ~ImageView()
Definition ImageView.cc:64
bool sizing
Definition ImageView.hh:89
void on_button_pressed(int n_press, double x, double y)
Button handling goes through a gesture controller rather than the on_button_{press,...
Definition ImageView.cc:108
double prev_x
Definition ImageView.hh:90
void on_save_as() const
Definition ImageView.cc:68
double prev_y
Definition ImageView.hh:90
Glib::RefPtr< cdb::ClickGesture > click_gesture
Definition ImageView.hh:95
void on_pointer_motion(double x, double y)
Drag-to-resize, shared between the toolkits.
Definition ImageView.cc:92
A right-click context menu.
Definition GtkCompat.hh:439
Functions to handle the exchange properties of two or more symbols in a product.
Definition Adjform.cc:83
void set(rset_t::iterator &num, multiplier_t fac)
Definition Storage.cc:1180