~linaro-graphics-wg/compiz-plugins-main/oneiric-gles2

« back to all changes in this revision

Viewing changes to ezoom/src/ezoom.h

  • Committer: Sam Spilsbury
  • Date: 2011-09-20 07:43:55 UTC
  • Revision ID: sam.spilsbury@canonical.com-20110920074355-puzdutejjwsu3ta2
Sync - Remove Plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2005 Novell, Inc.
3
 
 * Copyright (C) 2007, 2008 Kristian Lyngstøl
4
 
 *
5
 
 * Ported to compiz 0.9 by:
6
 
 * Copyright (C) 2009, Sam Spilsbury
7
 
 *
8
 
 * Permission to use, copy, modify, distribute, and sell this software
9
 
 * and its documentation for any purpose is hereby granted without
10
 
 * fee, provided that the above copyright notice appear in all copies
11
 
 * and that both that copyright notice and this permission notice
12
 
 * appear in supporting documentation, and that the name of
13
 
 * Novell, Inc. not be used in advertising or publicity pertaining to
14
 
 * distribution of the software without specific, written prior permission.
15
 
 * Novell, Inc. makes no representations about the suitability of this
16
 
 * software for any purpose. It is provided "as is" without express or
17
 
 * implied warranty.
18
 
 *
19
 
 * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
20
 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
21
 
 * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
22
 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
23
 
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
24
 
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
25
 
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26
 
 *
27
 
 *
28
 
 * Author(s):
29
 
 *      - Original zoom plug-in; David Reveman <davidr@novell.com>
30
 
 *      - Most features beyond basic zoom;
31
 
 *        Kristian Lyngstol <kristian@bohemians.org>
32
 
 *      - Sam I suppose? (for the c++)
33
 
 *
34
 
 * Todo: Un-puke the header-file. Five levels of indentation in a .h is a
35
 
 * clear sign that something is horribly wrong.
36
 
 *
37
 
 * Essentially, this needs to be re-done for C++. As is the case of most of
38
 
 * eZoom.
39
 
 *
40
 
 */
41
 
 
42
 
#include <core/core.h>
43
 
#include <core/serialization.h>
44
 
#include <composite/composite.h>
45
 
#include <opengl/opengl.h>
46
 
#include <mousepoll/mousepoll.h>
47
 
 
48
 
 
49
 
#include "ezoom_options.h"
50
 
 
51
 
#include <cmath>
52
 
 
53
 
class EZoomScreen :
54
 
    public PluginClassHandler <EZoomScreen, CompScreen>,
55
 
    public PluginStateWriter <EZoomScreen>,
56
 
    public EzoomOptions,
57
 
    public ScreenInterface,
58
 
    public CompositeScreenInterface,
59
 
    public GLScreenInterface
60
 
{
61
 
    public:
62
 
 
63
 
        EZoomScreen (CompScreen *);
64
 
        ~EZoomScreen ();
65
 
 
66
 
    public:
67
 
 
68
 
        CompositeScreen *cScreen;
69
 
        GLScreen        *gScreen;
70
 
 
71
 
    public:
72
 
 
73
 
        typedef enum {
74
 
            NORTHEAST,
75
 
            NORTHWEST,
76
 
            SOUTHEAST,
77
 
            SOUTHWEST,
78
 
            CENTER
79
 
        } ZoomGravity;
80
 
 
81
 
        typedef enum {
82
 
            NORTH,
83
 
            SOUTH,
84
 
            EAST,
85
 
            WEST
86
 
        } ZoomEdge;
87
 
 
88
 
        class CursorTexture
89
 
        {
90
 
            public:
91
 
                bool       isSet;
92
 
                GLuint     texture;
93
 
                CompScreen *screen;
94
 
                int        width;
95
 
                int        height;
96
 
                int        hotX;
97
 
                int        hotY;
98
 
            public:
99
 
                CursorTexture ();
100
 
        };
101
 
 
102
 
        /* Stores an actual zoom-setup. This can later be used to store/restore
103
 
         * zoom areas on the fly.
104
 
         *
105
 
         * [xy]Translate and newZoom are target values, and [xy]Translate always
106
 
         * ranges from -0.5 to 0.5.
107
 
         *
108
 
         * currentZoom is actual zoomed value
109
 
         *
110
 
         * real[XY]Translate are the currently used values in the same range as
111
 
         * [xy]Translate, and [xy]trans is adjusted for the zoom level in place.
112
 
         * [xyz]trans should never be modified except in updateActualTranslates()
113
 
         *
114
 
         * viewport is a mask of the viewport, or ~0 for "any".
115
 
         */
116
 
        class ZoomArea
117
 
        {
118
 
            public:
119
 
 
120
 
                template <class Archive>
121
 
                void serialize (Archive &ar, const unsigned int)
122
 
                {
123
 
                    ar & output;
124
 
                    ar & viewport;
125
 
                    ar & newZoom;
126
 
                    ar & xVelocity;
127
 
                    ar & yVelocity;
128
 
                    ar & xTranslate;
129
 
                    ar & yTranslate;
130
 
                    ar & realXTranslate;
131
 
                    ar & realYTranslate;
132
 
                    ar & xtrans;
133
 
                    ar & ytrans;
134
 
                    ar & locked;
135
 
                }
136
 
 
137
 
            public:
138
 
                int               output;
139
 
                unsigned long int viewport;
140
 
                GLfloat           currentZoom;
141
 
                GLfloat           newZoom;
142
 
                GLfloat           xVelocity;
143
 
                GLfloat           yVelocity;
144
 
                GLfloat           zVelocity;
145
 
                GLfloat           xTranslate;
146
 
                GLfloat           yTranslate;
147
 
                GLfloat           realXTranslate;
148
 
                GLfloat           realYTranslate;
149
 
                GLfloat           xtrans;
150
 
                GLfloat           ytrans;
151
 
                bool              locked;
152
 
            public:
153
 
 
154
 
                ZoomArea (int out);
155
 
                ZoomArea ();
156
 
 
157
 
                void
158
 
                updateActualTranslates ();
159
 
        };
160
 
 
161
 
    public:
162
 
 
163
 
        template <class Archive>
164
 
        void serialize (Archive &ar, const unsigned int version)
165
 
        {
166
 
            ar & zooms;
167
 
            ar & lastChange;
168
 
            ar & grabbed;
169
 
        }
170
 
 
171
 
        std::vector <ZoomArea>   zooms; // list of zooms (different zooms for
172
 
                                        // each output
173
 
        CompPoint                mouse; // we get this from mousepoll
174
 
        unsigned long int        grabbed;
175
 
        CompScreen::GrabHandle   grabIndex; // for zoomBox
176
 
        time_t                   lastChange;
177
 
        CursorTexture            cursor; // the texture for the faux-cursor
178
 
                                         // we paint to do fake input
179
 
                                         // handling
180
 
        bool                     cursorInfoSelected;
181
 
        bool                     cursorHidden;
182
 
        CompRect                 box;
183
 
        CompPoint                clickPos;
184
 
 
185
 
        MousePoller              pollHandle; // mouse poller object
186
 
 
187
 
     private:
188
 
 
189
 
        bool fixesSupported;
190
 
        int fixesEventBase;
191
 
        int fixesErrorBase;
192
 
        bool canHideCursor;
193
 
 
194
 
     public:
195
 
 
196
 
        void
197
 
        postLoad ();
198
 
 
199
 
        void
200
 
        preparePaint (int);
201
 
 
202
 
        bool
203
 
        glPaintOutput (const GLScreenPaintAttrib &,
204
 
                       const GLMatrix            &,
205
 
                       const CompRegion          &,
206
 
                       CompOutput                *,
207
 
                       unsigned int);
208
 
 
209
 
        void
210
 
        donePaint ();
211
 
 
212
 
        void
213
 
        handleEvent (XEvent *);
214
 
 
215
 
    public:
216
 
 
217
 
        int
218
 
        distanceToEdge (int out, EZoomScreen::ZoomEdge edge);
219
 
 
220
 
        bool
221
 
        isInMovement (int out);
222
 
 
223
 
        void
224
 
        adjustZoomVelocity (int out, float chunk);
225
 
 
226
 
        void
227
 
        adjustXYVelocity (int out, float chunk);
228
 
 
229
 
        void
230
 
        drawBox (const GLMatrix &transform,
231
 
                 CompOutput          *output,
232
 
                 CompRect             box);
233
 
 
234
 
        void
235
 
        setCenter (int x, int y, bool instant);
236
 
 
237
 
        void
238
 
        setZoomArea (int        x,
239
 
                     int        y,
240
 
                     int        width,
241
 
                     int        height,
242
 
                     bool       instant);
243
 
 
244
 
        void
245
 
        areaToWindow (CompWindow *w);
246
 
 
247
 
        void
248
 
        panZoom (int xvalue, int yvalue);
249
 
 
250
 
        void
251
 
        enableMousePolling ();
252
 
 
253
 
        void
254
 
        setScale (int out, float value);
255
 
 
256
 
        void
257
 
        syncCenterToMouse ();
258
 
 
259
 
        void
260
 
        convertToZoomed (int        out,
261
 
                         int        x,
262
 
                         int        y,
263
 
                         int        *resultX,
264
 
                         int        *resultY);
265
 
 
266
 
        void
267
 
        convertToZoomedTarget (int        out,
268
 
                               int        x,
269
 
                               int        y,
270
 
                               int        *resultX,
271
 
                               int        *resultY);
272
 
 
273
 
        bool
274
 
        ensureVisibility (int x, int y, int margin);
275
 
 
276
 
        void
277
 
        ensureVisibilityArea (int         x1,
278
 
                              int         y1,
279
 
                              int         x2,
280
 
                              int         y2,
281
 
                              int         margin,
282
 
                              ZoomGravity gravity);
283
 
 
284
 
        void
285
 
        restrainCursor (int out);
286
 
 
287
 
        void
288
 
        cursorMoved ();
289
 
 
290
 
        void
291
 
        updateMousePosition (const CompPoint &p);
292
 
 
293
 
        void
294
 
        updateMouseInterval (const CompPoint &p);
295
 
 
296
 
        /* Make dtor */
297
 
        void
298
 
        freeCursor (CursorTexture * cursor);
299
 
 
300
 
        void
301
 
        drawCursor (CompOutput          *output,
302
 
                    const GLMatrix      &transform);
303
 
 
304
 
        void
305
 
        updateCursor (CursorTexture * cursor);
306
 
 
307
 
        void
308
 
        cursorZoomInactive ();
309
 
 
310
 
        void
311
 
        cursorZoomActive (int);
312
 
 
313
 
    public:
314
 
 
315
 
        bool
316
 
        setZoomAreaAction (CompAction         *action,
317
 
                           CompAction::State  state,
318
 
                           CompOption::Vector options);
319
 
 
320
 
        bool
321
 
        ensureVisibilityAction (CompAction         *action,
322
 
                                CompAction::State  state,
323
 
                                CompOption::Vector options);
324
 
 
325
 
        bool
326
 
        zoomBoxActivate (CompAction         *action,
327
 
                         CompAction::State  state,
328
 
                         CompOption::Vector options);
329
 
 
330
 
        bool
331
 
        zoomBoxDeactivate (CompAction         *action,
332
 
                           CompAction::State  state,
333
 
                           CompOption::Vector options);
334
 
 
335
 
        bool
336
 
        zoomIn (CompAction         *action,
337
 
                CompAction::State  state,
338
 
                CompOption::Vector options);
339
 
 
340
 
        bool
341
 
        lockZoomAction (CompAction         *action,
342
 
                        CompAction::State  state,
343
 
                        CompOption::Vector options);
344
 
 
345
 
        bool
346
 
        zoomSpecific (CompAction         *action,
347
 
                      CompAction::State  state,
348
 
                      CompOption::Vector options,
349
 
                      float                  target);
350
 
 
351
 
        bool
352
 
        zoomToWindow (CompAction         *action,
353
 
                      CompAction::State  state,
354
 
                      CompOption::Vector options);
355
 
 
356
 
        bool
357
 
        zoomPan (CompAction         *action,
358
 
                 CompAction::State  state,
359
 
                 CompOption::Vector options,
360
 
                 float          horizAmount,
361
 
                 float          vertAmount);
362
 
 
363
 
        bool
364
 
        zoomCenterMouse (CompAction         *action,
365
 
                         CompAction::State  state,
366
 
                         CompOption::Vector options);
367
 
 
368
 
        bool
369
 
        zoomFitWindowToZoom (CompAction         *action,
370
 
                             CompAction::State  state,
371
 
                             CompOption::Vector options);
372
 
 
373
 
        bool
374
 
        initiate (CompAction         *action,
375
 
                  CompAction::State  state,
376
 
                  CompOption::Vector options);
377
 
 
378
 
        bool
379
 
        zoomOut (CompAction         *action,
380
 
                 CompAction::State  state,
381
 
                 CompOption::Vector options);
382
 
 
383
 
        bool
384
 
        terminate (CompAction         *action,
385
 
                   CompAction::State  state,
386
 
                   CompOption::Vector options);
387
 
 
388
 
        void
389
 
        focusTrack (XEvent *event);
390
 
};
391
 
 
392
 
#define ZOOM_SCREEN(s)                                                         \
393
 
     EZoomScreen *zs = EZoomScreen::get (s)
394
 
 
395
 
class ZoomPluginVTable :
396
 
    public CompPlugin::VTableForScreen <EZoomScreen>
397
 
{
398
 
    public:
399
 
 
400
 
        bool init ();
401
 
};