Rise
The Vieneo Province
Screen.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Page.h"
4 
5 class Screen
6 {
7  //Logger* logger;
8  //D3D10_VIEWPORT viewport;
9  //DeviceObject* pDevice;
10  //ID3DX10Font* pFont = nullptr;
11  //ID3D10RasterizerState* state = nullptr;
12  int lastPage = -1;
13  HRESULT hr = 0;
14  Bus* bus;
15 
16 public:
17  /*
18  D3DXMATRIX matProjection;
19  D3DXMATRIX matView;
20  bool initialized = false;*/
21  UINT currentPage = 0;
22 
23  // config items
24  std::string name;
25  std::vector<Page> pages;
26 
27  int width = 0;
28  int height = 0;
29  int x = 0;
30  int y = 0;
31  RECT rect = RECT();
32 
33  void Render()
34  {
35  if (currentPage >= pages.size())
36  throw std::exception("Tried to render a current page that is outside of the pages collection!");
37  pages.at(currentPage).Render();
38  }
39 
41  {
42  pages.clear();
43  }
44 
45  bool HandleKeyPress(short key, bool shift)
46  {
47  if (currentPage >= pages.size())
48  throw std::exception("Tried to handle keypress for current page that is outside of the pages collection!");
49  return pages.at(currentPage).HandleKeyPress(key, shift);
50  }
51 
52  void FrameMove(float fElapsed)
53  {
54  if (currentPage >= pages.size())
55  throw std::exception("Tried to frameMove a current page that is outside of the pages collection!");
56  pages.at(currentPage).FrameMove(fElapsed);
57  }
58 
59  bool ChangePage(const std::string& pageName)
60  {
61  for (UINT i = 0; i < pages.size(); i++)
62  {
63  if (pages.at(i).name == pageName)
64  {
65  ChangePage(i);
66  return true;
67  }
68  }
69  return false;
70  }
71 
72  void OnPageChange(bool sendUpdate = true)
73  {
74  pages.at(currentPage).OnPageChanged();
75 
76  if (!sendUpdate)
77  return;
78 
79  Command command;
80  command.name = "UpdateMfdPage";
81  command.ivalues[0] = currentPage;
82  command.ivalues[1] = lastPage;
83  bus->commandStream.emplace_back(command);
84  }
85 
86  void ChangePage(int i)
87  {
88  if (currentPage == i)
89  return; // no change
90 
91  if (i < 0 || i >= static_cast<int>(pages.size()))
92  throw std::exception("Tried to ChangePage using a current page that is outside of the pages collection!");
93 
95  currentPage = i;
96 
97  OnPageChange(false);
98  }
99 
100  void RestorePage()
101  {
102  if (lastPage != -1)
103  {
105  lastPage = -1;
106  if (currentPage < 0 || currentPage >= pages.size())
107  throw std::exception("Tried to RestorePage on a current page that is outside of the pages collection!");
108  OnPageChange();
109  }
110  }
111 
112  Screen(Bus* prmBus)
113  {
114  bus = prmBus;
115  }
116 };
void FrameMove(float fElapsed)
Definition: Screen.h:52
Screen(Bus *prmBus)
Definition: Screen.h:112
HRESULT hr
Definition: Screen.h:13
int ivalues[2]
Definition: Command.h:21
std::vector< Command > commandStream
Definition: Bus.h:342
int y
Definition: Screen.h:30
void RestorePage()
Definition: Screen.h:100
int x
Definition: Screen.h:29
Definition: Screen.h:5
~Screen()
Definition: Screen.h:40
bool HandleKeyPress(short key, bool shift)
Definition: Screen.h:45
Definition: Bus.h:16
std::string name
Definition: Command.h:11
int lastPage
Definition: Screen.h:12
void OnPageChange(bool sendUpdate=true)
Definition: Screen.h:72
std::vector< Page > pages
Definition: Screen.h:25
Bus * bus
Definition: Screen.h:14
UINT currentPage
Definition: Screen.h:21
Definition: Command.h:5
void ChangePage(int i)
Definition: Screen.h:86
std::string name
Definition: Screen.h:24
void Render()
Definition: Screen.h:33
int height
Definition: Screen.h:28
int width
Definition: Screen.h:27
bool ChangePage(const std::string &pageName)
Definition: Screen.h:59
RECT rect
Definition: Screen.h:31