PCL
Slider.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/Slider.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Slider_h
53 #define __PCL_Slider_h
54 
56 
57 #include <pcl/Defs.h>
58 
59 #include <pcl/Flags.h>
60 
61 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
62 
63 #include <pcl/AutoPointer.h>
64 #include <pcl/Control.h>
65 
66 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
67 
68 namespace pcl
69 {
70 
71 // ----------------------------------------------------------------------------
72 
86 namespace TickStyle
87 {
88  enum mask_type
89  {
90  NoTicks = 0x00,
91  Top = 0x01,
92  Bottom = 0x02,
93  Left = Top,
94  Right = Bottom,
95  BothSides = Top|Bottom
96  };
97 }
98 
103 
104 // ----------------------------------------------------------------------------
105 
106 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
107 
108 // ----------------------------------------------------------------------------
109 
116 class PCL_CLASS Slider : public Control
117 {
118 public:
119 
125  Slider( Control& parent = Control::Null(), bool vertical = false );
126 
130  ~Slider() override
131  {
132  }
133 
137  int Value() const;
138 
142  void SetValue( int v );
143 
148  double NormalizedValue() const;
149 
154  void SetNormalizedValue( double f );
155 
165  void GetRange( int& minValue, int& maxValue ) const;
166 
172  int MinValue() const
173  {
174  int m, dum; GetRange( m, dum ); return m;
175  }
176 
182  int MaxValue() const
183  {
184  int dum, m; GetRange( dum, m ); return m;
185  }
186 
195  void SetRange( int minValue, int maxValue );
196 
205  void SetMinValue( int m )
206  {
207  SetRange( m, MaxValue() );
208  }
209 
218  void SetMaxValue( int m )
219  {
220  SetRange( MinValue(), m );
221  }
222 
231  int StepSize() const;
232 
241  void SetStepSize( int );
242 
252  int PageSize() const;
253 
263  void SetPageSize( int );
264 
268  int TickInterval() const;
269 
273  void SetTickInterval( int );
274 
278  int TickFrequency() const
279  {
280  return TickInterval();
281  }
282 
286  void SetTickFrequency( int q )
287  {
288  SetTickInterval( q );
289  }
290 
295 
300 
308  {
309  SetTickStyle( TickStyle::NoTicks );
310  }
311 
323  bool IsTrackingEnabled() const;
324 
330  void EnableTracking ( bool = true );
331 
340  void DisableTracking( bool disable = true )
341  {
342  EnableTracking( !disable );
343  }
344 
345  // -------------------------------------------------------------------------
346  // Event handlers
347  //
348  // void OnValueUpdated( Slider& sender, int value );
349  // void OnRangeUpdated( Slider& sender, int minValue, int maxValue );
350 
367  using value_event_handler = void (Control::*)( Slider& sender, int value );
368 
382  using range_event_handler = void (Control::*)( Slider& sender, int minValue, int maxValue );
383 
395  void OnValueUpdated( value_event_handler handler, Control& receiver );
396 
408  void OnRangeUpdated( range_event_handler handler, Control& receiver );
409 
410 private:
411 
412  struct EventHandlers
413  {
414  value_event_handler onValueUpdated = nullptr;
415  range_event_handler onRangeUpdated = nullptr;
416 
417  EventHandlers() = default;
418  EventHandlers( const EventHandlers& ) = default;
419  EventHandlers& operator =( const EventHandlers& ) = default;
420  };
421 
422  AutoPointer<EventHandlers> m_handlers;
423 
424  friend class SliderEventDispatcher;
425 };
426 
427 // ----------------------------------------------------------------------------
428 
435 class PCL_CLASS HorizontalSlider : public Slider
436 {
437 public:
438 
443  : Slider( parent, false/*vertical*/ )
444  {
445  }
446 
450  ~HorizontalSlider() override
451  {
452  }
453 };
454 
455 // ----------------------------------------------------------------------------
456 
463 class PCL_CLASS VerticalSlider : public Slider
464 {
465 public:
466 
471  : Slider( parent, true/*vertical*/ )
472  {
473  }
474 
478  ~VerticalSlider() override
479  {
480  }
481 };
482 
483 // ----------------------------------------------------------------------------
484 
485 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
486 
487 } // pcl
488 
489 #endif // __PCL_Slider_h
490 
491 // ----------------------------------------------------------------------------
492 // EOF pcl/Slider.h - Released 2024-06-18T15:48:54Z
Client-side interface to a PixInsight Control object.
Definition: Control.h:126
static Control & Null()
A type-safe collection of enumerated flags.
Definition: Flags.h:85
Horizontal slider control.
Definition: Slider.h:436
~HorizontalSlider() override
Definition: Slider.h:450
HorizontalSlider(Control &parent=Control::Null())
Definition: Slider.h:442
Client-side interface to a PixInsight Slider control.
Definition: Slider.h:117
void DisableTicks()
Definition: Slider.h:307
void GetRange(int &minValue, int &maxValue) const
void SetTickFrequency(int q)
Definition: Slider.h:286
void EnableTracking(bool=true)
void DisableTracking(bool disable=true)
Definition: Slider.h:340
int TickInterval() const
int TickFrequency() const
Definition: Slider.h:278
int PageSize() const
int MinValue() const
Definition: Slider.h:172
TickStyles TickStyle() const
void SetStepSize(int)
int StepSize() const
void SetMaxValue(int m)
Definition: Slider.h:218
void SetTickInterval(int)
void SetMinValue(int m)
Definition: Slider.h:205
void SetNormalizedValue(double f)
Slider(Control &parent=Control::Null(), bool vertical=false)
void SetTickStyle(TickStyles)
void SetRange(int minValue, int maxValue)
~Slider() override
Definition: Slider.h:130
int MaxValue() const
Definition: Slider.h:182
void SetValue(int v)
bool IsTrackingEnabled() const
int Value() const
void SetPageSize(int)
double NormalizedValue() const
Vertical slider control.
Definition: Slider.h:464
~VerticalSlider() override
Definition: Slider.h:478
VerticalSlider(Control &parent=Control::Null())
Definition: Slider.h:470
void OnRangeUpdated(range_event_handler handler, Control &receiver)
void OnValueUpdated(value_event_handler handler, Control &receiver)
void(Control::*)(Slider &sender, int minValue, int maxValue) range_event_handler
Definition: Slider.h:382
void(Control::*)(Slider &sender, int value) value_event_handler
Definition: Slider.h:367
PCL root namespace.
Definition: AbstractImage.h:77