[avida-cvs] avida CVS commits: /current/source/qt-viewer map_view.cc map_view.hh map_view_widget.cc map_view_widget.hh
goingssh
avida-cvs at alife.org
Tue Jun 24 21:40:48 PDT 2003
goingssh Tue Jun 24 13:40:48 2003 EDT
Modified files:
/avida/current/source/qt-viewer map_view.cc map_view.hh
map_view_widget.cc
map_view_widget.hh
Log:
fixed zoom problems in qt-viewer, modified code so center remains constant during zooming in qt-viewer
Index: avida/current/source/qt-viewer/map_view.cc
diff -u avida/current/source/qt-viewer/map_view.cc:1.11 avida/current/source/qt-viewer/map_view.cc:1.12
--- avida/current/source/qt-viewer/map_view.cc:1.11 Sat May 17 12:33:56 2003
+++ avida/current/source/qt-viewer/map_view.cc Tue Jun 24 13:40:48 2003
@@ -11,6 +11,7 @@
#include <qlayout.h>
#include <qslider.h>
#include <qcombobox.h>
+#include <qspinbox.h>
using namespace std;
@@ -93,19 +94,21 @@
m_mode_combo->setCurrentItem(3);
setMapMode( 3 );
+ // add box for zoom value
hlayout->addWidget( new QLabel( "Zoom: ", this ) );
- m_zoom_slider = new QSlider( QSlider::Horizontal, this );
- m_zoom_slider->setRange( 10, 500 );
- // m_zoom_slider->setTracking( false );
- hlayout->addWidget( m_zoom_slider, 5 );
+ m_zoom_spinbox = new QSpinBox( this );
+ m_zoom_spinbox->setMinValue( 10 );
+ m_zoom_spinbox->setMaxValue( 500 );
+ m_zoom_spinbox->setLineStep( 10 );
+ hlayout->addWidget( m_zoom_spinbox);
layout->addLayout( hlayout );
- connect( m_zoom_slider, SIGNAL( valueChanged ( int ) ),
+ connect( m_zoom_spinbox, SIGNAL( valueChanged ( int ) ),
this, SLOT( generateZoomValue( int ) ) );
connect( this, SIGNAL( zoomValueChanged( double ) ),
m_map_view_widget, SLOT( setZoomFactor( double ) ) );
- m_zoom_slider->setValue( 50 );
+ m_zoom_spinbox->setValue( 50 );
// activate the layout
layout->activate();
@@ -125,7 +128,7 @@
void
MapView::repaintMap()
{
- m_map_view_widget->drawViewport();
+ m_map_view_widget->drawViewport(false);
}
void
Index: avida/current/source/qt-viewer/map_view.hh
diff -u avida/current/source/qt-viewer/map_view.hh:1.8 avida/current/source/qt-viewer/map_view.hh:1.9
--- avida/current/source/qt-viewer/map_view.hh:1.8 Sat May 17 02:48:11 2003
+++ avida/current/source/qt-viewer/map_view.hh Tue Jun 24 13:40:48 2003
@@ -16,6 +16,7 @@
class QSlider;
class QComboBox;
+class QSpinBox;
//class cPopulation;
class avd_MissionControl;
@@ -28,7 +29,7 @@
avd_MissionControl *m_mission_control; // pointer to avida population
MapViewWidget *m_map_view_widget; // the main widget
ColorScaleWidget *m_color_scale_widget; // the color scale widget
- QSlider *m_zoom_slider;
+ QSpinBox *m_zoom_spinbox;
QSlider *m_center_x_slider;
QSlider *m_center_y_slider;
QComboBox *m_mode_combo;
Index: avida/current/source/qt-viewer/map_view_widget.cc
diff -u avida/current/source/qt-viewer/map_view_widget.cc:1.13 avida/current/source/qt-viewer/map_view_widget.cc:1.14
--- avida/current/source/qt-viewer/map_view_widget.cc:1.13 Sat May 17 12:33:57 2003
+++ avida/current/source/qt-viewer/map_view_widget.cc Tue Jun 24 13:40:48 2003
@@ -79,7 +79,7 @@
{
// uncomment the following line if you want to play around
// with the automatic centering after zoom.
-//#define __AUTO_CENTER_ON_ZOOM__
+#define __AUTO_CENTER_ON_ZOOM__
if ( value > 0 ){
#ifdef __AUTO_CENTER_ON_ZOOM__
@@ -87,6 +87,7 @@
#endif
m_zoom = value;
+
blockSignals( true ); // block all signals (we want to draw only once).
@@ -111,15 +112,34 @@
// get the current center:
#ifdef __AUTO_CENTER_ON_ZOOM__
- int cx = contentsX() + visibleWidth()/2;
- int cy = contentsY() + visibleHeight()/2;
+
+ int width;
+ int height;
+
+ // use appropriate width to calculate new center, mapsize if it's
+ // smaller than visible area, otherwise visible area
+ if( visibleWidth() < m_world_x*old_zoom*m_cell_width )
+ width = visibleWidth();
+ else
+ width = m_world_x*old_zoom*m_cell_width;
+ if( visibleHeight() < m_world_y*old_zoom*m_cell_height )
+ height = visibleHeight();
+ else
+ height = m_world_y*old_zoom*m_cell_height;
+
// recalculate the new center:
- cx = (int) (cx*m_zoom/old_zoom);
- cy = (int) (cy*m_zoom/old_zoom);
+ double dcx = contentsX() + width/2.;
+ double dcy = contentsY() + height/2.;
+ int cx = (int) (dcx*m_zoom/old_zoom);
+ int cy = (int) (dcy*m_zoom/old_zoom);
center( cx, cy ); // make sure the center stays the same after zoom
#endif
- drawViewport();
+ //if zooming out so map is getting smaller, first erase then draw
+ bool redraw = false;
+ if (old_zoom > m_zoom) redraw = true;
+
+ drawViewport(redraw);
blockSignals( false ); // now we can allow signals again.
}
@@ -135,7 +155,7 @@
// reverse offset for better user experience
m_x_offset = m_world_x - 1 - value;
allChanged(); // mark all cells as changed
- drawViewport();
+ drawViewport(false);
}
}
@@ -146,7 +166,7 @@
// reverse offset for better user experience
m_y_offset = m_world_y - 1 - value;
allChanged(); // mark all cells as changed
- drawViewport();
+ drawViewport(false);
}
}
@@ -154,7 +174,7 @@
MapViewWidget::setMapMode( MapViewCellColorUtil::MapMode mode )
{
m_color_util->setMapMode( mode );
- drawViewport();
+ drawViewport(false);
}
void
@@ -240,9 +260,9 @@
void
-MapViewWidget::drawViewport()
+MapViewWidget::drawViewport(bool redraw)
{
- viewport()->repaint( false );
+ viewport()->repaint( redraw );
}
void
@@ -350,7 +370,7 @@
emit cellSelected( m_x_selected
+ m_world_x * m_y_selected );
- drawViewport();
+ drawViewport(false);
}
//#include "map_view_widget.moc"
Index: avida/current/source/qt-viewer/map_view_widget.hh
diff -u avida/current/source/qt-viewer/map_view_widget.hh:1.9 avida/current/source/qt-viewer/map_view_widget.hh:1.10
--- avida/current/source/qt-viewer/map_view_widget.hh:1.9 Sat May 17 02:48:11 2003
+++ avida/current/source/qt-viewer/map_view_widget.hh Tue Jun 24 13:40:48 2003
@@ -152,7 +152,7 @@
/**
* Redraws everything.
**/
- void drawViewport();
+ void drawViewport(bool redraw);
/**
More information about the Avida-cvs
mailing list