1
Fork 0

Drag -> drag.hpp

This commit is contained in:
Leonard Ritter 2010-02-10 19:40:50 +01:00
parent e979ca976d
commit 363f1a9dbe
5 changed files with 87 additions and 67 deletions

View File

@ -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',

59
drag.cpp Normal file
View File

@ -0,0 +1,59 @@
#include "drag.hpp"
#include <cmath>
#include <algorithm>
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

24
drag.hpp Normal file
View File

@ -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

View File

@ -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<Gtk::Builder>& builder)
: Gtk::Widget(cobject) {

View File

@ -7,6 +7,7 @@
#endif
#include "model.hpp"
#include "drag.hpp"
#include <set>
@ -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);
};
//=============================================================================