From 115dacb37ebec174aa2d465345549cd76303e347 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 19 May 2010 03:23:55 +0000 Subject: [PATCH] Clean up VisualFeature a bit and make most of OpenGlWrapper's methods const Originally committed to SVN as r4309. --- aegisub/src/gl_wrap.cpp | 16 ++-- aegisub/src/gl_wrap.h | 18 ++-- aegisub/src/visual_feature.cpp | 164 +++++++++++++-------------------- aegisub/src/visual_feature.h | 54 ++++------- aegisub/src/visual_tool.cpp | 2 +- 5 files changed, 98 insertions(+), 156 deletions(-) diff --git a/aegisub/src/gl_wrap.cpp b/aegisub/src/gl_wrap.cpp index f805d2ac1..7c2889eb1 100644 --- a/aegisub/src/gl_wrap.cpp +++ b/aegisub/src/gl_wrap.cpp @@ -89,7 +89,7 @@ OpenGLWrapper::OpenGLWrapper() { /// @param x2 /// @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(); glBegin(GL_LINES); glVertex2f(x1,y1); @@ -106,7 +106,7 @@ void OpenGLWrapper::DrawLine(float x1,float y1,float x2,float y2) { /// @param y2 /// @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)); int steps = (int)((dist-20)/step); 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 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); } @@ -136,7 +136,7 @@ void OpenGLWrapper::DrawEllipse(float x,float y,float radiusX,float radiusY) { /// @param x2 /// @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 if (a2 != 0.0) { SetModeFill(); @@ -170,7 +170,7 @@ void OpenGLWrapper::DrawRectangle(float x1,float y1,float x2,float y2) { /// @param x3 /// @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 if (a2 != 0.0) { SetModeFill(); @@ -203,7 +203,7 @@ void OpenGLWrapper::DrawTriangle(float x1,float y1,float x2,float y2,float x3,fl /// @param arcStart /// @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 if (r2 > r1) { float temp = r1; @@ -324,7 +324,7 @@ void OpenGLWrapper::SetFillColour(wxColour col,float alpha) { /// @brief Line /// -void OpenGLWrapper::SetModeLine() { +void OpenGLWrapper::SetModeLine() const { glColor4f(r1,g1,b1,a1); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); @@ -336,7 +336,7 @@ void OpenGLWrapper::SetModeLine() { /// @brief Fill /// -void OpenGLWrapper::SetModeFill() { +void OpenGLWrapper::SetModeFill() const { glColor4f(r2,g2,b2,a2); if (a2 == 1.0f) glDisable(GL_BLEND); else { diff --git a/aegisub/src/gl_wrap.h b/aegisub/src/gl_wrap.h index 2b8f44ca6..126992b81 100644 --- a/aegisub/src/gl_wrap.h +++ b/aegisub/src/gl_wrap.h @@ -90,21 +90,21 @@ public: void SetLineColour(wxColour col,float alpha=1.0f,int width=1); void SetFillColour(wxColour col,float alpha=1.0f); - void SetModeLine(); - void SetModeFill(); - void DrawLine(float x1,float y1,float x2,float y2); - void DrawDashedLine(float x1,float y1,float x2,float y2,float dashLen); - void DrawEllipse(float x,float y,float radiusX,float radiusY); + void SetModeLine() const; + void SetModeFill() const; + void DrawLine(float x1,float y1,float x2,float y2) const; + void DrawDashedLine(float x1,float y1,float x2,float y2,float dashLen) const; + void DrawEllipse(float x,float y,float radiusX,float radiusY) const; /// @brief DOCME /// @param x /// @param y /// @param radius /// - void DrawCircle(float x,float y,float radius) { DrawEllipse(x,y,radius,radius); } - void DrawRectangle(float x1,float y1,float x2,float y2); - void DrawRing(float x,float y,float r1,float r2,float ar=1.0f,float arcStart=0.0f,float arcEnd=0.0f); - void DrawTriangle(float x1,float y1,float x2,float y2,float x3,float y3); + void DrawCircle(float x,float y,float radius) const { DrawEllipse(x,y,radius,radius); } + 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) const; + void DrawTriangle(float x1,float y1,float x2,float y2,float x3,float y3) const; static bool IsExtensionSupported(const char *ext); }; diff --git a/aegisub/src/visual_feature.cpp b/aegisub/src/visual_feature.cpp index 812f90470..c5e6b41a8 100644 --- a/aegisub/src/visual_feature.cpp +++ b/aegisub/src/visual_feature.cpp @@ -34,117 +34,77 @@ /// @ingroup visual_ts /// - -/////////// -// Headers #include "config.h" -#include "ass_dialogue.h" #include "gl_wrap.h" #include "visual_feature.h" - -/// @brief Constructor -/// -VisualDraggableFeature::VisualDraggableFeature() { - type = DRAG_NONE; - x = INT_MIN; - y = INT_MIN; - value = value2 = 0; - layer = 0; - lineN = -1; - line = NULL; +VisualDraggableFeature::VisualDraggableFeature() +: type(DRAG_NONE) +, x(INT_MIN) +, y(INT_MIN) +, layer(0) +, value(0) +, value2(0) +, line(NULL) +, lineN(-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) { - // Square - if (type == DRAG_BIG_SQUARE) { - if (mx < x-8 || mx > x+8 || my < y-8 || my > y+8) return false; - return true; - } - - // Circle - else if (type == DRAG_BIG_CIRCLE) { - int dx = mx-x; - int dy = my-y; - if (dx*dx + dy*dy <= 64) return true; - return false; - } - - // Triangle - else if (type == DRAG_BIG_TRIANGLE) { - int _my = my+2; - if (_my < y-8 || _my > y+8) return false; - int dx = mx-x; - int dy = _my-y-8; - return (16*dx+9*dy < 0 && 16*dx-9*dy > 0); - } - - // Small square - 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); + switch (type) { + case DRAG_BIG_SQUARE: + return !(mx < x-8 || mx > x+8 || my < y-8 || my > y+8); + case DRAG_BIG_CIRCLE: { + int dx = mx-x; + int dy = my-y; + return dx*dx + dy*dy <= 64; + } + case DRAG_BIG_TRIANGLE: { + int _my = my+2; + if (_my < y-8 || _my > y+8) return false; + int dx = mx-x; + int dy = _my-y-8; + return (16*dx+9*dy < 0 && 16*dx-9*dy > 0); + } + case DRAG_SMALL_SQUARE: + return !(mx < x-4 || mx > x+4 || my < y-4 || my > y+4); + case DRAG_SMALL_CIRCLE: { + int dx = mx-x; + int dy = my-y; + return dx*dx + dy*dy <= 16; + } + default: + return false; } } - +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; + } +} diff --git a/aegisub/src/visual_feature.h b/aegisub/src/visual_feature.h index c51ca2507..fa65ec506 100644 --- a/aegisub/src/visual_feature.h +++ b/aegisub/src/visual_feature.h @@ -34,15 +34,9 @@ /// @ingroup visual_ts /// - -#pragma once - -////////////// -// Prototypes class OpenGLWrapper; class AssDialogue; - /// DOCME enum DraggableFeatureType { @@ -65,47 +59,35 @@ enum DraggableFeatureType { DRAG_SMALL_CIRCLE }; - - /// DOCME /// @class VisualDraggableFeature -/// @brief DOCME -/// -/// DOCME +/// @brief Onscreen control used by many visual tools which doesn't do much class VisualDraggableFeature { public: + /// @brief Constructor + VisualDraggableFeature(); - /// DOCME + /// Shape of feature DraggableFeatureType type; - /// DOCME + int x; /// x coordinate + int y; /// y coordinate - /// DOCME - int x,y; + int layer; /// Layer; Higher = above - /// DOCME - int layer; // Higher = above + int value; /// userdata + 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 value,value2; - - - /// DOCME - AssDialogue *line; - - /// DOCME - int lineN; - - - /// DOCME - int brother[4]; + int brother[4]; /// userdata; generall indexes of other features in an array + /// @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); - void Draw(OpenGLWrapper *gl); - - VisualDraggableFeature(); + /// @brief Draw this feature + /// @param gl OpenGLWrapper to use + void Draw(OpenGLWrapper const& gl); }; - - diff --git a/aegisub/src/visual_tool.cpp b/aegisub/src/visual_tool.cpp index 5fa76dcef..38e97bab4 100644 --- a/aegisub/src/visual_tool.cpp +++ b/aegisub/src/visual_tool.cpp @@ -312,7 +312,7 @@ void VisualTool::DrawAllFeatures() { for (size_t i=0;i