OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScriptGuiWindowProperty Class Reference

#include <C4ScriptGuiWindow.h>

Public Member Functions

 ~C4ScriptGuiWindowProperty ()
 
 C4ScriptGuiWindowProperty ()=default
 
void Set (const C4Value &value, C4String *tag)
 
int32_t GetInt ()
 
float GetFloat ()
 
C4ObjectGetObject ()
 
C4DefGetDef ()
 
C4GUI::FrameDecorationGetFrameDecoration ()
 
StdCopyStrBufGetStrBuf ()
 
C4ScriptGuiWindowActionGetAction ()
 
std::list
< C4ScriptGuiWindowAction * > 
GetAllActions ()
 
bool SwitchTag (C4String *tag)
 
C4StringGetCurrentTag ()
 
const C4Value ToC4Value ()
 
void ClearPointers (C4Object *pObj)
 

Friends

class C4ScriptGuiWindow
 

Detailed Description

Definition at line 118 of file C4ScriptGuiWindow.h.

Constructor & Destructor Documentation

C4ScriptGuiWindowProperty::~C4ScriptGuiWindowProperty ( )

Definition at line 285 of file C4ScriptGuiWindow.cpp.

286 {
287  // is cleaned up from destructor of C4ScriptGuiWindow
288 }
C4ScriptGuiWindowProperty::C4ScriptGuiWindowProperty ( )
default

Member Function Documentation

void C4ScriptGuiWindowProperty::ClearPointers ( C4Object pObj)

Definition at line 576 of file C4ScriptGuiWindow.cpp.

References onClickAction, onCloseAction, onMouseInAction, onMouseOutAction, and symbolObject.

Referenced by C4ScriptGuiWindow::ClearPointers().

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 }

Here is the caller graph for this function:

C4ScriptGuiWindowAction* C4ScriptGuiWindowProperty::GetAction ( )
inline

Definition at line 162 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::Close(), C4ScriptGuiWindow::OnMouseIn(), C4ScriptGuiWindow::OnMouseOut(), and C4ScriptGuiWindow::ProcessMouseInput().

162 { return current->action; }

Here is the caller graph for this function:

std::list< C4ScriptGuiWindowAction * > C4ScriptGuiWindowProperty::GetAllActions ( )

Definition at line 611 of file C4ScriptGuiWindow.cpp.

Referenced by C4ScriptGuiWindow::ExecuteCommand().

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 }

Here is the caller graph for this function:

C4String* C4ScriptGuiWindowProperty::GetCurrentTag ( )
inline

Definition at line 166 of file C4ScriptGuiWindow.h.

166 { return currentTag; }
C4Def* C4ScriptGuiWindowProperty::GetDef ( )
inline

Definition at line 159 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::Draw().

159 { return current->def; }

Here is the caller graph for this function:

float C4ScriptGuiWindowProperty::GetFloat ( )
inline

Definition at line 157 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::CalculateRelativeSize(), and C4ScriptGuiWindow::UpdateLayout().

157 { return current->f; }

Here is the caller graph for this function:

C4GUI::FrameDecoration* C4ScriptGuiWindowProperty::GetFrameDecoration ( )
inline

Definition at line 160 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::Draw().

160 { return current->deco; }

Here is the caller graph for this function:

int32_t C4ScriptGuiWindowProperty::GetInt ( )
inline

Definition at line 156 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::Draw(), C4ScriptGuiWindow::DrawChildren(), C4ScriptGuiWindow::GetClippingRect(), C4ScriptGuiWindow::IsVisibleTo(), C4ScriptGuiWindow::MouseInput(), C4ScriptGuiWindow::ProcessMouseInput(), C4ScriptGuiWindow::RequestLayoutUpdate(), and C4ScriptGuiWindow::UpdateLayout().

156 { return current->d; }

Here is the caller graph for this function:

C4Object* C4ScriptGuiWindowProperty::GetObject ( )
inline

Definition at line 158 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::Draw().

158 { return current->obj; }

Here is the caller graph for this function:

StdCopyStrBuf* C4ScriptGuiWindowProperty::GetStrBuf ( )
inline

Definition at line 161 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::Draw(), C4ScriptGuiWindow::OnMouseIn(), and C4ScriptGuiWindow::UpdateLayout().

161 { return current->strBuf; }

Here is the caller graph for this function:

void C4ScriptGuiWindowProperty::Set ( const C4Value value,
C4String tag 
)

Definition at line 439 of file C4ScriptGuiWindow.cpp.

References ANY_OWNER, backgroundColor, bottom, bottomMargin, C4VNull, StdStrBuf::Copy(), frameDecoration, C4Value::getArray(), C4String::GetCStr(), C4PropList::GetDef(), C4Value::getDef(), C4Value::getInt(), C4PropList::GetObject(), C4PropList::GetProperties(), C4PropList::GetPropertyByS(), C4Value::getPropList(), C4Value::getStr(), left, leftMargin, onClickAction, onCloseAction, onMouseInAction, onMouseOutAction, C4StringTable::P, P_Std, player, priority, relBottom, relBottomMargin, relLeft, relLeftMargin, relRight, relRightMargin, relTop, relTopMargin, right, rightMargin, Strings, style, symbolDef, symbolGraphicsName, symbolObject, text, tooltip, top, and topMargin.

Referenced by C4ScriptGuiWindow::CreateFromPropList().

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 }
C4String P[P_LAST]
C4String * getStr() const
Definition: C4Value.h:117
const char * GetCStr() const
Definition: C4StringTable.h:49
const int ANY_OWNER
Definition: C4Constants.h:139
virtual C4Object * GetObject()
Definition: C4PropList.cpp:663
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:681
C4StringTable Strings
Definition: C4Globals.cpp:42
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
Definition: C4PropList.cpp:753
virtual C4ValueArray * GetProperties() const
Definition: C4PropList.cpp:910
Definition: C4Def.h:98
C4ValueArray * getArray() const
Definition: C4Value.h:118
int32_t getInt() const
Definition: C4Value.h:112
const C4Value C4VNull
Definition: C4Value.cpp:30
C4Def * getDef() const
Definition: C4Value.cpp:78
void Copy()
Definition: StdBuf.h:467
void Set(const C4Value &value, C4String *tag)
C4PropList * getPropList() const
Definition: C4Value.h:116

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScriptGuiWindowProperty::SwitchTag ( C4String tag)

Definition at line 602 of file C4ScriptGuiWindow.cpp.

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 }
const C4Value C4ScriptGuiWindowProperty::ToC4Value ( )

Definition at line 345 of file C4ScriptGuiWindow.cpp.

References backgroundColor, bottom, bottomMargin, C4StringTable::FindString(), frameDecoration, left, leftMargin, C4PropList::New(), onClickAction, onCloseAction, onMouseInAction, onMouseOutAction, player, priority, C4StringTable::RegString(), relBottom, relBottomMargin, relLeft, relLeftMargin, relRight, relRightMargin, relTop, relTopMargin, right, rightMargin, s, C4PropList::SetPropertyByS(), Strings, style, symbolDef, symbolGraphicsName, symbolObject, text, tooltip, top, and topMargin.

Referenced by C4ScriptGuiWindow::ToC4Value().

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 }
C4String * FindString(const char *strString) const
C4String * RegString(StdStrBuf String)
C4StringTable Strings
Definition: C4Globals.cpp:42
virtual void SetPropertyByS(C4String *k, const C4Value &to)
Definition: C4PropList.cpp:948
#define s
static C4PropList * New(C4PropList *prototype=nullptr)
Definition: C4PropList.cpp:64

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4ScriptGuiWindow
friend

Definition at line 120 of file C4ScriptGuiWindow.h.


The documentation for this class was generated from the following files: