Add Draw Area for image show
This commit is contained in:
parent
bd11f73c9b
commit
0b48e73017
|
@ -47,9 +47,9 @@ if(WIN32)
|
|||
set_property(SOURCE ../icon.rc APPEND PROPERTY
|
||||
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/../icon.ico
|
||||
)
|
||||
add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} src/main.cc src/MyWin.cc)
|
||||
add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} src/main.cc src/MyWin.cc src/MyImage.cc)
|
||||
else()
|
||||
add_executable(${PROJECT_NAME} src/main.cc src/MyWin.cc)
|
||||
add_executable(${PROJECT_NAME} src/main.cc src/MyWin.cc src/MyImage.cc)
|
||||
|
||||
endif(WIN32)
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#include "MyImage.hh"
|
||||
|
||||
MyImage::MyImage(){
|
||||
|
||||
}
|
||||
|
||||
MyImage::~MyImage(){
|
||||
|
||||
}
|
||||
|
||||
bool MyImage::on_draw(const Cairo::RefPtr<Cairo::Context> &cr){
|
||||
if(!image){
|
||||
return false;
|
||||
}
|
||||
|
||||
int width = image->get_width();
|
||||
int height = image->get_height();
|
||||
|
||||
set_size_request(width,height);
|
||||
|
||||
// Draw the image in the middle of the drawing area, or (if the image is
|
||||
// larger than the drawing area) draw the middle part of the image.
|
||||
Gdk::Cairo::set_source_pixbuf(cr, image,
|
||||
(width - image->get_width())/2, (height - image->get_height())/2);
|
||||
cr->paint();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MyImage::set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf)
|
||||
{
|
||||
image = pixbuf;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
class MyImage : public Gtk::DrawingArea{
|
||||
public:
|
||||
MyImage();
|
||||
virtual ~MyImage();
|
||||
void set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf);
|
||||
protected:
|
||||
bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override;
|
||||
Glib::RefPtr<Gdk::Pixbuf> image;
|
||||
};
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
MyWin::MyWin()
|
||||
:main_box(Gtk::ORIENTATION_VERTICAL,5),
|
||||
btnbox(Gtk::ORIENTATION_VERTICAL,5)
|
||||
btnbox(Gtk::ORIENTATION_HORIZONTAL,5),
|
||||
btnopen("Open Image")
|
||||
{
|
||||
//Add Widgets
|
||||
set_default_size(800,450);
|
||||
|
@ -13,8 +14,25 @@ btnbox(Gtk::ORIENTATION_VERTICAL,5)
|
|||
sw.add(image_area);
|
||||
main_box.pack_start(sw);
|
||||
|
||||
//Initalize Scale
|
||||
m_adjustment = Gtk::Adjustment::create(1.0,0.1,10.0,0.1,0.1);
|
||||
scale.set_default_direction(Gtk::TEXT_DIR_LTR);
|
||||
scale.set_adjustment(m_adjustment);
|
||||
|
||||
//Add control widgets
|
||||
btnbox.pack_start(scale);
|
||||
btnbox.pack_start(btnopen,Gtk::PACK_SHRINK);
|
||||
main_box.pack_start(btnbox,Gtk::PACK_SHRINK);
|
||||
btnopen.signal_clicked().connect(sigc::mem_fun(*this,&MyWin::btnopen_clicked));
|
||||
|
||||
add(main_box);
|
||||
show_all_children();
|
||||
}
|
||||
|
||||
void MyWin::btnopen_clicked(){
|
||||
|
||||
}
|
||||
|
||||
void MyWin::dialog_response(int response_id){
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include "MyImage.hh"
|
||||
|
||||
class MyWin : public Gtk::Window{
|
||||
public:
|
||||
|
@ -8,10 +9,16 @@ class MyWin : public Gtk::Window{
|
|||
private:
|
||||
//Child widgets
|
||||
Gtk::ScrolledWindow sw;
|
||||
Gtk::DrawingArea image_area;
|
||||
MyImage image_area;
|
||||
Gtk::Box main_box,btnbox;
|
||||
Gtk::Button btnopen;
|
||||
Gtk::Scale scale;
|
||||
Glib::RefPtr<Gtk::Adjustment> m_adjustment;
|
||||
Glib::RefPtr<Gtk::FileChooserNative> dialog;
|
||||
|
||||
//Gesture control
|
||||
|
||||
//Signal Handlers
|
||||
void btnopen_clicked();
|
||||
void dialog_response(int response_id);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue