OpenClonk
C4ScriptGuiWindow.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2014-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16  /*
17  A flexible ingame menu system that can be used to compose large GUIs out of multiple windows.
18 
19  Every window is basically a rectangle that can contain some make-up-information (symbol/text/...) and coordinates.
20  Those coordinates can either be relative to the window's parent or in total pixels or a mixture of both.
21 
22  The entry point for all of the callbacks for mouse input, drawing, etc. is one normal window which always exists and happens
23  to be the parent of ALL of the script-created menus. Callbacks are usually forwarded to the children.
24 
25  If you want to add new window properties (similar to backgroundColor, onClickAction etc.) you have to make sure that they are
26  serialized correctly and cleaned up if necessary when a menu window is closed or the property is overwritten by a script call!
27 */
28 
29 #include "C4Include.h"
30 #include "gui/C4ScriptGuiWindow.h"
31 
32 #include "control/C4Control.h"
33 #include "game/C4Application.h"
34 #include "game/C4GraphicsSystem.h"
35 #include "game/C4Viewport.h"
36 #include "graphics/C4Draw.h"
38 #include "gui/C4MouseControl.h"
39 #include "lib/StdColors.h"
40 #include "object/C4Def.h"
41 #include "object/C4DefList.h"
42 #include "object/C4Object.h"
43 #include "player/C4Player.h"
44 #include "player/C4PlayerList.h"
45 
46 // Adds some helpful logs for hunting control & menu based desyncs.
47 //#define MenuDebugLogF(...) DebugLogF(__VA_ARGS__)
48 #define MenuDebugLogF(...) ((void)0)
49 
50 // This in in EM! Also, golden ratio
51 const float C4ScriptGuiWindow::standardWidth = 50.0f;
52 const float C4ScriptGuiWindow::standardHeight = 31.0f;
53 
54 float C4ScriptGuiWindow::Em2Pix(float em)
55 {
56  return static_cast<float>(::GraphicsResource.FontRegular.GetFontHeight()) * em;
57 }
58 
59 float C4ScriptGuiWindow::Pix2Em(float pix)
60 {
61  return pix / static_cast<float>(std::max<int32_t>(1, ::GraphicsResource.FontRegular.GetFontHeight()));
62 }
63 
65 {
66  if (text)
67  text->DecRef();
68  if (nextAction)
69  delete nextAction;
70 }
71 
73 {
74  C4ValueArray *array = new C4ValueArray();
75 
76  switch (action)
77  {
79  array->SetSize(4);
80  array->SetItem(0, C4Value(action));
81  array->SetItem(1, C4Value(target));
82  array->SetItem(2, C4Value(text));
83  array->SetItem(3, value);
84  break;
85 
87  array->SetSize(4);
88  array->SetItem(0, C4Value(action));
89  array->SetItem(1, C4Value(text));
90  array->SetItem(2, C4Value(subwindowID));
91  array->SetItem(3, C4Value(target));
92  break;
93 
94  case 0: // can actually happen if the action is invalidated
95  break;
96 
97  default:
98  assert(false && "trying to save C4ScriptGuiWindowAction without valid action");
99  break;
100  }
101 
102  assert (array->GetSize() < 6);
103  array->SetSize(6);
104  array->SetItem(5, C4Value(id));
105 
106  if (!first || !nextAction) return C4Value(array);
107 
108  // this action is the first in a chain of actions
109  // all following actions (and this one) have to be put into another array
110  C4ValueArray *container = new C4ValueArray();
111  int32_t size = 1;
112  container->SetSize(size);
113  container->SetItem(0, C4Value(array));
114 
115  C4ScriptGuiWindowAction *next = nextAction;
116  while (next)
117  {
118  C4Value val = next->ToC4Value(false);
119  ++size;
120  container->SetSize(size);
121  container->SetItem(size - 1, val);
122  next = next->nextAction;
123  }
124  return C4Value(container);
125 }
126 
128 {
129  C4Object *targetObj = target ? target->GetObject() : nullptr;
130 
131  if (targetObj == pObj)
132  {
133  // not only forget object, but completely invalidate action
134  action = 0;
135  target = nullptr;
136  }
137  if (nextAction)
138  nextAction->ClearPointers(pObj);
139 }
140 bool C4ScriptGuiWindowAction::Init(C4ValueArray *array, int32_t index)
141 {
142  if (array->GetSize() == 0) // safety
143  return false;
144 
145  // an array of actions?
146  if (array->GetItem(0).getArray())
147  {
148  // add action to action chain?
149  if (index+1 < array->GetSize())
150  {
151  nextAction = new C4ScriptGuiWindowAction();
152  nextAction->Init(array, index + 1);
153  }
154  // continue with one sub array
155  array = array->GetItem(index).getArray();
156  if (!array) return false;
157  }
158  // retrieve type of action
159  int newAction = array->GetItem(0).getInt();
160  action = 0; // still invalid!
161 
162  // when loading, the array has a size of 6 with the 5th element being the ID
163  if (array->GetSize() == 6)
164  id = array->GetItem(3).getInt();
165 
166  switch (newAction)
167  {
169  if (array->GetSize() < 3) return false;
170  target = array->GetItem(1).getPropList();
171  text = array->GetItem(2).getStr();
172  if (!target || !text) return false;
173  if (array->GetSize() >= 4)
174  value = C4Value(array->GetItem(3));
175  text->IncRef();
176 
177  // important! needed to identify actions later!
178  if (!id)
179  {
180  id = ::Game.ScriptGuiRoot->GenerateActionID();
181  MenuDebugLogF("assigning action ID %d\t\taction:%d, text:%s", id, newAction, text->GetCStr());
182  }
183 
184  break;
185 
187  if (array->GetSize() < 4) return false;
188  text = array->GetItem(1).getStr();
189  if (!text) return false;
190  text->IncRef();
191  subwindowID = array->GetItem(2).getInt();
192  target = array->GetItem(3).getObj(); // getObj on purpose. Need to validate that.
193  break;
194 
195  default:
196  return false;
197  }
198 
199  action = newAction;
200  return true;
201 }
202 
203 void C4ScriptGuiWindowAction::Execute(C4ScriptGuiWindow *parent, int32_t player, int32_t actionType)
204 {
205  assert(parent && "C4ScriptGuiWindow::Execute must always be called with parent");
206  MenuDebugLogF("Excuting action (nextAction: %x, subwID: %d, target: %x, text: %s, type: %d)", nextAction, subwindowID, target, text->GetCStr(), actionType);
207 
208  // invalid ID? can be set by removal of target object
209  if (action)
210  {
211  // get menu main window
212  C4ScriptGuiWindow *main = parent;
213  C4ScriptGuiWindow *from = main;
214  while (!from->IsRoot())
215  {
216  main = from;
217  from = static_cast<C4ScriptGuiWindow*>(from->GetParent());
218  }
219 
220  switch (action)
221  {
223  {
224  if (!target) // ohject removed in the meantime?
225  break;
226  MenuDebugLogF("[ACTION REQUEST] action /call/");
227  // the action needs to be synchronized! Assemble command and put it into control queue!
228  Game.Input.Add(CID_MenuCommand, new C4ControlMenuCommand(id, player, main->GetID(), parent->GetID(), parent->target, actionType));
229  break;
230  }
231 
233  {
234  C4ScriptGuiWindow *window = main;
235  if (subwindowID == 0)
236  window = parent;
237  else if (subwindowID > 0)
238  {
239  C4Object *targetObj = dynamic_cast<C4Object*> (target);
240  window = main->GetSubWindow(subwindowID, targetObj);
241  }
242  if (window)
243  window->SetTag(text);
244  break;
245  }
246 
247  default:
248  assert(false && "C4ScriptGuiWindowAction without valid or invalidated ID");
249  break;
250  }
251  } // action
252 
253  if (nextAction)
254  {
255  nextAction->Execute(parent, player, actionType);
256  }
257 }
258 
259 bool C4ScriptGuiWindowAction::ExecuteCommand(int32_t actionID, C4ScriptGuiWindow *parent, int32_t player)
260 {
261  MenuDebugLogF("checking action %d (==%d?)\t\tmy action: %d", id, actionID, action);
262  // target has already been checked for validity
263  if (id == actionID && action)
264  {
265  assert(action == C4ScriptGuiWindowActionID::Call && "C4ControlMenuCommand for invalid action!");
266 
267  // get menu main window
268  C4ScriptGuiWindow *main = parent;
269  C4ScriptGuiWindow *from = main;
270  while (!from->IsRoot())
271  {
272  main = from;
273  from = static_cast<C4ScriptGuiWindow*>(from->GetParent());
274  }
275  MenuDebugLogF("command synced.. target: %x, targetObj: %x, func: %s", target, target->GetObject(), text->GetCStr());
276  C4AulParSet Pars(value, C4VInt(player), C4VInt(main->GetID()), C4VInt(parent->GetID()), (parent->target && parent->target->Status) ? C4VObj(parent->target) : C4VNull);
277  target->Call(text->GetCStr(), &Pars);
278  return true;
279  }
280  if (nextAction)
281  return nextAction->ExecuteCommand(actionID, parent, player);
282  return false;
283 }
284 
286 {
287  // is cleaned up from destructor of C4ScriptGuiWindow
288 }
289 
290 void C4ScriptGuiWindowProperty::SetInt(int32_t to, C4String *tag)
291 {
292  if (!tag) tag = &Strings.P[P_Std];
293  taggedProperties[tag] = Prop();
294  current = &taggedProperties[tag];
295  current->d = to;
296 }
297 void C4ScriptGuiWindowProperty::SetFloat(float to, C4String *tag)
298 {
299  if (!tag) tag = &Strings.P[P_Std];
300  taggedProperties[tag] = Prop();
301  current = &taggedProperties[tag];
302  current->f = to;
303 }
304 void C4ScriptGuiWindowProperty::SetNull(C4String *tag)
305 {
306  if (!tag) tag = &Strings.P[P_Std];
307  taggedProperties[tag] = Prop();
308  current = &taggedProperties[tag];
309  current->data = nullptr;
310 }
311 
312 void C4ScriptGuiWindowProperty::CleanUp(Prop &prop)
313 {
314  switch (type)
315  {
317  if (prop.deco) delete prop.deco;
318  break;
323  if (prop.action) delete prop.action;
324  break;
328  if (prop.strBuf) delete prop.strBuf;
329  break;
330  default:
331  break;
332  }
333 }
334 
335 void C4ScriptGuiWindowProperty::CleanUpAll()
336 {
337  for (auto & taggedProperty : taggedProperties)
338  {
339  CleanUp(taggedProperty.second);
340  if (taggedProperty.first != &Strings.P[P_Std])
341  taggedProperty.first->DecRef();
342  }
343 }
344 
346 {
347  C4PropList *proplist = nullptr;
348 
349  bool onlyOneTag = taggedProperties.size() == 1;
350  if (!onlyOneTag) // we will need a tagged proplist
351  proplist = C4PropList::New();
352 
353  // go through all of the tagged properties and add a property to the proplist containing both the tag name
354  // and the serialzed C4Value of the properties' value
355  for(auto & taggedProperty : taggedProperties)
356  {
357  C4String *tagString = taggedProperty.first;
358  const Prop &prop = taggedProperty.second;
359 
360  C4Value val;
361 
362  // get value to save
363  switch (type)
364  {
381  assert (false && "Trying to get a single positional value from a GuiWindow for saving. Those should always be saved in pairs of two in a string.");
382  break;
383 
388  val = C4Value(prop.d);
389  break;
390 
392  val = C4Value(prop.obj);
393  break;
394 
396  val = C4Value(prop.def);
397  break;
398 
400  if (prop.deco)
401  val = C4Value(prop.deco->pSourceDef);
402  break;
403 
407  {
408  if (prop.strBuf)
409  {
410  // string existing?
411  C4String *s = Strings.FindString(prop.strBuf->getData());
412  if (!s) s = Strings.RegString(prop.strBuf->getData());
413  val = C4Value(s);
414  }
415  break;
416  }
417 
422  if (prop.action)
423  val = prop.action->ToC4Value();
424  break;
425 
426  default:
427  assert(false && "C4ScriptGuiWindowAction should never have undefined type");
428  break;
429  } // switch
430 
431  if (onlyOneTag) return val;
432  assert(proplist);
433  proplist->SetPropertyByS(tagString, val);
434  }
435 
436  return C4Value(proplist);
437 }
438 
440 {
441  C4PropList *proplist = value.getPropList();
442  bool isTaggedPropList = false;
443  if (proplist)
444  isTaggedPropList = !(proplist->GetDef() || proplist->GetObject());
445 
446  if (isTaggedPropList)
447  {
448  std::unique_ptr<C4ValueArray> properties(proplist->GetProperties());
449  properties->SortStrings();
450  for (int32_t i = 0; i < properties->GetSize(); ++i)
451  {
452  const C4Value &entry = properties->GetItem(i);
453  C4String *key = entry.getStr();
454  assert(key && "Proplist returns non-string as key");
455 
456  C4Value property;
457  proplist->GetPropertyByS(key, &property);
458  Set(property, key);
459  }
460  return;
461  }
462 
463  // special treatment for some that have to be deleted (due to owning string/frame deco/...)
464  if (taggedProperties.count(tag))
465  CleanUp(taggedProperties[tag]);
466  else // new tag, retain the proplist if not standard
467  if (tag != &Strings.P[P_Std])
468  tag->IncRef();
469 
470  taggedProperties[tag] = Prop();
471  // in order to make /current/ sane, always reset it - not relying on implementation details of std::map
472  // if the user wants a special tag selected, he should do that (standard selection will still be "Std")
473  current = &taggedProperties[tag];
474  currentTag = tag;
475 
476 
477  // now that a new property entry has been created and the old has been cleaned up, get the data from the C4Value
478  switch (type)
479  {
496  assert (false && "Trying to set positional properties directly. Those should always come parsed from a string.");
497  break;
498 
502  current->d = value.getInt();
503  break;
504 
506  if (value == C4VNull)
507  current->d = ANY_OWNER;
508  else
509  current->d = value.getInt();
510  break;
511 
513  {
514  C4PropList *symbol = value.getPropList();
515  if (symbol)
516  current->obj = symbol->GetObject();
517  else current->obj = nullptr;
518  break;
519  }
521  {
522  C4PropList *symbol = value.getPropList();
523  if (symbol)
524  current->def = symbol->GetDef();
525  else current->def = nullptr;
526  break;
527  }
529  {
530  C4Def *def = value.getDef();
531 
532  if (def)
533  {
534  current->deco = new C4GUI::FrameDecoration();
535  if (!current->deco->SetByDef(def))
536  {
537  delete current->deco;
538  current->deco = nullptr;
539  }
540  }
541  break;
542  }
546  {
547  C4String *string = value.getStr();
548  StdCopyStrBuf *buf = new StdCopyStrBuf();
549  if (string)
550  buf->Copy(string->GetCStr());
551  else buf->Copy("");
552  current->strBuf = buf;
553  break;
554  }
559  {
560  C4ValueArray *array = value.getArray();
561  if (array)
562  {
563  assert (!current->action && "Prop() contains action prior to assignment");
564  current->action = new C4ScriptGuiWindowAction();
565  current->action->Init(array);
566  }
567  break;
568  }
569 
570  default:
571  assert(false && "C4ScriptGuiWindowAction should never have undefined type");
572  break;
573  } // switch
574 }
575 
577 {
578  // assume that we actually contain an object
579  // go through all the tags and, in case the tag has anything to do with objects, check and clear it
580  for (auto & taggedProperty : taggedProperties)
581  {
582  switch (type)
583  {
585  if (taggedProperty.second.obj == pObj)
586  taggedProperty.second.obj = nullptr;
587  break;
588 
593  if (taggedProperty.second.action)
594  taggedProperty.second.action->ClearPointers(pObj);
595  break;
596  default:
597  return;
598  }
599  }
600 }
601 
603 {
604  if (!taggedProperties.count(tag)) return false; // tag not available
605  if (current == &taggedProperties[tag]) return false; // tag already set?
606  current = &taggedProperties[tag];
607  currentTag = tag;
608  return true;
609 }
610 
611 std::list<C4ScriptGuiWindowAction*> C4ScriptGuiWindowProperty::GetAllActions()
612 {
613  std::list<C4ScriptGuiWindowAction*> allActions;
614  for (auto & taggedProperty : taggedProperties)
615  {
616  Prop &p = taggedProperty.second;
617  if (p.action)
618  allActions.push_back(p.action);
619  }
620  return allActions;
621 }
622 
623 
625 {
626  Init();
627 }
628 
629 void C4ScriptGuiWindow::Init()
630 {
631  id = 0;
632  name = nullptr;
633 
634  isMainWindow = false;
635  mainWindowNeedsLayoutUpdate = false;
636 
637  // properties must know what they stand for
638  for (int32_t i = 0; i < C4ScriptGuiWindowPropertyName::_lastProp; ++i)
639  props[i].type = i;
640 
641  // standard values for all of the properties
642 
643  // exact offsets are standard 0
644  props[C4ScriptGuiWindowPropertyName::left].SetNull();
645  props[C4ScriptGuiWindowPropertyName::right].SetNull();
646  props[C4ScriptGuiWindowPropertyName::top].SetNull();
647  props[C4ScriptGuiWindowPropertyName::bottom].SetNull();
648  // relative offsets are standard full screen 0,0 - 1,1
650  props[C4ScriptGuiWindowPropertyName::relTop].SetNull();
651  props[C4ScriptGuiWindowPropertyName::relBottom].SetFloat(1.0f);
652  props[C4ScriptGuiWindowPropertyName::relRight].SetFloat(1.0f);
653  // all margins are always standard 0
662  // other properties are 0
667  props[C4ScriptGuiWindowPropertyName::text].SetNull();
674  props[C4ScriptGuiWindowPropertyName::style].SetNull();
677 
678  wasRemovedFromParent = false;
679  wasClosed = false;
681  target = nullptr;
682  pScrollBar->fAutoHide = true;
683 
684  rcBounds.x = rcBounds.y = 0;
685  rcBounds.Wdt = rcBounds.Hgt = 0;
686 }
687 
689 {
690  ClearChildren(false);
691 
692  // delete certain properties that contain allocated elements or referenced strings
693  for (auto & prop : props)
694  prop.CleanUpAll();
695 
696  if (pScrollBar)
697  delete pScrollBar;
698  if (name)
699  name->DecRef();
700 }
701 
702 // helper function
703 void C4ScriptGuiWindow::SetMarginProperties(const C4Value &property, C4String *tag)
704 {
705  // the value might be a tagged proplist again
706  if (property.GetType() == C4V_Type::C4V_PropList)
707  {
708  C4PropList *proplist = property.getPropList();
709  for (C4PropList::Iterator iter = proplist->begin(); iter != proplist->end(); ++iter)
710  {
711  SetMarginProperties(iter->Value, iter->Key);
712  }
713  return;
714  }
715 
716  // safety
717  if (property.GetType() == C4V_Type::C4V_Array && property.getArray()->GetSize() == 0)
718  return;
719 
720  // always set all four margins
721  for (int i = 0; i < 4; ++i)
722  {
723  C4ScriptGuiWindowPropertyName::type relative, absolute;
724  switch (i)
725  {
726  case 0:
729  break;
730  case 1:
733  break;
734  case 2:
737  break;
738  case 3:
741  break;
742  default:
743  assert(false);
744  }
745 
746  if (property.GetType() == C4V_Type::C4V_Array)
747  {
748  C4ValueArray *array = property.getArray();
749  int realIndex = i % array->GetSize();
750  SetPositionStringProperties(array->GetItem(realIndex), relative, absolute, tag);
751  }
752  else
753  // normal string, hopefully
754  SetPositionStringProperties(property, relative, absolute, tag);
755  }
756 }
757 
758 C4Value C4ScriptGuiWindow::MarginsToC4Value()
759 {
760  C4ValueArray *array = new C4ValueArray();
761  array->SetSize(4);
762 
767 
768  return C4Value(array);
769 }
770 
771 // helper function
772 void C4ScriptGuiWindow::SetPositionStringProperties(const C4Value &property, C4ScriptGuiWindowPropertyName::type relative, C4ScriptGuiWindowPropertyName::type absolute, C4String *tag)
773 {
774  // the value might be a tagged proplist again
775  if (property.GetType() == C4V_Type::C4V_PropList)
776  {
777  C4PropList *proplist = property.getPropList();
778  for (C4PropList::Iterator iter = proplist->begin(); iter != proplist->end(); ++iter)
779  {
780  SetPositionStringProperties(iter->Value, relative, absolute, iter->Key);
781  }
782  return;
783  }
784  // safety
785  if (property.GetType() != C4V_Type::C4V_String) {
786  if(property.GetType() != C4V_Type::C4V_Nil)
787  LogF("Warning: Got %s instead of expected menu format string.", property.GetTypeName());
788  return;
789  }
790 
791  float relativeValue = 0.0;
792  float absoluteValue = 0.0;
793 
794  std::locale c_locale("C");
795  std::istringstream reader(std::string(property.getStr()->GetCStr()));
796  reader.imbue(c_locale);
797  if(!reader.good()) return;
798 
799  while (!reader.eof())
800  {
801  reader >> std::ws; // eat white space
802 
803  // look for next float
804  float value;
805  // here comes the fun.
806  // strtod is locale dependent
807  // istringstream will try to parse scientific notation, so things like 3em will be tried to be parsed as 3e<exponent> and consequently fail
808  // thus, per stackoverflow recommendation, parse the float into a separate string and then let that be parsed
809  std::stringstream floatss;
810  floatss.imbue(c_locale);
811  if(reader.peek() == '+' || reader.peek() == '-') floatss.put(reader.get());
812  reader >> std::ws;
813  while(std::isdigit(reader.peek()) || reader.peek() == '.') floatss.put(reader.get());
814  floatss >> value;
815  reader >> std::ws;
816 
817  if (reader.peek() == '%')
818  {
819  relativeValue += value;
820  reader.get();
821  }
822  else if (reader.get() == 'e' && reader.get() == 'm')
823  {
824  absoluteValue += value;
825  }
826  else // error, abort! (readere is not in a clean state anyway)
827  {
828  LogF(R"(Warning: Could not parse menu format string "%s"!)", property.getStr()->GetCStr());
829  return;
830  }
831 
832  reader.peek(); // get eof bit to be set
833  }
834  props[relative].SetFloat(relativeValue / 100.0f, tag);
835  props[absolute].SetFloat(absoluteValue, tag);
836 }
837 
838 // for saving
839 C4Value C4ScriptGuiWindow::PositionToC4Value(C4ScriptGuiWindowPropertyName::type relativeName, C4ScriptGuiWindowPropertyName::type absoluteName)
840 {
841  // Go through all tags of the position attributes and save.
842  // Note that the tags for both the relative and the absolute attribute are always the same.
843  C4ScriptGuiWindowProperty &relative = props[relativeName];
844  C4ScriptGuiWindowProperty &absolute = props[absoluteName];
845 
846  C4PropList *proplist = nullptr;
847  const bool onlyStdTag = relative.taggedProperties.size() == 1;
848  for (auto & taggedProperty : relative.taggedProperties)
849  {
850  C4String *tag = taggedProperty.first;
851  StdStrBuf buf;
852  buf.Format("%f%%%+fem", 100.0f * taggedProperty.second.f, absolute.taggedProperties[tag].f);
853  C4String *propString = Strings.RegString(buf);
854 
855  if (onlyStdTag)
856  return C4Value(propString);
857  else
858  {
859  if (proplist == nullptr)
860  proplist = C4PropList::New();
861  proplist->SetPropertyByS(tag, C4Value(propString));
862  }
863  }
864  return C4Value(proplist);
865 }
866 
868 {
869  assert(IsRoot());
870  if (id == 0)
871  {
872  // nothing to do, note that the id is abused for the id in the enumeration
873  return;
874  }
875  C4Value value = numbers->GetValue(id);
876  id = 0;
877  CreateFromPropList(value.getPropList(), false, false, true);
878 
879  for (C4GUI::Element * element : *this)
880  {
881  C4ScriptGuiWindow *mainWindow = static_cast<C4ScriptGuiWindow*>(element);
882  mainWindow->RequestLayoutUpdate();
883  }
884 }
885 
887 {
888  C4PropList *proplist = C4PropList::New();
889 
890  // it is necessary that this list contains all of the properties which can also be set somehow
891  // if you add something, don't forget to also add the real serialization to the loop below
892  int32_t toSave[] =
893  {
894  P_Left,
895  P_Top,
896  P_Right,
897  P_Bottom,
898  P_Margin,
900  P_Decoration,
901  P_Symbol,
902  P_Target,
903  P_Text,
904  P_ID,
905  P_OnClick,
906  P_OnMouseIn,
907  P_OnMouseOut,
908  P_OnClose,
909  P_Style,
910  P_Mode,
911  P_Priority,
912  P_Player,
913  P_Tooltip
914  };
915 
916  for (int prop : toSave)
917  {
918  C4Value val;
919 
920  switch (prop)
921  {
922  case P_Left:
923  case P_Top:
924  case P_Right:
925  case P_Bottom:
926  {
927 #define PROPERTY_TUPLE(p, prop1, prop2) if (prop == p) { val = PositionToC4Value(prop1, prop2); }
932 #undef PROPERTY_TUPLE
933  break;
934  }
935  case P_Margin: val = MarginsToC4Value(); break;
938  case P_Symbol:
939  // either object or def
941  if (val == C4Value()) // is nil?
943  break;
944  case P_Target: val = C4Value(target); break;
945  case P_Text: val = props[C4ScriptGuiWindowPropertyName::text].ToC4Value(); break;
947  case P_Tooltip: val = props[C4ScriptGuiWindowPropertyName::tooltip].ToC4Value(); break;
948  case P_ID: val = C4Value(id); break;
953  case P_Style: val = props[C4ScriptGuiWindowPropertyName::style].ToC4Value(); break;
954  case P_Mode: val = C4Value(int32_t(currentMouseState)); break;
956  case P_Player: val = props[C4ScriptGuiWindowPropertyName::player].ToC4Value(); break;
957 
958  default:
959  assert(false);
960  break;
961  }
962 
963  // don't save "nil" values
964  if (val == C4Value()) continue;
965 
966  proplist->SetProperty(C4PropertyName(prop), val);
967  }
968 
969  // save children now, construct new names for them if necessary
970  int32_t childIndex = 0;
971  for (C4GUI::Element * element : *this)
972  {
973  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
974  C4Value val = child->ToC4Value();
975  C4String *childName = child->name;
976  if (!childName)
977  {
978  StdStrBuf childNameBuf;
979  childNameBuf.Format("_child_%03d", ++childIndex);
980  childName = Strings.RegString(childNameBuf);
981  }
982  proplist->SetPropertyByS(childName, val);
983  }
984 
985  return C4Value(proplist);
986 }
987 
988 bool C4ScriptGuiWindow::CreateFromPropList(C4PropList *proplist, bool resetStdTag, bool isUpdate, bool isLoading)
989 {
990  if (!proplist) return false;
991  C4ScriptGuiWindow * parent = static_cast<C4ScriptGuiWindow*>(GetParent());
992  assert((parent || isLoading) && "GuiWindow created from proplist without parent (fails for ID tag)");
993 
994  bool layoutUpdateRequired = false; // needed for position changes etc
995 
996  // Get properties from proplist and check for those, that match an allowed property to set them;
997  // We take ownership here. Automatically destroy the object when we're done.
998  std::unique_ptr<C4ValueArray> properties(proplist->GetProperties());
999  properties->SortStrings();
1000  C4String *stdTag = &Strings.P[P_Std];
1001  const int32_t propertySize = properties->GetSize();
1002  for (int32_t i = 0; i < propertySize; ++i)
1003  {
1004  const C4Value &entry = properties->GetItem(i);
1005  C4String *key = entry.getStr();
1006  assert(key && "PropList returns non-string as key");
1007  MenuDebugLogF("--%s\t\t(I am %d)", key->GetCStr(), id);
1008  C4Value property;
1009  proplist->GetPropertyByS(key, &property);
1010 
1011  if(&Strings.P[P_Left] == key)
1012  {
1013  SetPositionStringProperties(property, C4ScriptGuiWindowPropertyName::relLeft, C4ScriptGuiWindowPropertyName::left, stdTag);
1014  layoutUpdateRequired = true;
1015  }
1016  else if(&Strings.P[P_Top] == key)
1017  {
1018  SetPositionStringProperties(property, C4ScriptGuiWindowPropertyName::relTop, C4ScriptGuiWindowPropertyName::top, stdTag);
1019  layoutUpdateRequired = true;
1020  }
1021  else if(&Strings.P[P_Right] == key)
1022  {
1023  SetPositionStringProperties(property, C4ScriptGuiWindowPropertyName::relRight, C4ScriptGuiWindowPropertyName::right, stdTag);
1024  layoutUpdateRequired = true;
1025  }
1026  else if(&Strings.P[P_Bottom] == key)
1027  {
1028  SetPositionStringProperties(property, C4ScriptGuiWindowPropertyName::relBottom, C4ScriptGuiWindowPropertyName::bottom, stdTag);
1029  layoutUpdateRequired = true;
1030  }
1031  else if (&Strings.P[P_Margin] == key)
1032  {
1033  SetMarginProperties(property, stdTag);
1034  layoutUpdateRequired = true;
1035  }
1036  else if(&Strings.P[P_BackgroundColor] == key)
1037  props[C4ScriptGuiWindowPropertyName::backgroundColor].Set(property, stdTag);
1038  else if(&Strings.P[P_Target] == key)
1039  target = property.getObj();
1040  else if(&Strings.P[P_Symbol] == key)
1041  {
1042  props[C4ScriptGuiWindowPropertyName::symbolDef].Set(property, stdTag);
1043  props[C4ScriptGuiWindowPropertyName::symbolObject].Set(property, stdTag);
1044  }
1045  else if(&Strings.P[P_Decoration] == key)
1046  {
1047  props[C4ScriptGuiWindowPropertyName::frameDecoration].Set(property, stdTag);
1048  }
1049  else if(&Strings.P[P_Text] == key)
1050  {
1051  props[C4ScriptGuiWindowPropertyName::text].Set(property, stdTag);
1052  layoutUpdateRequired = true;
1053  }
1054  else if (&Strings.P[P_GraphicsName] == key)
1055  {
1056  props[C4ScriptGuiWindowPropertyName::symbolGraphicsName].Set(property, stdTag);
1057  }
1058  else if (&Strings.P[P_Tooltip] == key)
1059  {
1060  props[C4ScriptGuiWindowPropertyName::tooltip].Set(property, stdTag);
1061  }
1062  else if(&Strings.P[P_Prototype] == key)
1063  ; // do nothing
1064  else if (&Strings.P[P_Mode] == key) // note that "Mode" is abused here for saving whether we have mouse focus
1065  {
1066  if (isLoading)
1067  currentMouseState = property.getInt();
1068  }
1069  else if(&Strings.P[P_ID] == key)
1070  {
1071  // setting IDs is only valid for subwindows or when loading savegames!
1072  if (parent && !isMainWindow)
1073  {
1074  if (id) // already have an ID? remove from parent
1075  parent->ChildWithIDRemoved(this);
1076  id = property.getInt();
1077  if (id != 0)
1078  parent->ChildGotID(this);
1079  }
1080  else
1081  if (isLoading)
1082  id = property.getInt();
1083  }
1084  else if (&Strings.P[P_OnClick] == key)
1085  {
1086  MenuDebugLogF("Adding new action, I am window %d with parent %d", id, static_cast<C4ScriptGuiWindow*>(parent)->id);
1087  props[C4ScriptGuiWindowPropertyName::onClickAction].Set(property, stdTag);
1088  }
1089  else if(&Strings.P[P_OnMouseIn] == key)
1090  props[C4ScriptGuiWindowPropertyName::onMouseInAction].Set(property, stdTag);
1091  else if(&Strings.P[P_OnMouseOut] == key)
1092  props[C4ScriptGuiWindowPropertyName::onMouseOutAction].Set(property, stdTag);
1093  else if(&Strings.P[P_OnClose] == key)
1094  props[C4ScriptGuiWindowPropertyName::onCloseAction].Set(property, stdTag);
1095  else if(&Strings.P[P_Style] == key)
1096  {
1097  props[C4ScriptGuiWindowPropertyName::style].Set(property, stdTag);
1098  layoutUpdateRequired = true;
1099  }
1100  else if(&Strings.P[P_Priority] == key)
1101  {
1102  props[C4ScriptGuiWindowPropertyName::priority].Set(property, stdTag);
1103  layoutUpdateRequired = true;
1104  // resort into parent's list
1105  if (parent)
1106  parent->ChildChangedPriority(this);
1107  }
1108  else if(&Strings.P[P_Player] == key)
1109  props[C4ScriptGuiWindowPropertyName::player].Set(property, stdTag);
1110  else
1111  {
1112  // possibly sub-window?
1113  C4PropList *subwindow = property.getPropList();
1114  if (subwindow)
1115  {
1116  // remember the name of the child; but ignore names starting with underscores
1117  C4String *childName = nullptr;
1118  if (key->GetCStr()[0] != '_')
1119  childName = key;
1120 
1121  // Do we already have a child with that name? That implies that we are updating here.
1122  C4ScriptGuiWindow *child = GetChildByName(childName);
1123  bool freshlyAdded = false;
1124 
1125  // first time referencing a child with that name? Create a new one!
1126  if (!child)
1127  {
1128  child = new C4ScriptGuiWindow();
1129  if (childName != nullptr)
1130  {
1131  child->name = childName;
1132  child->name->IncRef();
1133  }
1134  AddChild(child);
1135  freshlyAdded = true;
1136  }
1137 
1138  if (!child->CreateFromPropList(subwindow, isUpdate == true, false, isLoading))
1139  {
1140  // Remove the child again if we just added it. However, ignore when just updating an existing child.
1141  if (freshlyAdded)
1142  RemoveChild(child, false);
1143  }
1144  else
1145  layoutUpdateRequired = true;
1146  }
1147  }
1148  }
1149 
1150  if (!isLoading && layoutUpdateRequired)
1152 
1153  if (resetStdTag || isLoading)
1154  SetTag(stdTag);
1155 
1156  return true;
1157 }
1158 
1160 {
1161  // not removing or clearing anything twice
1162  // if this flag is set, the object will not be used after this frame (callbacks?) anyway
1163  if (wasRemovedFromParent) return;
1164 
1165  // all properties which have anything to do with objects need to be called from here!
1171 
1172  for (auto iter = begin(); iter != end();)
1173  {
1174  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(*iter);
1175  // increment the iterator before (possibly) deleting the child
1176  ++iter;
1177  child->ClearPointers(pObj);
1178  }
1179 
1180  if (target == pObj)
1181  {
1182  MenuDebugLogF("Closing window (%d, %s, @%p, target: %p) due to target removal.", id, name, this, this->target);
1183  Close();
1184  }
1185 }
1186 
1188 {
1189  if (IsRoot())
1190  {
1191  child->SetID(GenerateMenuID());
1192  child->isMainWindow = true;
1193  // update all windows asap
1194  mainWindowNeedsLayoutUpdate = true;
1195  }
1196 
1197  // child's priority is ususally 0 here, so just insert it in front of other windows with a priority below 0
1198  // when the child's priority updates, the update function will be called and the child will be sorted to the correct position
1199  ChildChangedPriority(child);
1200 
1201  return child;
1202 }
1203 
1204 void C4ScriptGuiWindow::ChildChangedPriority(C4ScriptGuiWindow *child)
1205 {
1206  int prio = child->props[C4ScriptGuiWindowPropertyName::priority].GetInt();
1207  C4GUI::Element * insertBefore = nullptr;
1208 
1209  for (C4GUI::Element * element : *this)
1210  {
1211  C4ScriptGuiWindow * otherChild = static_cast<C4ScriptGuiWindow*>(element);
1212  if (otherChild->props[C4ScriptGuiWindowPropertyName::priority].GetInt() <= prio) continue;
1213  insertBefore = element;
1214  break;
1215  }
1216  // if the child is already at the correct position, do nothing
1217  assert(child != insertBefore);
1218  // resort
1219  // this method will take care of removing and re-adding the child
1220  InsertElement(child, insertBefore);
1221 }
1222 
1223 void C4ScriptGuiWindow::ChildWithIDRemoved(C4ScriptGuiWindow *child)
1224 {
1225  if (IsRoot()) return;
1226  if (!isMainWindow)
1227  return static_cast<C4ScriptGuiWindow*>(GetParent())->ChildWithIDRemoved(child);
1228  std::pair<std::multimap<int32_t, C4ScriptGuiWindow*>::iterator, std::multimap<int32_t, C4ScriptGuiWindow*>::iterator> range;
1229  range = childrenIDMap.equal_range(child->GetID());
1230 
1231  for (std::multimap<int32_t, C4ScriptGuiWindow*>::iterator iter = range.first; iter != range.second; ++iter)
1232  {
1233  if (iter->second != child) continue;
1234  childrenIDMap.erase(iter);
1235  MenuDebugLogF("child-map-size: %d, remove %d [I am %d]", childrenIDMap.size(), child->GetID(), id);
1236  return;
1237  }
1238 }
1239 
1240 void C4ScriptGuiWindow::ChildGotID(C4ScriptGuiWindow *child)
1241 {
1242  assert(!IsRoot() && "ChildGotID called on window root, should not propagate over main windows!");
1243  if (!isMainWindow)
1244  return static_cast<C4ScriptGuiWindow*>(GetParent())->ChildGotID(child);
1245  childrenIDMap.insert(std::make_pair(child->GetID(), child));
1246  MenuDebugLogF("child+map+size: %d, added %d [I am %d]", childrenIDMap.size(), child->GetID(), id);
1247 }
1248 
1250 {
1251  for (Element * element : *this)
1252  {
1253  C4ScriptGuiWindow * child = static_cast<C4ScriptGuiWindow*>(element);
1254  if (child->id != childID) continue;
1255  return child;
1256  }
1257  return nullptr;
1258 }
1259 
1261 {
1262  // invalid child names never match
1263  if (childName == nullptr) return nullptr;
1264 
1265  for (Element * element : *this)
1266  {
1267  C4ScriptGuiWindow * child = static_cast<C4ScriptGuiWindow*>(element);
1268  // every C4String is unique, so we can compare pointers here
1269  if (child->name != childName) continue;
1270  return child;
1271  }
1272  return nullptr;
1273 }
1274 
1276 {
1277  std::pair<std::multimap<int32_t, C4ScriptGuiWindow*>::iterator, std::multimap<int32_t, C4ScriptGuiWindow*>::iterator> range;
1278  range = childrenIDMap.equal_range(childID);
1279 
1280  for (std::multimap<int32_t, C4ScriptGuiWindow*>::iterator iter = range.first; iter != range.second; ++iter)
1281  {
1282  C4ScriptGuiWindow *subwindow = iter->second;
1283  if (subwindow->GetTarget() != childTarget) continue;
1284  return subwindow;
1285  }
1286  return nullptr;
1287 }
1288 
1289 void C4ScriptGuiWindow::RemoveChild(C4ScriptGuiWindow *child, bool close, bool all)
1290 {
1291  if (isRemovalLockedForClosingCallback())
1292  {
1293  // We are in potentially dangerous fields here (removing a window while another window is being removed).
1294  // This has a decent chance to lead to accessing dead memory.
1295  // It might still leave the GUI tree in an incorrect state (with dead target objects). But still better than a direct crash.
1296  throw C4AulExecError("Trying to remove script GUI window (or window target) from within window closing callback.");
1297  }
1298 
1299  // do a layout update asap
1300  if (!all && !IsRoot())
1302 
1303  if (child)
1304  {
1305  child->wasRemovedFromParent = true;
1306  if (close) child->Close();
1307  if (child->GetID() != 0)
1308  ChildWithIDRemoved(child);
1309  RemoveElement(static_cast<C4GUI::Element*>(child));
1310  MenuDebugLogF("Deleting child (%d, %s, @%p, target: %p) from parent (%d, %s, @%p, target: %p).",
1311  child->id, child->name, child, child->target,
1312  id, name, this, target);
1313  // RemoveElement does NOT delete the child itself.
1314  delete child;
1315  }
1316  else if (close) // close all children
1317  {
1318  assert(all);
1319  for (Element * element : *this)
1320  {
1321  C4ScriptGuiWindow * child = static_cast<C4ScriptGuiWindow*>(element);
1322  assert(child != nullptr);
1323  MenuDebugLogF("Closing child (%d, %s, @%p, target: %p) due to parent (%d, %s, @%p, target: %p) removal.",
1324  child->id, child->name, child, child->target,
1325  id, name, this, target);
1326  child->wasRemovedFromParent = true;
1327  child->Close();
1328  if (child->GetID() != 0)
1329  ChildWithIDRemoved(child);
1330  }
1331  }
1332 
1333  if (all)
1335 }
1336 
1338 {
1339  RemoveChild(nullptr, close, true);
1340 }
1341 
1343 {
1344  // This can only be called once.
1345  if (wasClosed)
1346  return;
1347  wasClosed = true;
1348  // first, close all children and dispose of them properly
1349  ClearChildren(true);
1350 
1351  // make call to target object if applicable
1353  // only calls are valid actions for OnClose
1354  if (action && action->action == C4ScriptGuiWindowActionID::Call)
1355  {
1356  // close is always syncronized (script call/object removal) and thus the action can be executed immediately
1357  // (otherwise the GUI&action would have been removed anyway..)
1358  lockRemovalForClosingCallback();
1359  action->ExecuteCommand(action->id, this, NO_OWNER);
1360  unlockRemovalForClosingCallback();
1361  }
1362 
1363  target = nullptr;
1364 
1365  if (!wasRemovedFromParent)
1366  {
1367  assert(GetParent() && "Close()ing GUIWindow without parent");
1368  static_cast<C4ScriptGuiWindow*>(GetParent())->RemoveChild(this);
1369  }
1370 }
1371 
1372 void C4ScriptGuiWindow::EnableScrollBar(bool enable, float childrenHeight)
1373 {
1374  const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
1375 
1377  {
1378  float height = float(rcBounds.Hgt)
1379  - Em2Pix(props[C4ScriptGuiWindowPropertyName::topMargin].GetFloat())
1380  - Em2Pix(props[C4ScriptGuiWindowPropertyName::bottomMargin].GetFloat());
1381  float adjustment = childrenHeight - height;
1382  props[C4ScriptGuiWindowPropertyName::bottom].current->f += Pix2Em(adjustment);
1383  assert(!std::isnan(props[C4ScriptGuiWindowPropertyName::bottom].current->f));
1384  // instantly pseudo-update the sizes in case of multiple refreshs before the next draw
1385  rcBounds.Hgt += adjustment;
1386  // parents that are somehow affected by their children will need to refresh their layout
1387  if (adjustment != 0.0)
1389  return;
1390  }
1391 
1393 
1395 }
1396 
1397 
1399 {
1400  const float widthOrHeight = Em2Pix(props[absoluteProperty].GetFloat())
1401  + float(parentWidthOrHeight) * props[relativeProperty].GetFloat();
1402  return widthOrHeight;
1403 }
1404 
1405 
1407 {
1408  const int32_t &width = rcBounds.Wdt;
1409  const int32_t &height = rcBounds.Hgt;
1410 
1411  const int32_t borderX(0), borderY(0);
1412  int32_t currentX = borderX;
1413  int32_t currentY = borderY;
1414  int32_t lowestChildRelY = 0;
1415  int32_t maxChildHeight = 0;
1416 
1417  for (C4GUI::Element * element : *this)
1418  {
1419  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
1420  // calculate the space the child needs, correctly respecting the margins
1421  using namespace C4ScriptGuiWindowPropertyName;
1422  const float childLeftMargin = child->CalculateRelativeSize(width, leftMargin, relLeftMargin);
1423  const float childTopMargin = child->CalculateRelativeSize(height, topMargin, relTopMargin);
1424  const float childRightMargin = child->CalculateRelativeSize(width, rightMargin, relRightMargin);
1425  const float childBottomMargin = child->CalculateRelativeSize(height, bottomMargin, relBottomMargin);
1426 
1427  const float childWdtF = float(child->rcBounds.Wdt) + childLeftMargin + childRightMargin;
1428  const float childHgtF = float(child->rcBounds.Hgt) + childTopMargin + childBottomMargin;
1429 
1430  auto doLineBreak = [&]()
1431  {
1432  currentX = borderX;
1433  currentY += maxChildHeight + borderY;
1434  maxChildHeight = 0;
1435  };
1436 
1437  // do all the rounding after the calculations
1438  const auto childWdt = (int32_t)(childWdtF + 0.5f);
1439  const auto childHgt = (int32_t)(childHgtF + 0.5f);
1440 
1441  // Check if the child even fits in the remainder of the row
1442  const bool fitsInRow = (width - currentX) >= childWdt;
1443  if (!fitsInRow) doLineBreak();
1444 
1445  // remember the highest child to make sure rows don't overlap
1446  if (!maxChildHeight || (childHgt > maxChildHeight))
1447  {
1448  maxChildHeight = childHgt;
1449  lowestChildRelY = currentY + childHgt;
1450  }
1451  child->rcBounds.x = currentX + static_cast<int32_t>(childLeftMargin);
1452  child->rcBounds.y = currentY + static_cast<int32_t>(childTopMargin);
1453 
1454  currentX += childWdt + borderX;
1455  }
1456 
1457  // do we need a scroll bar?
1458  EnableScrollBar(lowestChildRelY > height, lowestChildRelY);
1459 }
1460 
1461 // Similar to the grid layout but tries to fill spaces more thoroughly.
1462 // It's slower and might reorder items.
1464 {
1465  const int32_t &width = rcBounds.Wdt;
1466  const int32_t &height = rcBounds.Hgt;
1467  const int32_t borderX(0), borderY(0);
1468  int32_t lowestChildRelY = 0;
1469 
1470  std::list<C4ScriptGuiWindow*> alreadyPlacedChildren;
1471 
1472  for (C4GUI::Element * element : *this)
1473  {
1474  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
1475  // calculate the space the child needs, correctly respecting the margins
1476  using namespace C4ScriptGuiWindowPropertyName;
1477  const float childLeftMargin = child->CalculateRelativeSize(width, leftMargin, relLeftMargin);
1478  const float childTopMargin = child->CalculateRelativeSize(height, topMargin, relTopMargin);
1479  const float childRightMargin = child->CalculateRelativeSize(width, rightMargin, relRightMargin);
1480  const float childBottomMargin = child->CalculateRelativeSize(height, bottomMargin, relBottomMargin);
1481 
1482  const float childWdtF = float(child->rcBounds.Wdt) + childLeftMargin + childRightMargin;
1483  const float childHgtF = float(child->rcBounds.Hgt) + childTopMargin + childBottomMargin;
1484 
1485  // do all the rounding after the calculations
1486  const auto childWdt = (int32_t)(childWdtF + 0.5f);
1487  const auto childHgt = (int32_t)(childHgtF + 0.5f);
1488 
1489  // Look for a free spot.
1490  int32_t currentX = borderX;
1491  int32_t currentY = borderY;
1492 
1493  bool hadOverlap = false;
1494  int overlapRepeats = 0;
1495  do
1496  {
1497  auto overlapsWithOther = [&currentX, &currentY, &childWdt, &childHgt](C4ScriptGuiWindow *other)
1498  {
1499  if (currentX + childWdt <= other->rcBounds.x) return false;
1500  if (currentY + childHgt <= other->rcBounds.y) return false;
1501  if (currentX >= other->rcBounds.GetRight()) return false;
1502  if (currentY >= other->rcBounds.GetBottom()) return false;
1503  return true;
1504  };
1505 
1506  int32_t currentMinY = 0;
1507  hadOverlap = false;
1508  for (auto &other : alreadyPlacedChildren)
1509  {
1510  // Check if the other element is not yet above the new child.
1511  if ((other->rcBounds.GetBottom() > currentY) && other->rcBounds.Hgt > 0)
1512  {
1513  if (currentMinY == 0 || (other->rcBounds.GetBottom() < currentMinY))
1514  currentMinY = other->rcBounds.GetBottom();
1515  }
1516  // If overlapping, we must advance.
1517  if (overlapsWithOther(other))
1518  {
1519  hadOverlap = true;
1520  currentX = other->rcBounds.GetRight();
1521  // Break line if the element doesn't fit anymore.
1522  if (currentX + childWdt > width)
1523  {
1524  currentX = borderX;
1525  // Start forcing change once we start repeating the check. Otherwise, there might
1526  // be a composition of children that lead to infinite loop. The worst-case number
1527  // of sensible checks might O(N^2) be with a really unfortunate children list.
1528  const int32_t forcedMinimalChange = (overlapRepeats > alreadyPlacedChildren.size()) ? 1 : 0;
1529  currentY = std::max(currentY + forcedMinimalChange, currentMinY);
1530  }
1531  }
1532  }
1533  overlapRepeats += 1;
1534  } while (hadOverlap);
1535 
1536  alreadyPlacedChildren.push_back(child);
1537 
1538  lowestChildRelY = std::max(lowestChildRelY, currentY + childHgt);
1539  child->rcBounds.x = currentX + static_cast<int32_t>(childLeftMargin);
1540  child->rcBounds.y = currentY + static_cast<int32_t>(childTopMargin);
1541  }
1542 
1543  // do we need a scroll bar?
1544  EnableScrollBar(lowestChildRelY > height, lowestChildRelY);
1545 }
1546 
1548 {
1549  const int32_t borderY(0);
1550  int32_t currentY = borderY;
1551 
1552  for (C4GUI::Element * element : *this)
1553  {
1554  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
1555 
1556  // Do the calculations in floats first to not lose accuracy.
1557  // Take the height of the child and then add the margins.
1558  using namespace C4ScriptGuiWindowPropertyName;
1559  const float childTopMargin = child->CalculateRelativeSize(rcBounds.Hgt, topMargin, relTopMargin);
1560  const float childBottomMargin = child->CalculateRelativeSize(rcBounds.Hgt, bottomMargin, relBottomMargin);
1561 
1562  const float childHgtF = float(child->rcBounds.Hgt) + childTopMargin + childBottomMargin;
1563  const int32_t childHgt = (int32_t)(childHgtF + 0.5f);
1564 
1565  child->rcBounds.y = currentY + childTopMargin;
1566  currentY += childHgt + borderY;
1567  }
1568 
1569  // do we need a scroll bar?
1570  EnableScrollBar(currentY > rcBounds.Hgt, currentY);
1571 }
1572 
1573 bool C4ScriptGuiWindow::DrawChildren(C4TargetFacet &cgo, int32_t player, int32_t withMultipleFlag, C4Rect *currentClippingRect)
1574 {
1575  // remember old target rectangle and adjust
1576  float oldTargetX = cgo.TargetX;
1577  float oldTargetY = cgo.TargetY;
1578  C4Rect myClippingRect;
1579  if (IsRoot())
1580  {
1581  cgo.TargetX = 0;
1582  cgo.TargetY = 0;
1584  // default: full screen clipper
1585  myClippingRect = C4Rect(0, 0, cgo.Wdt * cgo.Zoom, cgo.Hgt * cgo.Zoom);
1586  currentClippingRect = &myClippingRect;
1587  }
1588 
1589  // if ANY PARENT has scroll bar, then adjust clipper
1590  int32_t clipX1(0), clipX2(0), clipY1(0), clipY2(0);
1591  bool clipping = GetClippingRect(clipX1, clipY1, clipX2, clipY2);
1592 
1593  const int32_t targetClipX1 = cgo.X + cgo.TargetX + clipX1;
1594  const int32_t targetClipY1 = cgo.Y + cgo.TargetY + clipY1;
1595  const int32_t targetClipX2 = cgo.X + cgo.TargetX + clipX2;
1596  const int32_t targetClipY2 = cgo.Y + cgo.TargetY + clipY2;
1597 
1598  if (clipping)
1599  {
1600  // Take either the parent rectangle or restrict it additionally by the child's geometry.
1601  myClippingRect = C4Rect(
1602  std::max(currentClippingRect->x, targetClipX1),
1603  std::max(currentClippingRect->y, targetClipY1),
1604  std::min(currentClippingRect->Wdt, targetClipX2),
1605  std::min(currentClippingRect->Hgt, targetClipY2));
1606  currentClippingRect = &myClippingRect;
1607  }
1608 
1609  if (withMultipleFlag != 1)
1610  {
1611  cgo.TargetX += rcBounds.x;
1612  cgo.TargetY += rcBounds.y - iScrollY;
1613  }
1614  else
1615  {
1616  assert(IsRoot());
1617  assert(withMultipleFlag == 1);
1618  }
1619 
1620 
1621  // note that withMultipleFlag only plays a roll for the root-menu
1622  bool oneDrawn = false; // was at least one child drawn?
1623  //for (auto iter = rbegin(); iter != rend(); ++iter)
1624  for (auto element : *this)
1625  {
1626  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
1627 
1628  if (withMultipleFlag != -1)
1629  {
1630  const int32_t &style = child->props[C4ScriptGuiWindowPropertyName::style].GetInt();
1631  if ((withMultipleFlag == 0) && (style & C4ScriptGuiWindowStyleFlag::Multiple)) continue;
1632  if ((withMultipleFlag == 1) && !(style & C4ScriptGuiWindowStyleFlag::Multiple)) continue;
1633  }
1634 
1635  pDraw->SetPrimaryClipper(currentClippingRect->x, currentClippingRect->y, currentClippingRect->Wdt, currentClippingRect->Hgt);
1636 
1637  if (child->Draw(cgo, player, currentClippingRect))
1638  oneDrawn = true;
1639  // draw only one window when drawing non-Multiple windows
1640  if (oneDrawn && (withMultipleFlag == 0)) break;
1641  }
1642 
1643  // Scrolling obviously does not affect the scroll bar.
1644  cgo.TargetY += iScrollY;
1645  // The scroll bar does not correct for the cgo offset (i.e. the upper board).
1646  cgo.TargetX += cgo.X;
1647  cgo.TargetY += cgo.Y;
1648 
1649  if (pScrollBar->IsVisible())
1650  pScrollBar->DrawElement(cgo);
1651 
1652  if (IsRoot())
1653  {
1655  }
1656 
1657  // restore target rectangle
1658  cgo.TargetX = oldTargetX;
1659  cgo.TargetY = oldTargetY;
1660  return oneDrawn;
1661 }
1662 
1664 {
1665  // directly requested on the root window?
1666  // That usually comes from another part of the engine (f.e. C4Viewport::RecalculateViewports) or from a multiple-window child
1667  if (!GetParent())
1668  {
1669  mainWindowNeedsLayoutUpdate = true;
1670  return;
1671  }
1672 
1673  // are we a direct child of the root?
1674  if (isMainWindow)
1675  {
1676  const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
1677 
1678  if (!(style & C4ScriptGuiWindowStyleFlag::Multiple)) // are we a simple centered window?
1679  {
1680  mainWindowNeedsLayoutUpdate = true;
1681  return;
1682  }
1683  else // we are one of the multiple windows.. the root better do a full refresh
1684  {}
1685  }
1686  // propagate to parent window
1687  static_cast<C4ScriptGuiWindow*>(GetParent())->RequestLayoutUpdate();
1688 }
1689 
1690 bool C4ScriptGuiWindow::UpdateChildLayout(C4TargetFacet &cgo, float parentWidth, float parentHeight)
1691 {
1692  for (Element * element : *this)
1693  {
1694  C4ScriptGuiWindow *window = static_cast<C4ScriptGuiWindow*>(element);
1695  window->UpdateLayout(cgo, parentWidth, parentHeight);
1696  }
1697  return true;
1698 }
1699 
1701 {
1702  assert(IsRoot()); // we are root
1703 
1704  // assume I am the root and use the a special rectangle in the viewport for drawing
1705  const float fullWidth = cgo.Wdt * cgo.Zoom - cgo.X;
1706  const float fullHeight = cgo.Hgt * cgo.Zoom - cgo.Y;
1707 
1708  // golden ratio defined default size!
1709  const float &targetWidthEm = C4ScriptGuiWindow::standardWidth;
1710  const float &targetHeightEm = C4ScriptGuiWindow::standardHeight;
1711 
1712  // adjust by viewport size
1713  const float minMarginPx = 50.0f;
1714  const float targetWidthPx = std::min(Em2Pix(targetWidthEm), fullWidth - 2.0f * minMarginPx);
1715  const float targetHeightPx = std::min(Em2Pix(targetHeightEm), fullHeight - 2.0f * minMarginPx);
1716 
1717  // calculate margins to center the window
1718  const float marginLeftRight = (fullWidth - targetWidthPx) / 2.0f;
1719  const float marginTopBottom = (fullHeight- targetHeightPx) / 2.0f;
1720 
1721  // we can only position the window by adjusting left/right/top/bottom
1722  const float &left = marginLeftRight;
1723  const float right = -marginLeftRight;
1724  const float &top = marginTopBottom;
1725  const float bottom = -marginTopBottom;
1726 
1727  // actual size, calculated from borders
1728  const float wdt = fullWidth - left + right;
1729  const float hgt = fullHeight - top + bottom;
1730 
1731  const bool needUpdate = mainWindowNeedsLayoutUpdate || (rcBounds.Wdt != int32_t(wdt)) || (rcBounds.Hgt != int32_t(hgt));
1732 
1733  if (needUpdate)
1734  {
1735  mainWindowNeedsLayoutUpdate = false;
1736 
1737  // these are the coordinates for the centered non-multiple windows
1738  rcBounds.x = static_cast<int>(left);
1739  rcBounds.y = static_cast<int>(top);
1740  rcBounds.Wdt = wdt;
1741  rcBounds.Hgt = hgt;
1742 
1743  // first update all multiple windows (that can cover the whole screen)
1744  for (Element * element : *this)
1745  {
1746  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
1747  const int32_t &style = child->props[C4ScriptGuiWindowPropertyName::style].GetInt();
1748  if (!(style & C4ScriptGuiWindowStyleFlag::Multiple)) continue;
1749  child->UpdateLayout(cgo, fullWidth, fullHeight);
1750  }
1751  // then update all "main" windows in the center of the screen
1752  // todo: adjust the size of the main window based on the border-windows drawn before
1753  for (Element * element : *this)
1754  {
1755  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
1756  const int32_t &style = child->props[C4ScriptGuiWindowPropertyName::style].GetInt();
1757  if ((style & C4ScriptGuiWindowStyleFlag::Multiple)) continue;
1758  child->UpdateLayout(cgo, wdt, hgt);
1759  }
1760 
1761  pScrollBar->SetVisibility(false);
1762  }
1763  return true;
1764 }
1765 
1766 bool C4ScriptGuiWindow::UpdateLayout(C4TargetFacet &cgo, float parentWidth, float parentHeight)
1767 {
1768  // fetch style
1769  const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
1770  // fetch current position as shortcut for overview
1771  const float &left = props[C4ScriptGuiWindowPropertyName::left].GetFloat();
1772  const float &right = props[C4ScriptGuiWindowPropertyName::right].GetFloat();
1773  const float &top = props[C4ScriptGuiWindowPropertyName::top].GetFloat();
1774  const float &bottom = props[C4ScriptGuiWindowPropertyName::bottom].GetFloat();
1775 
1778  const float &relTop = props[C4ScriptGuiWindowPropertyName::relTop].GetFloat();
1780 
1781  // same for margins
1786 
1791 
1792  // calculate drawing rectangle
1793  float leftDrawX = relLeft * parentWidth + Em2Pix(left) + (Em2Pix(leftMargin) + relLeftMargin * parentWidth);
1794  float rightDrawX = relRight * parentWidth + Em2Pix(right) - (Em2Pix(rightMargin) + relRightMargin * parentWidth);
1795  float topDrawY = relTop * parentHeight + Em2Pix(top) + (Em2Pix(topMargin) + relTopMargin * parentHeight);
1796  float bottomDrawY = relBottom * parentHeight + Em2Pix(bottom) - (Em2Pix(bottomMargin) + relBottomMargin * parentHeight);
1797  float width = rightDrawX - leftDrawX;
1798  float height = bottomDrawY - topDrawY;
1799 
1800  rcBounds.x = leftDrawX;
1801  rcBounds.y = topDrawY;
1802  rcBounds.Wdt = width;
1803  rcBounds.Hgt = height;
1804 
1805  // If this window contains text, we auto-fit to the text height;
1806  // but we only break text when the window /would/ crop it otherwise.
1808  int minRequiredTextHeight = 0;
1809  if (strBuf && !(style & C4ScriptGuiWindowStyleFlag::NoCrop))
1810  {
1811  StdStrBuf sText;
1812  const int32_t rawTextHeight = ::GraphicsResource.FontRegular.BreakMessage(strBuf->getData(), rcBounds.Wdt, &sText, true);
1813  // enable auto scroll
1814  if (rawTextHeight - 1 > rcBounds.Hgt)
1815  {
1816  // If we need to scroll, we will also have to add a scrollbar that takes up some width.
1817  // Recalculate the actual height, taking into account the scrollbar.
1818  // This is not done in the calculation earlier, because then e.g. a 2x1em field could not contain two letters
1819  // but would immediately add a linebreak.
1820  // In the case that this window auto-resizes (FitChildren), the small additional margin to the bottom should not matter much.
1821  const int32_t actualTextHeight = ::GraphicsResource.FontRegular.BreakMessage(strBuf->getData(), rcBounds.Wdt - pScrollBar->rcBounds.Wdt, &sText, true);
1822  minRequiredTextHeight = actualTextHeight;
1823  }
1824  else
1825  {
1826  // Otherwise, still set the minimum size to the text height (without scrollbar).
1827  // This is necessary so that e.g. Style::FitChildren works properly with pure text windows.
1828  minRequiredTextHeight = rawTextHeight;
1829  }
1830  }
1831 
1832  UpdateChildLayout(cgo, width, height);
1833 
1834  // update scroll bar
1835  // C4GUI::ScrollWindow::UpdateOwnPos();
1836 
1837  // special layout selected?
1839  UpdateLayoutGrid();
1844 
1845  // check if we need a scroll-bar
1846  int32_t topMostChild = 0;
1847  int32_t bottomMostChild = minRequiredTextHeight;
1848  for (Element * element : *this)
1849  {
1850  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
1851  const int32_t &childTop = child->rcBounds.y;
1852  const int32_t childBottom = childTop + child->rcBounds.Hgt;
1853  if (childTop < topMostChild) topMostChild = childTop;
1854  if (childBottom > bottomMostChild) bottomMostChild = childBottom;
1855  }
1856  // do we need to adjust our size to fit the child windows?
1858  {
1859  rcBounds.Hgt = bottomMostChild;
1860  }
1861  // update scroll rectangle:
1862  // (subtract one against rounding errors)
1863  bottomMostChild = std::max(bottomMostChild, rcBounds.Hgt);
1864  iClientHeight = bottomMostChild - topMostChild - 1;
1866 
1869  pScrollBar->rcBounds.y = 0;
1871  pScrollBar->Update();
1872 
1873  // never show scrollbar on non-cropping windows
1875  pScrollBar->SetVisibility(false);
1876  // The "dirty" flag is unset here. Note that it's only used for non "multiple"-style windows after startup.
1877  // The "multiple"-style windows are updated together when the root window does a full refresh.
1878  mainWindowNeedsLayoutUpdate = false;
1879  return true;
1880 }
1881 
1883 {
1884  assert(IsRoot()); // we are root
1885  if (!IsVisible()) return false;
1886  // if the viewport shows an upper-board, apply an offset to everything
1887  const int oldTargetX = cgo.TargetX;
1888  const int oldTargetY = cgo.TargetY;
1889  cgo.TargetX += cgo.X;
1890  cgo.TargetY += cgo.Y;
1891  // this will check whether the viewport resized and we need an update
1892  UpdateLayout(cgo);
1893  // step one: draw all multiple-tagged windows
1894  DrawChildren(cgo, player, 1);
1895  // TODO: adjust rectangle for main menu if multiple windows exist
1896  // step two: draw one "main" menu
1897  DrawChildren(cgo, player, 0);
1898  // ..and restore the offset
1899  cgo.TargetX = oldTargetX;
1900  cgo.TargetY = oldTargetY;
1901  return true;
1902 }
1903 
1904 bool C4ScriptGuiWindow::Draw(C4TargetFacet &cgo, int32_t player, C4Rect *currentClippingRect)
1905 {
1906  assert(!IsRoot()); // not root, root needs to receive DrawAll
1907 
1908  // message hidden?
1909  if (!IsVisibleTo(player)) return false;
1910 
1911  const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
1912 
1913  if (mainWindowNeedsLayoutUpdate)
1914  {
1915  assert(GetParent() && (static_cast<C4ScriptGuiWindow*>(GetParent())->IsRoot()));
1916  assert(isMainWindow);
1917  assert(!(style & C4ScriptGuiWindowStyleFlag::Multiple) && "\"Multiple\"-style window not updated by a full refresh of the root window.");
1918  C4ScriptGuiWindow * parent = static_cast<C4ScriptGuiWindow*>(GetParent());
1919  UpdateLayout(cgo, parent->rcBounds.Wdt, parent->rcBounds.Hgt);
1920  assert(!mainWindowNeedsLayoutUpdate);
1921  }
1922 
1923  const int32_t outDrawX = cgo.X + cgo.TargetX + rcBounds.x;
1924  const int32_t outDrawY = cgo.Y + cgo.TargetY + rcBounds.y;
1925  const int32_t outDrawWdt = rcBounds.Wdt;
1926  const int32_t outDrawHgt = rcBounds.Hgt;
1927  const int32_t outDrawRight = outDrawX + rcBounds.Wdt;
1928  const int32_t outDrawBottom = outDrawY + rcBounds.Hgt;
1929  // draw various properties
1930  C4Facet cgoOut(cgo.Surface, outDrawX, outDrawY, outDrawWdt, outDrawHgt);
1931 
1933  if (backgroundColor)
1934  pDraw->DrawBoxDw(cgo.Surface, outDrawX, outDrawY, outDrawRight - 1.0f, outDrawBottom - 1.0f, backgroundColor);
1935 
1937 
1938  if (frameDecoration)
1939  {
1940  // the frame decoration will adjust for cgo.TargetX/Y itself
1941  C4Rect rect(
1942  outDrawX - frameDecoration->iBorderLeft - cgo.TargetX,
1943  outDrawY - frameDecoration->iBorderTop - cgo.TargetY,
1944  outDrawWdt + frameDecoration->iBorderRight + frameDecoration->iBorderLeft,
1945  outDrawHgt + frameDecoration->iBorderBottom + frameDecoration->iBorderTop);
1946  frameDecoration->Draw(cgo, rect);
1947  }
1948 
1950  if (symbolObject)
1951  {
1952  symbolObject->DrawPicture(cgoOut, false, nullptr);
1953  }
1954  else
1955  {
1958  if (symbolDef)
1959  {
1960  symbolDef->Draw(cgoOut, false, 0UL, nullptr, 0, 0, nullptr, graphicsName ? graphicsName->getData() : nullptr);
1961  }
1962  }
1963 
1965 
1966  if (strBuf)
1967  {
1968  StdStrBuf sText;
1969  int alignment = ALeft;
1970  // If we are showing a scrollbar, we need to leave a bit of space for it so that it doesn't overlap the text.
1971  const int scrollbarXOffset = pScrollBar->IsVisible() ? pScrollBar->rcBounds.Wdt : 0;
1972  const int scrollbarScroll = pScrollBar->IsVisible() ? this->GetScrollY() : 0;
1973  const int actualDrawingWidth = outDrawWdt - scrollbarXOffset;
1974 
1975  // If we are set to NoCrop, the message will be split by string-defined line breaks only.
1976  int allowedTextWidth = actualDrawingWidth;
1977 
1979  allowedTextWidth = std::numeric_limits<int>::max();
1980  int32_t textHgt = ::GraphicsResource.FontRegular.BreakMessage(strBuf->getData(), allowedTextWidth, &sText, true);
1981  float textYOffset = static_cast<float>(-scrollbarScroll), textXOffset = 0.0f;
1983  textYOffset = float(outDrawHgt) / 2.0f - float(textHgt) / 2.0f;
1985  textYOffset = float(outDrawHgt) - float(textHgt);
1987  {
1988  int wdt, hgt;
1989  ::GraphicsResource.FontRegular.GetTextExtent(sText.getData(), wdt, hgt, true);
1990  textXOffset = float(actualDrawingWidth) / 2.0f;
1991  alignment = ACenter;
1992  }
1994  {
1995  alignment = ARight;
1996  int wdt, hgt;
1997  ::GraphicsResource.FontRegular.GetTextExtent(sText.getData(), wdt, hgt, true);
1998  textXOffset = float(actualDrawingWidth);
1999  }
2000  pDraw->TextOut(sText.getData(), ::GraphicsResource.FontRegular, 1.0, cgo.Surface, outDrawX + textXOffset, outDrawY + textYOffset, 0xffffffff, alignment);
2001  }
2002 
2003 
2004  if (GraphicsSystem.ShowMenuInfo) // print helpful debug info
2005  {
2006  DWORD frameColor = C4RGB(100, 150, 100);
2007  if (currentMouseState & MouseState::Focus) frameColor = C4RGB(0, 255, 0);
2008 
2009  pDraw->DrawFrameDw(cgo.Surface, outDrawX, outDrawY, outDrawRight, outDrawBottom, frameColor);
2010  if (target || id)
2011  {
2012  StdStrBuf buf = FormatString("%s(%d)", target ? target->GetName() : "", id);
2013  pDraw->TextOut(buf.getData(), ::GraphicsResource.FontCaption, 1.0, cgo.Surface, cgo.X + outDrawRight, cgo.Y + outDrawBottom - ::GraphicsResource.FontCaption.GetLineHeight(), 0xffff00ff, ARight);
2014  }
2015  //StdStrBuf buf2 = FormatString("(%d, %d, %d, %d)", rcBounds.x, rcBounds.y, rcBounds.Wdt, rcBounds.Hgt);
2016  //pDraw->TextOut(buf2.getData(), ::GraphicsResource.FontCaption, 1.0, cgo.Surface, cgo.X + outDrawX + rcBounds.Wdt / 2, cgo.Y + outDrawY + +rcBounds.Hgt / 2, 0xff00ffff, ACenter);
2017  }
2018 
2019  DrawChildren(cgo, player, -1, currentClippingRect);
2020  return true;
2021 }
2022 
2023 bool C4ScriptGuiWindow::GetClippingRect(int32_t &left, int32_t &top, int32_t &right, int32_t &bottom)
2024 {
2025  const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
2026  if (IsRoot() || (style & C4ScriptGuiWindowStyleFlag::NoCrop))
2027  return false;
2028 
2029  // Other windows always clip their children.
2030  // This implicitly clips childrens' text to the parent size, too.
2031  left = rcBounds.x;
2032  top = rcBounds.y;
2033  right = rcBounds.Wdt + left;
2034  bottom = rcBounds.Hgt + top;
2035  return true;
2036 }
2037 
2039 {
2040  // set tag on all properties
2041  for (uint32_t i = 0; i < C4ScriptGuiWindowPropertyName::_lastProp; ++i)
2042  if (props[i].SwitchTag(tag))
2043  {
2044  // only if tag could have changed position etc.
2047  }
2048 
2049  // .. and children
2050  for (C4GUI::Element * element : *this)
2051  (static_cast<C4ScriptGuiWindow*>(element))->SetTag(tag);
2052 }
2053 
2055 {
2056  assert(::MouseControl.GetPlayer() != NO_OWNER);
2057 }
2058 
2059 void C4ScriptGuiWindow::OnMouseIn(int32_t player, int32_t parentOffsetX, int32_t parentOffsetY)
2060 {
2061  assert(!HasMouseFocus() && "custom menu window properly loaded incorrectly!");
2062  currentMouseState = MouseState::Focus;
2063 
2064  // no need to notify children, this is done in MouseInput
2065 
2066  // update tooltip info if applicable
2068  if (strBuf)
2069  {
2070  C4Viewport * viewport = ::Viewports.GetViewport(player);
2071  if (viewport)
2072  {
2073  const float guiZoom = viewport->GetGUIZoom();
2074  const int32_t x = int32_t((parentOffsetX + rcBounds.x) / guiZoom);
2075  const int32_t y = int32_t((parentOffsetY + rcBounds.y) / guiZoom);
2076  const int32_t wdt = int32_t(rcBounds.Wdt / guiZoom);
2077  const int32_t hgt = int32_t(rcBounds.Hgt / guiZoom);
2078  ::MouseControl.SetTooltipRectangle(C4Rect(x, y, wdt, hgt));
2079  ::MouseControl.SetTooltipText(*strBuf);
2080  }
2081  }
2082  // execute action
2084  C4ScriptGuiWindowAction *action = props[actionType].GetAction();
2085  if (!action) return;
2086  action->Execute(this, player, actionType);
2087 }
2088 
2090 {
2091  assert(::MouseControl.GetPlayer() != NO_OWNER);
2092 
2093 }
2095 {
2096  assert(HasMouseFocus() && "custom menu window probably loaded incorrectly!");
2098 
2099  // needs to notify children
2100  for (C4GUI::Element *iter : *this)
2101  {
2102  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(iter);
2103  if (child->HasMouseFocus())
2104  child->OnMouseOut(player);
2105  }
2106 
2107  // execute action
2109  C4ScriptGuiWindowAction *action = props[actionType].GetAction();
2110  if (!action) return;
2111  action->Execute(this, player, actionType);
2112 }
2113 
2114 bool C4ScriptGuiWindow::MouseInput(int32_t button, int32_t mouseX, int32_t mouseY, DWORD dwKeyParam)
2115 {
2116  // only called on root
2117  assert(IsRoot());
2118  // This is only called during a mouse move event, where the MouseControl's player is available.
2119  const int32_t &player = ::MouseControl.GetPlayer();
2120  assert(player != NO_OWNER);
2121  // Only allow one window to catch the mouse input.
2122  // Do not simply return, however, since other windows might need OnMouseOut().
2123  bool oneActionAlreadyExecuted = false;
2124  // non-multiple-windows have a higher priority
2125  // this is important since they are also drawn on top
2126  for (int withMultipleFlag = 0; withMultipleFlag <= 1; ++withMultipleFlag)
2127  {
2128  for (auto iter = rbegin(); iter != rend(); ++iter)
2129  {
2130  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(*iter);
2131 
2132  const int32_t &style = child->props[C4ScriptGuiWindowPropertyName::style].GetInt();
2133  if ((withMultipleFlag == 0) && (style & C4ScriptGuiWindowStyleFlag::Multiple)) continue;
2134  if ((withMultipleFlag == 1) && !(style & C4ScriptGuiWindowStyleFlag::Multiple)) continue;
2135 
2136  // Do the visibility check first. The child itself won't do it, because we are handling mouse in/out here, too.
2137  if (!child->IsVisibleTo(player)) continue;
2138 
2139  // we are root, we have to adjust the position for the "main" windows that are centered
2140  int32_t adjustedMouseX = 0, adjustedMouseY = mouseY;
2141  int32_t offsetX = 0, offsetY = 0;
2142  if (withMultipleFlag == 0)
2143  {
2144  offsetX = -rcBounds.x;
2145  offsetY = -rcBounds.y;
2146  }
2147 
2148  adjustedMouseX = mouseX + offsetX;
2149  adjustedMouseY = mouseY + offsetY;
2150 
2151  int32_t childLeft = child->rcBounds.x;
2152  int32_t childRight = child->rcBounds.x + child->rcBounds.Wdt;
2153  int32_t childTop = child->rcBounds.y;
2154  int32_t childBottom = child->rcBounds.y + child->rcBounds.Hgt;
2155 
2156  bool inArea = true;
2157  if ((adjustedMouseX < childLeft) || (adjustedMouseX > childRight)) inArea = false;
2158  else if ((adjustedMouseY < childTop) || (adjustedMouseY > childBottom)) inArea = false;
2159 
2160  if (!inArea) // notify child if it had mouse focus before
2161  {
2162  if (child->HasMouseFocus())
2163  child->OnMouseOut(player);
2164  continue;
2165  }
2166  // Don't break since some more OnMouseOut might be necessary
2167  if (oneActionAlreadyExecuted) continue;
2168 
2169 
2170  // keep the mouse coordinates relative to the child's bounds
2171  if (child->ProcessMouseInput(button, adjustedMouseX - childLeft, adjustedMouseY - childTop - iScrollY, dwKeyParam, childLeft - offsetX, childTop + iScrollY - offsetY))
2172  {
2173  oneActionAlreadyExecuted = true;
2174  }
2175  }
2176  }
2177 
2178  return oneActionAlreadyExecuted;
2179 }
2180 
2181 bool C4ScriptGuiWindow::ProcessMouseInput(int32_t button, int32_t mouseX, int32_t mouseY, DWORD dwKeyParam, int32_t parentOffsetX, int32_t parentOffsetY)
2182 {
2183  const int32_t &player = ::MouseControl.GetPlayer();
2184  assert(player != NO_OWNER);
2185 
2186  // completely ignore mouse if the appropriate flag is set
2187  const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
2189  return false;
2190 
2191  // we have mouse focus! Is this new?
2192  if (!HasMouseFocus())
2193  OnMouseIn(player, parentOffsetX, parentOffsetY);
2194 
2195  // Make sure the UI does not catch release events without matching key-down events.
2196  // Otherwise, you could e.g. open a menu on left-down and then the menu would block the left-up event, leading to issues.
2197  if (button == C4MC_Button_LeftUp)
2198  {
2199  // Do not catch up-events without prior down-events!
2200  if (!(currentMouseState & MouseState::MouseDown)) return false;
2201  }
2202 
2203  // do not simply break the loop since some OnMouseOut might go missing
2204  bool oneActionAlreadyExecuted = false;
2205 
2206  const int32_t scrollAdjustedMouseY = mouseY + iScrollY;
2207 
2208  // children actually have a higher priority
2209  bool overChild = false; // remember for later, catch all actions that are in theory over children, even if not reaction (if main window)
2210  // use reverse iterator since children with higher Priority appear later in the list
2211  for (auto iter = rbegin(); iter != rend(); ++iter)
2212  {
2213  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(*iter);
2214 
2215  // Do the visibility check first. The child itself won't do it, because we are handling mouse in/out here, too.
2216  if (!child->IsVisibleTo(player)) continue;
2217 
2218  const int32_t childLeft = child->rcBounds.x;
2219  const int32_t childRight = child->rcBounds.x + child->rcBounds.Wdt;
2220  const int32_t childTop = child->rcBounds.y;
2221  const int32_t childBottom = child->rcBounds.y + child->rcBounds.Hgt;
2222 
2223  bool inArea = true;
2224  if ((mouseX <= childLeft) || (mouseX > childRight)) inArea = false;
2225  else if ((scrollAdjustedMouseY <= childTop) || (scrollAdjustedMouseY > childBottom)) inArea = false;
2226 
2227  if (!inArea) // notify child if it had mouse focus before
2228  {
2229  if (child->HasMouseFocus())
2230  child->OnMouseOut(player);
2231  continue;
2232  }
2233 
2234  if (oneActionAlreadyExecuted) continue;
2235 
2236  overChild = true;
2237  // keep coordinates relative to children
2238  if (child->ProcessMouseInput(button, mouseX - childLeft, scrollAdjustedMouseY - childTop, dwKeyParam, parentOffsetX + rcBounds.x, parentOffsetY + rcBounds.y - iScrollY))
2239  {
2240  oneActionAlreadyExecuted = true;
2241  }
2242  }
2243 
2244  if (oneActionAlreadyExecuted) return true;
2245 
2246  //C4GUI::Element::MouseInput(rMouse, button, mouseX, mouseY, dwKeyParam);
2247 
2248  // remember button-down events. The action will only be executed on button-up
2249  // The sequence for double-clicks is LeftDown-LeftUp-LeftDouble-LeftUp, so treat double as down
2250  if (button == C4MC_Button_LeftDown || button == C4MC_Button_LeftDouble)
2251  currentMouseState |= MouseState::MouseDown;
2252  // trigger!
2253  if (button == C4MC_Button_LeftUp)
2254  {
2257  if (action)
2258  {
2260  return true;
2261  }
2262  }
2263 
2264  // for scroll-enabled windows, scroll contents with wheel
2265  if (pScrollBar->IsVisible() && (button == C4MC_Button_Wheel))
2266  {
2267  short delta = (short)(dwKeyParam >> 16);
2268  ScrollBy(-delta);
2269  //float fac = (lastDrawPosition.bottomMostChild - lastDrawPosition.topMostChild);
2270  //if (fac == 0.0f) fac = 1.0f;
2271  //scrollBar->ScrollBy(-float(delta) / fac);
2272  return true;
2273  }
2274 
2275  // forward to scroll-bar if in area
2276  if (pScrollBar->IsVisible())
2277  {
2278  if ((mouseX > pScrollBar->rcBounds.x && mouseX < pScrollBar->rcBounds.x + pScrollBar->rcBounds.Wdt)
2279  && (mouseY > pScrollBar->rcBounds.y && mouseY < pScrollBar->rcBounds.y + pScrollBar->rcBounds.Hgt))
2280  {
2281  C4GUI::CMouse mouse(mouseX, mouseY);
2282  if (::MouseControl.IsLeftDown()) mouse.LDown = true;
2283  pScrollBar->MouseInput(mouse, button, mouseX - pScrollBar->rcBounds.x, mouseY - pScrollBar->rcBounds.y, dwKeyParam);
2284  }
2285  }
2286 
2287 
2288  // if the user still clicked on a menu - even if it didn't do anything, catch it
2289  // but do that only on the top-level to not stop traversing other branches
2290  if (isMainWindow)
2291  return overChild;
2292  return false;
2293 }
2294 
2295 bool C4ScriptGuiWindow::ExecuteCommand(int32_t actionID, int32_t player, int32_t subwindowID, int32_t actionType, C4Object *target)
2296 {
2297  if (isMainWindow && subwindowID) // we are a main window! try a shortcut through the ID?
2298  {
2299  MenuDebugLogF("passing command... instance:%d, plr:%d, subwin:%d, type:%d [I am %d, MW]", actionID, player, subwindowID, actionType, id);
2300  MenuDebugLogF("stats:");
2301  MenuDebugLogF("active menus:\t%d", GetElementCount());
2302  MenuDebugLogF("children ID map:\t%d", childrenIDMap.size());
2303  // the reasoning for that shortcut is that I assume that usually windows with actions will also have an ID assigned
2304  // this obviously doesn't have to be the case, but I believe it's worth the try
2305  std::pair<std::multimap<int32_t, C4ScriptGuiWindow*>::iterator, std::multimap<int32_t, C4ScriptGuiWindow*>::iterator> range;
2306  range = childrenIDMap.equal_range(subwindowID);
2307 
2308  for (std::multimap<int32_t, C4ScriptGuiWindow*>::iterator iter = range.first; iter != range.second; ++iter)
2309  {
2310  if (iter->second->ExecuteCommand(actionID, player, subwindowID, actionType, target))
2311  {
2312  MenuDebugLogF("shortcutting command sucessful!");
2313  return true;
2314  }
2315  }
2316  // it is not possible that another window would match the criteria. Abort later after self-check
2317  MenuDebugLogF("shortcutting command failed.. no appropriate window");
2318  }
2319 
2320  // are we elligible?
2321  if ((id == subwindowID) && (this->target == target))
2322  {
2323  MenuDebugLogF("stats: (I am %d)", id);
2324  MenuDebugLogF("children:\t%d", GetElementCount());
2325  MenuDebugLogF("all actions:\t%d", props[actionType].GetAllActions().size());
2326  std::list<C4ScriptGuiWindowAction*> allActions = props[actionType].GetAllActions();
2327  for (auto action : allActions)
2328  {
2329  assert(action && "C4ScriptGuiWindowProperty::GetAllActions returned list with null-pointer");
2330 
2331  if (action->ExecuteCommand(actionID, this, player))
2332  {
2333  MenuDebugLogF("executing command sucessful!");
2334  return true;
2335  }
2336  }
2337 
2338  // note that we should not simply return false here
2339  // there is no guarantee that only one window with that target&ID exists
2340  }
2341 
2342  // not caught, forward to children!
2343  // abort if main window, though. See above
2344  if (isMainWindow && subwindowID)
2345  {
2346  MenuDebugLogF("executing command failed!");
2347  return false;
2348  }
2349 
2350  // otherwise, just pass to children..
2351  for (C4GUI::Element *element : *this)
2352  {
2353  C4ScriptGuiWindow *child = static_cast<C4ScriptGuiWindow*>(element);
2354  if (child->ExecuteCommand(actionID, player, subwindowID, actionType, target))
2355  {
2356  MenuDebugLogF("passing command sucessful! (I am %d - &p)", id, this->target);
2357  return true;
2358  }
2359  }
2360  return false;
2361 }
2362 
2363 bool C4ScriptGuiWindow::IsRoot()
2364 {
2365  return this == Game.ScriptGuiRoot.get();
2366 }
2367 
2369 {
2370  // Not visible at all?
2371  if (!IsVisible()) return false;
2372  // We have a player assigned and it's a different one?
2373  const int32_t &myPlayer = props[C4ScriptGuiWindowPropertyName::player].GetInt();
2374  if (myPlayer != ANY_OWNER && player != myPlayer) return false;
2375  // We have a target object which is invisible to the player?
2376  if (target && !target->IsVisible(player, false)) return false;
2377  // Default to visible!
2378  return true;
2379 }
2380 
2381 void C4ScriptGuiWindow::lockRemovalForClosingCallback()
2382 {
2383  lockRemovalForClosingCallbackCounter += 1;
2384  if (!isMainWindow)
2385  static_cast<C4ScriptGuiWindow*>(GetParent())->lockRemovalForClosingCallback();
2386 }
2387 
2388 void C4ScriptGuiWindow::unlockRemovalForClosingCallback()
2389 {
2390  assert(lockRemovalForClosingCallbackCounter > 0);
2391  lockRemovalForClosingCallbackCounter -= 1;
2392  if (!isMainWindow)
2393  static_cast<C4ScriptGuiWindow*>(GetParent())->unlockRemovalForClosingCallback();
2394 }
#define s
const int ANY_OWNER
Definition: C4Constants.h:138
const int NO_OWNER
Definition: C4Constants.h:137
C4Draw * pDraw
Definition: C4Draw.cpp:42
C4Game Game
Definition: C4Globals.cpp:52
C4StringTable Strings
Definition: C4Globals.cpp:42
C4MouseControl MouseControl
Definition: C4Globals.cpp:47
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
C4GraphicsResource GraphicsResource
int main(int argc, char *argv[])
#define C4GUI_ScrollBarWdt
Definition: C4Gui.h:103
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
const int32_t C4MC_Button_LeftUp
const int32_t C4MC_Button_LeftDown
const int32_t C4MC_Button_LeftDouble
const int32_t C4MC_Button_Wheel
@ CID_MenuCommand
Definition: C4PacketBase.h:175
#define MenuDebugLogF(...)
#define PROPERTY_TUPLE(p, prop1, prop2)
C4PropertyName
@ P_ID
@ P_Margin
@ P_BackgroundColor
@ P_Priority
@ P_Bottom
@ P_OnMouseIn
@ P_Tooltip
@ P_GraphicsName
@ P_OnClose
@ P_Std
@ P_Top
@ P_OnClick
@ P_Prototype
@ P_Style
@ P_OnMouseOut
@ P_Target
@ P_Symbol
@ P_Text
@ P_Player
@ P_Left
@ P_Mode
@ P_Decoration
@ P_Right
const int ARight
Definition: C4Surface.h:41
const int ALeft
Definition: C4Surface.h:41
const int ACenter
Definition: C4Surface.h:41
C4Value C4VObj(C4Object *pObj)
Definition: C4Value.cpp:88
const C4Value C4VNull
Definition: C4Value.cpp:30
@ C4V_PropList
Definition: C4Value.h:28
@ C4V_Array
Definition: C4Value.h:30
@ C4V_Nil
Definition: C4Value.h:25
@ C4V_String
Definition: C4Value.h:29
C4Value C4VInt(int32_t i)
Definition: C4Value.h:239
C4ViewportList Viewports
uint32_t DWORD
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
#define C4RGB(r, g, b)
Definition: StdColors.h:26
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
Definition: C4Def.h:99
void DrawFrameDw(C4Surface *sfcDest, int x1, int y1, int x2, int y2, DWORD dwClr, float width=1.0f)
Definition: C4Draw.cpp:635
bool RestorePrimaryClipper()
Definition: C4Draw.cpp:210
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
Definition: C4Draw.cpp:840
bool StorePrimaryClipper()
Definition: C4Draw.cpp:203
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:217
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:561
C4Surface * Surface
Definition: C4Facet.h:117
float Hgt
Definition: C4Facet.h:118
float Wdt
Definition: C4Facet.h:118
float Y
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
bool LDown
Definition: C4Gui.h:2536
friend class Element
Definition: C4Gui.h:844
void RemoveElement(Element *pChild) override
Iterator end()
Definition: C4Gui.h:825
Iterator begin()
Definition: C4Gui.h:824
ReverseIterator rend()
Definition: C4Gui.h:827
ReverseIterator rbegin()
Definition: C4Gui.h:826
void InsertElement(Element *pChild, Element *pInsertBefore)
virtual void SetVisibility(bool fToValue)
Definition: C4Gui.cpp:207
bool IsVisible()
Definition: C4Gui.cpp:201
C4Rect rcBounds
Definition: C4Gui.h:385
Container * GetParent()
Definition: C4Gui.h:429
void MouseInput(CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam) override
void DrawElement(C4TargetFacet &cgo) override
bool fAutoHide
Definition: C4Gui.h:884
bool IsScrollingNecessary()
Definition: C4Gui.h:993
int32_t GetScrollY()
Definition: C4Gui.h:987
void SetScrollBarEnabled(bool fToVal, bool noAutomaticPositioning=false)
int32_t iScrollY
Definition: C4Gui.h:943
void ScrollBy(int iAmount)
ScrollBar * pScrollBar
Definition: C4Gui.h:942
int32_t iClientHeight
Definition: C4Gui.h:944
std::unique_ptr< C4ScriptGuiWindow > ScriptGuiRoot
Definition: C4Game.h:234
C4Control & Input
Definition: C4Game.h:82
int32_t GetPlayer()
void SetTooltipText(const StdStrBuf &text)
void SetTooltipRectangle(const C4Rect &rectangle)
bool IsVisible(int32_t iForPlr, bool fAsOverlay) const
virtual C4Object * GetObject()
Definition: C4PropList.cpp:636
virtual const char * GetName() const
Definition: C4PropList.cpp:618
virtual C4ValueArray * GetProperties() const
Definition: C4PropList.cpp:883
int32_t Status
Definition: C4PropList.h:173
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
Definition: C4PropList.cpp:726
Iterator begin()
Definition: C4PropList.cpp:995
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:654
Iterator end()
Definition: C4PropList.h:211
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:114
virtual void SetPropertyByS(C4String *k, const C4Value &to)
Definition: C4PropList.cpp:940
static C4PropList * New(C4PropList *prototype=nullptr)
Definition: C4PropList.cpp:40
void SetProperty(C4PropertyName k, const C4Value &to)
Definition: C4PropList.h:124
Definition: C4Rect.h:28
int32_t y
Definition: C4Rect.h:30
int32_t Hgt
Definition: C4Rect.h:30
int32_t Wdt
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30
void DecRef()
Definition: C4StringTable.h:28
void IncRef()
Definition: C4StringTable.h:27
bool Init(C4ValueArray *array, int32_t index=0)
const C4Value ToC4Value(bool first=true)
void Execute(C4ScriptGuiWindow *parent, int32_t player, int32_t actionType)
bool ExecuteCommand(int32_t actionID, C4ScriptGuiWindow *parent, int32_t player)
void ClearPointers(C4Object *pObj)
bool UpdateChildLayout(C4TargetFacet &cgo, float parentWidth, float parentHeight)
C4ScriptGuiWindow * GetChildByName(C4String *childName)
void RemoveChild(C4ScriptGuiWindow *child, bool close=true, bool all=false)
bool DrawChildren(C4TargetFacet &cgo, int32_t player, int32_t withMultipleFlag=-1, C4Rect *currentClippingRect=nullptr)
float CalculateRelativeSize(float parentWidthOrHeight, C4ScriptGuiWindowPropertyName::type absoluteProperty, C4ScriptGuiWindowPropertyName::type relativeProperty)
bool CreateFromPropList(C4PropList *proplist, bool resetStdTag=false, bool isUpdate=false, bool isLoading=false)
C4ScriptGuiWindow * GetChildByID(int32_t child)
C4ScriptGuiWindow * GetSubWindow(int32_t childID, C4Object *childTarget)
bool IsVisibleTo(int32_t player)
bool ExecuteCommand(int32_t actionID, int32_t player, int32_t subwindowID, int32_t actionType, C4Object *target)
void Draw(C4TargetFacet &cgo) override
const C4Value ToC4Value()
virtual bool ProcessMouseInput(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam, int32_t parentOffsetX, int32_t parentOffsetY)
bool DrawAll(C4TargetFacet &cgo, int32_t player)
bool GetClippingRect(int32_t &left, int32_t &top, int32_t &right, int32_t &bottom)
static const float standardHeight
void OnMouseIn(int32_t player, int32_t parentOffsetX, int32_t parentOffsetY)
virtual bool MouseInput(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam)
C4ScriptGuiWindow * AddChild()
static const float standardWidth
void Denumerate(C4ValueNumbers *numbers)
void SetTag(C4String *tag)
void MouseEnter(C4GUI::CMouse &rMouse) override
bool UpdateLayout(C4TargetFacet &cgo)
void MouseLeave(C4GUI::CMouse &rMouse) override
void ClearPointers(C4Object *pObj)
void OnMouseOut(int32_t player)
C4ScriptGuiWindowAction * GetAction()
void ClearPointers(C4Object *pObj)
std::list< C4ScriptGuiWindowAction * > GetAllActions()
void Set(const C4Value &value, C4String *tag)
bool SwitchTag(C4String *tag)
C4GUI::FrameDecoration * GetFrameDecoration()
const char * GetCStr() const
Definition: C4StringTable.h:49
C4String * FindString(const char *strString) const
C4String P[P_LAST]
C4String * RegString(StdStrBuf String)
float TargetY
Definition: C4Facet.h:165
float TargetX
Definition: C4Facet.h:165
float Zoom
Definition: C4Facet.h:165
const C4Value & GetItem(int32_t iElem) const
Definition: C4ValueArray.h:38
void SetSize(int32_t inSize)
void SetItem(int32_t iElemNr, const C4Value &Value)
int32_t GetSize() const
Definition: C4ValueArray.h:36
C4ValueArray * getArray() const
Definition: C4Value.h:118
C4Object * getObj() const
Definition: C4Value.cpp:68
int32_t getInt() const
Definition: C4Value.h:112
C4String * getStr() const
Definition: C4Value.h:117
C4V_Type GetType() const
Definition: C4Value.h:161
C4PropList * getPropList() const
Definition: C4Value.h:116
C4Def * getDef() const
Definition: C4Value.cpp:78
const char * GetTypeName() const
Definition: C4Value.h:164
const C4Value & GetValue(uint32_t)
Definition: C4Value.cpp:243
float GetGUIZoom() const
Definition: C4Viewport.h:50
C4Viewport * GetViewport(int32_t player_nr, C4Viewport *prev=nullptr)
int GetLineHeight() const
Definition: C4FontLoader.h:125
std::tuple< std::string, int > BreakMessage(const char *szMsg, int iWdt, bool fCheckMarkup, float fZoom=1.0f)
bool GetTextExtent(const char *szText, int32_t &rsx, int32_t &rsy, bool fCheckMarkup=true)
int GetFontHeight() const
Definition: C4FontLoader.h:134
const char * getData() const
Definition: StdBuf.h:442
void Copy()
Definition: StdBuf.h:467
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174