FINAL CUT
fswitch.h
1 /***********************************************************************
2 * fswitch.h - Widget FSwitch *
3 * *
4 * This file is part of the FINAL CUT widget toolkit *
5 * *
6 * Copyright 2015-2024 Markus Gans *
7 * *
8 * FINAL CUT is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation; either version 3 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * FINAL CUT is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this program. If not, see *
20 * <http://www.gnu.org/licenses/>. *
21 ***********************************************************************/
22 
23 /* Inheritance diagram
24  * ═══════════════════
25  *
26  * ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
27  * ▕ FVTerm ▏ ▕ FObject ▏
28  * ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
29  * ▲ ▲
30  * │ │
31  * └─────┬─────┘
32  * │
33  * ▕▔▔▔▔▔▔▔▔▔▏
34  * ▕ FWidget ▏
35  * ▕▁▁▁▁▁▁▁▁▁▏
36  * ▲
37  * │
38  * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
39  * ▕ FToggleButton ▏
40  * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
41  * ▲
42  * │
43  * ▕▔▔▔▔▔▔▔▔▔▏
44  * ▕ FSwitch ▏
45  * ▕▁▁▁▁▁▁▁▁▁▏
46  */
47 
48 #ifndef FSWITCH_H
49 #define FSWITCH_H
50 
51 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
52  #error "Only <final/final.h> can be included directly."
53 #endif
54 
55 #include "final/widget/ftogglebutton.h"
56 
57 namespace finalcut
58 {
59 
60 //----------------------------------------------------------------------
61 // class FSwitch
62 //----------------------------------------------------------------------
63 
64 class FSwitch : public FToggleButton
65 {
66  public:
67  // Constructors
68  explicit FSwitch (FWidget* = nullptr);
69  explicit FSwitch (const FString&, FWidget* = nullptr);
70 
71  // Destructor
72  ~FSwitch() noexcept override;
73 
74  // Accessor
75  auto getClassName() const -> FString override;
76 
77  // Mutator
78  void setText (const FString&) override;
79 
80  // Event handlers
81  void onKeyPress (FKeyEvent*) override;
82  void onMouseDown (FMouseEvent*) override;
83  void onMouseUp (FMouseEvent*) override;
84 
85  private:
86  // Inquiries
87  auto isMonoFocus() const -> bool;
88 
89  // Methods
90  void draw() override;
91  void drawCheckButton();
92  void drawSwitch();
93  void SetStyleForOn() const;
94  void SetStyleForOff() const;
95  auto createOnText() const -> FString;
96  auto createOffText() const -> FString;
97 
98  // Data members
99  std::size_t switch_offset_pos{0};
100  bool button_pressed{false};
101 };
102 
103 // FSwitch inline functions
104 //----------------------------------------------------------------------
105 inline auto FSwitch::getClassName() const -> FString
106 { return "FSwitch"; }
107 
108 } // namespace finalcut
109 
110 #endif // FSWITCH_H
Definition: fevent.h:144
Definition: class_template.cpp:25
Definition: fstring.h:79
Definition: fwidget.h:129
Definition: fswitch.h:64
Definition: fevent.h:124
Definition: ftogglebutton.h:62