Clean up VisualFeature a bit and make most of OpenGlWrapper's methods const

Originally committed to SVN as r4309.
This commit is contained in:
Thomas Goyne 2010-05-19 03:23:55 +00:00
parent 008d59d71e
commit 115dacb37e
5 changed files with 98 additions and 156 deletions

View file

@ -89,7 +89,7 @@ OpenGLWrapper::OpenGLWrapper() {
/// @param x2 /// @param x2
/// @param y2 /// @param y2
/// ///
void OpenGLWrapper::DrawLine(float x1,float y1,float x2,float y2) { void OpenGLWrapper::DrawLine(float x1,float y1,float x2,float y2) const {
SetModeLine(); SetModeLine();
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex2f(x1,y1); glVertex2f(x1,y1);
@ -106,7 +106,7 @@ void OpenGLWrapper::DrawLine(float x1,float y1,float x2,float y2) {
/// @param y2 /// @param y2
/// @param step /// @param step
/// ///
void OpenGLWrapper::DrawDashedLine(float x1,float y1,float x2,float y2,float step) { void OpenGLWrapper::DrawDashedLine(float x1,float y1,float x2,float y2,float step) const {
float dist = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)); float dist = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
int steps = (int)((dist-20)/step); int steps = (int)((dist-20)/step);
double stepx = double(x2-x1)/steps; double stepx = double(x2-x1)/steps;
@ -124,7 +124,7 @@ void OpenGLWrapper::DrawDashedLine(float x1,float y1,float x2,float y2,float ste
/// @param radiusX /// @param radiusX
/// @param radiusY /// @param radiusY
/// ///
void OpenGLWrapper::DrawEllipse(float x,float y,float radiusX,float radiusY) { void OpenGLWrapper::DrawEllipse(float x,float y,float radiusX,float radiusY) const {
DrawRing(x,y,radiusY,radiusY,radiusX/radiusY); DrawRing(x,y,radiusY,radiusY,radiusX/radiusY);
} }
@ -136,7 +136,7 @@ void OpenGLWrapper::DrawEllipse(float x,float y,float radiusX,float radiusY) {
/// @param x2 /// @param x2
/// @param y2 /// @param y2
/// ///
void OpenGLWrapper::DrawRectangle(float x1,float y1,float x2,float y2) { void OpenGLWrapper::DrawRectangle(float x1,float y1,float x2,float y2) const {
// Fill // Fill
if (a2 != 0.0) { if (a2 != 0.0) {
SetModeFill(); SetModeFill();
@ -170,7 +170,7 @@ void OpenGLWrapper::DrawRectangle(float x1,float y1,float x2,float y2) {
/// @param x3 /// @param x3
/// @param y3 /// @param y3
/// ///
void OpenGLWrapper::DrawTriangle(float x1,float y1,float x2,float y2,float x3,float y3) { void OpenGLWrapper::DrawTriangle(float x1,float y1,float x2,float y2,float x3,float y3) const {
// Fill // Fill
if (a2 != 0.0) { if (a2 != 0.0) {
SetModeFill(); SetModeFill();
@ -203,7 +203,7 @@ void OpenGLWrapper::DrawTriangle(float x1,float y1,float x2,float y2,float x3,fl
/// @param arcStart /// @param arcStart
/// @param arcEnd /// @param arcEnd
/// ///
void OpenGLWrapper::DrawRing(float x,float y,float r1,float r2,float ar,float arcStart,float arcEnd) { void OpenGLWrapper::DrawRing(float x,float y,float r1,float r2,float ar,float arcStart,float arcEnd) const {
// Make r1 bigger // Make r1 bigger
if (r2 > r1) { if (r2 > r1) {
float temp = r1; float temp = r1;
@ -324,7 +324,7 @@ void OpenGLWrapper::SetFillColour(wxColour col,float alpha) {
/// @brief Line /// @brief Line
/// ///
void OpenGLWrapper::SetModeLine() { void OpenGLWrapper::SetModeLine() const {
glColor4f(r1,g1,b1,a1); glColor4f(r1,g1,b1,a1);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
@ -336,7 +336,7 @@ void OpenGLWrapper::SetModeLine() {
/// @brief Fill /// @brief Fill
/// ///
void OpenGLWrapper::SetModeFill() { void OpenGLWrapper::SetModeFill() const {
glColor4f(r2,g2,b2,a2); glColor4f(r2,g2,b2,a2);
if (a2 == 1.0f) glDisable(GL_BLEND); if (a2 == 1.0f) glDisable(GL_BLEND);
else { else {

View file

@ -90,21 +90,21 @@ public:
void SetLineColour(wxColour col,float alpha=1.0f,int width=1); void SetLineColour(wxColour col,float alpha=1.0f,int width=1);
void SetFillColour(wxColour col,float alpha=1.0f); void SetFillColour(wxColour col,float alpha=1.0f);
void SetModeLine(); void SetModeLine() const;
void SetModeFill(); void SetModeFill() const;
void DrawLine(float x1,float y1,float x2,float y2); void DrawLine(float x1,float y1,float x2,float y2) const;
void DrawDashedLine(float x1,float y1,float x2,float y2,float dashLen); void DrawDashedLine(float x1,float y1,float x2,float y2,float dashLen) const;
void DrawEllipse(float x,float y,float radiusX,float radiusY); void DrawEllipse(float x,float y,float radiusX,float radiusY) const;
/// @brief DOCME /// @brief DOCME
/// @param x /// @param x
/// @param y /// @param y
/// @param radius /// @param radius
/// ///
void DrawCircle(float x,float y,float radius) { DrawEllipse(x,y,radius,radius); } void DrawCircle(float x,float y,float radius) const { DrawEllipse(x,y,radius,radius); }
void DrawRectangle(float x1,float y1,float x2,float y2); void DrawRectangle(float x1,float y1,float x2,float y2) const;
void DrawRing(float x,float y,float r1,float r2,float ar=1.0f,float arcStart=0.0f,float arcEnd=0.0f); void DrawRing(float x,float y,float r1,float r2,float ar=1.0f,float arcStart=0.0f,float arcEnd=0.0f) const;
void DrawTriangle(float x1,float y1,float x2,float y2,float x3,float y3); void DrawTriangle(float x1,float y1,float x2,float y2,float x3,float y3) const;
static bool IsExtensionSupported(const char *ext); static bool IsExtensionSupported(const char *ext);
}; };

View file

@ -34,117 +34,77 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
///////////
// Headers
#include "config.h" #include "config.h"
#include "ass_dialogue.h"
#include "gl_wrap.h" #include "gl_wrap.h"
#include "visual_feature.h" #include "visual_feature.h"
VisualDraggableFeature::VisualDraggableFeature()
/// @brief Constructor : type(DRAG_NONE)
/// , x(INT_MIN)
VisualDraggableFeature::VisualDraggableFeature() { , y(INT_MIN)
type = DRAG_NONE; , layer(0)
x = INT_MIN; , value(0)
y = INT_MIN; , value2(0)
value = value2 = 0; , line(NULL)
layer = 0; , lineN(-1)
lineN = -1; {
line = NULL;
for (int i=0;i<4;i++) brother[i] = -1; for (int i=0;i<4;i++) brother[i] = -1;
} }
/// @brief Is mouse over it?
/// @param mx
/// @param my
/// @return
///
bool VisualDraggableFeature::IsMouseOver(int mx,int my) { bool VisualDraggableFeature::IsMouseOver(int mx,int my) {
// Square switch (type) {
if (type == DRAG_BIG_SQUARE) { case DRAG_BIG_SQUARE:
if (mx < x-8 || mx > x+8 || my < y-8 || my > y+8) return false; return !(mx < x-8 || mx > x+8 || my < y-8 || my > y+8);
return true; case DRAG_BIG_CIRCLE: {
} int dx = mx-x;
int dy = my-y;
// Circle return dx*dx + dy*dy <= 64;
else if (type == DRAG_BIG_CIRCLE) { }
int dx = mx-x; case DRAG_BIG_TRIANGLE: {
int dy = my-y; int _my = my+2;
if (dx*dx + dy*dy <= 64) return true; if (_my < y-8 || _my > y+8) return false;
return false; int dx = mx-x;
} int dy = _my-y-8;
return (16*dx+9*dy < 0 && 16*dx-9*dy > 0);
// Triangle }
else if (type == DRAG_BIG_TRIANGLE) { case DRAG_SMALL_SQUARE:
int _my = my+2; return !(mx < x-4 || mx > x+4 || my < y-4 || my > y+4);
if (_my < y-8 || _my > y+8) return false; case DRAG_SMALL_CIRCLE: {
int dx = mx-x; int dx = mx-x;
int dy = _my-y-8; int dy = my-y;
return (16*dx+9*dy < 0 && 16*dx-9*dy > 0); return dx*dx + dy*dy <= 16;
} }
default:
// Small square return false;
else if (type == DRAG_SMALL_SQUARE) {
if (mx < x-4 || mx > x+4 || my < y-4 || my > y+4) return false;
return true;
}
// Small circle
else if (type == DRAG_SMALL_CIRCLE) {
int dx = mx-x;
int dy = my-y;
if (dx*dx + dy*dy <= 16) return true;
return false;
}
// Fallback
return false;
}
/// @brief Draw feature
/// @param gl
///
void VisualDraggableFeature::Draw(OpenGLWrapper *gl) {
wxASSERT(gl);
// Square
if (type == DRAG_BIG_SQUARE) {
gl->DrawRectangle(x-8,y-8,x+8,y+8);
gl->DrawLine(x,y-16,x,y+16);
gl->DrawLine(x-16,y,x+16,y);
}
// Circle
else if (type == DRAG_BIG_CIRCLE) {
gl->DrawCircle(x,y,8);
gl->DrawLine(x,y-16,x,y+16);
gl->DrawLine(x-16,y,x+16,y);
}
// Triangle
else if (type == DRAG_BIG_TRIANGLE) {
gl->DrawTriangle(x-9,y-6,x+9,y-6,x,y+10);
gl->DrawLine(x,y,x,y-16);
gl->DrawLine(x,y,x-14,y+8);
gl->DrawLine(x,y,x+14,y+8);
}
// Square
else if (type == DRAG_SMALL_SQUARE) {
gl->DrawRectangle(x-4,y-4,x+4,y+4);
}
// Small circle
else if (type == DRAG_SMALL_CIRCLE) {
gl->DrawCircle(x,y,4);
} }
} }
void VisualDraggableFeature::Draw(OpenGLWrapper const& gl) {
switch (type) {
case DRAG_BIG_SQUARE:
gl.DrawRectangle(x-8,y-8,x+8,y+8);
gl.DrawLine(x,y-16,x,y+16);
gl.DrawLine(x-16,y,x+16,y);
break;
case DRAG_BIG_CIRCLE:
gl.DrawCircle(x,y,8);
gl.DrawLine(x,y-16,x,y+16);
gl.DrawLine(x-16,y,x+16,y);
break;
case DRAG_BIG_TRIANGLE:
gl.DrawTriangle(x-9,y-6,x+9,y-6,x,y+10);
gl.DrawLine(x,y,x,y-16);
gl.DrawLine(x,y,x-14,y+8);
gl.DrawLine(x,y,x+14,y+8);
break;
case DRAG_SMALL_SQUARE:
gl.DrawRectangle(x-4,y-4,x+4,y+4);
break;
case DRAG_SMALL_CIRCLE:
gl.DrawCircle(x,y,4);
break;
default:
break;
}
}

View file

@ -34,15 +34,9 @@
/// @ingroup visual_ts /// @ingroup visual_ts
/// ///
#pragma once
//////////////
// Prototypes
class OpenGLWrapper; class OpenGLWrapper;
class AssDialogue; class AssDialogue;
/// DOCME /// DOCME
enum DraggableFeatureType { enum DraggableFeatureType {
@ -65,47 +59,35 @@ enum DraggableFeatureType {
DRAG_SMALL_CIRCLE DRAG_SMALL_CIRCLE
}; };
/// DOCME /// DOCME
/// @class VisualDraggableFeature /// @class VisualDraggableFeature
/// @brief DOCME /// @brief Onscreen control used by many visual tools which doesn't do much
///
/// DOCME
class VisualDraggableFeature { class VisualDraggableFeature {
public: public:
/// @brief Constructor
VisualDraggableFeature();
/// DOCME /// Shape of feature
DraggableFeatureType type; DraggableFeatureType type;
/// DOCME int x; /// x coordinate
int y; /// y coordinate
/// DOCME int layer; /// Layer; Higher = above
int x,y;
/// DOCME int value; /// userdata
int layer; // Higher = above int value2; /// more userdata
/// DOCME AssDialogue* line; /// The dialogue line this feature is for
int lineN; /// The line's index in the file
/// DOCME int brother[4]; /// userdata; generall indexes of other features in an array
int value,value2;
/// DOCME
AssDialogue *line;
/// DOCME
int lineN;
/// DOCME
int brother[4];
/// @brief Is the given point over this feature?
/// @param mx x coordinate to test
/// @param my y coordinate to test
bool IsMouseOver(int x,int y); bool IsMouseOver(int x,int y);
void Draw(OpenGLWrapper *gl); /// @brief Draw this feature
/// @param gl OpenGLWrapper to use
VisualDraggableFeature(); void Draw(OpenGLWrapper const& gl);
}; };

View file

@ -312,7 +312,7 @@ void VisualTool::DrawAllFeatures() {
for (size_t i=0;i<features.size();i++) { for (size_t i=0;i<features.size();i++) {
SetFillColour(colour[(signed)i == mouseOver ? 2 : 1],0.6f); SetFillColour(colour[(signed)i == mouseOver ? 2 : 1],0.6f);
SetLineColour(colour[0],1.0f,2); SetLineColour(colour[0],1.0f,2);
features[i].Draw(this); features[i].Draw(*this);
} }
} }