Formatted document

This commit is contained in:
daleclack 2021-12-28 16:43:23 +08:00
parent c8564d9af2
commit f8862162ae
3 changed files with 58 additions and 51 deletions

View File

@ -1,7 +1,7 @@
#include "MyImage.hh" #include "MyImage.hh"
MyImage::MyImage() MyImage::MyImage()
:scale_radio(1.0) : scale_radio(1.0)
{ {
} }
@ -17,8 +17,8 @@ bool MyImage::on_draw(const Cairo::RefPtr<Cairo::Context> &cr)
} }
// Set the default size for drawing area // Set the default size for drawing area
set_size_request(surface->get_width()*scale_radio, set_size_request(surface->get_width() * scale_radio,
surface->get_height()*scale_radio); surface->get_height() * scale_radio);
cr->scale(scale_radio, scale_radio); cr->scale(scale_radio, scale_radio);
cr->set_source(surface, 0, 0); cr->set_source(surface, 0, 0);
@ -31,11 +31,13 @@ bool MyImage::on_draw(const Cairo::RefPtr<Cairo::Context> &cr)
void MyImage::scale_draw(double scale) void MyImage::scale_draw(double scale)
{ {
// Set the scale radio and scale // Set the scale radio and scale
if(scale <= 0){ if (scale <= 0)
{
scale_radio = 0.1; scale_radio = 0.1;
return; return;
} }
if(scale > 10.0){ if (scale > 10.0)
{
scale_radio = 10.0; scale_radio = 10.0;
return; return;
} }
@ -62,7 +64,7 @@ void MyImage::set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf)
{ {
} }
//Get Image Size // Get Image Size
int width = image->get_width(); int width = image->get_width();
int height = image->get_height(); int height = image->get_height();
// Draw the image in the middle of the surface, or (if the image is // Draw the image in the middle of the surface, or (if the image is

View File

@ -2,18 +2,21 @@
#include <gtkmm.h> #include <gtkmm.h>
class MyImage : public Gtk::DrawingArea{ class MyImage : public Gtk::DrawingArea
public: {
MyImage(); public:
virtual ~MyImage(); MyImage();
//Set a Pixbuf to draw virtual ~MyImage();
void set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf); // Set a Pixbuf to draw
//Scale the image void set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf);
void scale_draw(double scale); // Scale the image
protected: void scale_draw(double scale);
bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override;
private: protected:
double scale_radio; bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override;
Cairo::RefPtr<Cairo::ImageSurface> surface;
Glib::RefPtr<Gdk::Pixbuf> image; private:
double scale_radio;
Cairo::RefPtr<Cairo::ImageSurface> surface;
Glib::RefPtr<Gdk::Pixbuf> image;
}; };

View File

@ -3,37 +3,39 @@
#include <gtkmm.h> #include <gtkmm.h>
#include "MyImage.hh" #include "MyImage.hh"
class MyWin : public Gtk::ApplicationWindow{ class MyWin : public Gtk::ApplicationWindow
public: {
MyWin(); public:
private: MyWin();
//Child widgets
Gtk::ScrolledWindow sw;
MyImage image_area;
Gtk::Box main_box,btnbox;
Gtk::Button btnopen;
Gtk::Scale scale;
Gtk::Overlay overlay;
Glib::RefPtr<Gtk::Adjustment> m_adjustment,hadjustment,vadjustment;
Glib::RefPtr<Gtk::FileChooserNative> dialog;
//Gesture control private:
Glib::RefPtr<Gtk::GestureDrag> gesture_drag; // Child widgets
Glib::RefPtr<Gtk::GestureMultiPress> gesture_click; Gtk::ScrolledWindow sw;
void drag_begin(double x,double y); MyImage image_area;
void drag_update(double x,double y); Gtk::Box main_box, btnbox;
void drag_end(double x,double y); Gtk::Button btnopen;
void move_to(double x,double y); Gtk::Scale scale;
Gtk::Overlay overlay;
Glib::RefPtr<Gtk::Adjustment> m_adjustment, hadjustment, vadjustment;
Glib::RefPtr<Gtk::FileChooserNative> dialog;
//Menu for image control // Gesture control
Gtk::PopoverMenu popover; Glib::RefPtr<Gtk::GestureDrag> gesture_drag;
void press(int n_press,double x,double y); Glib::RefPtr<Gtk::GestureMultiPress> gesture_click;
void drag_begin(double x, double y);
//Signal Handlers void drag_update(double x, double y);
void btnopen_clicked(); void drag_end(double x, double y);
void dialog_response(int response_id); void move_to(double x, double y);
void scale_changed();
void image_zoom_in(); // Menu for image control
void image_zoom_out(); Gtk::PopoverMenu popover;
void image_zoom_reset(); void press(int n_press, double x, double y);
// Signal Handlers
void btnopen_clicked();
void dialog_response(int response_id);
void scale_changed();
void image_zoom_in();
void image_zoom_out();
void image_zoom_reset();
}; };