From 363f1a9dbeb9fd14b2be8b470c7ebfe7e864eb57 Mon Sep 17 00:00:00 2001 From: Leonard Ritter Date: Wed, 10 Feb 2010 19:40:50 +0100 Subject: [PATCH] Drag -> drag.hpp --- SConstruct | 4 +++- drag.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ drag.hpp | 24 +++++++++++++++++++++ trackview.cpp | 49 ------------------------------------------ trackview.hpp | 18 +--------------- 5 files changed, 87 insertions(+), 67 deletions(-) create mode 100644 drag.cpp create mode 100644 drag.hpp diff --git a/SConstruct b/SConstruct index 93b7bc7..70708b5 100644 --- a/SConstruct +++ b/SConstruct @@ -137,7 +137,9 @@ json_files = [ objects = env.Object(['jack.cpp', 'player.cpp', 'jsong.cpp', - 'model.cpp'] + json_files) + 'model.cpp', + 'drag.cpp', + ] + json_files) gtk_objects = gtk_env.Object(['main.cpp', 'trackview.cpp', 'patternview.cpp', diff --git a/drag.cpp b/drag.cpp new file mode 100644 index 0000000..bd01df6 --- /dev/null +++ b/drag.cpp @@ -0,0 +1,59 @@ +#include "drag.hpp" + +#include +#include + +namespace Jacker { + +//============================================================================= + +Drag::Drag() { + x = y = 0; + start_x = start_y = 0; + threshold = 8; +} + +void Drag::start(int x, int y) { + this->x = this->start_x = x; + this->y = this->start_y = y; +} + +void Drag::update(int x, int y) { + this->x = x; + this->y = y; +} + +bool Drag::threshold_reached() { + int delta_x; + int delta_y; + get_delta(delta_x, delta_y); + float length = std::sqrt((float)(delta_x*delta_x + delta_y*delta_y)); + if ((int)(length+0.5) >= threshold) + return true; + return false; +} + +void Drag::get_delta(int &delta_x, int &delta_y) { + delta_x = (x - start_x); + delta_y = (y - start_y); +} + +void Drag::get_rect(int &x, int &y, int &w, int &h) { + int x0,y0,x1,y1; + x0 = this->start_x; + y0 = this->start_y; + x1 = this->x; + y1 = this->y; + if (x0 > x1) + std::swap(x0,x1); + if (y0 > y1) + std::swap(y0,y1); + x = x0; + y = y0; + w = std::abs(x1 - x0); + h = std::abs(y1 - y0); +} + +//============================================================================= + +} // namespace Jacker diff --git a/drag.hpp b/drag.hpp new file mode 100644 index 0000000..f4c2910 --- /dev/null +++ b/drag.hpp @@ -0,0 +1,24 @@ +#pragma once + +namespace Jacker { + +//============================================================================= + +class Drag { +public: + int start_x, start_y; + int x, y; + int threshold; + + Drag(); + void start(int x, int y); + void update(int x, int y); + // returns true if the threshold has been reached + bool threshold_reached(); + void get_delta(int &delta_x, int &delta_y); + void get_rect(int &x, int &y, int &w, int &h); +}; + +//============================================================================= + +} // namespace Jacker \ No newline at end of file diff --git a/trackview.cpp b/trackview.cpp index 0ea67c0..bff47c5 100644 --- a/trackview.cpp +++ b/trackview.cpp @@ -71,55 +71,6 @@ void TrackCursor::set_pos(int x, int y) { //============================================================================= -Drag::Drag() { - x = y = 0; - start_x = start_y = 0; - threshold = 8; -} - -void Drag::start(int x, int y) { - this->x = this->start_x = x; - this->y = this->start_y = y; -} - -void Drag::update(int x, int y) { - this->x = x; - this->y = y; -} - -bool Drag::threshold_reached() { - int delta_x; - int delta_y; - get_delta(delta_x, delta_y); - float length = std::sqrt((float)(delta_x*delta_x + delta_y*delta_y)); - if ((int)(length+0.5) >= threshold) - return true; - return false; -} - -void Drag::get_delta(int &delta_x, int &delta_y) { - delta_x = (x - start_x); - delta_y = (y - start_y); -} - -void Drag::get_rect(int &x, int &y, int &w, int &h) { - int x0,y0,x1,y1; - x0 = this->start_x; - y0 = this->start_y; - x1 = this->x; - y1 = this->y; - if (x0 > x1) - std::swap(x0,x1); - if (y0 > y1) - std::swap(y0,y1); - x = x0; - y = y0; - w = std::abs(x1 - x0); - h = std::abs(y1 - y0); -} - -//============================================================================= - TrackView::TrackView(BaseObjectType* cobject, const Glib::RefPtr& builder) : Gtk::Widget(cobject) { diff --git a/trackview.hpp b/trackview.hpp index 24794a4..a6b6a66 100644 --- a/trackview.hpp +++ b/trackview.hpp @@ -7,6 +7,7 @@ #endif #include "model.hpp" +#include "drag.hpp" #include @@ -46,23 +47,6 @@ protected: // the frame the cursor is on int frame; }; - -//============================================================================= - -class Drag { -public: - int start_x, start_y; - int x, y; - int threshold; - - Drag(); - void start(int x, int y); - void update(int x, int y); - // returns true if the threshold has been reached - bool threshold_reached(); - void get_delta(int &delta_x, int &delta_y); - void get_rect(int &x, int &y, int &w, int &h); -}; //=============================================================================