MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomViewPanel.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  AtomViewPanel.h Panel displaying details of selected Atom
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 
27 #ifndef ATOMVIEWPANEL_H
28 #define ATOMVIEWPANEL_H
29 
30 #include "MovablePanel.h"
31 #include "Grid.h"
32 #include "ToolboxPanel.h"
33 
34 namespace MFM
35 {
36  template <class GC>
37  class AtomViewPanel : public MovablePanel
38  {
39  private:
40  typedef typename GC::CORE_CONFIG::ATOM_TYPE T;
41  typedef typename GC::CORE_CONFIG CC;
42 
43  T* m_atom;
44 
45  Grid<GC>* m_grid;
46 
47  ToolboxPanel<CC>* m_toolboxPanel;
48 
49  static const u32 ATOM_DRAW_SIZE = 40;
50 
51  public:
52  AtomViewPanel() :
53  MovablePanel(300, 100),
54  m_atom(NULL),
55  m_grid(NULL),
56  m_toolboxPanel(NULL)
57  {
58  Panel::SetDesiredSize(300, 100);
59  }
60 
61  void SetToolboxPanel(ToolboxPanel<CC>* toolboxPanel)
62  {
63  m_toolboxPanel = toolboxPanel;
64  }
65 
66  virtual void PaintUpdateVisibility(Drawing& d)
67  {
68  bool visible =
69  m_toolboxPanel != NULL &&
70  (Panel::IsVisible() ||
71  (m_toolboxPanel->IsVisible() &&
72  m_toolboxPanel->GetSelectedTool() == TOOL_ATOM_SELECTOR));
73  this->SetVisibility(visible);
74  }
75 
76  void PaintDisplayAtomicControllers(Drawing & d, T& atom,const Element<CC>* elt)
77  {
78  // XXX DESIGN ME
79  // XXX WRITE ME
80  // XXX MAKE ME WORK
81 
82  const AtomicParameters<CC> & parms = elt->GetAtomicParameters();
83 
84  const AtomicParameter<CC> * p;
85  for (p = parms.GetFirstParameter(); p; p = p->GetNextParameter())
86  {
87  switch (p->GetType())
88  {
89  case VD::U32:
90  {
91  u32 val = 0;
92  bool got = p->LoadU32(atom, val);
93  LOG.Debug("u32 %s = %d (%d)", p->GetName(), (s32) val, got);
94  }
95  break;
96  default:
97  LOG.Debug("u32 %s unknown type %d", p->GetName(), p->GetType());
98  }
99 
100  }
101 
102  }
103 
104  virtual void PaintComponent(Drawing& d)
105  {
108  d.FillRect(Rect(SPoint(0, 0), Panel::GetDimensions()));
109 
110  if(!m_atom || !m_grid)
111  {
112  d.SetFont(AssetManager::Get(FONT_ASSET_HELPPANEL_SMALL));
113  d.SetForeground(Drawing::BLACK);
114  const char* message = "No atom selected.";
115  d.BlitText(message, UPoint(32, 32), MakeUnsigned(d.GetTextSize(message)));
116  }
117  else
118  {
119  const Element<CC>* element = m_grid->LookupElement(m_atom->GetType());
120  d.SetForeground(element->DefaultPhysicsColor());
121  d.FillCircle(2, 2, ATOM_DRAW_SIZE, ATOM_DRAW_SIZE, ATOM_DRAW_SIZE >> 1);
122  d.SetFont(FONT_ASSET_ELEMENT);
123  d.SetForeground(Drawing::WHITE);
124  d.SetBackground(Drawing::BLACK);
125 
126  /* As long as the font is monospaced, we can get the text size
127  of any 2-character string for this centering. */
128  const UPoint textSize = MakeUnsigned(d.GetTextSize("12"));
129  d.BlitBackedTextCentered(element->GetAtomicSymbol(), UPoint(8, 8), textSize);
130 
131  d.BlitBackedText(element->GetName(), UPoint(4 + ATOM_DRAW_SIZE, 2),
132  MakeUnsigned(d.GetTextSize(element->GetName())));
133 
134  OString64 desc;
135  element->AppendDescription(m_atom, desc);
136  const char* zstr = desc.GetZString();
137 
138  d.SetFont(FONT_ASSET_HELPPANEL_SMALL);
139  d.BlitBackedText(zstr, UPoint(4 + ATOM_DRAW_SIZE, 28),
140  MakeUnsigned(d.GetTextSize(zstr)));
141 
142  PaintDisplayAtomicControllers(d, *m_atom, element);
143  }
144  }
145 
146  void SetAtom(T* atom)
147  {
148  if(atom && atom->IsSane())
149  {
150  m_atom = atom;
151  }
152  else
153  {
154  m_atom = NULL;
155  }
156  }
157 
158  void SetGrid(Grid<GC>* grid)
159  {
160  m_grid = grid;
161  }
162  };
163 }
164 
165 #endif /* ATOMVIEWPANEL_H */
Definition: Rect.h:40
u32 GetBackground() const
Definition: Panel.h:212
void FillCircle(int x, int y, int w, int h, int radius) const
Definition: Drawing.cpp:135
void BlitBackedTextCentered(const char *message, UPoint loc, UPoint size)
Definition: Drawing.cpp:220
u32 SetForeground(const u32 color)
Definition: Drawing.h:188
virtual u32 DefaultPhysicsColor() const =0
Definition: MovablePanel.h:34
const char * GetName() const
Definition: Element.h:316
const char * GetZString()
Definition: OverflowableCharBufferByteSink.h:143
Definition: Grid.h:47
void BlitBackedText(const char *message, UPoint loc, UPoint size)
Definition: Drawing.cpp:233
SPoint GetTextSize(const char *message)
Definition: Drawing.cpp:201
u32 SetBackground(const u32 color)
Definition: Drawing.h:170
const AtomicParameter< CC > * GetFirstParameter() const
Definition: Parameter.h:1037
u32 GetForeground() const
Definition: Panel.h:248
virtual void PaintUpdateVisibility(Drawing &d)
Definition: AtomViewPanel.h:66
void Debug(const char *format,...)
Definition: Logger.h:301
Definition: Parameter.h:47
bool LoadU32(const T &atom, u32 &store) const
Routines to (attempt to) apply this parameter to any given atom.
Definition: Parameter.h:221
Definition: AtomViewPanel.h:37
Definition: Parameter.h:42
const char * GetAtomicSymbol() const
Definition: Element.h:305
void FillRect(int x, int y, int w, int h) const
Definition: Drawing.cpp:115
virtual void AppendDescription(const T *atom, OString64 &desc) const
Definition: Element.h:331
Definition: ToolboxPanel.h:46
const char * GetName() const
Definition: Parameter.h:352
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: Atom.h:43
Definition: Drawing.h:44
virtual void PaintComponent(Drawing &d)
Definition: AtomViewPanel.h:104