MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HelpPanel.h
Go to the documentation of this file.
1  /* -*- mode:C++ -*-
2  HelpPanel.h Panel for displaying controls and other help information
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
28 #ifndef HELPPANEL_H
29 #define HELPPANEL_H
30 
31 #include "AssetManager.h"
32 #include "MovablePanel.h"
33 
34 namespace MFM
35 {
40  class HelpPanel : public MovablePanel
41  {
42  private:
43 
48  static const char* m_helpMessages[];
49 
50  public:
55  {
56  Panel::SetBackground(Drawing::DARK_PURPLE);
57  Panel::SetAnchor(ANCHOR_WEST);
58  Panel::SetAnchor(ANCHOR_SOUTH);
59  }
60 
61  virtual void PaintBorder(Drawing& d)
62  { /* No border */ }
63 
64  virtual void PaintComponent(Drawing& d)
65  {
66  TTF_Font* bigFont = AssetManager::Get(FONT_ASSET_HELPPANEL_BIG);
67  TTF_Font* smFont = AssetManager::Get(FONT_ASSET_HELPPANEL_SMALL);
68 
70  d.FillRect(0, 0, Panel::GetWidth(), Panel::GetHeight());
71 
72  d.SetForeground(Drawing::WHITE);
73  d.SetFont(bigFont);
74 
75  d.BlitText("Help", UPoint(5, 5), MakeUnsigned(Panel::GetTextSize(bigFont, "Help")));
76 
77  d.SetFont(smFont);
78  UPoint maxCorner(0,0);
79 
80  for(u32 i = 0; m_helpMessages[i]; i++)
81  {
82  UPoint tsize = MakeUnsigned(Panel::GetTextSize(smFont, m_helpMessages[i]));
83  UPoint pos = UPoint(10, i * 18 + 35);
84  d.BlitText(m_helpMessages[i], pos, tsize);
85 
86  maxCorner = max(maxCorner, pos + tsize);
87  }
88  maxCorner += UPoint(10,10);
89 
90  if (maxCorner != this->GetDesiredSize())
91  {
92  this->SetDimensions(maxCorner.GetX(), maxCorner.GetY());
93  this->SetDesiredSize(maxCorner.GetX(), maxCorner.GetY());
94  if (Panel::m_parent != 0)
95  {
96  Panel::HandleResize(Panel::m_parent->GetDimensions());
97  }
98  }
99  }
100  };
101 }
102 
103 #endif /* HELPPANEL_H */
u32 GetBackground() const
Definition: Panel.h:212
virtual void PaintComponent(Drawing &d)
Definition: HelpPanel.h:64
u32 SetForeground(const u32 color)
Definition: Drawing.h:188
virtual void HandleResize(const UPoint &parentSize)
Definition: Panel.cpp:265
Definition: MovablePanel.h:34
Definition: HelpPanel.h:40
void SetAnchor(const GUIAnchor anchor)
Definition: Panel.cpp:243
T GetY() const
Definition: Point.tcc:40
HelpPanel()
Definition: HelpPanel.h:54
virtual void PaintBorder(Drawing &d)
Definition: HelpPanel.h:61
void FillRect(int x, int y, int w, int h) const
Definition: Drawing.cpp:115
SPoint GetTextSize(TTF_Font *font, const char *text)
Definition: Panel.cpp:364
TTF_Font * SetFont(TTF_Font *newFont)
Definition: Drawing.h:209
void BlitText(const char *message, UPoint loc, UPoint size) const
Definition: Drawing.cpp:172
Definition: Drawing.h:44
u32 SetBackground(const u32 color)
Definition: Panel.h:220
T GetX() const
Definition: Point.tcc:34