From 4872d564619269a200f000329cd3f5a41fda889f Mon Sep 17 00:00:00 2001 From: paolo Date: Wed, 13 Sep 2006 22:05:36 +0000 Subject: [PATCH] - holt_container: partial implemented (and commented) scaling menu - simulation_widget: added scaling popup menu git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1138 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/holt_container_window.cc | 43 ++++++++++++-- src/holt_container_window.hh | 3 + src/simulation_widget.cc | 111 +++++++++++++++++++++++++++++++++-- src/simulation_widget.hh | 6 +- 4 files changed, 153 insertions(+), 10 deletions(-) diff --git a/src/holt_container_window.cc b/src/holt_container_window.cc index 516a215..0d01878 100644 --- a/src/holt_container_window.cc +++ b/src/holt_container_window.cc @@ -76,37 +76,56 @@ HoltContainerWindow::on_button_press_event(GdkEventButton* event) "" " "; - HoltWidget::arrange_mode arrange = _holt_widget.get_arrange_mode(); + HoltWidget::arrange_mode arrange = _holt_widget.get_arrange_mode(); + CairoWidget::scaling_mode scaling = _holt_widget.get_scaling_mode(); RefPtr action_group = Gtk::ActionGroup::create(); if(_auto_dispose || arrange!=HoltWidget::arrange_vertical) { - action_group->add( Gtk::Action::create("DisposeVertical", "Dispose _Vertical"), + action_group->add( Gtk::Action::create("DisposeVertical", "Dispose _vertical"), sigc::mem_fun(*this, &HoltContainerWindow::_on_dispose_vertical) ); ui_info += " "; } if(_auto_dispose || arrange!=HoltWidget::arrange_horizontal) { - action_group->add( Gtk::Action::create("DisposeHorizontal", "Dispose _Horizontal"), + action_group->add( Gtk::Action::create("DisposeHorizontal", "Dispose _horizontal"), sigc::mem_fun(*this, &HoltContainerWindow::_on_dispose_horizontal) ); ui_info += " "; } if(_auto_dispose || arrange!=HoltWidget::arrange_circular) { - action_group->add( Gtk::Action::create("DisposeCircular", "Dispose _Circular"), + action_group->add( Gtk::Action::create("DisposeCircular", "Dispose _circular"), sigc::mem_fun(*this, &HoltContainerWindow::_on_dispose_circular) ); ui_info += " "; } if(!_auto_dispose) { - action_group->add( Gtk::Action::create("DisposeAuto", "_Auto Dispose"), + action_group->add( Gtk::Action::create("DisposeAuto", "_Auto dispose"), sigc::mem_fun(*this, &HoltContainerWindow::_on_dispose_auto) ); ui_info += " "; } + + /* disabled scaling options + if(scaling==CairoWidget::scaling_min) + { + action_group->add( Gtk::Action::create("ScalingNone", "Auto _resize window"), + sigc::mem_fun(*this, &HoltContainerWindow::_on_no_scaling) ); + ui_info += " " + " "; + } + else + { + // scaling==scaling_none + action_group->add( Gtk::Action::create("ScalingFit", "_Fit in window"), + sigc::mem_fun(*this, &HoltContainerWindow::_on_fit_scaling) ); + ui_info += " " + " "; + } + */ RefPtr UIManager = Gtk::UIManager::create(); UIManager->insert_action_group(action_group); @@ -157,6 +176,20 @@ HoltContainerWindow::_on_dispose_auto() _holt_widget.resize_redraw(); } +void +HoltContainerWindow::_on_no_scaling() +{ + _holt_widget.set_scaling_mode(CairoWidget::scaling_none); + _holt_widget.resize_redraw(); +} + +void +HoltContainerWindow::_on_fit_scaling() +{ + _holt_widget.set_scaling_mode(CairoWidget::scaling_min); + _holt_widget.resize_redraw(); +} + void HoltContainerWindow::set_disposition() { if(_auto_dispose){ diff --git a/src/holt_container_window.hh b/src/holt_container_window.hh index 1786400..5b1935f 100644 --- a/src/holt_container_window.hh +++ b/src/holt_container_window.hh @@ -60,6 +60,9 @@ namespace sgpem { void _on_dispose_circular(); void _on_dispose_horizontal(); void _on_dispose_auto(); + void _on_no_scaling(); + void _on_fit_scaling(); + HoltWidget _holt_widget; bool _auto_dispose; diff --git a/src/simulation_widget.cc b/src/simulation_widget.cc index 1f11fd0..910803d 100644 --- a/src/simulation_widget.cc +++ b/src/simulation_widget.cc @@ -19,11 +19,15 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "gettext.h" - #include "simulation_widget.hh" - #include "cairo_elements.hh" +#include +#include +#include +#include +#include + #include #include #include @@ -35,6 +39,8 @@ #endif using namespace sgpem; +using namespace Gtk; +using namespace Glib; SimulationWidget::SimulationWidget(Simulation& simulation) @@ -272,7 +278,6 @@ SimulationWidget::draw_grid(cairo_t* ctx) // - draw right VER line cairo_move_to(ctx, left_graph_margin + graph_width, top_margin); cairo_rel_line_to(ctx, 0, graph_height); - } cairo_stroke(ctx); @@ -281,7 +286,7 @@ SimulationWidget::draw_grid(cairo_t* ctx) cairo_save(ctx); cairo_set_line_width(ctx, 0.125 * cairo_get_line_width(ctx)); cairo_set_source_rgb(ctx, 0.3, 0.3, 0.3); - for(double step = 2.0 + _x_unit; step < graph_width - _x_unit; step += 5 * _x_unit) + for(double step = _x_unit; step < graph_width - _x_unit; step += 5 * _x_unit) { cairo_new_path(ctx); cairo_move_to(ctx, left_graph_margin + step, top_margin); @@ -529,3 +534,101 @@ SimulationWidget::make_gradients() cairo_pattern_add_color_stop_rgb(_blocked_process_gradient, 1.0, 0.65, 0.0, 0.0); } + + +bool +SimulationWidget::on_button_press_event(GdkEventButton* event) +{ + if((event->type & Gdk::BUTTON_PRESS) == Gdk::BUTTON_PRESS && (event->button == 3)) + { + Glib::ustring ui_info = + "" + " "; + + CairoWidget::scaling_mode scaling = get_scaling_mode(); + + RefPtr action_group = Gtk::ActionGroup::create(); + + + if(scaling!=CairoWidget::scaling_none) + { + action_group->add( Gtk::Action::create("ScalingNone", "_No scaling"), + sigc::mem_fun(*this, &SimulationWidget::_on_no_scaling) ); + ui_info += " "; + } + + if(scaling!=CairoWidget::scaling_min) + { + // scaling==scaling_none + action_group->add( Gtk::Action::create("ScalingFit", "_Fit in window"), + sigc::mem_fun(*this, &SimulationWidget::_on_fit_scaling) ); + ui_info += " "; + } + + if(scaling!=CairoWidget::scaling_all) + { + // scaling==scaling_none + action_group->add( Gtk::Action::create("ScalingStretch", "_Stretch in window"), + sigc::mem_fun(*this, &SimulationWidget::_on_stretch_scaling) ); + ui_info += " "; + } + + RefPtr UIManager = Gtk::UIManager::create(); + UIManager->insert_action_group(action_group); + + ui_info += + " " + ""; + + UIManager->add_ui_from_string(ui_info); + Gtk::Menu* menu = dynamic_cast(UIManager->get_widget("/PopupMenu")); + + menu->popup(event->button, event->time); + return true; //It has been handled. + } + else + return false; +} + +void +SimulationWidget::_on_no_scaling() +{ +#ifndef NDEBUG + std::cout << "before SimulationWidget::_on_no_scaling mode=" << get_scaling_mode() << std::endl; +#endif + set_scaling_mode(CairoWidget::scaling_none); +#ifndef NDEBUG + std::cout << "after SimulationWidget::_on_no_scaling mode=" << get_scaling_mode() << std::endl; +#endif + resize_redraw(); + set_size_request (20, 20); // force container redimensioning + +} + +void +SimulationWidget::_on_fit_scaling() +{ +#ifndef NDEBUG + std::cout << "before SimulationWidget::_on_fit_scaling mode=" << get_scaling_mode() << std::endl; +#endif + set_scaling_mode(CairoWidget::scaling_min); +#ifndef NDEBUG + std::cout << "after SimulationWidget::_on_fit_scaling mode=" << get_scaling_mode() << std::endl; +#endif + resize_redraw(); + set_size_request (20, 20); // force container redimensioning +} + +void +SimulationWidget::_on_stretch_scaling() +{ +#ifndef NDEBUG + std::cout << "before SimulationWidget::_on_stretch_scaling mode=" << get_scaling_mode() << std::endl; +#endif + set_scaling_mode(CairoWidget::scaling_all); +#ifndef NDEBUG + std::cout << "after SimulationWidget::_on_stretch_scaling mode=" << get_scaling_mode() << std::endl; +#endif + resize_redraw(); + set_size_request (20, 20); // force container redimensioning +} diff --git a/src/simulation_widget.hh b/src/simulation_widget.hh index a7f127d..9941f37 100644 --- a/src/simulation_widget.hh +++ b/src/simulation_widget.hh @@ -43,7 +43,7 @@ namespace sgpem bool set_show_threads(bool show); protected: - //virtual bool on_button_press_event(GdkEventButton* event); + virtual bool on_button_press_event(GdkEventButton* event); // void change_scaling_mode(); void draw_widget(cairo_t* ctx); @@ -60,6 +60,10 @@ namespace sgpem private: + void _on_no_scaling(); + void _on_fit_scaling(); + void _on_stretch_scaling(); + Simulation* _simulation; bool _show_threads;