From 1498ea34399110d081cd06cb8eefb8950e2312c7 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Wed, 2 May 2007 23:55:57 +0000 Subject: [PATCH] factor out viewport to display scaling functions --- alg/glseqbrowser.cpp | 10 ++++------ alg/glseqbrowser.hpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/alg/glseqbrowser.cpp b/alg/glseqbrowser.cpp index afcf6a9..df94626 100644 --- a/alg/glseqbrowser.cpp +++ b/alg/glseqbrowser.cpp @@ -144,10 +144,8 @@ void GlSeqBrowser::processSelection(GLuint hits, GLuint buffer[], GLuint bufsize void GlSeqBrowser::selectRegion(int top, int left, int bottom, int right) { - GLfloat x_scale = cur_ortho.width()/((float)viewport_size.x); - GLfloat y_scale = cur_ortho.height()/((float)viewport_size.y); - GLfloat x_left = cur_ortho.left + (left*x_scale); - GLfloat x_right = cur_ortho.left + (right * x_scale); + GLfloat x_left = viewportXtoWorldX(left); + GLfloat x_right = viewportXtoWorldX(right);cur_ortho.left; if (top > bottom) { // woah, someone gave us a rectangle with the origin in the lower left @@ -156,8 +154,8 @@ void GlSeqBrowser::selectRegion(int top, int left, int bottom, int right) top = temp; } // swap the orientation of canvas coordinates - GLfloat y_top = cur_ortho.top-(bottom*y_scale); - GLfloat y_bottom = cur_ortho.top - top * y_scale; + GLfloat y_top = viewportYtoWorldY(bottom); + GLfloat y_bottom = viewportYtoWorldY(top); selectedRegion = rect(y_top, x_left, y_bottom, x_right); // hopefully this will make a buffer big enough to receive diff --git a/alg/glseqbrowser.hpp b/alg/glseqbrowser.hpp index 3e75107..f88caf5 100644 --- a/alg/glseqbrowser.hpp +++ b/alg/glseqbrowser.hpp @@ -57,6 +57,11 @@ public: int viewportPixelHeight() const; //! return viewport width in pixels int viewportPixelWidth() const; + + //! convert x axis from display to world coordinates + float viewportXtoWorldX(int x); + //! convert y axis from display to world coordinates + float viewportYtoWorldY(int y); //! zoom out far enough to show the full size of the sequence double zoomOut(); @@ -227,4 +232,15 @@ protected: std::list selected_tracks; typedef std::list::iterator selected_track_iterator; }; + +inline float GlSeqBrowser::viewportXtoWorldX(int x) { + GLfloat x_scale = cur_ortho.width()/((float)viewport_size.x); + return (cur_ortho.left + (x * x_scale)); +} + +inline float GlSeqBrowser::viewportYtoWorldY(int y) { + GLfloat y_scale = cur_ortho.height()/((float)viewport_size.y); + return cur_ortho.top-(y * y_scale); +} + #endif -- 2.30.2