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

#include <C4ScriptGuiWindow.h>

Public Member Functions

 ~C4ScriptGuiWindowProperty ()
 
 C4ScriptGuiWindowProperty ()
 
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 121 of file C4ScriptGuiWindow.h.

Constructor & Destructor Documentation

C4ScriptGuiWindowProperty::~C4ScriptGuiWindowProperty ( )

Definition at line 288 of file C4ScriptGuiWindow.cpp.

289 {
290  // is cleaned up from destructor of C4ScriptGuiWindow
291 }
C4ScriptGuiWindowProperty::C4ScriptGuiWindowProperty ( )
inline

Definition at line 156 of file C4ScriptGuiWindow.h.

156 : current(0), currentTag(0), type(-1) {}

Member Function Documentation

void C4ScriptGuiWindowProperty::ClearPointers ( C4Object pObj)

Definition at line 579 of file C4ScriptGuiWindow.cpp.

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

Referenced by C4ScriptGuiWindow::ClearPointers().

580 {
581  // assume that we actually contain an object
582  // go through all the tags and, in case the tag has anything to do with objects, check and clear it
583  for (std::map<C4String*, Prop>::iterator iter = taggedProperties.begin(); iter != taggedProperties.end(); ++iter)
584  {
585  switch (type)
586  {
588  if (iter->second.obj == pObj)
589  iter->second.obj = 0;
590  break;
591 
596  if (iter->second.action)
597  iter->second.action->ClearPointers(pObj);
598  break;
599  default:
600  return;
601  }
602  }
603 }

Here is the caller graph for this function:

C4ScriptGuiWindowAction* C4ScriptGuiWindowProperty::GetAction ( )
inline

Definition at line 165 of file C4ScriptGuiWindow.h.

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

165 { return current->action; }

Here is the caller graph for this function:

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

Definition at line 614 of file C4ScriptGuiWindow.cpp.

Referenced by C4ScriptGuiWindow::ExecuteCommand().

615 {
616  std::list<C4ScriptGuiWindowAction*> allActions;
617  for (std::map<C4String*, Prop>::iterator iter = taggedProperties.begin(); iter != taggedProperties.end(); ++iter)
618  {
619  Prop &p = iter->second;
620  if (p.action)
621  allActions.push_back(p.action);
622  }
623  return allActions;
624 }

Here is the caller graph for this function:

C4String* C4ScriptGuiWindowProperty::GetCurrentTag ( )
inline

Definition at line 169 of file C4ScriptGuiWindow.h.

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

Definition at line 162 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::Draw().

162 { return current->def; }

Here is the caller graph for this function:

float C4ScriptGuiWindowProperty::GetFloat ( )
inline

Definition at line 160 of file C4ScriptGuiWindow.h.

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

160 { return current->f; }

Here is the caller graph for this function:

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

Definition at line 163 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::Draw().

163 { return current->deco; }

Here is the caller graph for this function:

int32_t C4ScriptGuiWindowProperty::GetInt ( )
inline

Definition at line 159 of file C4ScriptGuiWindow.h.

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

159 { return current->d; }

Here is the caller graph for this function:

C4Object* C4ScriptGuiWindowProperty::GetObject ( )
inline

Definition at line 161 of file C4ScriptGuiWindow.h.

Referenced by C4ScriptGuiWindow::Draw().

161 { return current->obj; }

Here is the caller graph for this function:

StdCopyStrBuf* C4ScriptGuiWindowProperty::GetStrBuf ( )
inline

Definition at line 164 of file C4ScriptGuiWindow.h.

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

164 { return current->strBuf; }

Here is the caller graph for this function:

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

Definition at line 442 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().

443 {
444  C4PropList *proplist = value.getPropList();
445  bool isTaggedPropList = false;
446  if (proplist)
447  isTaggedPropList = !(proplist->GetDef() || proplist->GetObject());
448 
449  if (isTaggedPropList)
450  {
451  std::unique_ptr<C4ValueArray> properties(proplist->GetProperties());
452  properties->SortStrings();
453  for (int32_t i = 0; i < properties->GetSize(); ++i)
454  {
455  const C4Value &entry = properties->GetItem(i);
456  C4String *key = entry.getStr();
457  assert(key && "Proplist returns non-string as key");
458 
459  C4Value property;
460  proplist->GetPropertyByS(key, &property);
461  Set(property, key);
462  }
463  return;
464  }
465 
466  // special treatment for some that have to be deleted (due to owning string/frame deco/...)
467  if (taggedProperties.count(tag))
468  CleanUp(taggedProperties[tag]);
469  else // new tag, retain the proplist if not standard
470  if (tag != &Strings.P[P_Std])
471  tag->IncRef();
472 
473  taggedProperties[tag] = Prop();
474  // in order to make /current/ sane, always reset it - not relying on implementation details of std::map
475  // if the user wants a special tag selected, he should do that (standard selection will still be "Std")
476  current = &taggedProperties[tag];
477  currentTag = tag;
478 
479 
480  // now that a new property entry has been created and the old has been cleaned up, get the data from the C4Value
481  switch (type)
482  {
499  assert (false && "Trying to set positional properties directly. Those should always come parsed from a string.");
500  break;
501 
505  current->d = value.getInt();
506  break;
507 
509  if (value == C4VNull)
510  current->d = ANY_OWNER;
511  else
512  current->d = value.getInt();
513  break;
514 
516  {
517  C4PropList *symbol = value.getPropList();
518  if (symbol)
519  current->obj = symbol->GetObject();
520  else current->obj = 0;
521  break;
522  }
524  {
525  C4PropList *symbol = value.getPropList();
526  if (symbol)
527  current->def = symbol->GetDef();
528  else current->def = 0;
529  break;
530  }
532  {
533  C4Def *def = value.getDef();
534 
535  if (def)
536  {
537  current->deco = new C4GUI::FrameDecoration();
538  if (!current->deco->SetByDef(def))
539  {
540  delete current->deco;
541  current->deco = 0;
542  }
543  }
544  break;
545  }
549  {
550  C4String *string = value.getStr();
551  StdCopyStrBuf *buf = new StdCopyStrBuf();
552  if (string)
553  buf->Copy(string->GetCStr());
554  else buf->Copy("");
555  current->strBuf = buf;
556  break;
557  }
562  {
563  C4ValueArray *array = value.getArray();
564  if (array)
565  {
566  assert (!current->action && "Prop() contains action prior to assignment");
567  current->action = new C4ScriptGuiWindowAction();
568  current->action->Init(array);
569  }
570  break;
571  }
572 
573  default:
574  assert(false && "C4ScriptGuiWindowAction should never have undefined type");
575  break;
576  } // switch
577 }
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:644
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:662
C4StringTable Strings
Definition: C4Globals.cpp:42
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
Definition: C4PropList.cpp:734
virtual C4ValueArray * GetProperties() const
Definition: C4PropList.cpp:891
Definition: C4Def.h:100
C4ValueArray * getArray() const
Definition: C4Value.h:118
int32_t getInt() const
Definition: C4Value.h:112
const C4Value C4VNull
Definition: C4Value.cpp:32
C4Def * getDef() const
Definition: C4Value.cpp:80
void Copy()
Definition: StdBuf.h:475
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 605 of file C4ScriptGuiWindow.cpp.

606 {
607  if (!taggedProperties.count(tag)) return false; // tag not available
608  if (current == &taggedProperties[tag]) return false; // tag already set?
609  current = &taggedProperties[tag];
610  currentTag = tag;
611  return true;
612 }
const C4Value C4ScriptGuiWindowProperty::ToC4Value ( )

Definition at line 348 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().

349 {
350  C4PropList *proplist = nullptr;
351 
352  bool onlyOneTag = taggedProperties.size() == 1;
353  if (!onlyOneTag) // we will need a tagged proplist
354  proplist = C4PropList::New();
355 
356  // go through all of the tagged properties and add a property to the proplist containing both the tag name
357  // and the serialzed C4Value of the properties' value
358  for(std::map<C4String*, Prop>::iterator iter = taggedProperties.begin(); iter != taggedProperties.end(); ++iter)
359  {
360  C4String *tagString = iter->first;
361  const Prop &prop = iter->second;
362 
363  C4Value val;
364 
365  // get value to save
366  switch (type)
367  {
384  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.");
385  break;
386 
391  val = C4Value(prop.d);
392  break;
393 
395  val = C4Value(prop.obj);
396  break;
397 
399  val = C4Value(prop.def);
400  break;
401 
403  if (prop.deco)
404  val = C4Value(prop.deco->pSourceDef);
405  break;
406 
410  {
411  if (prop.strBuf)
412  {
413  // string existing?
414  C4String *s = Strings.FindString(prop.strBuf->getData());
415  if (!s) s = Strings.RegString(prop.strBuf->getData());
416  val = C4Value(s);
417  }
418  break;
419  }
420 
425  if (prop.action)
426  val = prop.action->ToC4Value();
427  break;
428 
429  default:
430  assert(false && "C4ScriptGuiWindowAction should never have undefined type");
431  break;
432  } // switch
433 
434  if (onlyOneTag) return val;
435  assert(proplist);
436  proplist->SetPropertyByS(tagString, val);
437  }
438 
439  return C4Value(proplist);
440 }
C4String * FindString(const char *strString) const
C4String * RegString(StdStrBuf String)
static C4PropList * New(C4PropList *prototype=0)
Definition: C4PropList.cpp:64
C4StringTable Strings
Definition: C4Globals.cpp:42
virtual void SetPropertyByS(C4String *k, const C4Value &to)
Definition: C4PropList.cpp:929
#define s

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


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