ManaPlus
Public Member Functions | Protected Member Functions | Protected Attributes
SetupItemSlider2 Class Reference

#include <setupitem.h>

Inheritance diagram for SetupItemSlider2:
SetupItem ActionListener Widget2

Public Member Functions

 SetupItemSlider2 (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const int min, const int max, const int step, SetupItemNames *const values, const OnTheFly onTheFly, const MainConfig mainConfig, const DoNotAlign doNotAlign)
 
 SetupItemSlider2 (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const int min, const int max, const int step, SetupItemNames *const values, const std::string &def, const OnTheFly onTheFly, const MainConfig mainConfig, const DoNotAlign doNotAlign)
 
 ~SetupItemSlider2 ()
 
void createControls ()
 
void fromWidget ()
 
void toWidget ()
 
void action (const ActionEvent &event)
 
void apply (const std::string &eventName)
 
void setInvertValue (const int v)
 
- Public Member Functions inherited from SetupItem
 ~SetupItem ()
 
void load ()
 
virtual void save ()
 
void setWidget (Widget *widget)
 
WidgetgetWidget () const
 
ConfigurationgetConfig () const
 
virtual std::string getActionEventId () const
 
virtual void doAction ()
 
virtual void cancel (const std::string &eventName)
 
virtual void externalUpdated (const std::string &eventName)
 
virtual void externalUnloaded (const std::string &eventName)
 
MainConfig isMainConfig () const
 
void fixFirstItemSize (Widget *const widget)
 
virtual void rereadValue ()
 
void setValue (const std::string &str)
 
std::string getValue () const
 
std::string getEventName () const
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 

Protected Member Functions

void updateLabel ()
 
int getMaxWidth ()
 
- Protected Member Functions inherited from SetupItem
 SetupItem (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig)
 
 SetupItem (const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const std::string &def, const MainConfig mainConfig)
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 

Protected Attributes

HorizontContainermHorizont
 
LabelmLabel
 
LabelmLabel2
 
SlidermSlider
 
SetupItemNamesmValues
 
int mMin
 
int mMax
 
int mStep
 
int mInvertValue
 
bool mInvert
 
OnTheFly mOnTheFly
 
DoNotAlign mDoNotAlign
 
- Protected Attributes inherited from SetupItem
std::string mText
 
std::string mDescription
 
std::string mKeyName
 
SetupTabScrollmParent
 
std::string mEventName
 
std::string mValue
 
std::string mDefault
 
WidgetmWidget
 
std::list< Widget * > mTempWidgets
 
int mValueType
 
MainConfig mMainConfig
 
bool mUseDefault
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 

Additional Inherited Members

- Public Types inherited from SetupItem
enum  { VBOOL = 0 , VSTR , VINT , VNONE }
 

Detailed Description

Definition at line 455 of file setupitem.h.

Constructor & Destructor Documentation

◆ SetupItemSlider2() [1/2]

SetupItemSlider2::SetupItemSlider2 ( const std::string &  text,
const std::string &  description,
const std::string &  keyName,
SetupTabScroll *const  parent,
const std::string &  eventName,
const int  min,
const int  max,
const int  step,
SetupItemNames *const  values,
const OnTheFly  onTheFly,
const MainConfig  mainConfig,
const DoNotAlign  doNotAlign 
)

Definition at line 991 of file setupitem.cpp.

1002  :
1003  SetupItem(text, description, keyName, parent, eventName, mainConfig),
1004  mHorizont(nullptr),
1005  mLabel(nullptr),
1006  mLabel2(nullptr),
1007  mSlider(nullptr),
1008  mValues(values),
1009  mMin(min),
1010  mMax(max),
1011  mStep(step),
1012  mInvertValue(0),
1013  mInvert(false),
1014  mOnTheFly(onTheFly),
1015  mDoNotAlign(doNotAlign)
1016 {
1017  mValueType = VSTR;
1018  createControls();
1019 }
Label * mLabel
Definition: setupitem.h:503
OnTheFly mOnTheFly
Definition: setupitem.h:512
SetupItemNames * mValues
Definition: setupitem.h:506
Slider * mSlider
Definition: setupitem.h:505
Label * mLabel2
Definition: setupitem.h:504
HorizontContainer * mHorizont
Definition: setupitem.h:502
DoNotAlign mDoNotAlign
Definition: setupitem.h:513
SetupItem(const std::string &text, const std::string &description, const std::string &keyName, SetupTabScroll *const parent, const std::string &eventName, const MainConfig mainConfig)
Definition: setupitem.cpp:55
int mValueType
Definition: setupitem.h:147
CompositeGenerator< T > values(T val1, T val2)
Definition: catch.hpp:2472

References createControls(), SetupItem::mValueType, and SetupItem::VSTR.

◆ SetupItemSlider2() [2/2]

SetupItemSlider2::SetupItemSlider2 ( const std::string &  text,
const std::string &  description,
const std::string &  keyName,
SetupTabScroll *const  parent,
const std::string &  eventName,
const int  min,
const int  max,
const int  step,
SetupItemNames *const  values,
const std::string &  def,
const OnTheFly  onTheFly,
const MainConfig  mainConfig,
const DoNotAlign  doNotAlign 
)

Definition at line 1021 of file setupitem.cpp.

1033  :
1034  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
1035  mHorizont(nullptr),
1036  mLabel(nullptr),
1037  mLabel2(nullptr),
1038  mSlider(nullptr),
1039  mValues(values),
1040  mMin(min),
1041  mMax(max),
1042  mStep(step),
1043  mInvertValue(0),
1044  mInvert(false),
1045  mOnTheFly(onTheFly),
1046  mDoNotAlign(doNotAlign)
1047 {
1048  mValueType = VSTR;
1049  createControls();
1050 }

References createControls(), SetupItem::mValueType, and SetupItem::VSTR.

◆ ~SetupItemSlider2()

SetupItemSlider2::~SetupItemSlider2 ( )

Definition at line 1052 of file setupitem.cpp.

1053 {
1054  mHorizont = nullptr;
1055  mWidget = nullptr;
1056  mSlider = nullptr;
1057  mLabel = nullptr;
1058 }
Widget * mWidget
Definition: setupitem.h:143

References mHorizont, mLabel, mSlider, and SetupItem::mWidget.

Member Function Documentation

◆ action()

void SetupItemSlider2::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Reimplemented from SetupItem.

Definition at line 1137 of file setupitem.cpp.

1138 {
1139  fromWidget();
1140  updateLabel();
1141  if (mOnTheFly == OnTheFly_true)
1142  save();
1143 }
virtual void save()
Definition: setupitem.cpp:146
const bool OnTheFly_true
Definition: onthefly.h:30

References fromWidget(), mOnTheFly, OnTheFly_true, SetupItem::save(), and updateLabel().

◆ apply()

void SetupItemSlider2::apply ( const std::string &  eventName)
virtual

Reimplemented from SetupItem.

Definition at line 1162 of file setupitem.cpp.

1163 {
1164  if (eventName != mEventName)
1165  return;
1166 
1167  fromWidget();
1168  save();
1169 }
std::string mEventName
Definition: setupitem.h:137

References fromWidget(), SetupItem::mEventName, and SetupItem::save().

◆ createControls()

void SetupItemSlider2::createControls ( )

Definition at line 1060 of file setupitem.cpp.

1061 {
1062  load();
1063  mHorizont = new HorizontContainer(this, 32, 2);
1064 
1065  const int width = getMaxWidth();
1066 
1067  mLabel = new Label(this, mText);
1069  mLabel2 = new Label(this, "");
1070  mLabel2->setWidth(width);
1071  mSlider = new Slider(this, mMin, mMax, mStep);
1074  mSlider->setValue(atof(mValue.c_str()));
1075  mSlider->setHeight(30);
1076 
1077  mWidget = mSlider;
1078  mSlider->setWidth(150);
1079  mSlider->setHeight(40);
1082  mHorizont->add(mLabel);
1083  mHorizont->add(mSlider, -10);
1084  mHorizont->add(mLabel2);
1085 
1086  mParent->getContainer()->add2(mHorizont, true, 4);
1087  mParent->addControl(this);
1088  mParent->addActionListener(this);
1089  mWidget->addActionListener(this);
1090  updateLabel();
1091 }
void add(Widget *const widget)
Definition: label.h:91
SetupTabScroll * mParent
Definition: setupitem.h:135
std::string mDescription
Definition: setupitem.h:131
std::string mValue
Definition: setupitem.h:139
void fixFirstItemSize(Widget *const widget)
Definition: setupitem.cpp:198
std::string mText
Definition: setupitem.h:129
void load()
Definition: setupitem.cpp:113
void addControl(SetupItem *const widget)
VertContainer * getContainer() const
Definition: slider.h:89
void setValue(const double value)
Definition: slider.cpp:474
void setToolTip(const std::string &str)
void add2(Widget *const widget, const bool resizable, const int spacing)
void setWidth(const int width)
Definition: widget.cpp:133
void setHeight(const int height)
Definition: widget.cpp:140
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
const bool DoNotAlign_false
Definition: donotalign.h:30

References HorizontContainer::add(), VertContainer::add2(), Widget::addActionListener(), SetupTabScroll::addControl(), DoNotAlign_false, SetupItem::fixFirstItemSize(), SetupTabScroll::getContainer(), getMaxWidth(), SetupItem::load(), SetupItem::mDescription, mDoNotAlign, SetupItem::mEventName, mHorizont, mLabel, mLabel2, mMax, mMin, SetupItem::mParent, mSlider, mStep, SetupItem::mText, SetupItem::mValue, SetupItem::mWidget, Widget::setActionEventId(), Widget::setHeight(), ToolTipListener::setToolTip(), Slider::setValue(), Widget::setWidth(), and updateLabel().

Referenced by SetupItemSlider2().

◆ fromWidget()

void SetupItemSlider2::fromWidget ( )
virtual

Implements SetupItem.

Definition at line 1114 of file setupitem.cpp.

1115 {
1116  if (mSlider == nullptr)
1117  return;
1118 
1119  int val = roundDouble(mSlider->getValue());
1120  if (mInvert)
1121  val = mInvertValue - val;
1122  mValue = toString(val);
1123 }
double getValue() const
Definition: slider.h:204
int roundDouble(const double v)
Definition: mathutils.h:232
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774

References Slider::getValue(), mInvert, mInvertValue, mSlider, SetupItem::mValue, roundDouble(), and Catch::toString().

Referenced by action(), and apply().

◆ getMaxWidth()

int SetupItemSlider2::getMaxWidth ( )
protected

Definition at line 1093 of file setupitem.cpp.

1094 {
1095  if ((mValues == nullptr) || (gui == nullptr))
1096  return 1;
1097 
1098  int maxWidth = 0;
1099  SetupItemNamesConstIter it = mValues->begin();
1100  const SetupItemNamesConstIter it_end = mValues->end();
1101  const Font *const font = gui->getFont();
1102 
1103  while (it != it_end)
1104  {
1105  const int w = font->getWidth(*it);
1106  if (w > maxWidth)
1107  maxWidth = w;
1108 
1109  ++ it;
1110  }
1111  return maxWidth;
1112 }
Definition: font.h:90
int getWidth(const std::string &text) const
Definition: font.cpp:334
Font * getFont() const
Definition: gui.h:160
Gui * gui
Definition: gui.cpp:111
SetupItemNames::const_iterator SetupItemNamesConstIter
Definition: setupitem.h:453

References Gui::getFont(), Font::getWidth(), gui, and mValues.

Referenced by createControls().

◆ setInvertValue()

void SetupItemSlider2::setInvertValue ( const int  v)

Definition at line 1171 of file setupitem.cpp.

1172 {
1173  mInvert = true;
1174  mInvertValue = v;
1175  toWidget();
1176 }

References mInvert, mInvertValue, and toWidget().

◆ toWidget()

void SetupItemSlider2::toWidget ( )
virtual

Implements SetupItem.

Definition at line 1125 of file setupitem.cpp.

1126 {
1127  if (mSlider == nullptr)
1128  return;
1129 
1130  int val = roundDouble(atof(mValue.c_str()));
1131  if (mInvert)
1132  val = mInvertValue - val;
1133  mSlider->setValue(val);
1134  updateLabel();
1135 }

References mInvert, mInvertValue, mSlider, SetupItem::mValue, roundDouble(), Slider::setValue(), and updateLabel().

Referenced by setInvertValue().

◆ updateLabel()

void SetupItemSlider2::updateLabel ( )
protected

Definition at line 1145 of file setupitem.cpp.

1146 {
1147  int val = CAST_S32(mSlider->getValue()) - mMin;
1148  if (val < 0)
1149  {
1150  val = 0;
1151  }
1152  else
1153  {
1154  const int sz = CAST_S32(mValues->size());
1155  if (val >= sz)
1156  val = sz - 1;
1157  }
1158  std::string str = mValues->at(val);
1159  mLabel2->setCaption(str);
1160 }
#define CAST_S32
Definition: cast.h:30
void setCaption(const std::string &caption)
Definition: label.cpp:264

References CAST_S32, Slider::getValue(), mLabel2, mMin, mSlider, mValues, and Label::setCaption().

Referenced by action(), createControls(), and toWidget().

Field Documentation

◆ mDoNotAlign

DoNotAlign SetupItemSlider2::mDoNotAlign
protected

Definition at line 513 of file setupitem.h.

Referenced by createControls().

◆ mHorizont

HorizontContainer* SetupItemSlider2::mHorizont
protected

Definition at line 502 of file setupitem.h.

Referenced by createControls(), and ~SetupItemSlider2().

◆ mInvert

bool SetupItemSlider2::mInvert
protected

Definition at line 511 of file setupitem.h.

Referenced by fromWidget(), setInvertValue(), and toWidget().

◆ mInvertValue

int SetupItemSlider2::mInvertValue
protected

Definition at line 510 of file setupitem.h.

Referenced by fromWidget(), setInvertValue(), and toWidget().

◆ mLabel

Label* SetupItemSlider2::mLabel
protected

Definition at line 503 of file setupitem.h.

Referenced by createControls(), and ~SetupItemSlider2().

◆ mLabel2

Label* SetupItemSlider2::mLabel2
protected

Definition at line 504 of file setupitem.h.

Referenced by createControls(), and updateLabel().

◆ mMax

int SetupItemSlider2::mMax
protected

Definition at line 508 of file setupitem.h.

Referenced by createControls().

◆ mMin

int SetupItemSlider2::mMin
protected

Definition at line 507 of file setupitem.h.

Referenced by createControls(), and updateLabel().

◆ mOnTheFly

OnTheFly SetupItemSlider2::mOnTheFly
protected

Definition at line 512 of file setupitem.h.

Referenced by action().

◆ mSlider

Slider* SetupItemSlider2::mSlider
protected

Definition at line 505 of file setupitem.h.

Referenced by createControls(), fromWidget(), toWidget(), updateLabel(), and ~SetupItemSlider2().

◆ mStep

int SetupItemSlider2::mStep
protected

Definition at line 509 of file setupitem.h.

Referenced by createControls().

◆ mValues

SetupItemNames* SetupItemSlider2::mValues
protected

Definition at line 506 of file setupitem.h.

Referenced by getMaxWidth(), and updateLabel().


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