~ubuntu-branches/ubuntu/quantal/libcm/quantal

« back to all changes in this revision

Viewing changes to src/magtest.c

  • Committer: Bazaar Package Importer
  • Author(s): Loic Minier, Josselin Mouette, Loic Minier
  • Date: 2008-05-26 14:43:19 UTC
  • mfrom: (3.1.4 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080526144319-ddwovigo7i925ewr
Tags: 0.1.1-4
[ Josselin Mouette ]
* Allow libgl-dev and libglu-dev as alternative dependencies for
  libcm-dev. Closes: #478887.

[ Loic Minier ]
* Don't copy config.guess/.sub after unpatch in clean; should avoid having
  them in the .diff.gz -- not needed as we always update them after patching
  anyway -- and should fix conversion to source format 3.0; closes: #482728.
* Stop shipping *.la files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* libcm - A library with a xlib wrapper and a gl based scene graph
 
2
 * Copyright (C) 2005, 2006  Red Hat, Inc.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Library General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 * License along with this library; if not, write to the 
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA  02111-1307, USA.
 
18
 *
 
19
 * Author: Soren Sandmann (sandmann@redhat.com)
 
20
 */
 
21
#include "ws.h"
 
22
#include "wsint.h"
 
23
#include "grid.h"
 
24
#include "deform.h"
 
25
#include "ortho.h"
 
26
#include "magnifier.h"
 
27
#include <GL/glu.h>
 
28
#include <math.h>
 
29
 
 
30
static gboolean
 
31
paint_window (gpointer data)
 
32
{
 
33
    Display *display;
 
34
    XID xid;
 
35
    WsPixmap *pixmap = data;
 
36
    XGCValues gc_values;
 
37
    GC gc;
 
38
    
 
39
    display = WS_RESOURCE_XDISPLAY (pixmap);
 
40
    xid = WS_RESOURCE_XID (pixmap);
 
41
    
 
42
    g_print ("painting on %lx\n", xid);
 
43
    
 
44
    gc_values.foreground = 0xff00ff00;
 
45
    gc = XCreateGC (display, xid, GCForeground, &gc_values);
 
46
    
 
47
    XFillRectangle (display, xid, gc, 0, 0, 32000, 32000);
 
48
    
 
49
    XFreeGC (display, gc);
 
50
    
 
51
    return TRUE;
 
52
}
 
53
 
 
54
static void
 
55
wobble (int u, int v, int x, int y, int width, int height,
 
56
        int *deformed_x, int *deformed_y,
 
57
        gpointer data)
 
58
{
 
59
    double elapsed = *(double *)data;
 
60
 
 
61
    *deformed_x = u + cos((x * elapsed + u + y * elapsed + v) / 64.0) * 8;
 
62
    *deformed_y = v + sin((x * elapsed + u + y * elapsed + v) / 64.0) * 8;
 
63
}
 
64
 
 
65
static void
 
66
shape (CmGrid *grid)
 
67
{
 
68
    WsRectangle rect1 = { 200, 200, 500, 300 };
 
69
    WsRectangle rect2 = { 300, 300, 300, 100 };
 
70
    
 
71
    WsRegion *reg1 = ws_region_rectangle (&rect1);
 
72
    WsRegion *reg2 = ws_region_rectangle (&rect2);
 
73
 
 
74
    ws_region_subtract (reg1, reg2);
 
75
 
 
76
    cm_grid_set_region (grid, reg1);
 
77
}
 
78
 
 
79
int
 
80
main ()
 
81
{
 
82
    g_type_init ();
 
83
    
 
84
    WsDisplay *display = ws_display_new (NULL);
 
85
    WsScreen *screen = ws_display_get_default_screen (display);
 
86
    WsWindow *gl_window = ws_screen_get_gl_window (screen);
 
87
    WsWindow *root = ws_screen_get_root_window (screen);
 
88
    GMainLoop *loop = g_main_loop_new (NULL, TRUE);
 
89
    CmGrid *grid;
 
90
    CmMagnifier *mag;
 
91
    CmOrtho *ortho;
 
92
    CmDeform *deform;
 
93
    GTimer *timer = g_timer_new ();
 
94
    double time;
 
95
    WsRectangle source;
 
96
    WsRectangle target;
 
97
        
 
98
    ws_window_map (gl_window);
 
99
 
 
100
    grid = cm_grid_new (200, 200, 500, 300, 16, 16);
 
101
 
 
102
    shape (grid);
 
103
 
 
104
    source.x = 200;
 
105
    source.y = 200;
 
106
    source.width = 300;
 
107
    source.height = 300;
 
108
 
 
109
    target.x = 800;
 
110
    target.y = 1200 - 150;
 
111
    target.width = 150;
 
112
    target.height = 150;
 
113
    
 
114
    deform = cm_deform_new (CM_NODE (grid), 200, 200, 500, 300);
 
115
 
 
116
    ortho = cm_ortho_new (CM_NODE (deform), 0, 0, 1600, 1200);
 
117
    
 
118
    mag = cm_magnifier_new (ortho, &source, &target);
 
119
    
 
120
    cm_deform_set_deform (deform, wobble, &time);
 
121
 
 
122
    glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
 
123
#if 0
 
124
    glEnable (GL_POLYGON_SMOOTH);
 
125
#endif
 
126
    glEnable (GL_LINE_SMOOTH);
 
127
    glEnable (GL_BLEND);
 
128
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
129
    glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
 
130
 
 
131
    for (;;)
 
132
    {
 
133
        time = g_timer_elapsed (timer, NULL);
 
134
        glClearColor (1.0, 1.0, 1.0, 1.0);
 
135
        
 
136
        glClear (GL_COLOR_BUFFER_BIT);
 
137
 
 
138
        glColor4f (0.0, 0.0, 0.0, 1.0);
 
139
 
 
140
        cm_node_render (CM_NODE (mag), NULL);
 
141
 
 
142
        ws_window_gl_swap_buffers (gl_window);
 
143
        ws_window_gl_finish (gl_window);
 
144
    }    
 
145
    g_main_loop_run (loop);
 
146
    return 0;
 
147
}