2006-08-12 17:49:37 +02:00
|
|
|
// src/simulation_widget.cc - Copyright 2005, 2006, University
|
2006-07-12 11:24:57 +02:00
|
|
|
// of Padova, dept. of Pure and Applied
|
|
|
|
// Mathematics
|
|
|
|
//
|
|
|
|
// This file is part of SGPEMv2.
|
|
|
|
//
|
|
|
|
// This is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// SGPEMv2 is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with SGPEMv2; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2006-08-12 17:49:37 +02:00
|
|
|
#include "simulation_widget.hh"
|
2006-07-12 11:24:57 +02:00
|
|
|
|
2006-08-04 22:08:55 +02:00
|
|
|
#include "cairo_elements.hh"
|
2006-08-18 09:27:00 +02:00
|
|
|
#include "backend/history.hh"
|
|
|
|
#include "backend/simulation.hh"
|
|
|
|
#include "backend/string_utils.hh"
|
2006-08-03 13:16:16 +02:00
|
|
|
|
2006-08-03 17:43:21 +02:00
|
|
|
#include <cassert>
|
|
|
|
|
2006-08-12 17:49:37 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
#include <iostream>
|
|
|
|
#endif
|
|
|
|
|
2006-07-12 11:24:57 +02:00
|
|
|
using namespace sgpem;
|
|
|
|
|
|
|
|
|
2006-08-12 17:49:37 +02:00
|
|
|
SimulationWidget::SimulationWidget()
|
2006-08-18 09:27:00 +02:00
|
|
|
: Glib::ObjectBase("sgpem_SimulationWidget"), CairoWidget(),
|
|
|
|
_n_update(0)
|
|
|
|
{
|
|
|
|
// Register this observer:
|
|
|
|
Simulation::get_instance().get_history().attach(*this);
|
|
|
|
}
|
2006-08-09 16:38:45 +02:00
|
|
|
|
2006-07-12 11:24:57 +02:00
|
|
|
|
2006-08-12 17:49:37 +02:00
|
|
|
SimulationWidget::~SimulationWidget()
|
2006-08-18 09:27:00 +02:00
|
|
|
{
|
|
|
|
Simulation::get_instance().get_history().detach(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SimulationWidget::update(const History& history)
|
|
|
|
{
|
|
|
|
_n_update++;
|
|
|
|
std::cout << " update: " << _n_update << std::endl;
|
|
|
|
|
|
|
|
// Force redraw
|
|
|
|
redraw();
|
|
|
|
}
|
2006-07-28 17:24:56 +02:00
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
|
|
|
|
void
|
2006-08-12 17:49:37 +02:00
|
|
|
SimulationWidget::draw_widget(cairo_t* ctx)
|
2006-08-02 15:48:26 +02:00
|
|
|
{
|
2006-08-18 09:27:00 +02:00
|
|
|
cairo_set_source_rgb(ctx, 0, 0, 0);
|
|
|
|
cairo_move_to(ctx, 0, 0);
|
|
|
|
cairo_line_to(ctx, 300, 350);
|
|
|
|
cairo_stroke(ctx);
|
|
|
|
|
|
|
|
cairo_set_source_rgb(ctx, 0, 0, 0);
|
|
|
|
cairo_move_to(ctx, 0, 0);
|
|
|
|
cairo_line_to(ctx, 300, 350);
|
2006-07-28 17:24:56 +02:00
|
|
|
// NOTE: just to try
|
2006-08-02 15:48:26 +02:00
|
|
|
CairoElements ce(ctx);
|
2006-08-04 22:08:55 +02:00
|
|
|
|
2006-08-18 09:27:00 +02:00
|
|
|
Rectangle area = { 30, 30, 100, 100 };
|
2006-08-04 22:08:55 +02:00
|
|
|
ce.draw_container(area);
|
|
|
|
|
2006-07-28 17:24:56 +02:00
|
|
|
Color red = { 1, 0, 0 };
|
2006-08-18 09:27:00 +02:00
|
|
|
Point center = { 25, 25 };
|
|
|
|
ce.draw_3dsphere(center, 20, red);
|
|
|
|
|
|
|
|
Glib::ustring msg("Number of updates: "), number;
|
|
|
|
int_to_string(_n_update, number);
|
|
|
|
msg = msg + number;
|
|
|
|
cairo_move_to(ctx, 10, 105);
|
|
|
|
cairo_show_text(ctx,msg.c_str());
|
|
|
|
|
|
|
|
switch(get_scaling_mode())
|
|
|
|
{
|
|
|
|
case CairoWidget::scaling_none:
|
|
|
|
msg = "scaling_none = without any scaling";
|
|
|
|
break;
|
|
|
|
case CairoWidget::scaling_to_w:
|
|
|
|
msg = "scaling_to_w = uses width to calculate scale factor";
|
|
|
|
break;
|
|
|
|
case CairoWidget::scaling_to_h:
|
|
|
|
msg = "scaling_to_h = uses height to calculate scale factor";
|
|
|
|
break;
|
|
|
|
case CairoWidget::scaling_min:
|
|
|
|
msg = "scaling_min = uses minimum scale factor from width, height";
|
|
|
|
break;
|
|
|
|
case CairoWidget::scaling_max:
|
|
|
|
msg = "scaling_max = uses maximum scale factor from width, height";
|
|
|
|
break;
|
|
|
|
case CairoWidget::scaling_all:
|
|
|
|
msg = "scaling_all = scale to stretch into client area";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cairo_move_to(ctx, 10, 115);
|
|
|
|
cairo_show_text(ctx,msg.c_str());
|
|
|
|
msg = "clic to change mode...";
|
|
|
|
cairo_move_to(ctx, 10, 125);
|
|
|
|
cairo_show_text(ctx,msg.c_str());
|
2006-08-09 16:38:45 +02:00
|
|
|
|
2006-08-02 15:48:26 +02:00
|
|
|
}
|
|
|
|
|
2006-07-28 17:24:56 +02:00
|
|
|
|
2006-08-18 09:27:00 +02:00
|
|
|
void
|
|
|
|
SimulationWidget::calc_size(size_t& width, size_t& height) const
|
|
|
|
{
|
|
|
|
// FIXME: write me
|
|
|
|
// some magic here!
|
|
|
|
width = 300;
|
|
|
|
height = 350;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-08-12 17:49:37 +02:00
|
|
|
void
|
|
|
|
SimulationWidget::calc_size(const History& history, size_t& width, size_t& height) const
|
2006-08-02 15:48:26 +02:00
|
|
|
{
|
|
|
|
// FIXME: write me
|
2006-08-12 17:49:37 +02:00
|
|
|
width = get_allocation().get_width();
|
|
|
|
height = get_allocation().get_height();
|
|
|
|
|
2006-07-12 11:24:57 +02:00
|
|
|
}
|
2006-08-18 09:27:00 +02:00
|
|
|
*/
|