Formatted document
This commit is contained in:
parent
c8564d9af2
commit
f8862162ae
|
@ -1,7 +1,7 @@
|
|||
#include "MyImage.hh"
|
||||
|
||||
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_size_request(surface->get_width()*scale_radio,
|
||||
surface->get_height()*scale_radio);
|
||||
set_size_request(surface->get_width() * scale_radio,
|
||||
surface->get_height() * scale_radio);
|
||||
|
||||
cr->scale(scale_radio, scale_radio);
|
||||
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)
|
||||
{
|
||||
// Set the scale radio and scale
|
||||
if(scale <= 0){
|
||||
if (scale <= 0)
|
||||
{
|
||||
scale_radio = 0.1;
|
||||
return;
|
||||
}
|
||||
if(scale > 10.0){
|
||||
if (scale > 10.0)
|
||||
{
|
||||
scale_radio = 10.0;
|
||||
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 height = image->get_height();
|
||||
// Draw the image in the middle of the surface, or (if the image is
|
||||
|
|
|
@ -2,18 +2,21 @@
|
|||
|
||||
#include <gtkmm.h>
|
||||
|
||||
class MyImage : public Gtk::DrawingArea{
|
||||
public:
|
||||
MyImage();
|
||||
virtual ~MyImage();
|
||||
//Set a Pixbuf to draw
|
||||
void set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf);
|
||||
//Scale the image
|
||||
void scale_draw(double scale);
|
||||
protected:
|
||||
bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override;
|
||||
private:
|
||||
double scale_radio;
|
||||
Cairo::RefPtr<Cairo::ImageSurface> surface;
|
||||
Glib::RefPtr<Gdk::Pixbuf> image;
|
||||
class MyImage : public Gtk::DrawingArea
|
||||
{
|
||||
public:
|
||||
MyImage();
|
||||
virtual ~MyImage();
|
||||
// Set a Pixbuf to draw
|
||||
void set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf);
|
||||
// Scale the image
|
||||
void scale_draw(double scale);
|
||||
|
||||
protected:
|
||||
bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override;
|
||||
|
||||
private:
|
||||
double scale_radio;
|
||||
Cairo::RefPtr<Cairo::ImageSurface> surface;
|
||||
Glib::RefPtr<Gdk::Pixbuf> image;
|
||||
};
|
||||
|
|
|
@ -3,37 +3,39 @@
|
|||
#include <gtkmm.h>
|
||||
#include "MyImage.hh"
|
||||
|
||||
class MyWin : public Gtk::ApplicationWindow{
|
||||
public:
|
||||
MyWin();
|
||||
private:
|
||||
//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;
|
||||
class MyWin : public Gtk::ApplicationWindow
|
||||
{
|
||||
public:
|
||||
MyWin();
|
||||
|
||||
//Gesture control
|
||||
Glib::RefPtr<Gtk::GestureDrag> gesture_drag;
|
||||
Glib::RefPtr<Gtk::GestureMultiPress> gesture_click;
|
||||
void drag_begin(double x,double y);
|
||||
void drag_update(double x,double y);
|
||||
void drag_end(double x,double y);
|
||||
void move_to(double x,double y);
|
||||
private:
|
||||
// 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;
|
||||
|
||||
//Menu for image control
|
||||
Gtk::PopoverMenu popover;
|
||||
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();
|
||||
// Gesture control
|
||||
Glib::RefPtr<Gtk::GestureDrag> gesture_drag;
|
||||
Glib::RefPtr<Gtk::GestureMultiPress> gesture_click;
|
||||
void drag_begin(double x, double y);
|
||||
void drag_update(double x, double y);
|
||||
void drag_end(double x, double y);
|
||||
void move_to(double x, double y);
|
||||
|
||||
// Menu for image control
|
||||
Gtk::PopoverMenu popover;
|
||||
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();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue