2
* Copyright (c) 2013 Martin Decky
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* - Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* - Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* - The name of the author may not be used to endorse or promote products
15
* derived from this software without specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
#include <transform.h>
44
static void paint_internal(widget_t *widget)
46
canvas_t *canvas = (canvas_t *) widget;
48
surface_t *surface = window_claim(canvas->widget.window);
50
window_yield(canvas->widget.window);
53
transform_t transform;
54
transform_identity(&transform);
55
transform_translate(&transform, widget->hpos, widget->vpos);
59
source_set_transform(&source, transform);
60
source_set_texture(&source, canvas->surface, false);
63
drawctx_init(&drawctx, surface);
65
drawctx_set_source(&drawctx, &source);
66
drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width,
69
window_yield(canvas->widget.window);
72
void deinit_canvas(canvas_t *canvas)
74
widget_deinit(&canvas->widget);
77
static void canvas_destroy(widget_t *widget)
79
canvas_t *canvas = (canvas_t *) widget;
81
deinit_canvas(canvas);
85
static void canvas_reconfigure(widget_t *widget)
90
static void canvas_rearrange(widget_t *widget, sysarg_t hpos, sysarg_t vpos,
91
sysarg_t width, sysarg_t height)
93
canvas_t *canvas = (canvas_t *) widget;
95
widget_modify(widget, hpos, vpos, canvas->width, canvas->height);
96
paint_internal(widget);
99
static void canvas_repaint(widget_t *widget)
101
paint_internal(widget);
102
window_damage(widget->window);
105
static void canvas_handle_keyboard_event(widget_t *widget, kbd_event_t event)
110
static void canvas_handle_position_event(widget_t *widget, pos_event_t event)
115
bool init_canvas(canvas_t *canvas, widget_t *parent, sysarg_t width,
116
sysarg_t height, surface_t *surface)
118
widget_init(&canvas->widget, parent);
120
canvas->widget.width = width;
121
canvas->widget.height = height;
123
canvas->widget.width_min = width;
124
canvas->widget.height_min = height;
125
canvas->widget.width_ideal = width;
126
canvas->widget.height_ideal = height;
127
canvas->widget.width_max = width;
128
canvas->widget.height_max = height;
130
canvas->widget.destroy = canvas_destroy;
131
canvas->widget.reconfigure = canvas_reconfigure;
132
canvas->widget.rearrange = canvas_rearrange;
133
canvas->widget.repaint = canvas_repaint;
134
canvas->widget.handle_keyboard_event = canvas_handle_keyboard_event;
135
canvas->widget.handle_position_event = canvas_handle_position_event;
137
canvas->width = width;
138
canvas->height = height;
139
canvas->surface = surface;
144
canvas_t *create_canvas(widget_t *parent, sysarg_t width, sysarg_t height,
147
canvas_t *canvas = (canvas_t *) malloc(sizeof(canvas_t));
151
if (init_canvas(canvas, parent, width, height, surface))