source: mainline/uspace/lib/gui/canvas.c@ aeba767

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since aeba767 was 2bb6d04, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Curb the proliferation of libdraw headers

libdraw provides a lot of ambiguously named headers, which makes it
confusing. This change merges the subdirectories into single headers,
and moves all headers into draw subdirectory, so that it's obvious
at a glance what library the header belongs to.

Compare:

#include <path.h>
#include <source.h>
#include <font/bitmap_backend.h>
#include <font/pcf.h>

vs.

#include <draw/path.h>
#include <draw/source.h>
#include <draw/font.h>

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[e31ea20d]1/*
2 * Copyright (c) 2013 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
16 *
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.
27 */
28
29/** @addtogroup gui
30 * @{
31 */
32/**
33 * @file
34 */
35
[38d150e]36#include <stdlib.h>
[e31ea20d]37#include <transform.h>
[2bb6d04]38#include <draw/source.h>
39#include <draw/surface.h>
40#include <draw/drawctx.h>
[e31ea20d]41#include "window.h"
42#include "canvas.h"
43
44static void paint_internal(widget_t *widget)
45{
46 canvas_t *canvas = (canvas_t *) widget;
[a35b458]47
[e31ea20d]48 surface_t *surface = window_claim(canvas->widget.window);
49 if (!surface) {
50 window_yield(canvas->widget.window);
51 }
[a35b458]52
[e31ea20d]53 transform_t transform;
54 transform_identity(&transform);
55 transform_translate(&transform, widget->hpos, widget->vpos);
[a35b458]56
[e31ea20d]57 source_t source;
58 source_init(&source);
59 source_set_transform(&source, transform);
[00ddb40]60 source_set_texture(&source, canvas->surface,
61 PIXELMAP_EXTEND_TRANSPARENT_BLACK);
[a35b458]62
[e31ea20d]63 drawctx_t drawctx;
64 drawctx_init(&drawctx, surface);
[a35b458]65
[e31ea20d]66 drawctx_set_source(&drawctx, &source);
67 drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width,
68 widget->height);
[a35b458]69
[e31ea20d]70 window_yield(canvas->widget.window);
71}
72
73void deinit_canvas(canvas_t *canvas)
74{
75 widget_deinit(&canvas->widget);
76}
77
78static void canvas_destroy(widget_t *widget)
79{
80 canvas_t *canvas = (canvas_t *) widget;
[a35b458]81
[e31ea20d]82 deinit_canvas(canvas);
83 free(canvas);
84}
85
86static void canvas_reconfigure(widget_t *widget)
87{
88 /* No-op */
89}
90
91static void canvas_rearrange(widget_t *widget, sysarg_t hpos, sysarg_t vpos,
92 sysarg_t width, sysarg_t height)
93{
94 canvas_t *canvas = (canvas_t *) widget;
[a35b458]95
[e31ea20d]96 widget_modify(widget, hpos, vpos, canvas->width, canvas->height);
97 paint_internal(widget);
98}
99
100static void canvas_repaint(widget_t *widget)
101{
102 paint_internal(widget);
103 window_damage(widget->window);
104}
105
106static void canvas_handle_keyboard_event(widget_t *widget, kbd_event_t event)
107{
[d65be39]108 canvas_t *canvas = (canvas_t *) widget;
[a35b458]109
[d65be39]110 sig_send(&canvas->keyboard_event, &event);
[e31ea20d]111}
112
113static void canvas_handle_position_event(widget_t *widget, pos_event_t event)
114{
[a0ff947]115 canvas_t *canvas = (canvas_t *) widget;
116 pos_event_t tevent;
[a35b458]117
[a0ff947]118 tevent = event;
119 tevent.hpos -= widget->hpos;
120 tevent.vpos -= widget->vpos;
[a35b458]121
[a0ff947]122 sig_send(&canvas->position_event, &tevent);
[e31ea20d]123}
124
[10cb47e]125bool init_canvas(canvas_t *canvas, widget_t *parent, const void *data,
126 sysarg_t width, sysarg_t height, surface_t *surface)
[e31ea20d]127{
[10cb47e]128 widget_init(&canvas->widget, parent, data);
[a35b458]129
[e31ea20d]130 canvas->widget.width = width;
131 canvas->widget.height = height;
[a35b458]132
[e31ea20d]133 canvas->widget.width_min = width;
134 canvas->widget.height_min = height;
135 canvas->widget.width_ideal = width;
136 canvas->widget.height_ideal = height;
137 canvas->widget.width_max = width;
138 canvas->widget.height_max = height;
[a35b458]139
[e31ea20d]140 canvas->widget.destroy = canvas_destroy;
141 canvas->widget.reconfigure = canvas_reconfigure;
142 canvas->widget.rearrange = canvas_rearrange;
143 canvas->widget.repaint = canvas_repaint;
144 canvas->widget.handle_keyboard_event = canvas_handle_keyboard_event;
145 canvas->widget.handle_position_event = canvas_handle_position_event;
[a35b458]146
[e31ea20d]147 canvas->width = width;
148 canvas->height = height;
149 canvas->surface = surface;
[a35b458]150
[e31ea20d]151 return true;
152}
153
[d65be39]154bool update_canvas(canvas_t *canvas, surface_t *surface)
155{
156 if (surface != NULL)
157 canvas->surface = surface;
[a35b458]158
[d65be39]159 canvas_repaint(&canvas->widget);
160 return true;
161}
162
[10cb47e]163canvas_t *create_canvas(widget_t *parent, const void *data, sysarg_t width,
164 sysarg_t height, surface_t *surface)
[e31ea20d]165{
166 canvas_t *canvas = (canvas_t *) malloc(sizeof(canvas_t));
167 if (!canvas)
168 return NULL;
[a35b458]169
[10cb47e]170 if (init_canvas(canvas, parent, data, width, height, surface))
[e31ea20d]171 return canvas;
[a35b458]172
[e31ea20d]173 free(canvas);
174 return NULL;
175}
176
177/** @}
178 */
Note: See TracBrowser for help on using the repository browser.