2 * Copyright © 2008 Kristian Høgsberg
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
36 #include "wayland-client.h"
40 set_random_color(cairo_t *cr)
42 cairo_set_source_rgba(cr,
43 0.5 + (random() % 50) / 49.0,
44 0.5 + (random() % 50) / 49.0,
45 0.5 + (random() % 50) / 49.0,
46 0.5 + (random() % 100) / 99.0);
51 draw_stuff(cairo_surface_t *surface, int width, int height)
53 const int petal_count = 3 + random() % 5;
54 const double r1 = 60 + random() % 35;
55 const double r2 = 20 + random() % 40;
56 const double u = (10 + random() % 90) / 100.0;
57 const double v = (random() % 90) / 100.0;
61 double t, dt = 2 * M_PI / (petal_count * 2);
62 double x1, y1, x2, y2, x3, y3;
64 cr = cairo_create(surface);
65 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
66 cairo_set_source_rgba(cr, 0, 0, 0, 0);
69 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
70 cairo_translate(cr, width / 2, height / 2);
71 cairo_move_to(cr, cos(0) * r1, sin(0) * r1);
72 for (t = 0, i = 0; i < petal_count; i++, t += dt * 2) {
75 x2 = cos(t + dt) * r2;
76 y2 = sin(t + dt) * r2;
77 x3 = cos(t + 2 * dt) * r1;
78 y3 = sin(t + 2 * dt) * r1;
81 x1 - y1 * u, y1 + x1 * u,
82 x2 + y2 * v, y2 - x2 * v,
86 x2 - y2 * v, y2 + x2 * v,
87 x3 + y3 * u, y3 - x3 * u,
93 cairo_fill_preserve(cr);
101 motion_handler(struct window *window,
102 struct input *input, uint32_t time,
103 int32_t x, int32_t y,
104 int32_t sx, int32_t sy, void *data)
106 return POINTER_HAND1;
110 button_handler(struct window *window,
111 struct input *input, uint32_t time,
112 int button, int state, void *data)
115 window_move(window, input, time);
119 struct display *display;
120 struct window *window;
124 int main(int argc, char *argv[])
127 struct flower flower;
131 d = display_create(&argc, &argv, NULL);
133 fprintf(stderr, "failed to create display: %m\n");
137 gettimeofday(&tv, NULL);
143 flower.window = window_create(d, flower.width, flower.height);
145 window_set_title(flower.window, "flower");
146 window_set_decoration(flower.window, 0);
147 window_draw(flower.window);
148 s = window_get_surface(flower.window);
149 if (s == NULL || cairo_surface_status (s) != CAIRO_STATUS_SUCCESS) {
150 fprintf(stderr, "failed to create cairo egl surface\n");
154 draw_stuff(s, flower.width, flower.height);
155 cairo_surface_flush(s);
156 cairo_surface_destroy(s);
157 window_flush(flower.window);
159 window_set_motion_handler(flower.window, motion_handler);
160 window_set_button_handler(flower.window, button_handler);
161 window_set_user_data(flower.window, &flower);