1
/* libcm - A library with a xlib wrapper and a gl based scene graph
2
* Copyright (C) 2005, 2006 Red Hat, Inc.
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.
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.
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.
19
* Author: Soren Sandmann (sandmann@redhat.com)
26
#include "magnifier.h"
31
paint_window (gpointer data)
35
WsPixmap *pixmap = data;
39
display = WS_RESOURCE_XDISPLAY (pixmap);
40
xid = WS_RESOURCE_XID (pixmap);
42
g_print ("painting on %lx\n", xid);
44
gc_values.foreground = 0xff00ff00;
45
gc = XCreateGC (display, xid, GCForeground, &gc_values);
47
XFillRectangle (display, xid, gc, 0, 0, 32000, 32000);
49
XFreeGC (display, gc);
55
wobble (int u, int v, int x, int y, int width, int height,
56
int *deformed_x, int *deformed_y,
59
double elapsed = *(double *)data;
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;
68
WsRectangle rect1 = { 200, 200, 500, 300 };
69
WsRectangle rect2 = { 300, 300, 300, 100 };
71
WsRegion *reg1 = ws_region_rectangle (&rect1);
72
WsRegion *reg2 = ws_region_rectangle (&rect2);
74
ws_region_subtract (reg1, reg2);
76
cm_grid_set_region (grid, reg1);
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);
93
GTimer *timer = g_timer_new ();
98
ws_window_map (gl_window);
100
grid = cm_grid_new (200, 200, 500, 300, 16, 16);
110
target.y = 1200 - 150;
114
deform = cm_deform_new (CM_NODE (grid), 200, 200, 500, 300);
116
ortho = cm_ortho_new (CM_NODE (deform), 0, 0, 1600, 1200);
118
mag = cm_magnifier_new (ortho, &source, &target);
120
cm_deform_set_deform (deform, wobble, &time);
122
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
124
glEnable (GL_POLYGON_SMOOTH);
126
glEnable (GL_LINE_SMOOTH);
128
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
129
glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
133
time = g_timer_elapsed (timer, NULL);
134
glClearColor (1.0, 1.0, 1.0, 1.0);
136
glClear (GL_COLOR_BUFFER_BIT);
138
glColor4f (0.0, 0.0, 0.0, 1.0);
140
cm_node_render (CM_NODE (mag), NULL);
142
ws_window_gl_swap_buffers (gl_window);
143
ws_window_gl_finish (gl_window);
145
g_main_loop_run (loop);