zoomedit:
* Refactored some RenderArea methods
This commit is contained in:
parent
82a2bdabc4
commit
1464f33677
2 changed files with 20 additions and 27 deletions
|
@ -76,7 +76,24 @@ void RenderArea::onRealize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderArea::onConfigureEvent(GdkEventConfigure*) {
|
bool RenderArea::onConfigureEvent(GdkEventConfigure*) {
|
||||||
updateViewport();
|
if(!gdkGLBegin())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
glViewport(0, 0, get_width(), get_height());
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
if(get_width() != 0 && get_height() != 0)
|
||||||
|
glScalef(2.0f/get_width(), -2.0f/get_height(), 1);
|
||||||
|
|
||||||
|
gdkGLEnd();
|
||||||
|
|
||||||
|
viewWidth = get_width()/scale;
|
||||||
|
viewHeight = get_height()/scale;
|
||||||
|
|
||||||
|
queue_draw();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,31 +138,10 @@ void RenderArea::zoom(int zoom, float x, float y) {
|
||||||
zoomLevel = std::max(std::min(zoomLevel + zoom, 50), -100);
|
zoomLevel = std::max(std::min(zoomLevel + zoom, 50), -100);
|
||||||
scale = 100*std::pow(1.1f, zoomLevel);
|
scale = 100*std::pow(1.1f, zoomLevel);
|
||||||
|
|
||||||
updateScrolling(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderArea::updateViewport() {
|
|
||||||
if(!gdkGLBegin())
|
|
||||||
return;
|
|
||||||
|
|
||||||
glViewport(0, 0, get_width(), get_height());
|
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
if(get_width() != 0 && get_height() != 0)
|
|
||||||
glScalef(2.0f/get_width(), -2.0f/get_height(), 1);
|
|
||||||
|
|
||||||
gdkGLEnd();
|
|
||||||
|
|
||||||
updateScrolling();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderArea::updateScrolling(float x, float y) {
|
|
||||||
const float newWidth = get_width()/scale, newHeight = get_height()/scale;
|
const float newWidth = get_width()/scale, newHeight = get_height()/scale;
|
||||||
|
|
||||||
xCenter += (x-0.5)*(viewWidth-newWidth);
|
xCenter += (x-0.5f)*(viewWidth-newWidth);
|
||||||
yCenter += (y-0.5)*(viewHeight-newHeight);
|
yCenter += (y-0.5f)*(viewHeight-newHeight);
|
||||||
|
|
||||||
viewWidth = newWidth;
|
viewWidth = newWidth;
|
||||||
viewHeight = newHeight;
|
viewHeight = newHeight;
|
||||||
|
|
|
@ -74,9 +74,6 @@ class RenderArea : public Gtk::DrawingArea {
|
||||||
|
|
||||||
void zoom(int zoom, float x = 0.5f, float y = 0.5f);
|
void zoom(int zoom, float x = 0.5f, float y = 0.5f);
|
||||||
|
|
||||||
void updateViewport();
|
|
||||||
void updateScrolling(float x = 0.5f, float y = 0.5f);
|
|
||||||
|
|
||||||
bool gdkGLBegin() {
|
bool gdkGLBegin() {
|
||||||
GtkWidget *widget = GTK_WIDGET(gobj());
|
GtkWidget *widget = GTK_WIDGET(gobj());
|
||||||
|
|
||||||
|
|
Reference in a new issue