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

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

993  :
994  SetupItem(text, description, keyName, parent, eventName, mainConfig),
995  mHorizont(nullptr),
996  mLabel(nullptr),
997  mLabel2(nullptr),
998  mSlider(nullptr),
999  mValues(values),
1000  mMin(min),
1001  mMax(max),
1002  mStep(step),
1003  mInvertValue(0),
1004  mInvert(false),
1005  mOnTheFly(onTheFly),
1006  mDoNotAlign(doNotAlign)
1007 {
1008  mValueType = VSTR;
1009  createControls();
1010 }
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 1012 of file setupitem.cpp.

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

1024  :
1025  SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
1026  mHorizont(nullptr),
1027  mLabel(nullptr),
1028  mLabel2(nullptr),
1029  mSlider(nullptr),
1030  mValues(values),
1031  mMin(min),
1032  mMax(max),
1033  mStep(step),
1034  mInvertValue(0),
1035  mInvert(false),
1036  mOnTheFly(onTheFly),
1037  mDoNotAlign(doNotAlign)
1038 {
1039  mValueType = VSTR;
1040  createControls();
1041 }
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 1043 of file setupitem.cpp.

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

1044 {
1045  mHorizont = nullptr;
1046  mWidget = nullptr;
1047  mSlider = nullptr;
1048  mLabel = nullptr;
1049 }
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 1128 of file setupitem.cpp.

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

1129 {
1130  fromWidget();
1131  updateLabel();
1132  if (mOnTheFly == OnTheFly_true)
1133  save();
1134 }
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 1153 of file setupitem.cpp.

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

1154 {
1155  if (eventName != mEventName)
1156  return;
1157 
1158  fromWidget();
1159  save();
1160 }
std::string mEventName
Definition: setupitem.h:136
virtual void save()
Definition: setupitem.cpp:145

◆ createControls()

void SetupItemSlider2::createControls ( )

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

1052 {
1053  load();
1054  mHorizont = new HorizontContainer(this, 32, 2);
1055 
1056  const int width = getMaxWidth();
1057 
1058  mLabel = new Label(this, mText);
1060  mLabel2 = new Label(this, "");
1061  mLabel2->setWidth(width);
1062  mSlider = new Slider(this, mMin, mMax, mStep);
1065  mSlider->setValue(atof(mValue.c_str()));
1066  mSlider->setHeight(30);
1067 
1068  mWidget = mSlider;
1069  mSlider->setWidth(150);
1070  mSlider->setHeight(40);
1073  mHorizont->add(mLabel);
1074  mHorizont->add(mSlider, -10);
1075  mHorizont->add(mLabel2);
1076 
1077  mParent->getContainer()->add2(mHorizont, true, 4);
1078  mParent->addControl(this);
1079  mParent->addActionListener(this);
1080  mWidget->addActionListener(this);
1081  updateLabel();
1082 }
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 1105 of file setupitem.cpp.

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

Referenced by action(), and apply().

1106 {
1107  if (mSlider == nullptr)
1108  return;
1109 
1110  int val = roundDouble(mSlider->getValue());
1111  if (mInvert)
1112  val = mInvertValue - val;
1113  mValue = toString(val);
1114 }
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 1084 of file setupitem.cpp.

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

Referenced by createControls().

1085 {
1086  if ((mValues == nullptr) || (gui == nullptr))
1087  return 1;
1088 
1089  int maxWidth = 0;
1090  SetupItemNamesConstIter it = mValues->begin();
1091  const SetupItemNamesConstIter it_end = mValues->end();
1092  const Font *const font = gui->getFont();
1093 
1094  while (it != it_end)
1095  {
1096  const int w = font->getWidth(*it);
1097  if (w > maxWidth)
1098  maxWidth = w;
1099 
1100  ++ it;
1101  }
1102  return maxWidth;
1103 }
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 1162 of file setupitem.cpp.

References mInvert, mInvertValue, and toWidget().

1163 {
1164  mInvert = true;
1165  mInvertValue = v;
1166  toWidget();
1167 }

◆ toWidget()

void SetupItemSlider2::toWidget ( )
virtual

Implements SetupItem.

Definition at line 1116 of file setupitem.cpp.

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

Referenced by setInvertValue().

1117 {
1118  if (mSlider == nullptr)
1119  return;
1120 
1121  int val = roundDouble(atof(mValue.c_str()));
1122  if (mInvert)
1123  val = mInvertValue - val;
1124  mSlider->setValue(val);
1125  updateLabel();
1126 }
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 1136 of file setupitem.cpp.

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

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

1137 {
1138  int val = CAST_S32(mSlider->getValue()) - mMin;
1139  if (val < 0)
1140  {
1141  val = 0;
1142  }
1143  else
1144  {
1145  const int sz = CAST_S32(mValues->size());
1146  if (val >= sz)
1147  val = sz - 1;
1148  }
1149  std::string str = mValues->at(val);
1150  mLabel2->setCaption(str);
1151 }
#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: