1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
22 #include "ui/controls/control.h"
23 
24 #include <memory>
25 
26 namespace Ui
27 {
28 
29 enum EditValueType
30 {
31     EVT_INT     = 1,    // integer
32     EVT_FLOAT   = 2,    // float value
33     EVT_100     = 3,    // percent (0 .. 1)
34 };
35 
36 class CEdit;
37 class CButton;
38 class CInterface;
39 
40 
41 
42 class CEditValue : public CControl
43 {
44 public:
45     CEditValue();
46     virtual ~CEditValue();
47 
48     bool        Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override;
49 
50     void        SetPos(Math::Point pos) override;
51     void        SetDim(Math::Point dim) override;
52 
53     bool        EventProcess(const Event &event) override;
54     void        Draw() override;
55 
56     void        SetType(EditValueType type);
57     EditValueType GetType();
58 
59     void        SetValue(float value, bool bSendMessage=false);
60     float       GetValue();
61 
62     void        SetStepValue(float value);
63     float       GetStepValue();
64 
65     void        SetMinValue(float value);
66     float       GetMinValue();
67 
68     void        SetMaxValue(float value);
69     float       GetMaxValue();
70 
71     void        SetInterface(Ui::CInterface* interface);
72 
73 protected:
74     void        MoveAdjust();
75     void        HiliteValue(const Event &event);
76 
77     Ui::CInterface* m_interface;
78     std::unique_ptr<Ui::CEdit> m_edit;
79     std::unique_ptr<Ui::CButton> m_buttonUp;
80     std::unique_ptr<Ui::CButton> m_buttonDown;
81     EditValueType   m_type;
82     float           m_stepValue;
83     float           m_minValue;
84     float           m_maxValue;
85 };
86 
87 
88 } // namespace Ui
89