|
|
538bb7 |
#include <iostream></iostream>
|
|
|
538bb7 |
#include <utility></utility>
|
|
|
538bb7 |
|
|
|
538bb7 |
#include <gdkmm pixbuf.h=""></gdkmm>
|
|
|
538bb7 |
#include <gtkmm hvbox.h=""></gtkmm>
|
|
|
538bb7 |
#include <gtkmm image.h=""></gtkmm>
|
|
|
538bb7 |
|
|
|
538bb7 |
#include "generator.h"
|
|
|
538bb7 |
#include "surface.h"
|
|
|
538bb7 |
|
|
|
538bb7 |
#include "mainwindow.h"
|
|
|
538bb7 |
|
|
|
538bb7 |
|
|
|
538bb7 |
MainWindow::MainWindow():
|
|
|
538bb7 |
src_rect0 (new View::Point( Vector2(-10, -10) )),
|
|
|
538bb7 |
src_rect1 (new View::Point( Vector2( 10, 10) )),
|
|
|
538bb7 |
dst_rect0 (new View::Point( Vector2(-10, -10) )),
|
|
|
538bb7 |
dst_rect1 (new View::Point( Vector2( 10, -10) )),
|
|
|
538bb7 |
dst_rect2 (new View::Point( Vector2( 10, 10) )),
|
|
|
538bb7 |
dst_rect3 (new View::Point( Vector2(-10, 10) )),
|
|
|
538bb7 |
dst_bounds0 (new View::Point( Vector2(-20, -20) )),
|
|
|
538bb7 |
dst_bounds1 (new View::Point( Vector2( 20, 20) ))
|
|
|
538bb7 |
{
|
|
|
538bb7 |
set_default_size(200, 200);
|
|
|
538bb7 |
|
|
|
538bb7 |
Gtk::HBox *hbox = manage(new Gtk::HBox());
|
|
|
538bb7 |
hbox->set_homogeneous(true);
|
|
|
538bb7 |
|
|
|
538bb7 |
src_view.points.push_back(src_rect0);
|
|
|
538bb7 |
src_view.points.push_back(src_rect1);
|
|
|
538bb7 |
src_view.signal_point_motion.connect(
|
|
|
538bb7 |
sigc::mem_fun(*this, &MainWindow::on_point_motion) );
|
|
|
538bb7 |
src_view.signal_point_changed.connect(
|
|
|
538bb7 |
sigc::mem_fun(*this, &MainWindow::on_point_changed) );
|
|
|
538bb7 |
src_view.signal_draw_view.connect(
|
|
|
538bb7 |
sigc::mem_fun(*this, &MainWindow::on_draw_src_view) );
|
|
|
538bb7 |
hbox->add(src_view);
|
|
|
538bb7 |
|
|
|
538bb7 |
dst_view.points.push_back(dst_rect0);
|
|
|
538bb7 |
dst_view.points.push_back(dst_rect1);
|
|
|
538bb7 |
dst_view.points.push_back(dst_rect2);
|
|
|
538bb7 |
dst_view.points.push_back(dst_rect3);
|
|
|
538bb7 |
dst_view.points.push_back(dst_bounds0);
|
|
|
538bb7 |
dst_view.points.push_back(dst_bounds1);
|
|
|
538bb7 |
dst_view.signal_point_motion.connect(
|
|
|
538bb7 |
sigc::mem_fun(*this, &MainWindow::on_point_motion) );
|
|
|
538bb7 |
dst_view.signal_point_changed.connect(
|
|
|
538bb7 |
sigc::mem_fun(*this, &MainWindow::on_point_changed) );
|
|
|
538bb7 |
dst_view.signal_draw_view.connect(
|
|
|
538bb7 |
sigc::mem_fun(*this, &MainWindow::on_draw_dst_view) );
|
|
|
538bb7 |
hbox->add(dst_view);
|
|
|
538bb7 |
|
|
|
538bb7 |
hbox->add(*manage(generator_demo()));
|
|
|
538bb7 |
|
|
|
538bb7 |
add(*hbox);
|
|
|
538bb7 |
show_all();
|
|
|
538bb7 |
}
|
|
|
538bb7 |
|
|
|
538bb7 |
Gtk::Widget*
|
|
|
538bb7 |
MainWindow::generator_demo() {
|
|
|
538bb7 |
std::cout << "generator demo: generate" << std::endl;
|
|
|
538bb7 |
Generator generator;
|
|
|
538bb7 |
DataSurface surface(256, 256);
|
|
|
538bb7 |
generator.generate(surface, Vector2(0, 0), Vector2(16, 16));
|
|
|
538bb7 |
|
|
|
538bb7 |
std::cout << "generator demo: convert" << std::endl;
|
|
|
538bb7 |
Glib::RefPtr<gdk::pixbuf> pixbuf = Gdk::Pixbuf::create(</gdk::pixbuf>
|
|
|
538bb7 |
Gdk::COLORSPACE_RGB, true, 8, surface.width(), surface.height() );
|
|
|
538bb7 |
guint8 *pixel = pixbuf->get_pixels();
|
|
|
538bb7 |
for(int r = 0; r < surface.height(); ++r) {
|
|
|
538bb7 |
Color *row = surface[r];
|
|
|
538bb7 |
for(int c = 0; c < surface.width(); ++c) {
|
|
|
538bb7 |
const Color &color = row[c];
|
|
|
538bb7 |
*(pixel++) = (guint8)(color.r*255.9);
|
|
|
538bb7 |
*(pixel++) = (guint8)(color.g*255.9);
|
|
|
538bb7 |
*(pixel++) = (guint8)(color.b*255.9);
|
|
|
538bb7 |
*(pixel++) = (guint8)(color.a*255.9);
|
|
|
538bb7 |
}
|
|
|
538bb7 |
}
|
|
|
538bb7 |
|
|
|
538bb7 |
return new Gtk::Image(pixbuf);
|
|
|
538bb7 |
}
|
|
|
538bb7 |
|
|
|
538bb7 |
void
|
|
|
538bb7 |
MainWindow::on_point_motion(const View::PointPtr &/*point*/) {
|
|
|
538bb7 |
queue_draw();
|
|
|
538bb7 |
}
|
|
|
538bb7 |
|
|
|
538bb7 |
void
|
|
|
538bb7 |
MainWindow::on_point_changed(const View::PointPtr &/*point*/) {
|
|
|
538bb7 |
}
|
|
|
538bb7 |
|
|
|
538bb7 |
void
|
|
|
538bb7 |
MainWindow::on_draw_src_view(const Cairo::RefPtr<cairo::context> &context) {</cairo::context>
|
|
|
538bb7 |
const Real ps = src_view.get_pixel_size();
|
|
|
538bb7 |
|
|
|
538bb7 |
context->save();
|
|
|
538bb7 |
|
|
|
538bb7 |
context->move_to(src_rect0->position.x, src_rect0->position.y);
|
|
|
538bb7 |
context->line_to(src_rect0->position.x, src_rect1->position.y);
|
|
|
538bb7 |
context->line_to(src_rect1->position.x, src_rect1->position.y);
|
|
|
538bb7 |
context->line_to(src_rect1->position.x, src_rect0->position.y);
|
|
|
538bb7 |
context->close_path();
|
|
|
538bb7 |
context->set_line_width(ps);
|
|
|
538bb7 |
context->set_source_rgba(1, 1, 0, 0.5);
|
|
|
538bb7 |
context->stroke();
|
|
|
538bb7 |
|
|
|
538bb7 |
context->restore();
|
|
|
538bb7 |
}
|
|
|
538bb7 |
|
|
|
538bb7 |
void
|
|
|
538bb7 |
MainWindow::on_draw_dst_view(const Cairo::RefPtr<cairo::context> &context) {</cairo::context>
|
|
|
538bb7 |
const Real ps = src_view.get_pixel_size();
|
|
|
538bb7 |
|
|
|
538bb7 |
context->save();
|
|
|
538bb7 |
|
|
|
538bb7 |
context->move_to(dst_rect0->position.x, dst_rect0->position.y);
|
|
|
538bb7 |
context->line_to(dst_rect1->position.x, dst_rect1->position.y);
|
|
|
538bb7 |
context->line_to(dst_rect2->position.x, dst_rect2->position.y);
|
|
|
538bb7 |
context->line_to(dst_rect3->position.x, dst_rect3->position.y);
|
|
|
538bb7 |
context->close_path();
|
|
|
538bb7 |
context->set_line_width(ps);
|
|
|
538bb7 |
context->set_source_rgba(1, 1, 0, 0.5);
|
|
|
538bb7 |
context->stroke();
|
|
|
538bb7 |
|
|
|
538bb7 |
context->move_to(dst_bounds0->position.x, dst_bounds0->position.y);
|
|
|
538bb7 |
context->line_to(dst_bounds0->position.x, dst_bounds1->position.y);
|
|
|
538bb7 |
context->line_to(dst_bounds1->position.x, dst_bounds1->position.y);
|
|
|
538bb7 |
context->line_to(dst_bounds1->position.x, dst_bounds0->position.y);
|
|
|
538bb7 |
context->close_path();
|
|
|
538bb7 |
context->set_line_width(ps);
|
|
|
538bb7 |
context->set_source_rgba(1, 0, 0, 0.5);
|
|
|
538bb7 |
context->stroke();
|
|
|
538bb7 |
|
|
|
538bb7 |
context->restore();
|
|
|
538bb7 |
}
|