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- }
0 commit comments