]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_qtextureviewer.h
Initial vogl checkin
[vogl] / src / vogleditor / vogleditor_qtextureviewer.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 #ifndef VOGLEDITOR_QTEXTUREVIEWER_H
27 #define VOGLEDITOR_QTEXTUREVIEWER_H
28
29 #include <QWidget>
30
31 QT_BEGIN_NAMESPACE
32 class QPainter;
33 class QPaintEvent;
34 QT_END_NAMESPACE
35
36 #include <QBrush>
37 #include <QFont>
38 #include <QPen>
39
40 #include "vogl_core.h"
41 #include "vogl_map.h"
42 #include "vogl_mipmapped_texture.h"
43 #include "vogl_ktx_texture.h"
44
45 typedef enum ChannelSelectionOptions
46 {
47     VOGL_CSO_RGBA = 0,
48     VOGL_CSO_RGB,
49     VOGL_CSO_R,
50     VOGL_CSO_G,
51     VOGL_CSO_B,
52     VOGL_CSO_A,
53     VOGL_CSO_ONE_MINUS_RGBA,
54     VOGL_CSO_ONE_MINUS_RGB,
55     VOGL_CSO_ONE_MINUS_R,
56     VOGL_CSO_ONE_MINUS_G,
57     VOGL_CSO_ONE_MINUS_B,
58     VOGL_CSO_ONE_MINUS_A,
59     VOGL_CSO_ONE_OVER_RGBA,
60     VOGL_CSO_ONE_OVER_RGB,
61     VOGL_CSO_ONE_OVER_R,
62     VOGL_CSO_ONE_OVER_G,
63     VOGL_CSO_ONE_OVER_B,
64     VOGL_CSO_ONE_OVER_A,
65 } ChannelSelectionOption;
66
67 class QTextureViewer : public QWidget
68 {
69    Q_OBJECT
70 public:
71    explicit QTextureViewer(QWidget *parent = 0);
72    void paint(QPainter *painter, QPaintEvent *event);
73
74    void setTexture(const vogl::ktx_texture* pTexture, uint baseMipLevel, uint maxMipLevel);
75
76    void setChannelSelectionOption(ChannelSelectionOption channels)
77    {
78        if (m_channelSelection != channels)
79        {
80            delete_pixmaps();
81            m_channelSelection = channels;
82            repaint();
83        }
84    }
85
86    void clear()
87    {
88       m_draw_enabled = false;
89       m_pKtxTexture = NULL;
90       m_mipmappedTexture.clear();
91    }
92
93    inline QColor getBackgroundColor() const { return m_background.color(); }
94
95    inline void setBackgroundColor(QBrush color)
96    {
97       m_draw_enabled = true;
98       m_background = color;
99       delete_pixmaps();
100       repaint();
101    }
102
103    double getZoomFactor() const { return m_zoomFactor; }
104    void setZoomFactor(double zoomFactor)
105    {
106        if (m_zoomFactor != zoomFactor)
107        {
108            m_zoomFactor = zoomFactor;
109            repaint();
110        }
111    }
112
113    bool getInverted() const { return m_bInvert; }
114    void setInverted(bool bInvert)
115    {
116        if (m_bInvert != bInvert)
117        {
118            m_bInvert = bInvert;
119            repaint();
120        }
121    }
122
123    uint get_preferred_height() const
124    {
125        uint height = 0;
126        if (m_pKtxTexture != NULL)
127        {
128            height += (m_pKtxTexture->get_height() * m_zoomFactor);
129        }
130        return height;
131    }
132
133 private:
134    bool m_draw_enabled;
135    QBrush m_background;
136    QPen m_outlinePen;
137    ChannelSelectionOption m_channelSelection;
138    double m_zoomFactor;
139    bool m_bInvert;
140
141    vogl::map<uint,QPixmap> m_pixmaps;
142    vogl::map<uint, vogl::color_quad_u8*> m_pixmapData;
143
144    const vogl::ktx_texture* m_pKtxTexture;
145    vogl::mipmapped_texture m_mipmappedTexture;
146    uint m_baseMipLevel;
147    uint m_maxMipLevel;
148
149    void delete_pixmaps()
150    {
151       m_pixmaps.clear();
152       for (vogl::map<uint, vogl::color_quad_u8*>::iterator iter = m_pixmapData.begin(); iter != m_pixmapData.end(); iter++)
153       {
154           delete [] iter->second;
155           iter->second = NULL;
156       }
157       m_pixmapData.clear();
158    }
159
160    void adjustChannels(ChannelSelectionOption selection, unsigned char& r, unsigned char& g, unsigned char& b, unsigned char& a);
161
162 protected:
163     void paintEvent(QPaintEvent *event);
164
165 signals:
166
167 public slots:
168
169 };
170
171 #endif // VOGLEDITOR_QTEXTUREVIEWER_H