summaryrefslogtreecommitdiffstats
path: root/Project
diff options
context:
space:
mode:
Diffstat (limited to 'Project')
-rw-r--r--Project/Constant.cpp32
-rw-r--r--Project/Constant.h5
-rw-r--r--Project/Gain.cpp41
-rw-r--r--Project/Gain.h5
-rw-r--r--Project/IOControl.cpp39
-rw-r--r--Project/IOControl.h5
-rw-r--r--Project/MainFrame.cpp4
-rw-r--r--Project/OpenGLText.cpp158
-rw-r--r--Project/OpenGLText.h60
-rw-r--r--Project/Project.mk16
-rw-r--r--Project/Project.project4
-rw-r--r--Project/Project.txt2
-rw-r--r--Project/Text.cpp222
-rw-r--r--Project/Text.h17
-rw-r--r--Project/TransferFunction.cpp52
-rw-r--r--Project/TransferFunction.h6
-rw-r--r--Project/Workspace.cpp7
-rw-r--r--Project/data/images/control/io.pngbin944 -> 927 bytes
-rw-r--r--Project/wxGLString.cpp465
-rw-r--r--Project/wxGLString.h202
20 files changed, 346 insertions, 996 deletions
diff --git a/Project/Constant.cpp b/Project/Constant.cpp
index 1c375f1..9991d90 100644
--- a/Project/Constant.cpp
+++ b/Project/Constant.cpp
@@ -28,7 +28,10 @@ Constant::Constant(int id) : ControlElement(id)
m_nodeList.push_back(nodeOut);
}
-Constant::~Constant() {}
+Constant::~Constant()
+{
+ if(m_glText) delete m_glText;
+}
void Constant::Draw(wxPoint2DDouble translation, double scale) const
{
glLineWidth(1.0);
@@ -43,11 +46,7 @@ void Constant::Draw(wxPoint2DDouble translation, double scale) const
DrawRectangle(m_position, m_width, m_height, GL_LINE_LOOP);
// Plot number.
- glEnable(GL_TEXTURE_2D);
- glColor4d(0.0, 0.0, 0.0, 1.0);
- m_glStringValue->bind();
- m_glStringValue->render(m_position.m_x, m_position.m_y);
- glDisable(GL_TEXTURE_2D);
+ m_glText->Draw(m_position);
glColor4d(0.0, 0.0, 0.0, 1.0);
DrawNodes();
@@ -103,19 +102,13 @@ void Constant::SetValue(double value)
m_value = value;
wxString text = StringFromDouble(m_value);
- wxFont font(m_fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
- wxScreenDC dc;
-
- if(m_glStringValue) {
- delete m_glStringValue;
- m_glStringValue = NULL;
- }
- m_glStringValue = new wxGLString(text);
- m_glStringValue->setFont(font);
- m_glStringValue->consolidate(&dc);
+ if(m_glText)
+ m_glText->SetText(text);
+ else
+ m_glText = new OpenGLText(text);
- m_width = m_glStringValue->getWidth() + 6 + 2 * m_borderSize;
- m_height = m_glStringValue->getheight() + 6 + 2 * m_borderSize;
+ m_width = m_glText->GetWidth() + 6 + 2 * m_borderSize;
+ m_height = m_glText->GetHeight() + 6 + 2 * m_borderSize;
UpdatePoints();
}
@@ -124,7 +117,6 @@ Element* Constant::GetCopy()
{
Constant* copy = new Constant(m_elementID);
*copy = *this;
- m_glStringValue = NULL;
- SetValue(m_value);
+ copy->m_glText = m_glText->GetCopy();
return copy;
}
diff --git a/Project/Constant.h b/Project/Constant.h
index 367916d..abc7871 100644
--- a/Project/Constant.h
+++ b/Project/Constant.h
@@ -21,7 +21,7 @@
#include "ControlElement.h"
#include <wx/dcscreen.h>
-#include "wxGLString.h"
+#include "OpenGLText.h"
class ConstantForm;
@@ -53,8 +53,7 @@ class Constant : public ControlElement
protected:
double m_value = 1.0;
- wxGLString* m_glStringValue = NULL;
- int m_fontSize = 10;
+ OpenGLText* m_glText = NULL;
};
#endif // CONSTANT_H
diff --git a/Project/Gain.cpp b/Project/Gain.cpp
index 98dfa8c..8962bf8 100644
--- a/Project/Gain.cpp
+++ b/Project/Gain.cpp
@@ -31,7 +31,10 @@ Gain::Gain(int id) : ControlElement(id)
m_nodeList.push_back(nodeOut);
}
-Gain::~Gain() {}
+Gain::~Gain()
+{
+ if(m_glText) delete m_glText;
+}
void Gain::Draw(wxPoint2DDouble translation, double scale) const
{
if(m_selected) {
@@ -64,22 +67,15 @@ void Gain::Draw(wxPoint2DDouble translation, double scale) const
DrawTriangle(m_triPts, GL_LINE_LOOP);
// Plot number.
- glEnable(GL_TEXTURE_2D);
glColor4d(0.0, 0.0, 0.0, 1.0);
- m_glStringValue->bind();
if(m_angle == 0.0)
- m_glStringValue->render(m_position.m_x - m_width / 2 + m_glStringValue->getWidth() / 2 + 2 + m_borderSize,
- m_position.m_y);
+ m_glText->Draw(m_position + wxPoint2DDouble(-m_width / 2 + m_glText->GetWidth() / 2 + 2 + m_borderSize, 0.0));
else if(m_angle == 90.0)
- m_glStringValue->render(m_position.m_x,
- m_position.m_y - m_height / 2 + m_glStringValue->getheight() / 2 + 2 + m_borderSize);
+ m_glText->Draw(m_position + wxPoint2DDouble(0.0, -m_height / 2 + m_glText->GetHeight() / 2 + 2 + m_borderSize));
else if(m_angle == 180.0)
- m_glStringValue->render(m_position.m_x + m_width / 2 - m_glStringValue->getWidth() / 2 - 2 - m_borderSize,
- m_position.m_y);
+ m_glText->Draw(m_position + wxPoint2DDouble(m_width / 2 - m_glText->GetWidth() / 2 - 2 - m_borderSize, 0.0));
else if(m_angle == 270.0)
- m_glStringValue->render(m_position.m_x,
- m_position.m_y + m_height / 2 - m_glStringValue->getheight() / 2 - 2 - m_borderSize);
- glDisable(GL_TEXTURE_2D);
+ m_glText->Draw(m_position + wxPoint2DDouble(0.0, m_height / 2 - m_glText->GetHeight() / 2 - 2 - m_borderSize));
glColor4d(0.0, 0.0, 0.0, 1.0);
DrawNodes();
@@ -124,19 +120,13 @@ void Gain::SetValue(double value)
else
text = StringFromDouble(m_value);
- wxFont font(m_fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
- wxScreenDC dc;
-
- if(m_glStringValue) {
- delete m_glStringValue;
- m_glStringValue = NULL;
- }
- m_glStringValue = new wxGLString(text);
- m_glStringValue->setFont(font);
- m_glStringValue->consolidate(&dc);
+ if(m_glText)
+ m_glText->SetText(text);
+ else
+ m_glText = new OpenGLText(text);
- m_width = m_glStringValue->getWidth() + 18 + 2 * m_borderSize;
- m_height = m_glStringValue->getheight() + 18 + 2 * m_borderSize;
+ m_width = m_glText->GetWidth() + 18 + 2 * m_borderSize;
+ m_height = m_glText->GetHeight() + 18 + 2 * m_borderSize;
if(m_width > m_height)
m_height = m_width;
@@ -195,7 +185,6 @@ Element* Gain::GetCopy()
{
Gain* copy = new Gain(m_elementID);
*copy = *this;
- m_glStringValue = NULL;
- SetValue(m_value);
+ copy->m_glText = m_glText->GetCopy();
return copy;
}
diff --git a/Project/Gain.h b/Project/Gain.h
index 7245e2f..50c9162 100644
--- a/Project/Gain.h
+++ b/Project/Gain.h
@@ -21,7 +21,7 @@
#include "ControlElement.h"
#include <wx/dcscreen.h>
-#include "wxGLString.h"
+#include "OpenGLText.h"
class GainForm;
@@ -63,8 +63,7 @@ class Gain : public ControlElement
protected:
double m_value = 1.0;
- wxGLString* m_glStringValue = NULL;
- int m_fontSize = 10;
+ OpenGLText* m_glText = NULL;
std::vector<wxPoint2DDouble> m_triPts;
};
diff --git a/Project/IOControl.cpp b/Project/IOControl.cpp
index 44cbf8e..7f3e49f 100644
--- a/Project/IOControl.cpp
+++ b/Project/IOControl.cpp
@@ -32,7 +32,11 @@ IOControl::IOControl(int ioFlags, int id) : ControlElement(id)
node->StartMove(m_position);
}
-IOControl::~IOControl() {}
+IOControl::~IOControl()
+{
+ if(m_glText) delete m_glText;
+}
+
void IOControl::Draw(wxPoint2DDouble translation, double scale) const
{
std::vector<wxPoint2DDouble> pts;
@@ -100,21 +104,17 @@ void IOControl::Draw(wxPoint2DDouble translation, double scale) const
DrawLine(pts, GL_LINE_LOOP);
// Plot number.
- glEnable(GL_TEXTURE_2D);
glColor4d(0.0, 0.0, 0.0, 1.0);
- m_glStringValue->bind();
if(m_angle == 0.0) {
- m_glStringValue->render(m_position.m_x - 5, m_position.m_y);
+ m_glText->Draw(m_position + wxPoint2DDouble(-5.0, 0.0));
} else if(m_angle == 90.0) {
- m_glStringValue->render(m_position.m_x, m_position.m_y - 5);
+ m_glText->Draw(m_position + wxPoint2DDouble(0.0, -5.0));
} else if(m_angle == 180.0) {
- m_glStringValue->render(m_position.m_x + 5, m_position.m_y);
+ m_glText->Draw(m_position + wxPoint2DDouble(5.0, 0.0));
} else if(m_angle == 270.0) {
- m_glStringValue->render(m_position.m_x, m_position.m_y + 5);
+ m_glText->Draw(m_position + wxPoint2DDouble(0.0, 5.0));
}
- glDisable(GL_TEXTURE_2D);
-
glColor4d(0.0, 0.0, 0.0, 1.0);
DrawNodes();
}
@@ -209,19 +209,13 @@ void IOControl::SetValue(IOFlags value)
m_value = value;
wxString text = GenerateText();
- wxFont font(m_fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
- wxScreenDC dc;
-
- if(m_glStringValue) {
- delete m_glStringValue;
- m_glStringValue = NULL;
- }
- m_glStringValue = new wxGLString(text);
- m_glStringValue->setFont(font);
- m_glStringValue->consolidate(&dc);
+ if(m_glText)
+ m_glText->SetText(text);
+ else
+ m_glText = new OpenGLText(text);
- m_width = m_glStringValue->getWidth() + 10 + 2 * m_borderSize;
- m_height = m_glStringValue->getheight() + 10 + 2 * m_borderSize;
+ m_width = m_glText->GetWidth() + 10 + 2 * m_borderSize;
+ m_height = m_glText->GetHeight() + 10 + 2 * m_borderSize;
SetPosition(m_position); // Update rectangle.
@@ -266,7 +260,6 @@ Element* IOControl::GetCopy()
{
IOControl* copy = new IOControl(m_ioFlags, m_elementID);
*copy = *this;
- m_glStringValue = NULL;
- SetValue(m_value);
+ copy->m_glText = m_glText->GetCopy();
return copy;
}
diff --git a/Project/IOControl.h b/Project/IOControl.h
index 084367d..3f59a73 100644
--- a/Project/IOControl.h
+++ b/Project/IOControl.h
@@ -21,7 +21,7 @@
#include "ControlElement.h"
#include <wx/dcscreen.h>
-#include "wxGLString.h"
+#include "OpenGLText.h"
class IOControlForm;
@@ -73,8 +73,7 @@ class IOControl : public ControlElement
Node::NodeType m_ioNodeType = Node::NODE_IN;
- wxGLString* m_glStringValue = NULL;
- int m_fontSize = 10;
+ OpenGLText* m_glText = NULL;
};
#endif // IOCONTROL_H
diff --git a/Project/MainFrame.cpp b/Project/MainFrame.cpp
index 429eabf..1cae4bc 100644
--- a/Project/MainFrame.cpp
+++ b/Project/MainFrame.cpp
@@ -59,8 +59,8 @@ MainFrame::MainFrame(wxWindow* parent, wxLocale* locale, PropertiesData* initPro
m_auiNotebook->AddPage(newWorkspace, newWorkspace->GetName(), true);
m_auiNotebook->Layout();
- newWorkspace->Redraw();
- newWorkspace->SetJustOpened(true);
+ //newWorkspace->Redraw();
+ //newWorkspace->SetJustOpened(true);
m_projectNumber++;
}
}
diff --git a/Project/OpenGLText.cpp b/Project/OpenGLText.cpp
new file mode 100644
index 0000000..ebbc763
--- /dev/null
+++ b/Project/OpenGLText.cpp
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2017 Thales Lima Oliveira <thales@ufu.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "OpenGLText.h"
+
+OpenGLText::OpenGLText() { Init(); }
+OpenGLText::OpenGLText(wxString text)
+{
+ Init();
+ SetText(text);
+}
+
+OpenGLText::~OpenGLText()
+{
+ if(m_textureID) {
+ glDeleteTextures(1, m_textureID);
+ }
+}
+
+void OpenGLText::Init()
+{
+ m_textCoord = new wxPoint2DDouble[2];
+ m_textCoord[0] = wxPoint2DDouble(0, 1);
+ m_textCoord[1] = wxPoint2DDouble(1, 0);
+}
+
+void OpenGLText::Draw(wxPoint2DDouble position) const
+{
+ if(m_textureID) {
+ glPushMatrix();
+
+ glTranslated(position.m_x - m_bitmapSize.GetWidth() / 2, position.m_y - m_bitmapSize.GetHeight() / 2, 0);
+
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, m_textureID[0]);
+
+ glBegin(GL_QUADS);
+
+ glTexCoord2f(m_textCoord[0].m_x, m_textCoord[0].m_y);
+ glVertex2f(0, 0);
+
+ glTexCoord2f(m_textCoord[1].m_x, m_textCoord[0].m_y);
+ glVertex2f(m_bitmapSize.GetWidth(), 0);
+
+ glTexCoord2f(m_textCoord[1].m_x, m_textCoord[1].m_y);
+ glVertex2f(m_bitmapSize.GetWidth(), m_bitmapSize.GetHeight());
+
+ glTexCoord2f(m_textCoord[0].m_x, m_textCoord[1].m_y);
+ glVertex2f(0, m_bitmapSize.GetHeight());
+ glEnd();
+
+ glDisable(GL_TEXTURE_2D);
+
+ glPopMatrix();
+ }
+}
+
+void OpenGLText::SetText(wxString text)
+{
+ m_text = text;
+ TextToBitmap();
+ LoadTextTexture();
+}
+
+int OpenGLText::RoundToPowerOfTwo(int value, int min)
+{
+ //[Ref] https://stackoverflow.com/questions/466204/rounding-up-to-next-power-of-2
+ double baseOfTwo = std::log(static_cast<double>(value)) / std::log(2.0);
+ int powerOfTwo = static_cast<int>(std::pow(2.0, static_cast<int>(std::ceil(baseOfTwo))));
+ return std::max(min, powerOfTwo);
+}
+
+void OpenGLText::TextToBitmap()
+{
+ wxFont font = wxFont(m_fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
+
+ wxMemoryDC memDC;
+ memDC.SetFont(font);
+ m_bitmapSize = memDC.GetTextExtent(m_text);
+
+ int p2w = RoundToPowerOfTwo(m_bitmapSize.GetWidth());
+ int p2h = RoundToPowerOfTwo(m_bitmapSize.GetHeight());
+
+ m_bitmap = wxBitmap(p2w, p2h);
+
+ memDC.SelectObject(m_bitmap);
+ memDC.SetBackground(*wxWHITE_BRUSH);
+ memDC.Clear();
+ memDC.DrawText(m_text, 0, 0);
+
+ m_textCoord[1].m_x = static_cast<double>(m_bitmapSize.GetWidth()) / static_cast<double>(p2w);
+ m_textCoord[1].m_y = 1.0 - static_cast<double>(m_bitmapSize.GetHeight()) / static_cast<double>(p2h);
+}
+
+void OpenGLText::LoadTextTexture()
+{
+ if(m_textureID) glDeleteTextures(1, m_textureID);
+ m_textureID = new GLuint[1];
+ glGenTextures(1, &m_textureID[0]);
+
+ glBindTexture(GL_TEXTURE_2D, *m_textureID);
+
+ wxImage img = m_bitmap.ConvertToImage();
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ const int w = img.GetWidth(), h = img.GetHeight();
+ int bytesPerPixel = 4;
+ GLubyte* bitmapData = img.GetData();
+ int imageSize = w * h * bytesPerPixel;
+ GLubyte* imageData = new GLubyte[imageSize];
+ int revVal = h - 1;
+
+ for(int y = 0; y < h; y++) {
+ for(int x = 0; x < w; x++) {
+ imageData[(x + y * w) * bytesPerPixel + 0] = 255;
+ imageData[(x + y * w) * bytesPerPixel + 1] = 255;
+ imageData[(x + y * w) * bytesPerPixel + 2] = 255;
+
+ // alpha
+ imageData[(x + y * w) * bytesPerPixel + 3] = 255 - bitmapData[(x + (revVal - y) * w) * 3];
+ }
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, 0, bytesPerPixel, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
+ delete imageData;
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+}
+
+OpenGLText* OpenGLText::GetCopy()
+{
+ OpenGLText* copy = new OpenGLText();
+ *copy = *this;
+ copy->m_textureID = NULL;
+ copy->m_bitmapSize = wxSize(0, 0);
+ copy->m_bitmap = wxNullBitmap;
+ copy->SetText(copy->m_text);
+ return copy;
+}
diff --git a/Project/OpenGLText.h b/Project/OpenGLText.h
new file mode 100644
index 0000000..c07dab1
--- /dev/null
+++ b/Project/OpenGLText.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017 Thales Lima Oliveira <thales@ufu.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef OPENGLTEXT_H
+#define OPENGLTEXT_H
+
+#include <GL/gl.h>
+#include <wx/dcmemory.h>
+
+/**
+ * @class OpenGLText
+ * @author Thales Lima Oliveira <thales@ufu.br>
+ * @date 24/10/2017
+ * @brief Class to draw text on OpenGL using wxWidgets.
+ * @file OpenGLText.h
+ */
+class OpenGLText
+{
+ public:
+ OpenGLText();
+ OpenGLText(wxString text);
+ virtual ~OpenGLText();
+
+ virtual void Draw(wxPoint2DDouble position) const;
+ virtual OpenGLText* GetCopy();
+
+ virtual void SetText(wxString text);
+ virtual wxString GetText() const { return m_text; }
+ virtual int GetWidth() const { return m_bitmapSize.GetWidth(); }
+ virtual int GetHeight() const { return m_bitmapSize.GetHeight(); }
+ protected:
+ void Init();
+ int RoundToPowerOfTwo(int value, int min = 32);
+ void TextToBitmap();
+ void LoadTextTexture();
+
+ wxString m_text = _("Text");
+ int m_fontSize = 10;
+
+ wxBitmap m_bitmap = wxNullBitmap;
+ wxSize m_bitmapSize = wxSize(0, 0);
+ wxPoint2DDouble* m_textCoord = NULL;
+ GLuint* m_textureID = NULL;
+};
+
+#endif // OPENGLTEXT_H
diff --git a/Project/Project.mk b/Project/Project.mk
index cd4caaa..fbf6dd0 100644
--- a/Project/Project.mk
+++ b/Project/Project.mk
@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=NDSE-69
-Date :=23/10/2017
+Date :=24/10/2017
CodeLitePath :="C:/Program Files/CodeLite"
LinkerName :=C:/TDM-GCC-64/bin/g++.exe
SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC
@@ -64,7 +64,7 @@ AS := C:/TDM-GCC-64/bin/as.exe
CodeLiteDir:=C:\Program Files\CodeLite
WXWIN:=C:\wxWidgets-3.1.0
WXCFG:=gcc_dll\mswu
-Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/win_resources.rc$(ObjectSuffix) $(IntermediateDirectory)/PropertiesData.cpp$(ObjectSuffix) $(IntermediateDirectory)/ArtMetro.cpp$(ObjectSuffix) $(IntermediateDirectory)/wxGLString.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrameBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/WorkspaceBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/BusFormBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/ElementFormBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/ControlEditorBitmaps.cpp$(ObjectSuffix) \
+Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IntermediateDirectory)/win_resources.rc$(ObjectSuffix) $(IntermediateDirectory)/PropertiesData.cpp$(ObjectSuffix) $(IntermediateDirectory)/ArtMetro.cpp$(ObjectSuffix) $(IntermediateDirectory)/OpenGLText.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrameBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/WorkspaceBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/BusFormBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/ElementFormBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/ControlEditorBitmaps.cpp$(ObjectSuffix) \
$(IntermediateDirectory)/ChartViewBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/PropertiesFormBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/DataReportBitmaps.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrameBase.cpp$(ObjectSuffix) $(IntermediateDirectory)/WorkspaceBase.cpp$(ObjectSuffix) $(IntermediateDirectory)/ElementForm.cpp$(ObjectSuffix) $(IntermediateDirectory)/ControlEditorBase.cpp$(ObjectSuffix) $(IntermediateDirectory)/ChartViewBase.cpp$(ObjectSuffix) $(IntermediateDirectory)/PropertiesForm.cpp$(ObjectSuffix) $(IntermediateDirectory)/DataReportBase.cpp$(ObjectSuffix) \
$(IntermediateDirectory)/ElectricCalculation.cpp$(ObjectSuffix) $(IntermediateDirectory)/PowerFlow.cpp$(ObjectSuffix) $(IntermediateDirectory)/Fault.cpp$(ObjectSuffix) $(IntermediateDirectory)/Electromechanical.cpp$(ObjectSuffix) $(IntermediateDirectory)/Element.cpp$(ObjectSuffix) $(IntermediateDirectory)/ElementDataObject.cpp$(ObjectSuffix) $(IntermediateDirectory)/ElementPlotData.cpp$(ObjectSuffix) $(IntermediateDirectory)/wxMathPlot_mathplot.cpp$(ObjectSuffix) $(IntermediateDirectory)/Camera.cpp$(ObjectSuffix) $(IntermediateDirectory)/MainFrame.cpp$(ObjectSuffix) \
$(IntermediateDirectory)/Workspace.cpp$(ObjectSuffix) $(IntermediateDirectory)/ChartView.cpp$(ObjectSuffix) $(IntermediateDirectory)/ControlEditor.cpp$(ObjectSuffix) $(IntermediateDirectory)/DataReport.cpp$(ObjectSuffix) $(IntermediateDirectory)/FileHanding.cpp$(ObjectSuffix) $(IntermediateDirectory)/ConnectionLine.cpp$(ObjectSuffix) $(IntermediateDirectory)/Constant.cpp$(ObjectSuffix) $(IntermediateDirectory)/ControlElement.cpp$(ObjectSuffix) $(IntermediateDirectory)/ControlElementContainer.cpp$(ObjectSuffix) $(IntermediateDirectory)/ControlElementSolver.cpp$(ObjectSuffix) \
@@ -132,13 +132,13 @@ $(IntermediateDirectory)/ArtMetro.cpp$(DependSuffix): ArtMetro.cpp
$(IntermediateDirectory)/ArtMetro.cpp$(PreprocessSuffix): ArtMetro.cpp
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/ArtMetro.cpp$(PreprocessSuffix) ArtMetro.cpp
-$(IntermediateDirectory)/wxGLString.cpp$(ObjectSuffix): wxGLString.cpp $(IntermediateDirectory)/wxGLString.cpp$(DependSuffix)
- $(CXX) $(IncludePCH) $(SourceSwitch) "C:/Users/NDSE-69/Documents/GitHub/PSP/Project/wxGLString.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/wxGLString.cpp$(ObjectSuffix) $(IncludePath)
-$(IntermediateDirectory)/wxGLString.cpp$(DependSuffix): wxGLString.cpp
- @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/wxGLString.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/wxGLString.cpp$(DependSuffix) -MM wxGLString.cpp
+$(IntermediateDirectory)/OpenGLText.cpp$(ObjectSuffix): OpenGLText.cpp $(IntermediateDirectory)/OpenGLText.cpp$(DependSuffix)
+ $(CXX) $(IncludePCH) $(SourceSwitch) "C:/Users/NDSE-69/Documents/GitHub/PSP/Project/OpenGLText.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/OpenGLText.cpp$(ObjectSuffix) $(IncludePath)
+$(IntermediateDirectory)/OpenGLText.cpp$(DependSuffix): OpenGLText.cpp
+ @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/OpenGLText.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/OpenGLText.cpp$(DependSuffix) -MM OpenGLText.cpp
-$(IntermediateDirectory)/wxGLString.cpp$(PreprocessSuffix): wxGLString.cpp
- $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/wxGLString.cpp$(PreprocessSuffix) wxGLString.cpp
+$(IntermediateDirectory)/OpenGLText.cpp$(PreprocessSuffix): OpenGLText.cpp
+ $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/OpenGLText.cpp$(PreprocessSuffix) OpenGLText.cpp
$(IntermediateDirectory)/MainFrameBitmaps.cpp$(ObjectSuffix): MainFrameBitmaps.cpp $(IntermediateDirectory)/MainFrameBitmaps.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) "C:/Users/NDSE-69/Documents/GitHub/PSP/Project/MainFrameBitmaps.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/MainFrameBitmaps.cpp$(ObjectSuffix) $(IncludePath)
diff --git a/Project/Project.project b/Project/Project.project
index c7fb7bf..104504d 100644
--- a/Project/Project.project
+++ b/Project/Project.project
@@ -176,8 +176,8 @@
<VirtualDirectory Name="wxMathPlot">
<File Name="wxMathPlot/mathplot.h"/>
</VirtualDirectory>
- <File Name="wxGLString.cpp"/>
- <File Name="wxGLString.h"/>
+ <File Name="OpenGLText.h"/>
+ <File Name="OpenGLText.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="controller">
<VirtualDirectory Name="files">
diff --git a/Project/Project.txt b/Project/Project.txt
index 4845d86..f7bee09 100644
--- a/Project/Project.txt
+++ b/Project/Project.txt
@@ -1,2 +1,2 @@
-./Release_Windows_x64/main.cpp.o ./Release_Windows_x64/win_resources.rc.o ./Release_Windows_x64/PropertiesData.cpp.o ./Release_Windows_x64/ArtMetro.cpp.o ./Release_Windows_x64/wxGLString.cpp.o ./Release_Windows_x64/MainFrameBitmaps.cpp.o ./Release_Windows_x64/WorkspaceBitmaps.cpp.o ./Release_Windows_x64/BusFormBitmaps.cpp.o ./Release_Windows_x64/ElementFormBitmaps.cpp.o ./Release_Windows_x64/ControlEditorBitmaps.cpp.o ./Release_Windows_x64/ChartViewBitmaps.cpp.o ./Release_Windows_x64/PropertiesFormBitmaps.cpp.o ./Release_Windows_x64/DataReportBitmaps.cpp.o ./Release_Windows_x64/MainFrameBase.cpp.o ./Release_Windows_x64/WorkspaceBase.cpp.o ./Release_Windows_x64/ElementForm.cpp.o ./Release_Windows_x64/ControlEditorBase.cpp.o ./Release_Windows_x64/ChartViewBase.cpp.o ./Release_Windows_x64/PropertiesForm.cpp.o ./Release_Windows_x64/DataReportBase.cpp.o ./Release_Windows_x64/ElectricCalculation.cpp.o ./Release_Windows_x64/PowerFlow.cpp.o ./Release_Windows_x64/Fault.cpp.o ./Release_Windows_x64/Electromechanical.cpp.o ./Release_Windows_x64/Element.cpp.o ./Release_Windows_x64/ElementDataObject.cpp.o ./Release_Windows_x64/ElementPlotData.cpp.o ./Release_Windows_x64/wxMathPlot_mathplot.cpp.o ./Release_Windows_x64/Camera.cpp.o ./Release_Windows_x64/MainFrame.cpp.o ./Release_Windows_x64/Workspace.cpp.o ./Release_Windows_x64/ChartView.cpp.o ./Release_Windows_x64/ControlEditor.cpp.o ./Release_Windows_x64/DataReport.cpp.o ./Release_Windows_x64/FileHanding.cpp.o ./Release_Windows_x64/ConnectionLine.cpp.o ./Release_Windows_x64/Constant.cpp.o ./Release_Windows_x64/ControlElement.cpp.o ./Release_Windows_x64/ControlElementContainer.cpp.o ./Release_Windows_x64/ControlElementSolver.cpp.o ./Release_Windows_x64/Exponential.cpp.o ./Release_Windows_x64/Gain.cpp.o ./Release_Windows_x64/IOControl.cpp.o ./Release_Windows_x64/Limiter.cpp.o ./Release_Windows_x64/Multiplier.cpp.o ./Release_Windows_x64/RateLimiter.cpp.o ./Release_Windows_x64/Sum.cpp.o ./Release_Windows_x64/TransferFunction.cpp.o ./Release_Windows_x64/Divider.cpp.o ./Release_Windows_x64/MathOperation.cpp.o ./Release_Windows_x64/GraphicalElement.cpp.o ./Release_Windows_x64/Text.cpp.o ./Release_Windows_x64/Branch.cpp.o ./Release_Windows_x64/Bus.cpp.o ./Release_Windows_x64/Capacitor.cpp.o ./Release_Windows_x64/IndMotor.cpp.o ./Release_Windows_x64/Inductor.cpp.o ./Release_Windows_x64/Line.cpp.o ./Release_Windows_x64/Load.cpp.o ./Release_Windows_x64/Machines.cpp.o ./Release_Windows_x64/PowerElement.cpp.o ./Release_Windows_x64/Shunt.cpp.o ./Release_Windows_x64/SyncGenerator.cpp.o ./Release_Windows_x64/SyncMotor.cpp.o
+./Release_Windows_x64/main.cpp.o ./Release_Windows_x64/win_resources.rc.o ./Release_Windows_x64/PropertiesData.cpp.o ./Release_Windows_x64/ArtMetro.cpp.o ./Release_Windows_x64/OpenGLText.cpp.o ./Release_Windows_x64/MainFrameBitmaps.cpp.o ./Release_Windows_x64/WorkspaceBitmaps.cpp.o ./Release_Windows_x64/BusFormBitmaps.cpp.o ./Release_Windows_x64/ElementFormBitmaps.cpp.o ./Release_Windows_x64/ControlEditorBitmaps.cpp.o ./Release_Windows_x64/ChartViewBitmaps.cpp.o ./Release_Windows_x64/PropertiesFormBitmaps.cpp.o ./Release_Windows_x64/DataReportBitmaps.cpp.o ./Release_Windows_x64/MainFrameBase.cpp.o ./Release_Windows_x64/WorkspaceBase.cpp.o ./Release_Windows_x64/ElementForm.cpp.o ./Release_Windows_x64/ControlEditorBase.cpp.o ./Release_Windows_x64/ChartViewBase.cpp.o ./Release_Windows_x64/PropertiesForm.cpp.o ./Release_Windows_x64/DataReportBase.cpp.o ./Release_Windows_x64/ElectricCalculation.cpp.o ./Release_Windows_x64/PowerFlow.cpp.o ./Release_Windows_x64/Fault.cpp.o ./Release_Windows_x64/Electromechanical.cpp.o ./Release_Windows_x64/Element.cpp.o ./Release_Windows_x64/ElementDataObject.cpp.o ./Release_Windows_x64/ElementPlotData.cpp.o ./Release_Windows_x64/wxMathPlot_mathplot.cpp.o ./Release_Windows_x64/Camera.cpp.o ./Release_Windows_x64/MainFrame.cpp.o ./Release_Windows_x64/Workspace.cpp.o ./Release_Windows_x64/ChartView.cpp.o ./Release_Windows_x64/ControlEditor.cpp.o ./Release_Windows_x64/DataReport.cpp.o ./Release_Windows_x64/FileHanding.cpp.o ./Release_Windows_x64/ConnectionLine.cpp.o ./Release_Windows_x64/Constant.cpp.o ./Release_Windows_x64/ControlElement.cpp.o ./Release_Windows_x64/ControlElementContainer.cpp.o ./Release_Windows_x64/ControlElementSolver.cpp.o ./Release_Windows_x64/Exponential.cpp.o ./Release_Windows_x64/Gain.cpp.o ./Release_Windows_x64/IOControl.cpp.o ./Release_Windows_x64/Limiter.cpp.o ./Release_Windows_x64/Multiplier.cpp.o ./Release_Windows_x64/RateLimiter.cpp.o ./Release_Windows_x64/Sum.cpp.o ./Release_Windows_x64/TransferFunction.cpp.o ./Release_Windows_x64/Divider.cpp.o ./Release_Windows_x64/MathOperation.cpp.o ./Release_Windows_x64/GraphicalElement.cpp.o ./Release_Windows_x64/Text.cpp.o ./Release_Windows_x64/Branch.cpp.o ./Release_Windows_x64/Bus.cpp.o ./Release_Windows_x64/Capacitor.cpp.o ./Release_Windows_x64/IndMotor.cpp.o ./Release_Windows_x64/Inductor.cpp.o ./Release_Windows_x64/Line.cpp.o ./Release_Windows_x64/Load.cpp.o ./Release_Windows_x64/Machines.cpp.o ./Release_Windows_x64/PowerElement.cpp.o ./Release_Windows_x64/Shunt.cpp.o ./Release_Windows_x64/SyncGenerator.cpp.o ./Release_Windows_x64/SyncMotor.cpp.o
./Release_Windows_x64/Transformer.cpp.o ./Release_Windows_x64/GeneralPropertiesForm.cpp.o ./Release_Windows_x64/SimulationsSettingsForm.cpp.o ./Release_Windows_x64/AboutForm.cpp.o ./Release_Windows_x64/ConstantForm.cpp.o ./Release_Windows_x64/ControlSystemTest.cpp.o ./Release_Windows_x64/ExponentialForm.cpp.o ./Release_Windows_x64/GainForm.cpp.o ./Release_Windows_x64/IOControlForm.cpp.o ./Release_Windows_x64/LimiterForm.cpp.o ./Release_Windows_x64/RateLimiterForm.cpp.o ./Release_Windows_x64/SumForm.cpp.o ./Release_Windows_x64/TransferFunctionForm.cpp.o ./Release_Windows_x64/TextForm.cpp.o ./Release_Windows_x64/BusForm.cpp.o ./Release_Windows_x64/GeneratorStabForm.cpp.o ./Release_Windows_x64/IndMotorForm.cpp.o ./Release_Windows_x64/LineForm.cpp.o ./Release_Windows_x64/LoadForm.cpp.o ./Release_Windows_x64/ReactiveShuntElementForm.cpp.o ./Release_Windows_x64/SwitchingForm.cpp.o ./Release_Windows_x64/SyncMachineForm.cpp.o ./Release_Windows_x64/TransformerForm.cpp.o
diff --git a/Project/Text.cpp b/Project/Text.cpp
index d633bdc..3e0eb1c 100644
--- a/Project/Text.cpp
+++ b/Project/Text.cpp
@@ -32,34 +32,14 @@
#include "Inductor.h"
#include "Capacitor.h"
-Text::Text() : GraphicalElement()
-{
- Init();
- SetText(m_text);
-}
+Text::Text() : GraphicalElement() { SetText(m_text); }
Text::Text(wxPoint2DDouble position) : GraphicalElement()
{
m_position = position;
- Init();
SetText(m_text);
}
-Text::~Text()
-{
- // if(m_glString) delete m_glString;
- // if(m_glStringArray) delete m_glStringArray;
- if(m_textureID) {
- glDeleteTextures(1, m_textureID);
- }
-}
-
-void Text::Init()
-{
- m_textCoord = new wxPoint2DDouble[2];
- m_textCoord[0] = wxPoint2DDouble(0, 1);
- m_textCoord[1] = wxPoint2DDouble(1, 0);
-}
-
+Text::~Text() {}
bool Text::Contains(wxPoint2DDouble position) const
{
wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle);
@@ -68,8 +48,6 @@ bool Text::Contains(wxPoint2DDouble position) const
void Text::Draw(wxPoint2DDouble translation, double scale)
{
- // wxScreenDC dc;
-
// Draw selection rectangle
// Push the current matrix on stack.
@@ -86,35 +64,17 @@ void Text::Draw(wxPoint2DDouble translation, double scale)
}
// Draw text (layer 2)
- glEnable(GL_TEXTURE_2D);
glColor4d(0.0, 0.0, 0.0, 1.0);
- if(m_textureID) {
- glPushMatrix();
-
- glTranslated(m_position.m_x - m_width / 2, m_position.m_y - m_height / 2, 0);
- if(m_angle != 0) glRotatef(m_angle, 0, 0, 1);
-
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, m_textureID[0]);
-
- glBegin(GL_QUADS);
-
- glTexCoord2f(m_textCoord[0].m_x, m_textCoord[0].m_y);
- glVertex2f(0, 0);
-
- glTexCoord2f(m_textCoord[1].m_x, m_textCoord[0].m_y);
- glVertex2f(m_width, 0);
-
- glTexCoord2f(m_textCoord[1].m_x, m_textCoord[1].m_y);
- glVertex2f(m_width, m_height);
-
- glTexCoord2f(m_textCoord[0].m_x, m_textCoord[1].m_y);
- glVertex2f(0, m_height);
- glEnd();
-
- glDisable(GL_TEXTURE_2D);
-
- glPopMatrix();
+ if(m_isMultlineText) {
+ for(unsigned int i = 0; i < m_openGLTextList.size(); ++i) {
+ m_openGLTextList[i]->Draw(
+ m_position +
+ wxPoint2DDouble(0.0, (m_height * static_cast<double>(i) / static_cast<double>(m_numberOfLines)) -
+ (m_height * static_cast<double>(m_numberOfLines - 1) /
+ static_cast<double>(2 * m_numberOfLines))));
+ }
+ } else if(m_openGLTextList.size() > 0) {
+ m_openGLTextList[0]->Draw(m_position);
}
glPopMatrix();
}
@@ -127,74 +87,28 @@ bool Text::Intersects(wxRect2DDouble rect) const
void Text::SetText(wxString text)
{
- /*
- glEnable(GL_TEXTURE_2D);
m_text = text;
- wxFont font(m_fontSize, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
- //wxFont font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
-
- wxScreenDC dc;
- GLuint* idString = NULL;
- GLuint* idStringArray = NULL;
-
- if(m_glString) {
- delete m_glString;
- m_glString = NULL;
-
- idString = new GLuint;
- glGenTextures(1, idString);
- }
- if(m_glStringArray) {
- delete m_glStringArray;
- m_glStringArray = NULL;
- idStringArray = new GLuint;
- glGenTextures(1, idStringArray);
+ // Clear OpenGL text list
+ for(auto it = m_openGLTextList.begin(), itEnd = m_openGLTextList.end(); it != itEnd; ++it) {
+ delete *it;
}
+ m_openGLTextList.clear();
m_numberOfLines = m_text.Freq('\n') + 1;
- if(m_numberOfLines == 1) { // Only one line
- m_isMultlineText = false;
- m_glString = new wxGLString(m_text);
- m_glString->setFont(font);
- m_glString->consolidate(&dc);
- m_width = m_glString->getWidth();
- m_height = m_glString->getheight();
- } else {
- m_isMultlineText = true;
- m_glStringArray = new wxGLStringArray();
- dc.SetFont(font);
-
- m_width = 0.0;
- m_height = 0.0;
- wxString multText = m_text;
- for(int i = 0; i < m_numberOfLines; ++i) {
- wxString nextLine;
- wxString currentLine = multText.BeforeFirst('\n', &nextLine);
- multText = nextLine;
- m_glStringArray->addString(currentLine);
-
- wxSize size = dc.GetTextExtent(currentLine);
- if(size.GetWidth() > m_width) m_width = size.GetWidth();
- m_height += size.GetHeight();
- }
-
- m_glStringArray->setFont(font);
- m_glStringArray->consolidate(&dc);
+ if(m_numberOfLines > 1) m_isMultlineText = true;
+ m_width = 0.0;
+ m_height = 0.0;
+ wxString multText = m_text;
+ for(int i = 0; i < m_numberOfLines; ++i) {
+ wxString nextLine;
+ wxString currentLine = multText.BeforeFirst('\n', &nextLine);
+ multText = nextLine;
+ m_openGLTextList.push_back(new OpenGLText(currentLine));
+ if(m_openGLTextList[i]->GetWidth() > m_width) m_width = m_openGLTextList[i]->GetWidth();
+ m_height += m_openGLTextList[i]->GetHeight();
}
-
- if(idString) glDeleteTextures(1, idString);
- if(idStringArray) glDeleteTextures(1, idStringArray);
-
- // Update text rectangle.
- SetPosition(m_position);
- glDisable(GL_TEXTURE_2D);*/
- m_text = text;
- TextToBitmap();
- LoadTextTexture();
- m_width = m_bitmapSize.GetWidth();
- m_height = m_bitmapSize.GetHeight();
- SetPosition(m_position);
+ SetPosition(m_position); // Update element rectangle.
}
void Text::Rotate(bool clockwise)
@@ -1006,80 +920,10 @@ Element* Text::GetCopy()
{
Text* copy = new Text();
*copy = *this;
- copy->Init();
- copy->m_textureID = NULL;
- copy->m_bitmapSize = wxSize(0, 0);
- copy->m_bitmap = wxNullBitmap;
- copy->SetText(copy->m_text);
- return copy;
-}
-
-void Text::TextToBitmap()
-{
- wxFont font = wxFont(m_fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
-
- wxMemoryDC memDC;
- memDC.SetFont(font);
- m_bitmapSize = memDC.GetTextExtent(m_text);
-
- int p2w = RoundToPowerOfTwo(m_bitmapSize.GetWidth());
- int p2h = RoundToPowerOfTwo(m_bitmapSize.GetHeight());
-
- m_bitmap = wxBitmap(p2w, p2h);
-
- memDC.SelectObject(m_bitmap);
- memDC.SetBackground(*wxWHITE_BRUSH);
- memDC.Clear();
- memDC.DrawText(m_text, 0, 0);
-
- m_textCoord[1].m_x = static_cast<double>(m_bitmapSize.GetWidth()) / static_cast<double>(p2w);
- m_textCoord[1].m_y = 1.0 - static_cast<double>(m_bitmapSize.GetHeight()) / static_cast<double>(p2h);
-}
-
-void Text::LoadTextTexture()
-{
- if(m_textureID) glDeleteTextures(1, m_textureID);
- m_textureID = new GLuint[1];
- glGenTextures(1, &m_textureID[0]);
-
- glBindTexture(GL_TEXTURE_2D, *m_textureID);
-
- wxImage img = m_bitmap.ConvertToImage();
-
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
- const int w = img.GetWidth(), h = img.GetHeight();
- int bytesPerPixel = 4;
- GLubyte* bitmapData = img.GetData();
- int imageSize = w * h * bytesPerPixel;
- GLubyte* imageData = new GLubyte[imageSize];
- int revVal = h - 1;
-
- for(int y = 0; y < h; y++) {
- for(int x = 0; x < w; x++) {
- imageData[(x + y * w) * bytesPerPixel + 0] = 255;
- imageData[(x + y * w) * bytesPerPixel + 1] = 255;
- imageData[(x + y * w) * bytesPerPixel + 2] = 255;
-
- // alpha
- imageData[(x + y * w) * bytesPerPixel + 3] = 255 - bitmapData[(x + (revVal - y) * w) * 3];
- }
+ std::vector<OpenGLText*> copyList;
+ for(auto it = m_openGLTextList.begin(), itEnd = m_openGLTextList.end(); it != itEnd; ++it) {
+ copyList.push_back((*it)->GetCopy());
}
-
- glTexImage2D(GL_TEXTURE_2D, 0, bytesPerPixel, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
- delete imageData;
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-}
-
-int Text::RoundToPowerOfTwo(int value, int min)
-{
- //[Ref] https://stackoverflow.com/questions/466204/rounding-up-to-next-power-of-2
- double baseOfTwo = std::log(static_cast<double>(value)) / std::log(2.0);
- int powerOfTwo = static_cast<int>(std::pow(2.0, static_cast<int>(std::ceil(baseOfTwo))));
- return std::max(min, powerOfTwo);
+ copy->m_openGLTextList = copyList;
+ return copy;
} \ No newline at end of file
diff --git a/Project/Text.h b/Project/Text.h
index 04e9892..284353c 100644
--- a/Project/Text.h
+++ b/Project/Text.h
@@ -23,6 +23,7 @@
#include "GraphicalElement.h"
#include "PowerElement.h"
+#include "OpenGLText.h"
class TextForm;
@@ -94,7 +95,6 @@ class Text : public GraphicalElement
void SetElement(Element* element) { m_element = element; }
void SetElementNumber(int elementNumber) { m_elementNumber = elementNumber; }
void SetElementType(const ElementType elementType) { m_elementType = elementType; }
- void SetFontSize(int fontSize) { m_fontSize = fontSize; }
void SetUnit(const ElectricalUnit unit) { m_unit = unit; }
void SetDecimalPlaces(int decimalPlaces) { m_decimalPlaces = decimalPlaces; }
const DataType GetDataType() const { return m_dataType; }
@@ -102,25 +102,14 @@ class Text : public GraphicalElement
Element* GetElement() { return m_element; }
int GetElementNumber() const { return m_elementNumber; }
const ElementType GetElementType() const { return m_elementType; }
- int GetFontSize() const { return m_fontSize; }
const ElectricalUnit GetUnit() const { return m_unit; }
int GetDecimalPlaces() const { return m_decimalPlaces; }
-
protected:
- void Init();
- int RoundToPowerOfTwo(int value, int min = 32);
- void TextToBitmap();
- void LoadTextTexture();
-
wxString m_text = _("Text");
- int m_numberOfLines;
+ int m_numberOfLines = 0;
bool m_isMultlineText = false;
- int m_fontSize = 10;
- wxBitmap m_bitmap = wxNullBitmap;
- wxSize m_bitmapSize = wxSize(0, 0);
- wxPoint2DDouble* m_textCoord = NULL;
- GLuint* m_textureID = NULL;
+ std::vector<OpenGLText*> m_openGLTextList;
Element* m_element = NULL;
ElementType m_elementType = TYPE_NONE;
diff --git a/Project/TransferFunction.cpp b/Project/TransferFunction.cpp
index ed6640a..c932608 100644
--- a/Project/TransferFunction.cpp
+++ b/Project/TransferFunction.cpp
@@ -48,7 +48,11 @@ TransferFunction::TransferFunction(int id) : ControlElement(id)
m_nodeList.push_back(node2);
}
-TransferFunction::~TransferFunction() {}
+TransferFunction::~TransferFunction()
+{
+ if(m_glTextDen) delete m_glTextDen;
+ if(m_glTextNum) delete m_glTextNum;
+}
void TransferFunction::Draw(wxPoint2DDouble translation, double scale) const
{
glLineWidth(1.0);
@@ -69,41 +73,28 @@ void TransferFunction::Draw(wxPoint2DDouble translation, double scale) const
DrawNodes();
- glEnable(GL_TEXTURE_2D);
glColor4d(0.0, 0.0, 0.0, 1.0);
- m_glStringNum->bind();
- m_glStringNum->render(m_position.m_x, m_position.m_y - m_height / 4);
- m_glStringDen->bind();
- m_glStringDen->render(m_position.m_x, m_position.m_y + m_height / 4);
- glDisable(GL_TEXTURE_2D);
+ m_glTextNum->Draw(m_position + wxPoint2DDouble(0.0, -m_height / 4));
+ m_glTextDen->Draw(m_position + wxPoint2DDouble(0.0, m_height / 4));
}
void TransferFunction::SetText(wxString numerator, wxString denominator)
{
- wxFont font(m_fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
- wxScreenDC dc;
-
- if(m_glStringNum) {
- delete m_glStringNum;
- m_glStringNum = NULL;
- }
- m_glStringNum = new wxGLString(numerator);
- m_glStringNum->setFont(font);
- m_glStringNum->consolidate(&dc);
+ if(m_glTextNum)
+ m_glTextNum->SetText(numerator);
+ else
+ m_glTextNum = new OpenGLText(numerator);
- if(m_glStringDen) {
- delete m_glStringDen;
- m_glStringDen = NULL;
- }
- m_glStringDen = new wxGLString(denominator);
- m_glStringDen->setFont(font);
- m_glStringDen->consolidate(&dc);
+ if(m_glTextDen)
+ m_glTextDen->SetText(denominator);
+ else
+ m_glTextDen = new OpenGLText(denominator);
- double nWidth = m_glStringNum->getWidth() + 5 + m_borderSize;
- double dWidth = m_glStringDen->getWidth() + 5 + m_borderSize;
+ double nWidth = m_glTextNum->GetWidth() + 5 + m_borderSize;
+ double dWidth = m_glTextDen->GetWidth() + 5 + m_borderSize;
m_width = nWidth > dWidth ? nWidth : dWidth;
- m_height = m_glStringNum->getheight() + m_glStringDen->getheight() + 2 * m_borderSize;
+ m_height = m_glTextNum->GetHeight() + m_glTextDen->GetHeight() + 2 * m_borderSize;
SetPosition(m_position); // Update rect properly.
}
@@ -273,7 +264,7 @@ void TransferFunction::CalculateSpaceState(int maxIteration, double error)
int order = static_cast<int>(m_denominator.size());
std::vector<double> denominator = m_denominator;
std::vector<double> numerator;
-
+
//[Ref.] http://lpsa.swarthmore.edu/Representations/SysRepTransformations/TF2SS.html
int k = order;
for(int i = 0; i < order; i++) {
@@ -378,8 +369,7 @@ Element* TransferFunction::GetCopy()
{
TransferFunction* copy = new TransferFunction(m_elementID);
*copy = *this;
- m_glStringNum = NULL;
- m_glStringDen = NULL;
- UpdateTFText();
+ copy->m_glTextNum = m_glTextNum->GetCopy();
+ copy->m_glTextDen = m_glTextDen->GetCopy();
return copy;
}
diff --git a/Project/TransferFunction.h b/Project/TransferFunction.h
index af84ba5..364298e 100644
--- a/Project/TransferFunction.h
+++ b/Project/TransferFunction.h
@@ -21,7 +21,7 @@
#include "ControlElement.h"
#include <wx/dcscreen.h>
-#include "wxGLString.h"
+#include "OpenGLText.h"
class TransferFunctionForm;
@@ -84,8 +84,8 @@ class TransferFunction : public ControlElement
wchar_t m_supNumber[10];
- wxGLString* m_glStringNum = NULL;
- wxGLString* m_glStringDen = NULL;
+ OpenGLText* m_glTextNum = NULL;
+ OpenGLText* m_glTextDen = NULL;
int m_fontSize = 10;
std::vector<double> m_numerator;
diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp
index dfdf65f..9c491c4 100644
--- a/Project/Workspace.cpp
+++ b/Project/Workspace.cpp
@@ -1153,9 +1153,14 @@ bool Workspace::RunPowerFlow()
void Workspace::UpdateTextElements()
{
+ double basePower = m_properties->GetSimulationPropertiesData().basePower;
+ if(m_properties->GetSimulationPropertiesData().basePowerUnit == UNIT_kVA)
+ basePower *= 1e3;
+ else if(m_properties->GetSimulationPropertiesData().basePowerUnit == UNIT_MVA)
+ basePower *= 1e6;
for(auto it = m_textList.begin(), itEnd = m_textList.end(); it != itEnd; ++it) {
Text* text = *it;
- text->UpdateText(m_properties->GetSimulationPropertiesData().basePower);
+ text->UpdateText(basePower);
}
}
diff --git a/Project/data/images/control/io.png b/Project/data/images/control/io.png
index 0d1da22..8f34594 100644
--- a/Project/data/images/control/io.png
+++ b/Project/data/images/control/io.png
Binary files differ
diff --git a/Project/wxGLString.cpp b/Project/wxGLString.cpp
deleted file mode 100644
index d9b8324..0000000
--- a/Project/wxGLString.cpp
+++ /dev/null
@@ -1,465 +0,0 @@
-#include "wxGLString.h"
-
-#ifdef __WXMAC__
-#include "OpenGL/gl.h"
-#else
-#include <GL/gl.h>
-#endif
-
-#include "wx/wx.h"
-
-GLuint* loadImage(wxImage* img)
-{
- GLuint* ID = new GLuint;
- glGenTextures(1, ID);
-
- glBindTexture(GL_TEXTURE_2D, *ID);
-
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
- const int w = img->GetWidth(), h = img->GetHeight();
-
- // note: must make a local copy before passing the data to OpenGL, as GetData() returns RGB
- // and we want the Alpha channel. Furthermore, the current rendering is black-on-white, we'll
- // convert it to an alpha channel by the way (not all platforms support transparency in wxDCs
- // so it's the easiest way to go)
- GLubyte* bitmapData = img->GetData();
- GLubyte* imageData = NULL;
-
- int bytesPerPixel = 4;
-
- int imageSize = w * h * bytesPerPixel;
- imageData = (GLubyte*)malloc(imageSize);
-
- int rev_val = h - 1;
-
- for(int y = 0; y < h; y++) {
- for(int x = 0; x < w; x++) {
- imageData[(x + y * w) * bytesPerPixel + 0] = 255;
- imageData[(x + y * w) * bytesPerPixel + 1] = 255;
- imageData[(x + y * w) * bytesPerPixel + 2] = 255;
-
- // alpha
- imageData[(x + y * w) * bytesPerPixel + 3] = 255 - bitmapData[(x + (rev_val - y) * w) * 3];
- } // next
- } // next
-
- glTexImage2D(GL_TEXTURE_2D, 0, bytesPerPixel, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
-
- free(imageData);
-
- // set texture parameters as you wish
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- // GL_CLAMP_TO_EDGE
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-
- return ID;
-}
-
-class TextTexture
-{
- friend class wxGLString;
- friend class wxGLStringArray;
- friend class wxGLStringNumber;
-
- private:
- GLuint* ID = NULL;
-
- protected:
- GLuint* getID();
-
- TextTexture();
- TextTexture(wxBitmap& bmp);
- void load(wxImage* img);
-
- public:
- ~TextTexture();
-};
-
-#if 0
-#pragma mark -
-#pragma mark TextGLDrawable implementation
-#endif
-
-TextGLDrawable::TextGLDrawable(TextTexture* image_arg)
-{
- x = 0;
- y = 0;
- angle = 0;
-
- xscale = 1;
- yscale = 1;
-
- xflip = false;
- yflip = false;
-
- if(image_arg)
- setImage(image_arg);
- else
- image = NULL;
-
- tex_coord_x1 = 0;
- tex_coord_y1 = 1;
- tex_coord_x2 = 1;
- tex_coord_y2 = 0;
-}
-
-void TextGLDrawable::setFlip(bool x, bool y)
-{
- xflip = x;
- yflip = y;
-}
-
-void TextGLDrawable::move(double x, double y)
-{
- TextGLDrawable::x = x;
- TextGLDrawable::y = y;
-}
-
-void TextGLDrawable::scale(float x, float y)
-{
- TextGLDrawable::xscale = x;
- TextGLDrawable::yscale = y;
-}
-
-void TextGLDrawable::scale(float k)
-{
- TextGLDrawable::xscale = k;
- TextGLDrawable::yscale = k;
-}
-
-void TextGLDrawable::setImage(TextTexture* image) { TextGLDrawable::image = image; }
-void TextGLDrawable::rotate(int angle) { TextGLDrawable::angle = angle; }
-void TextGLDrawable::render() const
-{
- assert(image);
-
- glPushMatrix();
- glTranslatef(x - w / 2, y - h / 2, 0);
- if(xscale != 1 || yscale != 1) glScalef(xscale, yscale, 1);
- if(angle != 0) glRotatef(angle, 0, 0, 1);
-
- glBegin(GL_QUADS);
-
- glTexCoord2f(xflip ? tex_coord_x2 : tex_coord_x1, yflip ? tex_coord_y2 : tex_coord_y1);
- glVertex2f(0, 0);
-
- glTexCoord2f(xflip ? tex_coord_x1 : tex_coord_x2, yflip ? tex_coord_y2 : tex_coord_y1);
- glVertex2f(w, 0);
-
- glTexCoord2f(xflip ? tex_coord_x1 : tex_coord_x2, yflip ? tex_coord_y1 : tex_coord_y2);
- glVertex2f(w, h);
-
- glTexCoord2f(xflip ? tex_coord_x2 : tex_coord_x1, yflip ? tex_coord_y1 : tex_coord_y2);
- glVertex2f(0, h);
-
- glEnd();
- glPopMatrix();
-}
-
-#if 0
-#pragma mark -
-#pragma mark TextTexture implementation
-#endif
-
-TextTexture::TextTexture() {}
-TextTexture::TextTexture(wxBitmap& bmp)
-{
- wxImage img = bmp.ConvertToImage();
- load(&img);
-}
-void TextTexture::load(wxImage* img) { ID = loadImage(img); }
-GLuint* TextTexture::getID() { return ID; }
-TextTexture::~TextTexture()
-{
- glDeleteTextures(1, ID);
- if(ID) delete ID; // Memory leak?
-}
-
-#if 0
-#pragma mark -
-#pragma mark wxGLString implementation
-#endif
-
-wxGLString::wxGLString() : wxString(wxT("")), TextGLDrawable() { img = NULL; }
-wxGLString::wxGLString(wxString message) : wxString(message), TextGLDrawable() { img = NULL; }
-void wxGLString::operator=(wxString& string) { (*((wxString*)this)) = string; }
-void wxGLString::bind() const
-{
- if(img->getID()) {
- glBindTexture(GL_TEXTURE_2D, *img->getID());
- }
-}
-void wxGLString::calculateSize(wxDC* dc, const bool ignore_font /* when from array */)
-{
- if(!ignore_font) {
- if(font.IsOk())
- dc->SetFont(font);
- else
- dc->SetFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
- }
-
- dc->GetTextExtent(*this, &w, &h);
-}
-
-void wxGLString::consolidate(wxDC* dc)
-{
- calculateSize(dc);
- const int power_of_2_w = std::max(32, (int)pow((double)2, (int)ceil((float)log((double)w) / log(2.0))));
- const int power_of_2_h = std::max(32, (int)pow((double)2, (int)ceil((float)log((double)h) / log(2.0))));
-
- wxBitmap bmp(power_of_2_w, power_of_2_h);
- assert(bmp.IsOk());
-
- {
- wxMemoryDC temp_dc(bmp);
-
- temp_dc.SetBrush(*wxWHITE_BRUSH);
- temp_dc.Clear();
-
- if(font.IsOk())
- temp_dc.SetFont(font);
- else
- temp_dc.SetFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
-
- temp_dc.DrawText(*this, 0, 0);
- }
-
- if(img) delete img;
- img = new TextTexture(bmp);
-
- TextGLDrawable::texw = power_of_2_w;
- TextGLDrawable::texh = power_of_2_h;
- TextGLDrawable::tex_coord_x2 = (float)w / (float)power_of_2_w;
- TextGLDrawable::tex_coord_y2 = 1 - (float)h / (float)power_of_2_h;
- TextGLDrawable::tex_coord_y1 = 1;
-
- TextGLDrawable::setImage(img);
-}
-
-void wxGLString::consolidateFromArray(wxDC* dc, double x, double y) { dc->DrawText(*this, x, y); }
-void wxGLString::setFont(wxFont font) { wxGLString::font = font; }
-void wxGLString::render(const double x, const double y)
-{
- TextGLDrawable::move(x, y);
- TextGLDrawable::render();
-}
-wxGLString::~wxGLString()
-{
- if(img) delete img;
-}
-
-#if 0
-#pragma mark -
-#pragma mark wxGLNumberRenderer implementation
-#endif
-
-wxGLNumberRenderer::wxGLNumberRenderer() : wxGLString(wxT("0 1 2 3 4 5 6 7 8 9 . - "))
-{
- number_location = new int[13];
-}
-wxGLNumberRenderer::~wxGLNumberRenderer() { delete[] number_location; }
-void wxGLNumberRenderer::consolidate(wxDC* dc)
-{
- wxGLString::consolidate(dc);
-
- if(font.IsOk())
- dc->SetFont(font);
- else
- dc->SetFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
-
- number_location[0] = 0;
- number_location[1] = dc->GetTextExtent(wxT("0 ")).GetWidth();
- number_location[2] = dc->GetTextExtent(wxT("0 1 ")).GetWidth();
- number_location[3] = dc->GetTextExtent(wxT("0 1 2 ")).GetWidth();
- number_location[4] = dc->GetTextExtent(wxT("0 1 2 3 ")).GetWidth();
- number_location[5] = dc->GetTextExtent(wxT("0 1 2 3 4 ")).GetWidth();
- number_location[6] = dc->GetTextExtent(wxT("0 1 2 3 4 5 ")).GetWidth();
- number_location[7] = dc->GetTextExtent(wxT("0 1 2 3 4 5 6 ")).GetWidth();
- number_location[8] = dc->GetTextExtent(wxT("0 1 2 3 4 5 6 7 ")).GetWidth();
- number_location[9] = dc->GetTextExtent(wxT("0 1 2 3 4 5 6 7 8 ")).GetWidth();
- number_location[10] = dc->GetTextExtent(wxT("0 1 2 3 4 5 6 7 8 9 ")).GetWidth();
- number_location[11] = dc->GetTextExtent(wxT("0 1 2 3 4 5 6 7 8 9 . ")).GetWidth();
- number_location[12] = dc->GetTextExtent(wxT("0 1 2 3 4 5 6 7 8 9 . - ")).GetWidth();
-
- space_w = dc->GetTextExtent(wxT(" ")).GetWidth();
-}
-void wxGLNumberRenderer::renderNumber(int i, double x, double y)
-{
- wxString s;
- s << i;
- renderNumber(s, x, y);
-}
-void wxGLNumberRenderer::renderNumber(float f, double x, double y)
-{
- wxString s;
- s << f;
- renderNumber(s, x, y);
-}
-void wxGLNumberRenderer::renderNumber(wxString s, double x, double y)
-{
- const int full_string_w = TextGLDrawable::texw;
-
- const int char_amount = s.Length();
- for(int c = 0; c < char_amount; c++) {
- int charid = -1;
-
- char schar = s[c];
- switch(schar) {
- case '0':
- charid = 0;
- break;
- case '1':
- charid = 1;
- break;
- case '2':
- charid = 2;
- break;
- case '3':
- charid = 3;
- break;
- case '4':
- charid = 4;
- break;
- case '5':
- charid = 5;
- break;
- case '6':
- charid = 6;
- break;
- case '7':
- charid = 7;
- break;
- case '8':
- charid = 8;
- break;
- case '9':
- charid = 9;
- break;
- case '.':
- case ',':
- charid = 10;
- break;
- case '-':
- charid = 11;
- break;
- default:
- printf("Warning: character %c unexpected in number!\n", schar);
- continue;
- }
-
- assert(charid != -1);
-
- TextGLDrawable::tex_coord_x1 = (float)number_location[charid] / (float)full_string_w;
- TextGLDrawable::tex_coord_x2 = (float)(number_location[charid + 1] - space_w) / (float)full_string_w;
-
- const int char_width = number_location[charid + 1] - number_location[charid] - space_w;
- TextGLDrawable::w = char_width;
-
- TextGLDrawable::move(x, y);
- TextGLDrawable::render();
-
- x += char_width;
- } // next
-
- // TextGLDrawable::w = full_string_w;
-}
-
-#if 0
-#pragma mark -
-#pragma mark wxGLStringArray implementation
-#endif
-
-wxGLStringArray::wxGLStringArray() { img = NULL; }
-wxGLStringArray::wxGLStringArray(const wxString strings_arg[], int amount)
-{
- img = NULL;
-
- for(int n = 0; n < amount; n++) strings.push_back(wxGLString(strings_arg[n]));
-}
-wxGLStringArray::~wxGLStringArray()
-{
- if(img) delete img;
-}
-
-wxGLString& wxGLStringArray::get(const int id) { return strings[id]; }
-void wxGLStringArray::bind()
-{
- if(img->getID()) {
- glBindTexture(GL_TEXTURE_2D, *img->getID());
- }
-}
-void wxGLStringArray::addString(wxString string) { strings.push_back(wxGLString(string)); }
-void wxGLStringArray::setFont(wxFont font) { wxGLStringArray::font = font; }
-void wxGLStringArray::consolidate(wxDC* dc)
-{
- int x = 0, y = 0;
-
- if(font.IsOk())
- dc->SetFont(font);
- else
- dc->SetFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
-
- // find how much space we need
- int longest_string = 0;
-
- const int amount = strings.size();
- for(int n = 0; n < amount; n++) {
- strings[n].calculateSize(dc, true);
- y += strings[n].h;
- if(strings[n].w > longest_string) longest_string = strings[n].w;
- } // next
-
- const int average_string_height = y / amount;
-
- // split in multiple columns if necessary
- int column_amount = 1;
- while(amount / column_amount > 30 && column_amount < 10) column_amount++;
-
- const int power_of_2_w =
- pow((double)2, (int)ceil((float)log((double)longest_string * (double)column_amount) / log(2.0)));
- const int power_of_2_h = pow((double)2, (int)ceil((float)log((double)y / (double)column_amount) / log(2.0)));
-
- // std::cout << "bitmap size : " << power_of_2_w << ", " << power_of_2_h << " // " << column_amount << " columns"
- // << std::endl;
-
- wxBitmap bmp(power_of_2_w, power_of_2_h);
- assert(bmp.IsOk());
-
- {
- wxMemoryDC temp_dc(bmp);
-
- temp_dc.SetBrush(*wxWHITE_BRUSH);
- temp_dc.Clear();
-
- y = 0;
- x = 0;
- if(font.IsOk())
- temp_dc.SetFont(font);
- else
- temp_dc.SetFont(wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT));
-
- for(int n = 0; n < amount; n++) {
- strings[n].consolidateFromArray(&temp_dc, x, y);
-
- strings[n].tex_coord_x1 = (float)x / (float)power_of_2_w;
- strings[n].tex_coord_y1 = 1.0 - (float)y / (float)power_of_2_h;
- strings[n].tex_coord_x2 = (float)(x + strings[n].w) / (float)power_of_2_w;
- strings[n].tex_coord_y2 = 1.0 - (float)(y + strings[n].h) / (float)power_of_2_h;
-
- y += strings[n].h;
- if(y > power_of_2_h - average_string_height) // check if we need to switch to next column
- {
- y = 0;
- x += longest_string;
- }
- }
- }
- if(img) delete img;
- img = new TextTexture(bmp);
-
- for(int n = 0; n < amount; n++) strings[n].setImage(img);
-}
diff --git a/Project/wxGLString.h b/Project/wxGLString.h
deleted file mode 100644
index 2c31e5a..0000000
--- a/Project/wxGLString.h
+++ /dev/null
@@ -1,202 +0,0 @@
-#ifndef _glstring_
-#define _glstring_
-
-#ifdef __WXMAC__
-#include "OpenGL/gl.h"
-#else
-#include <GL/gl.h>
-#endif
-
-#include "wx/wx.h"
-#include <vector>
-
-class TextTexture;
-
-/** base class for renderable elements. You won't create this one directly,
-but may use its public members from wxGLString since it inherits from TextGLDrawable.
-This class will be useful if you wish to apply effects to the text like rotation or
-scaling. */
-class TextGLDrawable
-{
- friend class wxGLString;
- friend class wxGLStringArray;
- friend class wxGLStringNumber;
-protected:
-
- double x,y, angle;
- float xscale, yscale;
- TextTexture* image = NULL;
- bool xflip, yflip;
-
- float tex_coord_x1, tex_coord_y1;
- float tex_coord_x2, tex_coord_y2;
- int w, h, texw, texh;
-
- TextGLDrawable(TextTexture* image=(TextTexture*)0);
- void setImage(TextTexture* image);
- void move(double x, double y);
-public:
-
- void render() const;
-
- /** allows you to flip the rendering vertically and/or horizontally */
- void setFlip(bool x, bool y);
-
- /** scale the rendering , horizontally and vertically (allows stretching) */
- void scale(float x, float y);
-
- /** scale the rendering and keep the same aspect ratio */
- void scale(float k);
-
- /** rotate the rendering by 'angle' degrees */
- void rotate(int angle);
-
- /** returns the width of this element */
- int getWidth() const { return w; }
- /** returns the height of this element */
- int getheight() const { return h; }
-
-};
-
-class wxGLStringArray;
-
-/** wxGLString is the simplest class you can use. It draws a single string on a single line.
-If you plan to render multiple strings, this class is not the fastest.
-
-Use example :
-
-wxGLString my_message(wxT("Hello World"));
-...
-if(first_render)
- my_message.consolidate(&dc);
-
-glColor3f(0,0,0); // black text
-my_message.bind();
-my_message.render(x, y);
-*/
-class wxGLString : public wxString, public TextGLDrawable
-{
-protected:
- TextTexture* img = NULL;
- wxFont font;
-
- friend class wxGLStringArray;
-
- void calculateSize(wxDC* dc, const bool ignore_font=false /* when from array */);
- void consolidateFromArray(wxDC* dc, double x, double y);
-public:
- /** constructs an empty GLString. Set string later with operator=. */
- wxGLString();
- /** constructs a GLstring with 'message' as contents. */
- wxGLString(wxString message);
- virtual ~wxGLString();
-
- /** call just before render() - binds the OpenGL. If you render the same string many
- times, or render from an array, bind only once, this will improve performance */
- void bind() const;
-
- /** set how to draw string for next consolidate() - has no immediate effect,
- you need to call consolidate() to get results */
- void setFont(wxFont font);
-
- /** consolidates the current string info into a GL string. call this after
- setting up strings, font and color (if necessary), and before rendering.
- The wxDC argument is only used to calculate text extents and will not be rendered on. */
- virtual void consolidate(wxDC* dc);
-
- /** render this string at coordinates (x,y). Must be called after bind(). */
- void render(const double x, const double y);
-
- /** changes the string of this element */
- void operator=(wxString& string);
-};
-
-
-/** This class allows rendering numbers.
-
-Use example :
-
-wxGLNumberRenderer glnumbers;
-...
-if(first_render)
- glnumbers.consolidate();
-
-glColor3f(0,0,0); // black numbers
-glnumbers.bind();
-glnumbers.renderNumber( 3.141593f, x, y );
-*/
-class wxGLNumberRenderer : public wxGLString
-{
- int* number_location;
- int space_w;
-public:
- wxGLNumberRenderer();
- virtual ~wxGLNumberRenderer();
-
- /** inits the class to be ready to render.
- The wxDC argument is only used to calculate text extents and will not be rendered on. */
- void consolidate(wxDC* dc);
-
- /** render this number at coordinates (x,y), where wxString s contains the string
- representation of a number. Must be called after bind(). */
- void renderNumber(wxString s, double x, double y);
- /** render this number at coordinates (x,y). Must be called after bind(). */
- void renderNumber(int i, double x, double y);
- /** render this number at coordinates (x,y). Must be called after bind(). */
- void renderNumber(float f, double x, double y);
-};
-
-
-/** This class is useful to render a serie of strings that are usually rendered at the same time.
-It behaves exactly like wxGLString but is more efficient.
-
-
-Use example :
-
-wxGLStringArray my_messages();
-my_messages.addString("wxMac");
-my_messages.addString("wxGTK");
-my_messages.addString("wxMSW");
-...
-
-glColor3f(0,0,0); // black text
-my_messages.bind();
-my_messages.get(0).render( x, y );
-my_messages.get(1).render( x, y + 25 );
-my_messages.get(2).render( x, y + 50 );
-*/
-class wxGLStringArray
-{
- std::vector<wxGLString> strings;
- TextTexture* img = NULL;
- wxFont font;
-public:
- /** constructs an empty array - add elements later using addString */
- wxGLStringArray();
- /** construct an array with 'strings_arg' elemnts in it */
- wxGLStringArray(const wxString strings_arg[], int amount);
- ~wxGLStringArray();
-
- /** get a sub-element - useful mainly for rendering, e.g. my_array.get(0).render(x, y); */
- wxGLString& get(const int id);
-
- /** call just before render() - binds the OpenGL. If you render the same string many
- times, or render from an array, bind only once, this will improve performance */
- void bind();
-
- /** add a string to the list for next consolidate() - has no
- immediate effect, you need to call consolidate() to get results */
- void addString(wxString string);
-
- /** set how to draw string for next consolidate() - has no immediate effect,
- you need to call consolidate() to get results */
- void setFont(wxFont font);
-
- /** consolidates the current string info into a GL string. call this after
- setting up strings, font and color (if necessary), and before rendering.
- The wxDC argument is only used to calculate text extents and will not be rendered on. */
- void consolidate(wxDC* dc);
-};
-
-
-#endif \ No newline at end of file