Skip to content

Commit 324cc44

Browse files
committed
Add status bar and connection status image button.
This button uses SVG icons to display the connection status. A new 'Resources' folder has been introduced and copied to the final build location.
1 parent 019a39c commit 324cc44

File tree

7 files changed

+222
-2
lines changed

7 files changed

+222
-2
lines changed

Resources/LinkOff.svg

Lines changed: 1 addition & 0 deletions
Loading

Resources/LinkOn.svg

Lines changed: 1 addition & 0 deletions
Loading

Source/Client/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ set(TARGET CLIENT)
22

33
find_package(OctaneGUI REQUIRED)
44

5-
add_executable(${TARGET} Main.cpp)
5+
set(SOURCE
6+
Controls/ConnectionButton.cpp
7+
Main.cpp
8+
)
9+
10+
add_executable(${TARGET} ${SOURCE})
611

712
set_target_properties(
813
${TARGET}
@@ -21,3 +26,4 @@ target_link_libraries(
2126
)
2227

2328
file(COPY ${OctaneGUI_RESOURCES_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
29+
file(COPY ${PROJECT_SOURCE_DIR}/Resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
3+
MIT License
4+
5+
Copyright (c) 2022-2023 Mitchell Davis <mdavisprog@gmail.com>
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
#include "ConnectionButton.h"
28+
#include "OctaneGUI/OctaneGUI.h"
29+
30+
namespace Snippet
31+
{
32+
namespace Controls
33+
{
34+
35+
ConnectionButton::ConnectionButton(OctaneGUI::Window* Window)
36+
: ImageButton(Window)
37+
{
38+
SetProperty(OctaneGUI::ThemeProperties::Button_Padding, OctaneGUI::Vector2{0.0f, 0.0f});
39+
UpdateColors();
40+
41+
m_LinkOn = Window->App().GetTextureCache().LoadSVG("Resources/LinkOn.svg", 20, 20);
42+
m_LinkOff = Window->App().GetTextureCache().LoadSVG("Resources/LinkOff.svg", 20, 20);
43+
SetTexture(m_LinkOff);
44+
45+
m_Timer = Window->CreateTimer(1000, false, [this]() -> void
46+
{
47+
OnTimer();
48+
});
49+
m_Timer->Start();
50+
}
51+
52+
void ConnectionButton::OnTimer()
53+
{
54+
}
55+
56+
void ConnectionButton::UpdateColors()
57+
{
58+
if (m_ConnectionStatus != Common::ConnectionStatus::Connected)
59+
{
60+
SetProperty(OctaneGUI::ThemeProperties::Button, OctaneGUI::Color{70, 0, 0, 255});
61+
SetProperty(OctaneGUI::ThemeProperties::Button_Hovered, OctaneGUI::Color{115, 0, 0, 255});
62+
SetProperty(OctaneGUI::ThemeProperties::Button_Pressed, OctaneGUI::Color{170, 0, 0, 255});
63+
}
64+
else
65+
{
66+
SetProperty(OctaneGUI::ThemeProperties::Button, OctaneGUI::Color{0, 70, 0, 255});
67+
SetProperty(OctaneGUI::ThemeProperties::Button_Hovered, OctaneGUI::Color{0, 115, 0, 255});
68+
SetProperty(OctaneGUI::ThemeProperties::Button_Pressed, OctaneGUI::Color{0, 170, 0, 255});
69+
}
70+
}
71+
72+
}
73+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
3+
MIT License
4+
5+
Copyright (c) 2022-2023 Mitchell Davis <mdavisprog@gmail.com>
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
#pragma once
28+
29+
#include "../../Common/ConnectionStatus.h"
30+
#include "OctaneGUI/Controls/ImageButton.h"
31+
32+
namespace OctaneGUI
33+
{
34+
class Texture;
35+
class Timer;
36+
}
37+
38+
namespace Snippet
39+
{
40+
namespace Controls
41+
{
42+
43+
class ConnectionButton : public OctaneGUI::ImageButton
44+
{
45+
public:
46+
ConnectionButton(OctaneGUI::Window* Window);
47+
48+
private:
49+
void OnTimer();
50+
void UpdateColors();
51+
52+
std::shared_ptr<OctaneGUI::Texture> m_LinkOn { nullptr };
53+
std::shared_ptr<OctaneGUI::Texture> m_LinkOff { nullptr };
54+
std::shared_ptr<OctaneGUI::Timer> m_Timer { nullptr };
55+
Common::ConnectionStatus m_ConnectionStatus { Common::ConnectionStatus::NotConnected };
56+
};
57+
58+
}
59+
}

Source/Client/Main.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
/**
2+
3+
MIT License
4+
5+
Copyright (c) 2022-2023 Mitchell Davis <mdavisprog@gmail.com>
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
#include "Controls/ConnectionButton.h"
128
#include "Frontend.h"
229
#include "OctaneGUI/OctaneGUI.h"
330

@@ -16,7 +43,15 @@ int main(int argc, char** argv)
1643
]},
1744
"Body": {"Controls": [
1845
{"Type": "MarginContainer", "Expand": "Both", "Margins": [4, 4, 4, 4], "Controls": [
19-
{"Type": "Canvas", "Expand": "Both", "BackgroundColor": [96, 96, 96, 255]}
46+
{"Type": "VerticalContainer", "Expand": "Both", "Controls": [
47+
{"Type": "Canvas", "ID": "Canvas", "Expand": "Both", "BackgroundColor": [96, 96, 96, 255]},
48+
{"Type": "HorizontalContainer", "Expand": "Width", "Controls": [
49+
{"Type": "MarginContainer", "Expand": "Both", "Controls": [
50+
{"Type": "Panel", "Expand": "Both"},
51+
{"Type": "HorizontalContainer", "Expand": "Width", "ID": "StatusBar"}
52+
]}
53+
]}
54+
]}
2055
]}
2156
]}
2257
}
@@ -36,5 +71,8 @@ int main(int argc, char** argv)
3671
Application.Quit();
3772
});
3873

74+
const std::shared_ptr<OctaneGUI::Container> StatusBar = Controls["Main"].To<OctaneGUI::Container>("StatusBar");
75+
const std::shared_ptr<Snippet::Controls::ConnectionButton> ConnectionButton = StatusBar->AddControl<Snippet::Controls::ConnectionButton>();
76+
3977
return Application.Run();
4078
}

Source/Common/ConnectionStatus.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
3+
MIT License
4+
5+
Copyright (c) 2022-2023 Mitchell Davis <mdavisprog@gmail.com>
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
#pragma once
28+
29+
namespace Snippet
30+
{
31+
namespace Common
32+
{
33+
34+
enum ConnectionStatus : unsigned char
35+
{
36+
NotConnected,
37+
Connecting,
38+
Connected,
39+
};
40+
41+
}
42+
}

0 commit comments

Comments
 (0)