OpenClonk
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 124 of file C4ScriptGuiWindow.h.

Constructor & Destructor Documentation

◆ ~C4ScriptGuiWindowProperty()

C4ScriptGuiWindowProperty::~C4ScriptGuiWindowProperty ( )

Definition at line 285 of file C4ScriptGuiWindow.cpp.

286 {
287  // is cleaned up from destructor of C4ScriptGuiWindow
288 }

◆ C4ScriptGuiWindowProperty()

C4ScriptGuiWindowProperty::C4ScriptGuiWindowProperty ( )
default

Member Function Documentation

◆ ClearPointers()

void C4ScriptGuiWindowProperty::ClearPointers ( C4Object pObj)

Definition at line 576 of file C4ScriptGuiWindow.cpp.

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 }

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

Referenced by C4ScriptGuiWindow::ClearPointers().

Here is the caller graph for this function:

◆ GetAction()

C4ScriptGuiWindowAction* C4ScriptGuiWindowProperty::GetAction ( )
inline

Definition at line 168 of file C4ScriptGuiWindow.h.

168 { return current->action; }

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

Here is the caller graph for this function:

◆ GetAllActions()

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

Definition at line 611 of file C4ScriptGuiWindow.cpp.

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 }

Referenced by C4ScriptGuiWindow::ExecuteCommand().

Here is the caller graph for this function:

◆ GetCurrentTag()

C4String* C4ScriptGuiWindowProperty::GetCurrentTag ( )
inline

Definition at line 172 of file C4ScriptGuiWindow.h.

172 { return currentTag; }

◆ GetDef()

C4Def* C4ScriptGuiWindowProperty::GetDef ( )
inline

Definition at line 165 of file C4ScriptGuiWindow.h.

165 { return current->def; }

Referenced by C4ScriptGuiWindow::Draw().

Here is the caller graph for this function:

◆ GetFloat()

float C4ScriptGuiWindowProperty::GetFloat ( )
inline

Definition at line 163 of file C4ScriptGuiWindow.h.

163 { return current->f; }

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

Here is the caller graph for this function:

◆ GetFrameDecoration()

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

Definition at line 166 of file C4ScriptGuiWindow.h.

166 { return current->deco; }

Referenced by C4ScriptGuiWindow::Draw().

Here is the caller graph for this function:

◆ GetInt()

int32_t C4ScriptGuiWindowProperty::GetInt ( )
inline

Definition at line 162 of file C4ScriptGuiWindow.h.

162 { return current->d; }

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

Here is the caller graph for this function:

◆ GetObject()

C4Object* C4ScriptGuiWindowProperty::GetObject ( )
inline

Definition at line 164 of file C4ScriptGuiWindow.h.

164 { return current->obj; }

Referenced by C4ScriptGuiWindow::Draw().

Here is the caller graph for this function:

◆ GetStrBuf()

StdCopyStrBuf* C4ScriptGuiWindowProperty::GetStrBuf ( )
inline

Definition at line 167 of file C4ScriptGuiWindow.h.

167 { return current->strBuf; }

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

Here is the caller graph for this function:

◆ Set()

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

Definition at line 439 of file C4ScriptGuiWindow.cpp.

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

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

Referenced by C4ScriptGuiWindow::CreateFromPropList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SwitchTag()

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 }

◆ ToC4Value()

const C4Value C4ScriptGuiWindowProperty::ToC4Value ( )

Definition at line 345 of file C4ScriptGuiWindow.cpp.

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

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

Referenced by C4ScriptGuiWindow::ToC4Value().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4ScriptGuiWindow

friend class C4ScriptGuiWindow
friend

Definition at line 126 of file C4ScriptGuiWindow.h.


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