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 86 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 97 of file slider.cpp.

99  :
100  Widget(widget),
101  MouseListener(),
102  KeyListener(),
103  mValue(0),
104  mStepLength(stepLength),
105  mScaleStart(0),
106  mScaleEnd(scaleEnd),
109  mMarkerLength(10),
110  mHasMouse(false)
111 {
112  init();
113 }
double mScaleEnd
Definition: slider.h:320
OrientationT mOrientation
Definition: slider.h:326
void init()
Definition: slider.cpp:148
double mStepLength
Definition: slider.h:310
ImageCollection * mVertexes
Definition: slider.h:328
bool mHasMouse
Definition: slider.h:335
double mScaleStart
Definition: slider.h:315
double mValue
Definition: slider.h:304
int mMarkerLength
Definition: slider.h:333
Widget(const Widget2 *const widget)
Definition: widget.cpp:85

References init().

◆ Slider() [2/2]

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

Constructor.

Definition at line 115 of file slider.cpp.

118  :
119  Widget(widget),
120  MouseListener(),
121  KeyListener(),
122  mValue(scaleStart),
123  mStepLength(stepLength),
124  mScaleStart(scaleStart),
125  mScaleEnd(scaleEnd),
128  mMarkerLength(10),
129  mHasMouse(false)
130 {
131  init();
132 }

References init().

◆ ~Slider()

Slider::~Slider ( )

Destructor.

Definition at line 134 of file slider.cpp.

135 {
136  if (gui != nullptr)
137  gui->removeDragged(this);
138 
140  mInstances--;
141  if (mInstances == 0)
142  {
143  for (int mode = 0; mode < 2; mode ++)
144  Theme::unloadRect(buttons[mode], 0, 8);
145  }
146 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
static ImageRect buttons[2]
Definition: slider.h:297
static int mInstances
Definition: slider.h:299
static void unloadRect(const ImageRect &rect, const int start, const int end)
Definition: theme.cpp:915
#define delete2(var)
Definition: delete2.h:25
Gui * gui
Definition: gui.cpp:111

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

Member Function Documentation

◆ draw()

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

Draws the slider.

Implements Widget.

Definition at line 195 of file slider.cpp.

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

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

◆ getMarkerLength()

int Slider::getMarkerLength ( ) const
inline

Gets the length of the marker.

Returns
The length of the marker.
See also
setMarkerLength

Definition at line 213 of file slider.h.

214  { return mMarkerLength; }

References mMarkerLength.

◆ 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 294 of file slider.h.

295  { return valueToMarkerPosition(getValue()); }
double getValue() const
Definition: slider.h:204
int valueToMarkerPosition(const double value) const
Definition: slider.cpp:499

References getValue(), and valueToMarkerPosition().

Referenced by draw(), and safeDraw().

◆ 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 242 of file slider.h.

243  { return mOrientation; }

References mOrientation.

◆ 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 178 of file slider.h.

179  { return mScaleEnd; }

References mScaleEnd.

◆ 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 160 of file slider.h.

161  { return mScaleStart; }

References mScaleStart.

Referenced by Setup_Video::action().

◆ 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 262 of file slider.h.

263  { return mStepLength; }

References mStepLength.

◆ getValue()

double Slider::getValue ( ) const
inline

◆ init()

void Slider::init ( )
private

Used to initialize instances.

Definition at line 148 of file slider.cpp.

149 {
150  mAllowLogic = false;
151  setFocusable(true);
152  setFrameSize(1);
153 
154  addMouseListener(this);
155  addKeyListener(this);
156 
157  setFrameSize(0);
158 
159  // Load resources
160  if (mInstances == 0)
161  {
162  if (theme != nullptr)
163  {
164  for (int mode = 0; mode < 2; mode ++)
165  theme->loadRect(buttons[mode], data[mode], "slider.xml", 0, 8);
166  }
167  updateAlpha();
168  }
169 
170  mInstances++;
171 
172  if (buttons[0].grid[SliderGrid::HGRIP] != nullptr)
174 }
void setMarkerLength(const int length)
Definition: slider.h:222
void loadRect(ImageRect &image, const std::string &name, const std::string &name2, const int start, const int end)
Definition: theme.cpp:883
void setFrameSize(const unsigned int frameSize)
Definition: widget.h:168
void setFocusable(const bool focusable)
Definition: widget.cpp:192
bool mAllowLogic
Definition: widget.h:1160
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
static std::string const data[2]
Definition: slider.cpp:91
Theme * theme
Definition: theme.cpp:62

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

◆ 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 432 of file slider.cpp.

433 {
434  const InputActionT action = event.getActionId();
435 
437  {
438  if (action == InputAction::GUI_RIGHT)
439  {
442  event.consume();
443  }
444  else if (action == InputAction::GUI_LEFT)
445  {
448  event.consume();
449  }
450  }
451  else
452  {
453  if (action == InputAction::GUI_UP)
454  {
457  event.consume();
458  }
459  else if (action == InputAction::GUI_DOWN)
460  {
463  event.consume();
464  }
465  }
466 }
void setValue(const double value)
Definition: slider.cpp:474
void distributeActionEvent()
Definition: widget.cpp:493
InputAction ::T InputActionT
Definition: inputaction.h:717

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

◆ 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 487 of file slider.cpp.

488 {
489  int w;
491  w = mDimension.width;
492  else
493  w = mDimension.height;
494 
495  const double pos = v / (static_cast<double>(w) - mMarkerLength);
496  return (1.0 - pos) * mScaleStart + pos * mScaleEnd;
497 }
int width
Definition: rect.h:219

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

Referenced by mouseDragged(), and mousePressed().

◆ 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 401 of file slider.cpp.

402 {
404  {
406  }
407  else
408  {
410  mDimension.height - event.getY() - mMarkerLength / 2));
411  }
412 
414 
415  event.consume();
416 }
int getX() const
Definition: mouseevent.h:127
int getY() const
Definition: mouseevent.h:138
double markerPositionToValue(const int position) const
Definition: slider.cpp:487

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

◆ mouseEntered()

void Slider::mouseEntered ( MouseEvent event)
virtual

Called when the mouse enteres the widget area.

Reimplemented from MouseListener.

Definition at line 370 of file slider.cpp.

371 {
372  mHasMouse = true;
373  mRedraw = true;
374 }

References mHasMouse, and Widget::mRedraw.

◆ mouseExited()

void Slider::mouseExited ( MouseEvent event)
virtual

Called when the mouse leaves the widget area.

Reimplemented from MouseListener.

Definition at line 376 of file slider.cpp.

377 {
378  mHasMouse = false;
379  mRedraw = true;
380 }

References mHasMouse, and Widget::mRedraw.

◆ 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 382 of file slider.cpp.

383 {
384  const int x = event.getX();
385  const int y = event.getY();
386  const int width = mDimension.width;
387  const int height = mDimension.height;
388 
389  if (event.getButton() == MouseButton::LEFT
390  && x >= 0 && x <= width && y >= 0 && y <= height)
391  {
392  event.consume();
395  else
398  }
399 }
MouseButtonT getButton() const
Definition: mouseevent.h:116

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

◆ 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 425 of file slider.cpp.

426 {
429  event.consume();
430 }

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

◆ 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 418 of file slider.cpp.

419 {
422  event.consume();
423 }

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

◆ safeDraw()

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

Implements Widget.

Definition at line 296 of file slider.cpp.

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

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

◆ 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 222 of file slider.h.

223  { mMarkerLength = length; }

References mMarkerLength.

Referenced by init().

◆ 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 232 of file slider.h.

233  { mOrientation = orientation; }

References mOrientation.

◆ 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 468 of file slider.cpp.

469 {
470  mScaleStart = scaleStart;
471  mScaleEnd = scaleEnd;
472 }

References mScaleEnd, and mScaleStart.

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

◆ 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 187 of file slider.h.

188  { mScaleEnd = scaleEnd; }

References mScaleEnd.

◆ 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 169 of file slider.h.

170  { mScaleStart = scaleStart; }

References mScaleStart.

◆ 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 252 of file slider.h.

253  { mStepLength = length; }

References mStepLength.

◆ setValue()

void Slider::setValue ( const double  value)

◆ updateAlpha()

void Slider::updateAlpha ( )

Update the alpha value to the graphic components.

Definition at line 176 of file slider.cpp.

177 {
178  const float alpha = std::max(settings.guiAlpha,
180 
181  if (alpha != mAlpha)
182  {
183  mAlpha = alpha;
184  for (int f = 0; f < 2; f ++)
185  {
186  for (int d = 0; d < SliderGrid::SLIDER_MAX; d ++)
187  {
188  if (buttons[f].grid[d] != nullptr)
189  buttons[f].grid[d]->setAlpha(mAlpha);
190  }
191  }
192  }
193 }
float guiAlpha
Definition: settings.h:131
static float mAlpha
Definition: slider.h:298
float getMinimumOpacity() const
Definition: theme.h:124
Settings settings
Definition: settings.cpp:32

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

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

◆ 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 499 of file slider.cpp.

500 {
501  int v;
503  v = mDimension.width;
504  else
505  v = mDimension.height;
506 
507  const int w = CAST_S32((v - mMarkerLength)
508  * (value - mScaleStart)
509  / (mScaleEnd - mScaleStart));
510 
511  if (w < 0)
512  return 0;
513 
514  if (w > v - mMarkerLength)
515  return v - mMarkerLength;
516 
517  return w;
518 }

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

Referenced by getMarkerPosition().

Field Documentation

◆ buttons

ImageRect Slider::buttons
staticprivate

Definition at line 297 of file slider.h.

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

◆ mAlpha

float Slider::mAlpha = 1.0
staticprivate

Definition at line 298 of file slider.h.

Referenced by updateAlpha().

◆ mHasMouse

bool Slider::mHasMouse
private

Definition at line 335 of file slider.h.

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

◆ mInstances

int Slider::mInstances = 0
staticprivate

Definition at line 299 of file slider.h.

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

◆ mMarkerLength

int Slider::mMarkerLength
private

Holds the length of the marker.

Definition at line 333 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 326 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 320 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 315 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 310 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 304 of file slider.h.

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

◆ mVertexes

ImageCollection* Slider::mVertexes
private

Definition at line 328 of file slider.h.

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


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