ManaPlus
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

#include <slider.h>

Inheritance diagram for Slider:
Widget MouseListener KeyListener Widget2

Public Member Functions

 Slider (Widget2 *const widget, const double scaleEnd, const double stepLength)
 
 Slider (Widget2 *const widget, const double scaleStart, const double scaleEnd, const double stepLength)
 
 ~Slider ()
 
void updateAlpha ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void mouseEntered (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseWheelMovedUp (MouseEvent &event)
 
void mouseWheelMovedDown (MouseEvent &event)
 
void keyPressed (KeyEvent &event)
 
void setScale (const double scaleStart, const double scaleEnd)
 
double getScaleStart () const
 
void setScaleStart (const double scaleStart)
 
double getScaleEnd () const
 
void setScaleEnd (const double scaleEnd)
 
void setValue (const double value)
 
double getValue () const
 
int getMarkerLength () const
 
void setMarkerLength (const int length)
 
void setOrientation (const OrientationT orientation)
 
OrientationT getOrientation () const
 
void setStepLength (const double length)
 
double getStepLength () const
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
virtual void logic ()
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
virtual void setFocusHandler (FocusHandler *const focusHandler)
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
virtual WidgetgetWidgetAt (int x, int y)
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual Rect getChildrenArea ()
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
virtual void moveToTop (Widget *widget)
 
virtual void moveToBottom (Widget *widget)
 
virtual void focusNext ()
 
virtual void focusPrevious ()
 
virtual void showWidgetPart (Widget *const widget, const Rect &area)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- 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)
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseMoved (MouseEvent &event)
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 

Private Member Functions

void init ()
 
double markerPositionToValue (const int position) const
 
int valueToMarkerPosition (const double value) const
 
int getMarkerPosition () const
 

Private Attributes

double mValue
 
double mStepLength
 
double mScaleStart
 
double mScaleEnd
 
OrientationT mOrientation
 
ImageCollectionmVertexes
 
int mMarkerLength
 
bool mHasMouse
 

Static Private Attributes

static ImageRect buttons [2]
 
static float mAlpha = 1.0
 
static int mInstances = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Slider widget. Same as the Guichan slider but with custom look.

Definition at line 85 of file slider.h.

Constructor & Destructor Documentation

◆ Slider() [1/2]

Slider::Slider ( Widget2 *const  widget,
const double  scaleEnd,
const double  stepLength 
)

Constructor with scale start equal to 0.

Definition at line 96 of file slider.cpp.

References init().

98  :
99  Widget(widget),
100  MouseListener(),
101  KeyListener(),
102  mValue(0),
103  mStepLength(stepLength),
104  mScaleStart(0),
105  mScaleEnd(scaleEnd),
108  mMarkerLength(10),
109  mHasMouse(false)
110 {
111  init();
112 }
OrientationT mOrientation
Definition: slider.h:325
double mStepLength
Definition: slider.h:309
ImageCollection * mVertexes
Definition: slider.h:327
void init()
Definition: slider.cpp:147
int mMarkerLength
Definition: slider.h:332
double mScaleEnd
Definition: slider.h:319
bool mHasMouse
Definition: slider.h:334
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
double mValue
Definition: slider.h:303
double mScaleStart
Definition: slider.h:314

◆ Slider() [2/2]

Slider::Slider ( Widget2 *const  widget,
const double  scaleStart,
const double  scaleEnd,
const double  stepLength 
)

Constructor.

Definition at line 114 of file slider.cpp.

References init().

117  :
118  Widget(widget),
119  MouseListener(),
120  KeyListener(),
121  mValue(scaleStart),
122  mStepLength(stepLength),
123  mScaleStart(scaleStart),
124  mScaleEnd(scaleEnd),
127  mMarkerLength(10),
128  mHasMouse(false)
129 {
130  init();
131 }
OrientationT mOrientation
Definition: slider.h:325
double mStepLength
Definition: slider.h:309
ImageCollection * mVertexes
Definition: slider.h:327
void init()
Definition: slider.cpp:147
int mMarkerLength
Definition: slider.h:332
double mScaleEnd
Definition: slider.h:319
bool mHasMouse
Definition: slider.h:334
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
double mValue
Definition: slider.h:303
double mScaleStart
Definition: slider.h:314

◆ ~Slider()

Slider::~Slider ( )

Destructor.

Definition at line 133 of file slider.cpp.

References buttons, delete2, gui, mInstances, mVertexes, Gui::removeDragged(), and Theme::unloadRect().

134 {
135  if (gui != nullptr)
136  gui->removeDragged(this);
137 
139  mInstances--;
140  if (mInstances == 0)
141  {
142  for (int mode = 0; mode < 2; mode ++)
143  Theme::unloadRect(buttons[mode], 0, 8);
144  }
145 }
static int mInstances
Definition: slider.h:298
static ImageRect buttons[2]
Definition: slider.h:296
Gui * gui
Definition: gui.cpp:110
ImageCollection * mVertexes
Definition: slider.h:327
#define delete2(var)
Definition: delete2.h:24
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1160
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:914

Member Function Documentation

◆ draw()

void Slider::draw ( Graphics *const  graphics)
virtual

Draws the slider.

Implements Widget.

Definition at line 194 of file slider.cpp.

References BLOCK_END, BLOCK_START, buttons, Graphics::calcPattern(), Graphics::calcTileCollection(), ImageCollection::clear(), Graphics::drawTileCollection(), Graphics::finalize(), Image::getHeight(), Widget::getHeight(), getMarkerPosition(), Graphics::getRedraw(), Image::getWidth(), Widget::getWidth(), ImageRect::grid, Rect::height, SliderGrid::HEND, SliderGrid::HGRIP, SliderGrid::HMID, SliderGrid::HSTART, Widget::mDimension, mHasMouse, Widget::mRedraw, mVertexes, updateAlpha(), x, and y.

195 {
196  BLOCK_START("Slider::draw")
197  if ((buttons[0].grid[SliderGrid::HSTART] == nullptr) ||
198  (buttons[1].grid[SliderGrid::HSTART] == nullptr) ||
199  (buttons[0].grid[SliderGrid::HEND] == nullptr))
200  {
201  BLOCK_END("Slider::draw")
202  return;
203  }
204 
205  int w = getWidth();
206  const int h = getHeight();
207  const int y = mHasMouse ?
208  (h - buttons[1].grid[SliderGrid::HSTART]->getHeight()) / 2 :
209  (h - buttons[0].grid[SliderGrid::HSTART]->getHeight()) / 2;
210 
211  updateAlpha();
212 
213  if (mRedraw || graphics->getRedraw())
214  {
215  int x = 0;
216  mRedraw = false;
217  mVertexes->clear();
218  if (!mHasMouse)
219  {
220  graphics->calcTileCollection(mVertexes,
221  buttons[0].grid[SliderGrid::HSTART],
222  x, y);
223 
224  const int width = buttons[0].grid[SliderGrid::HSTART]->getWidth();
225  w -= width + buttons[0].grid[SliderGrid::HEND]->getWidth();
226  x += width;
227 
228  if (buttons[0].grid[SliderGrid::HMID] != nullptr)
229  {
230  const Image *const hMid = buttons[0].grid[SliderGrid::HMID];
231  graphics->calcPattern(mVertexes,
232  hMid,
233  x, y,
234  w, hMid->getHeight());
235  }
236 
237  x += w;
238  graphics->calcTileCollection(mVertexes,
239  buttons[0].grid[SliderGrid::HEND],
240  x, y);
241 
242  const Image *const img = buttons[0].grid[SliderGrid::HGRIP];
243  if (img != nullptr)
244  {
245  graphics->calcTileCollection(mVertexes,
246  img,
248  (mDimension.height - img->getHeight()) / 2);
249  }
250  }
251  else
252  {
253  graphics->calcTileCollection(mVertexes,
254  buttons[1].grid[SliderGrid::HSTART],
255  x, y);
256 
257  const int width = buttons[1].grid[SliderGrid::HSTART]->getWidth();
258  w -= width;
259  if (buttons[1].grid[SliderGrid::HEND] != nullptr)
261  x += width;
262 
263  if (buttons[1].grid[SliderGrid::HMID] != nullptr)
264  {
265  const Image *const hMid = buttons[1].grid[SliderGrid::HMID];
266  graphics->calcPattern(mVertexes,
267  hMid,
268  x, y,
269  w, hMid->getHeight());
270  }
271 
272  x += w;
273  if (buttons[1].grid[SliderGrid::HEND] != nullptr)
274  {
275  graphics->calcTileCollection(mVertexes,
276  buttons[1].grid[SliderGrid::HEND], x, y);
277  }
278 
279  const Image *const img = buttons[1].grid[SliderGrid::HGRIP];
280  if (img != nullptr)
281  {
282  graphics->calcTileCollection(mVertexes,
283  img,
285  (mDimension.height - img->getHeight()) / 2);
286  }
287  }
288  graphics->finalize(mVertexes);
289  }
290  graphics->drawTileCollection(mVertexes);
291 
292  BLOCK_END("Slider::draw")
293 }
int getWidth() const
Definition: widget.h:220
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
void updateAlpha()
Definition: slider.cpp:175
static ImageRect buttons[2]
Definition: slider.h:296
ImageCollection * mVertexes
Definition: slider.h:327
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
bool mHasMouse
Definition: slider.h:334
virtual void finalize(ImageCollection *const col)
Definition: graphics.h:464
int getMarkerPosition() const
Definition: slider.h:293
Image * grid[9]
Definition: imagerect.h:41
int height
Definition: rect.h:223
virtual void calcPattern(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
bool mRedraw
Definition: widget.h:1163
Definition: image.h:61
virtual void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)=0
int getHeight() const
Definition: widget.h:239
int getWidth() const A_INLINE
Definition: image.h:116
Rect mDimension
Definition: widget.h:1100
int getHeight() const A_INLINE
Definition: image.h:122

◆ getMarkerLength()

int Slider::getMarkerLength ( ) const
inline

Gets the length of the marker.

Returns
The length of the marker.
See also
setMarkerLength

Definition at line 212 of file slider.h.

References mMarkerLength.

213  { return mMarkerLength; }
int mMarkerLength
Definition: slider.h:332

◆ getMarkerPosition()

int Slider::getMarkerPosition ( ) const
inlineprivate

Gets the marker position of the current selected value.

Returns
The marker position of the current selected value.

Definition at line 293 of file slider.h.

References getValue(), and valueToMarkerPosition().

Referenced by draw(), and safeDraw().

294  { return valueToMarkerPosition(getValue()); }
double getValue() const
Definition: slider.h:203
int valueToMarkerPosition(const double value) const
Definition: slider.cpp:498

◆ getOrientation()

OrientationT Slider::getOrientation ( ) const
inline

Gets the orientation of the slider. A slider can be drawn vertically or horizontally.

Returns
The orientation of the slider.
See also
setOrientation

Definition at line 241 of file slider.h.

References mOrientation.

242  { return mOrientation; }
OrientationT mOrientation
Definition: slider.h:325

◆ getScaleEnd()

double Slider::getScaleEnd ( ) const
inline

Gets the end value of the scale.

Returns
The end value of the scale.
See also
setScaleEnd, setScale

Definition at line 177 of file slider.h.

References mScaleEnd.

178  { return mScaleEnd; }
double mScaleEnd
Definition: slider.h:319

◆ getScaleStart()

double Slider::getScaleStart ( ) const
inline

Gets the start value of the scale.

Returns
The start value of the scale.
See also
setScaleStart, setScale

Definition at line 159 of file slider.h.

References mScaleStart.

Referenced by Setup_Video::action().

160  { return mScaleStart; }
double mScaleStart
Definition: slider.h:314

◆ getStepLength()

double Slider::getStepLength ( ) const
inline

Gets the step length. The step length is used when the keys LEFT and RIGHT are pressed to step in the scale.

Returns
the step length.
See also
setStepLength

Definition at line 261 of file slider.h.

References init(), markerPositionToValue(), mStepLength, and valueToMarkerPosition().

262  { return mStepLength; }
double mStepLength
Definition: slider.h:309

◆ getValue()

double Slider::getValue ( ) const
inline

◆ init()

void Slider::init ( )
private

Used to initialize instances.

Definition at line 147 of file slider.cpp.

References Widget::addKeyListener(), Widget::addMouseListener(), buttons, data, Widget::getWidth(), SliderGrid::HGRIP, Theme::loadRect(), Widget::mAllowLogic, mInstances, Widget::setFocusable(), Widget::setFrameSize(), setMarkerLength(), theme, and updateAlpha().

Referenced by getStepLength(), and Slider().

148 {
149  mAllowLogic = false;
150  setFocusable(true);
151  setFrameSize(1);
152 
153  addMouseListener(this);
154  addKeyListener(this);
155 
156  setFrameSize(0);
157 
158  // Load resources
159  if (mInstances == 0)
160  {
161  if (theme != nullptr)
162  {
163  for (int mode = 0; mode < 2; mode ++)
164  theme->loadRect(buttons[mode], data[mode], "slider.xml", 0, 8);
165  }
166  updateAlpha();
167  }
168 
169  mInstances++;
170 
171  if (buttons[0].grid[SliderGrid::HGRIP] != nullptr)
173 }
void loadRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:882
void setMarkerLength(const int length)
Definition: slider.h:221
int getWidth() const
Definition: widget.h:220
static int mInstances
Definition: slider.h:298
void updateAlpha()
Definition: slider.cpp:175
static ImageRect buttons[2]
Definition: slider.h:296
static std::string const data[2]
Definition: slider.cpp:90
void setFrameSize(const unsigned int frameSize)
Definition: widget.h:167
bool mAllowLogic
Definition: widget.h:1159
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
Theme * theme
Definition: theme.cpp:61
void setFocusable(const bool focusable)
Definition: widget.cpp:191

◆ keyPressed()

void Slider::keyPressed ( KeyEvent event)
virtual

Called if a key is pressed when the widget has keyboard focus. If a key is held down the widget will generate multiple key presses.

Parameters
eventDiscribes the event.

Reimplemented from KeyListener.

Definition at line 431 of file slider.cpp.

References Widget::distributeActionEvent(), InputAction::GUI_DOWN, InputAction::GUI_LEFT, InputAction::GUI_RIGHT, InputAction::GUI_UP, Orientation::HORIZONTAL, mOrientation, mStepLength, mValue, and setValue().

432 {
433  const InputActionT action = event.getActionId();
434 
436  {
437  if (action == InputAction::GUI_RIGHT)
438  {
441  event.consume();
442  }
443  else if (action == InputAction::GUI_LEFT)
444  {
447  event.consume();
448  }
449  }
450  else
451  {
452  if (action == InputAction::GUI_UP)
453  {
456  event.consume();
457  }
458  else if (action == InputAction::GUI_DOWN)
459  {
462  event.consume();
463  }
464  }
465 }
OrientationT mOrientation
Definition: slider.h:325
double mStepLength
Definition: slider.h:309
void distributeActionEvent()
Definition: widget.cpp:492
InputAction ::T InputActionT
Definition: inputaction.h:715
double mValue
Definition: slider.h:303
void setValue(const double value)
Definition: slider.cpp:473

◆ markerPositionToValue()

double Slider::markerPositionToValue ( const int  position) const
private

Converts a marker position to a value in the scale.

Parameters
positionThe position to convert.
Returns
A scale value corresponding to the position.
See also
valueToMarkerPosition

Definition at line 486 of file slider.cpp.

References Rect::height, Orientation::HORIZONTAL, Widget::mDimension, mMarkerLength, mOrientation, mScaleEnd, mScaleStart, and Rect::width.

Referenced by getStepLength(), mouseDragged(), and mousePressed().

487 {
488  int w;
490  w = mDimension.width;
491  else
492  w = mDimension.height;
493 
494  const double pos = v / (static_cast<double>(w) - mMarkerLength);
495  return (1.0 - pos) * mScaleStart + pos * mScaleEnd;
496 }
int width
Definition: rect.h:218
OrientationT mOrientation
Definition: slider.h:325
int mMarkerLength
Definition: slider.h:332
double mScaleEnd
Definition: slider.h:319
int height
Definition: rect.h:223
double mScaleStart
Definition: slider.h:314
Rect mDimension
Definition: widget.h:1100

◆ mouseDragged()

void Slider::mouseDragged ( MouseEvent event)
virtual

Called when the mouse has moved and the mouse has previously been pressed on the widget.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 400 of file slider.cpp.

References Widget::distributeActionEvent(), MouseEvent::getX(), MouseEvent::getY(), Rect::height, Orientation::HORIZONTAL, markerPositionToValue(), Widget::mDimension, mMarkerLength, mOrientation, and setValue().

401 {
403  {
405  }
406  else
407  {
409  mDimension.height - event.getY() - mMarkerLength / 2));
410  }
411 
413 
414  event.consume();
415 }
OrientationT mOrientation
Definition: slider.h:325
int mMarkerLength
Definition: slider.h:332
void distributeActionEvent()
Definition: widget.cpp:492
double markerPositionToValue(const int position) const
Definition: slider.cpp:486
int height
Definition: rect.h:223
int getY() const
Definition: mouseevent.h:137
void setValue(const double value)
Definition: slider.cpp:473
int getX() const
Definition: mouseevent.h:126
Rect mDimension
Definition: widget.h:1100

◆ mouseEntered()

void Slider::mouseEntered ( MouseEvent event)
virtual

Called when the mouse enteres the widget area.

Reimplemented from MouseListener.

Definition at line 369 of file slider.cpp.

References mHasMouse, and Widget::mRedraw.

370 {
371  mHasMouse = true;
372  mRedraw = true;
373 }
bool mHasMouse
Definition: slider.h:334
bool mRedraw
Definition: widget.h:1163

◆ mouseExited()

void Slider::mouseExited ( MouseEvent event)
virtual

Called when the mouse leaves the widget area.

Reimplemented from MouseListener.

Definition at line 375 of file slider.cpp.

References mHasMouse, and Widget::mRedraw.

376 {
377  mHasMouse = false;
378  mRedraw = true;
379 }
bool mHasMouse
Definition: slider.h:334
bool mRedraw
Definition: widget.h:1163

◆ mousePressed()

void Slider::mousePressed ( MouseEvent event)
virtual

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 381 of file slider.cpp.

References Widget::distributeActionEvent(), MouseEvent::getButton(), Rect::height, Orientation::HORIZONTAL, MouseButton::LEFT, markerPositionToValue(), Widget::mDimension, mMarkerLength, mOrientation, setValue(), Rect::width, x, and y.

382 {
383  const int x = event.getX();
384  const int y = event.getY();
385  const int width = mDimension.width;
386  const int height = mDimension.height;
387 
388  if (event.getButton() == MouseButton::LEFT
389  && x >= 0 && x <= width && y >= 0 && y <= height)
390  {
391  event.consume();
394  else
395  setValue(markerPositionToValue(height - y - mMarkerLength / 2));
397  }
398 }
int width
Definition: rect.h:218
OrientationT mOrientation
Definition: slider.h:325
MouseButtonT getButton() const
Definition: mouseevent.h:115
int mMarkerLength
Definition: slider.h:332
void distributeActionEvent()
Definition: widget.cpp:492
double markerPositionToValue(const int position) const
Definition: slider.cpp:486
int height
Definition: rect.h:223
void setValue(const double value)
Definition: slider.cpp:473
Rect mDimension
Definition: widget.h:1100

◆ mouseWheelMovedDown()

void Slider::mouseWheelMovedDown ( MouseEvent event)
virtual

Called when the mouse wheel has moved down on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 424 of file slider.cpp.

References Widget::distributeActionEvent(), mStepLength, mValue, and setValue().

425 {
428  event.consume();
429 }
double mStepLength
Definition: slider.h:309
void distributeActionEvent()
Definition: widget.cpp:492
double mValue
Definition: slider.h:303
void setValue(const double value)
Definition: slider.cpp:473

◆ mouseWheelMovedUp()

void Slider::mouseWheelMovedUp ( MouseEvent event)
virtual

Called when the mouse wheel has moved up on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 417 of file slider.cpp.

References Widget::distributeActionEvent(), mStepLength, mValue, and setValue().

418 {
421  event.consume();
422 }
double mStepLength
Definition: slider.h:309
void distributeActionEvent()
Definition: widget.cpp:492
double mValue
Definition: slider.h:303
void setValue(const double value)
Definition: slider.cpp:473

◆ safeDraw()

void Slider::safeDraw ( Graphics *const  graphics)
virtual

Implements Widget.

Definition at line 295 of file slider.cpp.

References BLOCK_END, BLOCK_START, buttons, Graphics::drawImage(), Graphics::drawPattern(), Image::getHeight(), Widget::getHeight(), getMarkerPosition(), Image::getWidth(), Widget::getWidth(), ImageRect::grid, Rect::height, SliderGrid::HEND, SliderGrid::HGRIP, SliderGrid::HMID, SliderGrid::HSTART, Widget::mDimension, mHasMouse, updateAlpha(), x, and y.

296 {
297  BLOCK_START("Slider::draw")
298  if ((buttons[0].grid[SliderGrid::HSTART] == nullptr) ||
299  (buttons[1].grid[SliderGrid::HSTART] == nullptr) ||
300  (buttons[0].grid[SliderGrid::HEND] == nullptr))
301  {
302  BLOCK_END("Slider::draw")
303  return;
304  }
305 
306  int w = getWidth();
307  const int h = getHeight();
308  int x = 0;
309  const int y = mHasMouse ?
310  (h - buttons[1].grid[SliderGrid::HSTART]->getHeight()) / 2 :
311  (h - buttons[0].grid[SliderGrid::HSTART]->getHeight()) / 2;
312 
313  updateAlpha();
314 
315  if (!mHasMouse)
316  {
317  graphics->drawImage(buttons[0].grid[SliderGrid::HSTART], x, y);
318  const int width = buttons[0].grid[SliderGrid::HSTART]->getWidth();
319  w -= width + buttons[0].grid[SliderGrid::HEND]->getWidth();
320  x += width;
321 
322  if (buttons[0].grid[SliderGrid::HMID] != nullptr)
323  {
324  const Image *const hMid = buttons[0].grid[SliderGrid::HMID];
325  graphics->drawPattern(hMid, x, y, w, hMid->getHeight());
326  }
327 
328  x += w;
329  graphics->drawImage(buttons[0].grid[SliderGrid::HEND], x, y);
330 
331  const Image *const img = buttons[0].grid[SliderGrid::HGRIP];
332  if (img != nullptr)
333  {
334  graphics->drawImage(img, getMarkerPosition(),
335  (mDimension.height - img->getHeight()) / 2);
336  }
337  }
338  else
339  {
340  graphics->drawImage(buttons[1].grid[SliderGrid::HSTART], x, y);
341 
342  const int width = buttons[1].grid[SliderGrid::HSTART]->getWidth();
343  w -= width;
344  if (buttons[1].grid[SliderGrid::HEND] != nullptr)
346  x += width;
347 
348  if (buttons[1].grid[SliderGrid::HMID] != nullptr)
349  {
350  const Image *const hMid = buttons[1].grid[SliderGrid::HMID];
351  graphics->drawPattern(hMid, x, y, w, hMid->getHeight());
352  }
353 
354  x += w;
355  if (buttons[1].grid[SliderGrid::HEND] != nullptr)
356  graphics->drawImage(buttons[1].grid[SliderGrid::HEND], x, y);
357 
358  const Image *const img = buttons[1].grid[SliderGrid::HGRIP];
359  if (img != nullptr)
360  {
361  graphics->drawImage(img, getMarkerPosition(),
362  (mDimension.height - img->getHeight()) / 2);
363  }
364  }
365 
366  BLOCK_END("Slider::draw")
367 }
int getWidth() const
Definition: widget.h:220
void updateAlpha()
Definition: slider.cpp:175
static ImageRect buttons[2]
Definition: slider.h:296
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
bool mHasMouse
Definition: slider.h:334
int getMarkerPosition() const
Definition: slider.h:293
Image * grid[9]
Definition: imagerect.h:41
int height
Definition: rect.h:223
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Definition: image.h:61
int getHeight() const
Definition: widget.h:239
int getWidth() const A_INLINE
Definition: image.h:116
virtual void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)=0
Rect mDimension
Definition: widget.h:1100
int getHeight() const A_INLINE
Definition: image.h:122

◆ setMarkerLength()

void Slider::setMarkerLength ( const int  length)
inline

Sets the length of the marker.

Parameters
lengthThe length for the marker.
See also
getMarkerLength

Definition at line 221 of file slider.h.

References mMarkerLength.

Referenced by init().

222  { mMarkerLength = length; }
int mMarkerLength
Definition: slider.h:332

◆ setOrientation()

void Slider::setOrientation ( const OrientationT  orientation)
inline

Sets the orientation of the slider. A slider can be drawn vertically or horizontally.

Parameters
orientationThe orientation of the slider.
See also
getOrientation

Definition at line 231 of file slider.h.

References mOrientation.

232  { mOrientation = orientation; }
OrientationT mOrientation
Definition: slider.h:325

◆ setScale()

void Slider::setScale ( const double  scaleStart,
const double  scaleEnd 
)

Sets the scale of the slider.

Parameters
scaleStartThe start value of the scale.
scaleEndtThe end of value the scale.
See also
getScaleStart, getScaleEnd

Definition at line 467 of file slider.cpp.

References mScaleEnd, and mScaleStart.

Referenced by BuyDialog::updateSlider(), Setup_Colors::valueChanged(), SellDialog::valueChanged(), and BuyDialog::valueChanged().

468 {
469  mScaleStart = scaleStart;
470  mScaleEnd = scaleEnd;
471 }
double mScaleEnd
Definition: slider.h:319
double mScaleStart
Definition: slider.h:314

◆ setScaleEnd()

void Slider::setScaleEnd ( const double  scaleEnd)
inline

Sets the end value of the scale.

Parameters
scaleEndThe end value of the scale.
See also
getScaleEnd

Definition at line 186 of file slider.h.

References mScaleEnd, and setValue().

187  { mScaleEnd = scaleEnd; }
double mScaleEnd
Definition: slider.h:319

◆ setScaleStart()

void Slider::setScaleStart ( const double  scaleStart)
inline

Sets the start value of the scale.

Parameters
scaleStartThe start value of the scale.
See also
getScaleStart

Definition at line 168 of file slider.h.

References mScaleStart.

169  { mScaleStart = scaleStart; }
double mScaleStart
Definition: slider.h:314

◆ setStepLength()

void Slider::setStepLength ( const double  length)
inline

Sets the step length. The step length is used when the keys LEFT and RIGHT are pressed to step in the scale.

Parameters
lengthThe step length.
See also
getStepLength

Definition at line 251 of file slider.h.

References mStepLength.

252  { mStepLength = length; }
double mStepLength
Definition: slider.h:309

◆ setValue()

void Slider::setValue ( const double  value)

Sets the current selected value.

Parameters
valueThe current selected value.
See also
getValue

Definition at line 473 of file slider.cpp.

References CAST_S32, Widget::mRedraw, mScaleEnd, mScaleStart, mStepLength, and mValue.

Referenced by Setup_Video::action(), ItemAmountWindow::action(), SellDialog::action(), BuyDialog::action(), Setup_Colors::cancel(), Setup_Video::cancel(), SetupItemSlider::createControls(), SetupItemSlider2::createControls(), keyPressed(), ItemAmountWindow::keyReleased(), mouseDragged(), mousePressed(), mouseWheelMovedDown(), mouseWheelMovedUp(), SellDialog::reset(), BuyDialog::reset(), NpcSellDialog::sellOneItem(), Setup_Colors::setEntry(), setScaleEnd(), Setup_Colors::Setup_Colors(), Setup_Video::Setup_Video(), SetupItemSlider::toWidget(), SetupItemSlider2::toWidget(), BuyDialog::updateSlider(), Setup_Colors::valueChanged(), SellDialog::valueChanged(), and BuyDialog::valueChanged().

474 {
475  mRedraw = true;
476  if (value > mScaleEnd)
477  mValue = mScaleEnd;
478  else if (value < mScaleStart)
480  else
481  mValue = value;
484 }
double mStepLength
Definition: slider.h:309
double mScaleEnd
Definition: slider.h:319
#define CAST_S32
Definition: cast.h:29
double mValue
Definition: slider.h:303
double mScaleStart
Definition: slider.h:314
bool mRedraw
Definition: widget.h:1163

◆ updateAlpha()

void Slider::updateAlpha ( )

Update the alpha value to the graphic components.

Definition at line 175 of file slider.cpp.

References buttons, Theme::getMinimumOpacity(), ImageRect::grid, Settings::guiAlpha, mAlpha, Image::setAlpha(), settings, SliderGrid::SLIDER_MAX, and theme.

Referenced by draw(), init(), and safeDraw().

176 {
177  const float alpha = std::max(settings.guiAlpha,
179 
180  if (alpha != mAlpha)
181  {
182  mAlpha = alpha;
183  for (int f = 0; f < 2; f ++)
184  {
185  for (int d = 0; d < SliderGrid::SLIDER_MAX; d ++)
186  {
187  if (buttons[f].grid[d] != nullptr)
188  buttons[f].grid[d]->setAlpha(mAlpha);
189  }
190  }
191  }
192 }
static ImageRect buttons[2]
Definition: slider.h:296
float getMinimumOpacity() const
Definition: theme.h:123
Settings settings
Definition: settings.cpp:31
virtual void setAlpha(const float alpha)
Definition: image.cpp:286
Image * grid[9]
Definition: imagerect.h:41
Theme * theme
Definition: theme.cpp:61
static float mAlpha
Definition: slider.h:297
float guiAlpha
Definition: settings.h:129

◆ valueToMarkerPosition()

int Slider::valueToMarkerPosition ( const double  value) const
private

Converts a value to a marker position.

Parameters
valueThe value to convert.
Returns
A marker position corresponding to the value.
See also
markerPositionToValue

Definition at line 498 of file slider.cpp.

References CAST_S32, Rect::height, Orientation::HORIZONTAL, Widget::mDimension, mMarkerLength, mOrientation, mScaleEnd, mScaleStart, and Rect::width.

Referenced by getMarkerPosition(), and getStepLength().

499 {
500  int v;
502  v = mDimension.width;
503  else
504  v = mDimension.height;
505 
506  const int w = CAST_S32((v - mMarkerLength)
507  * (value - mScaleStart)
508  / (mScaleEnd - mScaleStart));
509 
510  if (w < 0)
511  return 0;
512 
513  if (w > v - mMarkerLength)
514  return v - mMarkerLength;
515 
516  return w;
517 }
int width
Definition: rect.h:218
OrientationT mOrientation
Definition: slider.h:325
int mMarkerLength
Definition: slider.h:332
double mScaleEnd
Definition: slider.h:319
#define CAST_S32
Definition: cast.h:29
int height
Definition: rect.h:223
double mScaleStart
Definition: slider.h:314
Rect mDimension
Definition: widget.h:1100

Field Documentation

◆ buttons

ImageRect Slider::buttons
staticprivate

Definition at line 296 of file slider.h.

Referenced by draw(), init(), safeDraw(), updateAlpha(), and ~Slider().

◆ mAlpha

float Slider::mAlpha = 1.0
staticprivate

Definition at line 297 of file slider.h.

Referenced by updateAlpha().

◆ mHasMouse

bool Slider::mHasMouse
private

Definition at line 334 of file slider.h.

Referenced by draw(), mouseEntered(), mouseExited(), and safeDraw().

◆ mInstances

int Slider::mInstances = 0
staticprivate

Definition at line 298 of file slider.h.

Referenced by init(), and ~Slider().

◆ mMarkerLength

int Slider::mMarkerLength
private

Holds the length of the marker.

Definition at line 332 of file slider.h.

Referenced by getMarkerLength(), markerPositionToValue(), mouseDragged(), mousePressed(), setMarkerLength(), and valueToMarkerPosition().

◆ mOrientation

OrientationT Slider::mOrientation
private

Holds the orientation of the slider. A slider can be drawn vertically or horizontally.

Definition at line 325 of file slider.h.

Referenced by getOrientation(), keyPressed(), markerPositionToValue(), mouseDragged(), mousePressed(), setOrientation(), and valueToMarkerPosition().

◆ mScaleEnd

double Slider::mScaleEnd
private

Holds the end value of the scale.

Definition at line 319 of file slider.h.

Referenced by getScaleEnd(), markerPositionToValue(), setScale(), setScaleEnd(), setValue(), and valueToMarkerPosition().

◆ mScaleStart

double Slider::mScaleStart
private

Holds the start value of the scale.

Definition at line 314 of file slider.h.

Referenced by getScaleStart(), markerPositionToValue(), setScale(), setScaleStart(), setValue(), and valueToMarkerPosition().

◆ mStepLength

double Slider::mStepLength
private

Holds the step length. The step length is used when the keys LEFT and RIGHT are pressed to step in the scale.

Definition at line 309 of file slider.h.

Referenced by getStepLength(), keyPressed(), mouseWheelMovedDown(), mouseWheelMovedUp(), setStepLength(), and setValue().

◆ mValue

double Slider::mValue
private

Holds the current selected value.

Definition at line 303 of file slider.h.

Referenced by getValue(), keyPressed(), mouseWheelMovedDown(), mouseWheelMovedUp(), and setValue().

◆ mVertexes

ImageCollection* Slider::mVertexes
private

Definition at line 327 of file slider.h.

Referenced by draw(), and ~Slider().


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