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 454 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 990 of file setupitem.cpp.

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

1001  :
1002  SetupItem(text, description, keyName, parent, eventName, mainConfig),
1003  mHorizont(nullptr),
1004  mLabel(nullptr),
1005  mLabel2(nullptr),
1006  mSlider(nullptr),
1007  mValues(values),
1008  mMin(min),
1009  mMax(max),
1010  mStep(step),
1011  mInvertValue(0),
1012  mInvert(false),
1013  mOnTheFly(onTheFly),
1014  mDoNotAlign(doNotAlign)
1015 {
1016  mValueType = VSTR;
1017  createControls();
1018 }
HorizontContainer * mHorizont
Definition: setupitem.h:501
int mValueType
Definition: setupitem.h:146
Label * mLabel
Definition: setupitem.h:502
DoNotAlign mDoNotAlign
Definition: setupitem.h:512
SetupItemNames * mValues
Definition: setupitem.h:505
Slider * mSlider
Definition: setupitem.h:504
Label * mLabel2
Definition: setupitem.h:503
CompositeGenerator< T > values(T val1, T val2)
Definition: catch.hpp:2472
OnTheFly mOnTheFly
Definition: setupitem.h:511
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:54

◆ 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 1020 of file setupitem.cpp.

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

1032  :
1033  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
1034  mHorizont(nullptr),
1035  mLabel(nullptr),
1036  mLabel2(nullptr),
1037  mSlider(nullptr),
1038  mValues(values),
1039  mMin(min),
1040  mMax(max),
1041  mStep(step),
1042  mInvertValue(0),
1043  mInvert(false),
1044  mOnTheFly(onTheFly),
1045  mDoNotAlign(doNotAlign)
1046 {
1047  mValueType = VSTR;
1048  createControls();
1049 }
HorizontContainer * mHorizont
Definition: setupitem.h:501
int mValueType
Definition: setupitem.h:146
Label * mLabel
Definition: setupitem.h:502
DoNotAlign mDoNotAlign
Definition: setupitem.h:512
SetupItemNames * mValues
Definition: setupitem.h:505
Slider * mSlider
Definition: setupitem.h:504
Label * mLabel2
Definition: setupitem.h:503
CompositeGenerator< T > values(T val1, T val2)
Definition: catch.hpp:2472
OnTheFly mOnTheFly
Definition: setupitem.h:511
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:54

◆ ~SetupItemSlider2()

SetupItemSlider2::~SetupItemSlider2 ( )

Definition at line 1051 of file setupitem.cpp.

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

1052 {
1053  mHorizont = nullptr;
1054  mWidget = nullptr;
1055  mSlider = nullptr;
1056  mLabel = nullptr;
1057 }
HorizontContainer * mHorizont
Definition: setupitem.h:501
Label * mLabel
Definition: setupitem.h:502
Widget * mWidget
Definition: setupitem.h:142
Slider * mSlider
Definition: setupitem.h:504

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 1136 of file setupitem.cpp.

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

1137 {
1138  fromWidget();
1139  updateLabel();
1140  if (mOnTheFly == OnTheFly_true)
1141  save();
1142 }
const bool OnTheFly_true
Definition: onthefly.h:29
virtual void save()
Definition: setupitem.cpp:145
OnTheFly mOnTheFly
Definition: setupitem.h:511

◆ apply()

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

Reimplemented from SetupItem.

Definition at line 1161 of file setupitem.cpp.

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

1162 {
1163  if (eventName != mEventName)
1164  return;
1165 
1166  fromWidget();
1167  save();
1168 }
std::string mEventName
Definition: setupitem.h:136
virtual void save()
Definition: setupitem.cpp:145

◆ createControls()

void SetupItemSlider2::createControls ( )

Definition at line 1059 of file setupitem.cpp.

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().

1060 {
1061  load();
1062  mHorizont = new HorizontContainer(this, 32, 2);
1063 
1064  const int width = getMaxWidth();
1065 
1066  mLabel = new Label(this, mText);
1068  mLabel2 = new Label(this, "");
1069  mLabel2->setWidth(width);
1070  mSlider = new Slider(this, mMin, mMax, mStep);
1073  mSlider->setValue(atof(mValue.c_str()));
1074  mSlider->setHeight(30);
1075 
1076  mWidget = mSlider;
1077  mSlider->setWidth(150);
1078  mSlider->setHeight(40);
1081  mHorizont->add(mLabel);
1082  mHorizont->add(mSlider, -10);
1083  mHorizont->add(mLabel2);
1084 
1085  mParent->getContainer()->add2(mHorizont, true, 4);
1086  mParent->addControl(this);
1087  mParent->addActionListener(this);
1088  mWidget->addActionListener(this);
1089  updateLabel();
1090 }
void load()
Definition: setupitem.cpp:112
std::string mEventName
Definition: setupitem.h:136
void addControl(SetupItem *const widget)
HorizontContainer * mHorizont
Definition: setupitem.h:501
void setWidth(const int width)
Definition: widget.cpp:132
std::string mValue
Definition: setupitem.h:138
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
std::string mDescription
Definition: setupitem.h:130
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
VertContainer * getContainer() const
Label * mLabel
Definition: setupitem.h:502
void add2(Widget *const widget, const bool resizable, const int spacing)
Definition: label.h:87
Widget * mWidget
Definition: setupitem.h:142
SetupTabScroll * mParent
Definition: setupitem.h:134
DoNotAlign mDoNotAlign
Definition: setupitem.h:512
void add(Widget *const widget)
void fixFirstItemSize(Widget *const widget)
Definition: setupitem.cpp:197
void setHeight(const int height)
Definition: widget.cpp:139
void setToolTip(const std::string &str)
void setValue(const double value)
Definition: slider.cpp:473
Slider * mSlider
Definition: setupitem.h:504
Label * mLabel2
Definition: setupitem.h:503
Definition: slider.h:85
const bool DoNotAlign_false
Definition: donotalign.h:29
std::string mText
Definition: setupitem.h:128

◆ fromWidget()

void SetupItemSlider2::fromWidget ( )
virtual

Implements SetupItem.

Definition at line 1113 of file setupitem.cpp.

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

Referenced by action(), and apply().

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

◆ getMaxWidth()

int SetupItemSlider2::getMaxWidth ( )
protected

Definition at line 1092 of file setupitem.cpp.

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

Referenced by createControls().

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

◆ setInvertValue()

void SetupItemSlider2::setInvertValue ( const int  v)

Definition at line 1170 of file setupitem.cpp.

References mInvert, mInvertValue, and toWidget().

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

◆ toWidget()

void SetupItemSlider2::toWidget ( )
virtual

Implements SetupItem.

Definition at line 1124 of file setupitem.cpp.

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

Referenced by setInvertValue().

1125 {
1126  if (mSlider == nullptr)
1127  return;
1128 
1129  int val = roundDouble(atof(mValue.c_str()));
1130  if (mInvert)
1131  val = mInvertValue - val;
1132  mSlider->setValue(val);
1133  updateLabel();
1134 }
std::string mValue
Definition: setupitem.h:138
int roundDouble(const double v)
Definition: mathutils.h:231
void setValue(const double value)
Definition: slider.cpp:473
Slider * mSlider
Definition: setupitem.h:504

◆ updateLabel()

void SetupItemSlider2::updateLabel ( )
protected

Definition at line 1144 of file setupitem.cpp.

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

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

1145 {
1146  int val = CAST_S32(mSlider->getValue()) - mMin;
1147  if (val < 0)
1148  {
1149  val = 0;
1150  }
1151  else
1152  {
1153  const int sz = CAST_S32(mValues->size());
1154  if (val >= sz)
1155  val = sz - 1;
1156  }
1157  std::string str = mValues->at(val);
1158  mLabel2->setCaption(str);
1159 }
#define CAST_S32
Definition: cast.h:29
void setCaption(const std::string &caption)
Definition: label.cpp:261
double getValue() const
Definition: slider.h:203
SetupItemNames * mValues
Definition: setupitem.h:505
Slider * mSlider
Definition: setupitem.h:504
Label * mLabel2
Definition: setupitem.h:503

Field Documentation

◆ mDoNotAlign

DoNotAlign SetupItemSlider2::mDoNotAlign
protected

Definition at line 512 of file setupitem.h.

Referenced by createControls().

◆ mHorizont

HorizontContainer* SetupItemSlider2::mHorizont
protected

Definition at line 501 of file setupitem.h.

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

◆ mInvert

bool SetupItemSlider2::mInvert
protected

Definition at line 510 of file setupitem.h.

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

◆ mInvertValue

int SetupItemSlider2::mInvertValue
protected

Definition at line 509 of file setupitem.h.

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

◆ mLabel

Label* SetupItemSlider2::mLabel
protected

Definition at line 502 of file setupitem.h.

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

◆ mLabel2

Label* SetupItemSlider2::mLabel2
protected

Definition at line 503 of file setupitem.h.

Referenced by createControls(), and updateLabel().

◆ mMax

int SetupItemSlider2::mMax
protected

Definition at line 507 of file setupitem.h.

Referenced by createControls().

◆ mMin

int SetupItemSlider2::mMin
protected

Definition at line 506 of file setupitem.h.

Referenced by createControls(), and updateLabel().

◆ mOnTheFly

OnTheFly SetupItemSlider2::mOnTheFly
protected

Definition at line 511 of file setupitem.h.

Referenced by action().

◆ mSlider

Slider* SetupItemSlider2::mSlider
protected

Definition at line 504 of file setupitem.h.

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

◆ mStep

int SetupItemSlider2::mStep
protected

Definition at line 508 of file setupitem.h.

Referenced by createControls().

◆ mValues

SetupItemNames* SetupItemSlider2::mValues
protected

Definition at line 505 of file setupitem.h.

Referenced by getMaxWidth(), and updateLabel().


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