Skip to content

Commit 5f97eee

Browse files
author
Sebastian Pape
committed
Adjusting to 3D_rendering branch
1 parent 1ef7fb1 commit 5f97eee

File tree

8 files changed

+76
-87
lines changed

8 files changed

+76
-87
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ target_link_libraries(DasherUI PRIVATE imgui glfw OpenGL::GL DasherCore nfd)
8383
# Copy Data files
8484
file(GLOB RESOURCE_FILES
8585
${PROJECT_SOURCE_DIR}/DasherCore/Data/alphabets/alphabet*.xml
86-
${PROJECT_SOURCE_DIR}/DasherCore/Data/colours/colour*.xml
86+
${PROJECT_SOURCE_DIR}/DasherCore/Data/colors/color*.xml
8787
${PROJECT_SOURCE_DIR}/DasherCore/Data/control/control*.xml
8888
${PROJECT_SOURCE_DIR}/DasherCore/Data/training/training*.txt
8989
)

DasherCore

src/DasherController.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ void DasherController::editDelete(const std::string& strText, Dasher::CDasherNod
2626
CDasherInterfaceBase::editDelete(strText, pNode);
2727
}
2828

29-
unsigned DasherController::ctrlMove(bool bForwards, Dasher::CControlManager::EditDistance dist)
29+
unsigned DasherController::ctrlMove(bool bForwards, Dasher::EditDistance dist)
3030
{
31-
if (dist == Dasher::CControlManager::EditDistance::EDIT_CHAR) {
31+
if (dist == Dasher::EditDistance::EDIT_CHAR) {
3232
if (bForwards) Cursor++;
3333
else Cursor--;
3434
}
3535
return Cursor;
3636
}
3737

38-
unsigned DasherController::ctrlDelete(bool bForwards, Dasher::CControlManager::EditDistance dist)
38+
unsigned DasherController::ctrlDelete(bool bForwards, Dasher::EditDistance dist)
3939
{
40-
if(dist == Dasher::CControlManager::EditDistance::EDIT_CHAR) {
40+
if(dist == Dasher::EditDistance::EDIT_CHAR) {
4141

4242
Buffer.erase(Cursor - (bForwards ? 0 : 1), 1);
4343
}
@@ -58,9 +58,9 @@ std::string DasherController::GetAllContext()
5858
return CurrentBuffer;
5959
}
6060

61-
std::string DasherController::GetTextAroundCursor(Dasher::CControlManager::EditDistance iDist) {
61+
std::string DasherController::GetTextAroundCursor(Dasher::EditDistance iDist) {
6262
if (Buffer.length() > Cursor && Buffer.length() >= 2) {
63-
if (iDist == Dasher::CControlManager::EditDistance::EDIT_CHAR) {
63+
if (iDist == Dasher::EditDistance::EDIT_CHAR) {
6464
return Buffer.substr(Cursor - 1, 2);
6565
}
6666

@@ -87,8 +87,7 @@ void DasherController::CreateModules()
8787
{
8888
CDashIntfScreenMsgs::CreateModules();
8989

90-
RegisterModule(ScreenModule.get());
91-
SetDefaultInputDevice(ScreenModule.get());
90+
GetModuleManager()->RegisterInputDeviceModule(ScreenModule.get(), true);
9291
}
9392

9493
void DasherController::CopyToClipboard(const std::string& text)

src/DasherController.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class DasherController : public Dasher::CDashIntfScreenMsgs
1414

1515
void editOutput(const std::string& strText, Dasher::CDasherNode* pNode) override;
1616
void editDelete(const std::string& strText, Dasher::CDasherNode* pNode) override;
17-
unsigned ctrlMove(bool bForwards, Dasher::CControlManager::EditDistance dist) override;
18-
unsigned ctrlDelete(bool bForwards, Dasher::CControlManager::EditDistance dist) override;
17+
unsigned ctrlMove(bool bForwards, Dasher::EditDistance dist) override;
18+
unsigned ctrlDelete(bool bForwards, Dasher::EditDistance dist) override;
1919
std::string GetContext(unsigned iStart, unsigned iLength) override;
2020
std::string GetAllContext() override;
21-
std::string GetTextAroundCursor(Dasher::CControlManager::EditDistance iDist) override;
21+
std::string GetTextAroundCursor(Dasher::EditDistance iDist) override;
2222
int GetAllContextLenght() override;
2323

2424
void Initialize();

src/DasherUIScreen.cpp

Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "MainWindow.h"
44
#include "imgui/imgui_internal.h"
55

6-
DasherUIScreen::DasherUIScreen(): Dasher::CDasherScreen(100,100), CScreenCoordInput(0, _("Mouse Input"))
6+
DasherUIScreen::DasherUIScreen(): Dasher::CDasherScreen(100,100), CScreenCoordInput("Mouse Input")
77
{
88
Font = MainWindow::LoadFonts(50.0f);
99
}
@@ -14,71 +14,91 @@ std::pair<Dasher::screenint, Dasher::screenint> DasherUIScreen::TextSize(Label*
1414
return {static_cast<Dasher::screenint>(Size.x), static_cast<Dasher::screenint>(Size.y)};
1515
}
1616

17-
void DasherUIScreen::DrawString(Label* label, Dasher::screenint x, Dasher::screenint y, unsigned iFontSize, int iColour)
17+
void DasherUIScreen::Display(){}
18+
19+
bool DasherUIScreen::IsPointVisible(Dasher::screenint, Dasher::screenint){
20+
return true;
21+
}
22+
23+
bool DasherUIScreen::SetCanvasSize(const ImVec2 position, const ImVec2 size)
1824
{
19-
const Dasher::CColourIO::ColourInfo::PaletteColor Color = this->pColorScheme->Colors[iColour];
20-
const ImVec4 ImColor = { static_cast<float>(Color.Red) / 255.0f, static_cast<float>(Color.Green) / 255.0f, static_cast<float>(Color.Blue) / 255.0f, 1.0f };
25+
if(fabs(this->CanvasSize.x - size.x) > std::numeric_limits<float>::epsilon() || fabs(this->CanvasSize.y - size.y) > std::numeric_limits<float>::epsilon())
26+
{
27+
resize(static_cast<Dasher::screenint>(size.x), static_cast<Dasher::screenint>(size.y));
28+
this->CanvasSize = size;
29+
this->CanvasPos = position;
30+
return true;
31+
}
32+
33+
this->CanvasPos = position;
34+
return false;
35+
}
36+
37+
bool DasherUIScreen::GetScreenCoords(Dasher::screenint& iX, Dasher::screenint& iY, Dasher::CDasherView* pView)
38+
{
39+
const ImVec2 MousePos = ImGui::GetMousePos();
40+
if (MousePos.x < 0 || MousePos.y < 0) return false;
41+
iX = static_cast<Dasher::screenint>(MousePos.x - CanvasPos.x);
42+
iY = static_cast<Dasher::screenint>(MousePos.y - CanvasPos.y);
43+
return true;
44+
}
45+
46+
void DasherUIScreen::DrawString(Label* label, Dasher::screenint x, Dasher::screenint y, unsigned iFontSize, const Dasher::ColorPalette::Color& color)
47+
{
48+
const ImVec4 ImColor = { static_cast<float>(color.Red) / 255.0f, static_cast<float>(color.Green) / 255.0f, static_cast<float>(color.Blue) / 255.0f, static_cast<float>(color.Alpha) / 255.0f };
2149
const ImVec2 Pos = { static_cast<float>(x),static_cast<float>(y)};
2250
ImGui::GetWindowDrawList()->AddText(Font, static_cast<float>(iFontSize), Pos + CanvasPos, ImGui::ColorConvertFloat4ToU32(ImColor), label->m_strText.c_str());
2351
}
2452

25-
void DasherUIScreen::DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Dasher::screenint x2, Dasher::screenint y2, int Colour, int iOutlineColour, int iThickness)
53+
void DasherUIScreen::DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Dasher::screenint x2, Dasher::screenint y2, const Dasher::ColorPalette::Color& color, const Dasher::ColorPalette::Color& outlineColor, int iThickness)
2654
{
27-
const Dasher::CColourIO::ColourInfo::PaletteColor FillColor = this->pColorScheme->Colors[Colour];
28-
const ImVec4 ImFillColor = { static_cast<float>(FillColor.Red) / 255.0f, static_cast<float>(FillColor.Green) / 255.0f, static_cast<float>(FillColor.Blue) / 255.0f, 1.0f };
55+
const ImVec4 ImFillColor = { static_cast<float>(color.Red) / 255.0f, static_cast<float>(color.Green) / 255.0f, static_cast<float>(color.Blue) / 255.0f, static_cast<float>(color.Alpha) / 255.0f };
2956
const ImVec2 p1 = { static_cast<float>(x1), static_cast<float>(y1)};
3057
const ImVec2 p2 = { static_cast<float>(x2), static_cast<float>(y2)};
3158

3259
ImGui::GetWindowDrawList()->AddRectFilled(CanvasPos + p1, CanvasPos + p2, ImGui::ColorConvertFloat4ToU32(ImFillColor));
3360

3461
if(iThickness > 0)
3562
{
36-
const Dasher::CColourIO::ColourInfo::PaletteColor OutlineColor = this->pColorScheme->Colors[iOutlineColour > 0 ? iOutlineColour : 3]; //Apparently Outline Color 3 is the default
37-
const ImVec4 ImOutlineColor = { static_cast<float>(OutlineColor.Red) / 255.0f, static_cast<float>(OutlineColor.Green) / 255.0f, static_cast<float>(OutlineColor.Blue) / 255.0f, 1.0f };
38-
63+
const ImVec4 ImOutlineColor = { static_cast<float>(outlineColor.Red) / 255.0f, static_cast<float>(outlineColor.Green) / 255.0f, static_cast<float>(outlineColor.Blue) / 255.0f, static_cast<float>(outlineColor.Alpha) / 255.0f };
3964
ImGui::GetWindowDrawList()->AddRect(CanvasPos + p1, CanvasPos + p2, ImGui::ColorConvertFloat4ToU32(ImOutlineColor),0,0, static_cast<float>(iThickness));
4065
}
4166
}
4267

43-
void DasherUIScreen::DrawCircle(Dasher::screenint iCX, Dasher::screenint iCY, Dasher::screenint iR, int iFillColour, int iLineColour, int iLineWidth)
68+
void DasherUIScreen::DrawCircle(Dasher::screenint iCX, Dasher::screenint iCY, Dasher::screenint iR, const Dasher::ColorPalette::Color& fillColor, const Dasher::ColorPalette::Color& lineColor, int iLineWidth)
4469
{
45-
const Dasher::CColourIO::ColourInfo::PaletteColor FillColor = this->pColorScheme->Colors[iFillColour];
46-
const ImVec4 ImFillColor = { static_cast<float>(FillColor.Red) / 255.0f, static_cast<float>(FillColor.Green) / 255.0f, static_cast<float>(FillColor.Blue) / 255.0f, 1.0f };
47-
70+
const ImVec4 ImFillColor = { static_cast<float>(fillColor.Red) / 255.0f, static_cast<float>(fillColor.Green) / 255.0f, static_cast<float>(fillColor.Blue) / 255.0f, static_cast<float>(fillColor.Alpha) / 255.0f };
4871
ImGui::GetWindowDrawList()->AddCircleFilled(CanvasPos + ImVec2(static_cast<float>(iCX), static_cast<float>(iCY)), static_cast<float>(iR), ImGui::ColorConvertFloat4ToU32(ImFillColor));
4972

5073
if (iLineWidth > 0)
5174
{
52-
const Dasher::CColourIO::ColourInfo::PaletteColor OutlineColor = this->pColorScheme->Colors[iLineColour > 0 ? iLineColour : 3];
53-
const ImVec4 ImOutlineColor = { static_cast<float>(OutlineColor.Red) / 255.0f, static_cast<float>(OutlineColor.Green) / 255.0f, static_cast<float>(OutlineColor.Blue) / 255.0f, 1.0f };
75+
const ImVec4 ImOutlineColor = { static_cast<float>(lineColor.Red) / 255.0f, static_cast<float>(lineColor.Green) / 255.0f, static_cast<float>(lineColor.Blue) / 255.0f, static_cast<float>(lineColor.Alpha) / 255.0f };
5476

5577
ImGui::GetWindowDrawList()->AddCircle(CanvasPos + ImVec2(static_cast<float>(iCX), static_cast<float>(iCY)), static_cast<float>(iR), ImGui::ColorConvertFloat4ToU32(ImFillColor),0, static_cast<float>(iLineWidth));
5678
}
5779
}
5880

59-
void DasherUIScreen::Polyline(point* Points, int Number, int iWidth, int Colour)
81+
void DasherUIScreen::Polyline(point* Points, int Number, int iWidth, const Dasher::ColorPalette::Color& color)
6082
{
61-
const Dasher::CColourIO::ColourInfo::PaletteColor LineColor = this->pColorScheme->Colors[Colour];
62-
const ImVec4 ImLineColor = { static_cast<float>(LineColor.Red) / 255.0f, static_cast<float>(LineColor.Green) / 255.0f, static_cast<float>(LineColor.Blue) / 255.0f, 1.0f };
83+
const ImVec4 ImLineColor = { static_cast<float>(color.Red) / 255.0f, static_cast<float>(color.Green) / 255.0f, static_cast<float>(color.Blue) / 255.0f, static_cast<float>(color.Alpha) / 255.0f };
6384

6485
std::vector<ImVec2> points;
6586

66-
for(unsigned int i = 0; i < Number; i++)
87+
for(int i = 0; i < Number; i++)
6788
{
6889
points.push_back(CanvasPos + ImVec2(static_cast<float>(Points[i].x), static_cast<float>(Points[i].y)));
6990
}
7091

7192
ImGui::GetWindowDrawList()->AddPolyline(points.data(), Number, ImGui::ColorConvertFloat4ToU32(ImLineColor), 0, static_cast<float>(iWidth));
7293
}
7394

74-
void DasherUIScreen::Polygon(point* Points, int Number, int fillColour, int outlineColour, int lineWidth)
95+
void DasherUIScreen::Polygon(point* Points, int Number, const Dasher::ColorPalette::Color& fillColor, const Dasher::ColorPalette::Color& outlineColor, int lineWidth)
7596
{
76-
const Dasher::CColourIO::ColourInfo::PaletteColor FillColor = this->pColorScheme->Colors[fillColour];
77-
const ImVec4 ImFillColor = { static_cast<float>(FillColor.Red) / 255.0f, static_cast<float>(FillColor.Green) / 255.0f, static_cast<float>(FillColor.Blue) / 255.0f, 1.0f };
97+
const ImVec4 ImFillColor = { static_cast<float>(fillColor.Red) / 255.0f, static_cast<float>(fillColor.Green) / 255.0f, static_cast<float>(fillColor.Blue) / 255.0f, static_cast<float>(fillColor.Alpha) / 255.0f };
7898

7999
std::vector<ImVec2> points;
80100

81-
for (unsigned int i = 0; i < Number; i++)
101+
for (int i = 0; i < Number; i++)
82102
{
83103
points.push_back(CanvasPos + ImVec2(static_cast<float>(Points[i].x), static_cast<float>(Points[i].y)));
84104
}
@@ -87,40 +107,6 @@ void DasherUIScreen::Polygon(point* Points, int Number, int fillColour, int outl
87107

88108
if(lineWidth > 0)
89109
{
90-
Polyline(Points, Number, lineWidth, outlineColour);
110+
Polyline(Points, Number, lineWidth, outlineColor);
91111
}
92112
}
93-
94-
void DasherUIScreen::Display(){}
95-
96-
void DasherUIScreen::SetColourScheme(const Dasher::CColourIO::ColourInfo* pColourScheme)
97-
{
98-
this->pColorScheme = pColourScheme;
99-
}
100-
101-
bool DasherUIScreen::IsPointVisible(Dasher::screenint, Dasher::screenint){
102-
return true;
103-
}
104-
105-
bool DasherUIScreen::SetCanvasSize(const ImVec2 position, const ImVec2 size)
106-
{
107-
if(fabs(this->CanvasSize.x - size.x) > std::numeric_limits<float>::epsilon() || fabs(this->CanvasSize.y - size.y) > std::numeric_limits<float>::epsilon())
108-
{
109-
resize(static_cast<Dasher::screenint>(size.x), static_cast<Dasher::screenint>(size.y));
110-
this->CanvasSize = size;
111-
this->CanvasPos = position;
112-
return true;
113-
}
114-
115-
this->CanvasPos = position;
116-
return false;
117-
}
118-
119-
bool DasherUIScreen::GetScreenCoords(Dasher::screenint& iX, Dasher::screenint& iY, Dasher::CDasherView* pView)
120-
{
121-
const ImVec2 MousePos = ImGui::GetMousePos();
122-
if (MousePos.x < 0 || MousePos.y < 0) return false;
123-
iX = static_cast<Dasher::screenint>(MousePos.x - CanvasPos.x);
124-
iY = static_cast<Dasher::screenint>(MousePos.y - CanvasPos.y);
125-
return true;
126-
}

src/DasherUIScreen.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,20 @@ class DasherUIScreen : public Dasher::CDasherScreen, public Dasher::CScreenCoord
1111
DasherUIScreen();
1212

1313
std::pair<Dasher::screenint, Dasher::screenint> TextSize(Label* label, unsigned iFontSize) override;
14-
void DrawString(Label* label, Dasher::screenint x, Dasher::screenint y, unsigned iFontSize, int iColour) override;
15-
void DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Dasher::screenint x2, Dasher::screenint y2, int Colour, int iOutlineColour, int iThickness) override;
16-
void DrawCircle(Dasher::screenint iCX, Dasher::screenint iCY, Dasher::screenint iR, int iFillColour, int iLineColour, int iLineWidth) override;
17-
void Polyline(point* Points, int Number, int iWidth, int Colour) override;
18-
void Polygon(point* Points, int Number, int fillColour, int outlineColour, int lineWidth) override;
1914
void Display() override;
20-
void SetColourScheme(const Dasher::CColourIO::ColourInfo* pColourScheme) override;
2115
bool IsPointVisible(Dasher::screenint x, Dasher::screenint y) override;
22-
23-
bool MultiSizeFonts() override { return true; }
24-
25-
bool SetCanvasSize(ImVec2 CanvasPos, ImVec2 CanvasSize);
16+
17+
bool SetCanvasSize(const ImVec2 position, const ImVec2 size);
2618

2719
bool GetScreenCoords(Dasher::screenint& iX, Dasher::screenint& iY, Dasher::CDasherView* pView) override;
2820

21+
void DrawString(Label* label, Dasher::screenint x, Dasher::screenint y, unsigned iFontSize, const Dasher::ColorPalette::Color& color) override;
22+
void DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Dasher::screenint x2, Dasher::screenint y2, const Dasher::ColorPalette::Color& color, const Dasher::ColorPalette::Color& outlineColor, int iThickness) override;
23+
void DrawCircle(Dasher::screenint iCX, Dasher::screenint iCY, Dasher::screenint iR, const Dasher::ColorPalette::Color& fillColor, const Dasher::ColorPalette::Color& lineColor, int iLineWidth) override;
24+
void Polyline(point* Points, int Number, int iWidth, const Dasher::ColorPalette::Color& color) override;
25+
void Polygon(point* Points, int Number, const Dasher::ColorPalette::Color& fillColor, const Dasher::ColorPalette::Color& outlineColor, int lineWidth) override;
26+
2927
private:
30-
const Dasher::CColourIO::ColourInfo* pColorScheme;
3128
ImVec2 CanvasPos;
3229
ImVec2 CanvasSize;
3330

src/MainWindow.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ MainWindow::MainWindow()
1818
Controller->Initialize();
1919

2020
Controller->GetPermittedValues(Dasher::SP_ALPHABET_ID, Alphabets);
21-
21+
Controller->GetPermittedValues(Dasher::SP_COLOUR_ID, ColorPalettes);
2222
}
2323

2424
#define FORWARD_KEY(ImGui_Key, DasherKey) { \
@@ -106,10 +106,16 @@ bool MainWindow::render(float DeltaTime)
106106
Controller->SetLongParameter(Dasher::LP_MAX_BITRATE, speed);
107107
}
108108

109-
static int item_current = 0;
110-
if(ImGui::Combo("Alphabet", &item_current, [](void* data, int idx, const char** out_text) { *out_text = static_cast<const std::vector<std::string>*>(data)->at(idx).c_str(); return true; }, (void*)&Alphabets, static_cast<int>(Alphabets.size()), 10))
109+
static int item_current_alphabet = 0;
110+
if(ImGui::Combo("Alphabet", &item_current_alphabet, [](void* data, int idx, const char** out_text) { *out_text = static_cast<const std::vector<std::string>*>(data)->at(idx).c_str(); return true; }, (void*)&Alphabets, static_cast<int>(Alphabets.size()), 10))
111+
{
112+
Controller->SetStringParameter(Dasher::SP_ALPHABET_ID, Alphabets[item_current_alphabet]);
113+
}
114+
115+
static int item_current_colorpalette = 0;
116+
if(ImGui::Combo("Color Palette", &item_current_colorpalette, [](void* data, int idx, const char** out_text) { *out_text = static_cast<const std::vector<std::string>*>(data)->at(idx).c_str(); return true; }, (void*)&ColorPalettes, static_cast<int>(ColorPalettes.size()), 10))
111117
{
112-
Controller->SetStringParameter(Dasher::SP_ALPHABET_ID, Alphabets[item_current]);
118+
Controller->SetStringParameter(Dasher::SP_COLOUR_ID, ColorPalettes[item_current_colorpalette]);
113119
}
114120

115121
ImGui::EndMenu();

src/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ class MainWindow : public Dasher::CommandlineErrorDisplay
3232
std::unique_ptr <Dasher::XmlSettingsStore> Settings;
3333
std::unique_ptr<DasherController> Controller;
3434
std::vector<std::string> Alphabets;
35+
std::vector<std::string> ColorPalettes;
3536
};
3637

0 commit comments

Comments
 (0)