Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GameTimeMenu Struct Reference

#include <GameTimeMenu.hxx>

+ Inheritance diagram for GameTimeMenu:
+ Collaboration diagram for GameTimeMenu:

Public Member Functions

void draw () const override
 
- Public Member Functions inherited from GameMenu
virtual ~GameMenu ()=default
 
virtual bool isMouseHovered () const
 
virtual void closeSubmenus ()
 

Additional Inherited Members

- Public Types inherited from GameMenu
using Ptr = std::shared_ptr< GameMenu >
 

Detailed Description

Definition at line 6 of file GameTimeMenu.hxx.

Member Function Documentation

◆ draw()

void GameTimeMenu::draw ( ) const
overridevirtual

Reimplemented from GameMenu.

Definition at line 15 of file GameTimeMenu.cxx.

16 {
17  ImVec2 screenSize = ui::GetIO().DisplaySize;
18 
19  auto &uiManager = UIManager::instance();
20 
21  const auto &layout = uiManager.getLayouts()["BuildMenuButtons"];
22  const ImVec2 buttonSize(32, 32);
23  const int spacing = 8;
24  ImVec2 windowSize((buttonSize.x + spacing) * 4 + spacing, buttonSize.y + spacing * 2);
25  ImVec2 pos(screenSize.x - windowSize.x, 0);
26  const ImRect bb(ImVec2{0, 0}, ImVec2{0, 0} + windowSize);
27 
28  struct
29  {
30  uint8_t clr, frame, frameShade, bottomFrame, bottomFrameShade;
31  } bg;
32  bg = {128, 150, 200, 106, 84};
33 
34  const ImVec2 timeFramePos = bb.Min + ImVec2(spacing, spacing);
35 
36  ui::PushFont(layout.font);
37  ui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
38  ui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
39  ui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{0, 0});
40 
41  ui::SetNextWindowPos(pos);
42  ui::SetNextWindowSize(windowSize);
43 
44  bool open = true;
45  ui::Begin("##gametimemenu", &open,
46  ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar |
47  ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoDecoration);
48 
49  ImGuiWindow *window = ImGui::GetCurrentWindow();
50 
51  /*window->DrawList->PathLineTo(window->Pos);
52  window->DrawList->PathLineTo(window->Pos + ImVec2(64, 0));
53  window->DrawList->PathLineTo(window->Pos + ImVec2(windowSize.x / 2, windowSize.y - 64));
54  window->DrawList->PathLineTo(window->Pos + ImVec2(windowSize.x / 2, windowSize.y));
55  window->DrawList->PathLineTo(window->Pos + ImVec2(0, windowSize.y));
56  window->DrawList->PathFillConvex(ImColor{ bg.clr, bg.clr, bg.clr });
57 
58  window->DrawList->PathLineTo(window->Pos + ImVec2(windowSize.x / 2, windowSize.y - 64));
59  window->DrawList->PathLineTo(window->Pos + ImVec2(windowSize.x, windowSize.y - 64));
60  window->DrawList->PathLineTo(window->Pos + ImVec2(windowSize.x, windowSize.y));
61  window->DrawList->PathLineTo(window->Pos + ImVec2(windowSize.x / 2, windowSize.y));
62  window->DrawList->PathFillConvex(ImColor{ bg.clr, bg.clr, bg.clr });
63 
64  const ImVec2 &wpos = window->Pos + ImVec2(window->WindowBorderSize, window->WindowBorderSize);
65  const ImVec2 upOffset{0, 2};
66  const ImVec2 sideOffset{2, 0};
67  ImColor bgShade{bg.bottomFrameShade, bg.bottomFrameShade, bg.bottomFrameShade};
68  ImColor bgFrame{bg.bottomFrame, bg.bottomFrame, bg.bottomFrame};
69 
70  ImVec2 last = wpos;
71  auto borderLine = [&] (auto p, auto c) { window->DrawList->AddLine(last, p, c, 2); last = p; };
72  borderLine(wpos + ImVec2(64, 0), bgShade); // 0-> top left to middle
73  borderLine(wpos + ImVec2(windowSize.x * 2 / 4, windowSize.y - 64), bgFrame); // slop top midle to bottom middle
74  borderLine(wpos + ImVec2(windowSize.x, windowSize.y - 64) - sideOffset * 2, bgFrame); // -> line bottom middle to rigth side
75  borderLine(wpos + ImVec2(windowSize.x, windowSize.y) - (sideOffset + upOffset) * 2, bgFrame); // | rigth side to rbottom corner
76  borderLine(wpos + ImVec2(0, windowSize.y) - upOffset * 2, bgShade); // <- bottom line to left side
77  borderLine(wpos, bgShade); // |0 left line to left top corner */
78 
79  ui::SetCursorPos(timeFramePos);
80  const float speedFactor = GameClock::instance().getGameClockSpeed();
81  auto is_interval = [&](float val) { return fabs(speedFactor - val) < 0.1f ? ImGuiButtonFlags_ForcePressed : 0; };
82  if (ui::ButtonCtEx("||", buttonSize, is_interval(0.f)))
83  {
85  }
86 
87  ui::SameLine(0, spacing);
88  if (ui::ButtonCtEx(">", buttonSize, is_interval(1.f)))
89  {
91  }
92 
93  ui::SameLine(0, spacing);
94  if (ui::ButtonCtEx(">>", buttonSize, is_interval(2.f)))
95  {
97  }
98 
99  ui::SameLine(0, spacing);
100  if (ui::ButtonCtEx(">>>", buttonSize, is_interval(8.f)))
101  {
103  }
104  ui::PopFont();
105  ui::PopStyleVar(3);
106 
107  ui::End();
108 }
+ Here is the call graph for this function:

The documentation for this struct was generated from the following files:
Singleton< UIManager >::instance
static UIManager & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
GameClock::getGameClockSpeed
float getGameClockSpeed() const
Definition: GameClock.hxx:83
GameClock::setGameClockSpeed
void setGameClockSpeed(float speedFactor)
Set game clock speed.
Definition: GameClock.cxx:77