summaryrefslogtreecommitdiff
path: root/indra/llui/llvirtualtrackball.h
blob: ebf7c8ba7babc19d8d0d9c571a8f258486fc87ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* @file virtualtrackball.h
* @author Andrey Lihatskiy
* @brief Header file for LLVirtualTrackball
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2018, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
* $/LicenseInfo$
*/

// A control for positioning the sun and the moon in the celestial sphere.

#ifndef LL_LLVIRTUALTRACKBALL_H
#define LL_LLVIRTUALTRACKBALL_H

#include "lluictrl.h"
#include "llpanel.h"
#include "lltextbox.h"
#include "llbutton.h"

class LLVirtualTrackball
    : public LLUICtrl
{
public:
    enum ThumbMode
    {
        SUN,
        MOON
    };
    enum DragMode
    {
        DRAG_SET,
        DRAG_SCROLL
    };

    struct Params
        : public LLInitParam::Block<Params, LLUICtrl::Params>
    {
        Optional<LLViewBorder::Params>	    border;
        Optional<LLUIImage*>                image_moon_back,
            image_moon_front,
            image_sphere,
            image_sun_back,
            image_sun_front;

        Optional<std::string>               thumb_mode;
        Optional<F32>                       increment_angle_mouse,
            increment_angle_btn;

        Optional<LLTextBox::Params>         lbl_N,
            lbl_S,
            lbl_W,
            lbl_E;

        Optional<LLButton::Params>          btn_rotate_top,
            btn_rotate_bottom,
            btn_rotate_left,
            btn_rotate_right;

        Params();
    };


    virtual ~LLVirtualTrackball();
    /*virtual*/ bool postBuild();

    virtual bool    handleHover(S32 x, S32 y, MASK mask);
    virtual bool    handleMouseUp(S32 x, S32 y, MASK mask);
    virtual bool    handleMouseDown(S32 x, S32 y, MASK mask);
    virtual bool    handleRightMouseDown(S32 x, S32 y, MASK mask);
    virtual bool    handleKeyHere(KEY key, MASK mask);

    virtual void    draw();

    virtual void    setValue(const LLSD& value);
    void            setValue(F32 x, F32 y, F32 z, F32 w);
    virtual LLSD    getValue() const;

    void            setRotation(const LLQuaternion &value);
    LLQuaternion    getRotation() const;

    static void             getAzimuthAndElevation(const LLQuaternion &quat, F32 &azimuth, F32 &elevation);
    static void             getAzimuthAndElevationDeg(const LLQuaternion &quat, F32 &azimuth, F32 &elevation);

protected:
    friend class LLUICtrlFactory;
    LLVirtualTrackball(const Params&);
    void onEditChange();

protected:
    LLTextBox*          mNLabel;
    LLTextBox*          mELabel;
    LLTextBox*          mSLabel;
    LLTextBox*          mWLabel;

    LLButton*           mBtnRotateTop;
    LLButton*           mBtnRotateBottom;
    LLButton*           mBtnRotateLeft;
    LLButton*           mBtnRotateRight;

    LLTextBox*          mLabelN;
    LLTextBox*          mLabelS;
    LLTextBox*          mLabelW;
    LLTextBox*          mLabelE;

    LLPanel*            mTouchArea;
    LLViewBorder*       mBorder;

private:
    void setValueAndCommit(const LLQuaternion &value);
    void drawThumb(S32 x, S32 y, ThumbMode mode, bool upperHemi = true);
    bool pointInTouchCircle(S32 x, S32 y) const;

    void onRotateTopClick();
    void onRotateBottomClick();
    void onRotateLeftClick();
    void onRotateRightClick();

    void onRotateTopMouseEnter();
    void onRotateBottomMouseEnter();
    void onRotateLeftMouseEnter();
    void onRotateRightMouseEnter();

    S32 mPrevX;
    S32 mPrevY;

    LLUIImage*     mImgMoonBack;
    LLUIImage*     mImgMoonFront;
    LLUIImage*     mImgSunBack;
    LLUIImage*     mImgSunFront;
    LLUIImage*     mImgBtnRotTop;
    LLUIImage*     mImgBtnRotLeft;
    LLUIImage*     mImgBtnRotRight;
    LLUIImage*     mImgBtnRotBottom;
    LLUIImage*     mImgSphere;

    LLQuaternion   mValue;
    ThumbMode      mThumbMode;
    DragMode       mDragMode;

    F32            mIncrementMouse;
    F32            mIncrementBtn;
};

#endif