1 | /*
|
---|
2 | * Copyright (c) 2012 Petr Koupy
|
---|
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 |
|
---|
36 | #include <malloc.h>
|
---|
37 | #include <surface.h>
|
---|
38 |
|
---|
39 | #include "window.h"
|
---|
40 | #include "minimal.h"
|
---|
41 |
|
---|
42 | static void paint_internal(widget_t *w)
|
---|
43 | {
|
---|
44 | minimal_t *min = (minimal_t *) w;
|
---|
45 |
|
---|
46 | surface_t *surface = window_claim(min->widget.window);
|
---|
47 | if (!surface) {
|
---|
48 | window_yield(min->widget.window);
|
---|
49 | }
|
---|
50 |
|
---|
51 | for (sysarg_t y = w->vpos; y < w->vpos + w->height; ++y) {
|
---|
52 | for (sysarg_t x = w->hpos; x < w->hpos + w->width; ++x) {
|
---|
53 | if (y % 2) {
|
---|
54 | if (x % 2) {
|
---|
55 | surface_put_pixel(surface, x, y, min->pix_a);
|
---|
56 | } else {
|
---|
57 | surface_put_pixel(surface, x, y, min->pix_b);
|
---|
58 | }
|
---|
59 | } else {
|
---|
60 | if (x % 2) {
|
---|
61 | surface_put_pixel(surface, x, y, min->pix_b);
|
---|
62 | } else {
|
---|
63 | surface_put_pixel(surface, x, y, min->pix_a);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | window_yield(min->widget.window);
|
---|
70 | }
|
---|
71 |
|
---|
72 | void deinit_minimal(minimal_t *min)
|
---|
73 | {
|
---|
74 | widget_deinit(&min->widget);
|
---|
75 | }
|
---|
76 |
|
---|
77 | static void minimal_destroy(widget_t *widget)
|
---|
78 | {
|
---|
79 | minimal_t *min = (minimal_t *) widget;
|
---|
80 |
|
---|
81 | deinit_minimal(min);
|
---|
82 |
|
---|
83 | free(min);
|
---|
84 | }
|
---|
85 |
|
---|
86 | static void minimal_reconfigure(widget_t *widget)
|
---|
87 | {
|
---|
88 | /* no-op */
|
---|
89 | }
|
---|
90 |
|
---|
91 | static void minimal_rearrange(widget_t *widget, sysarg_t hpos, sysarg_t vpos,
|
---|
92 | sysarg_t width, sysarg_t height)
|
---|
93 | {
|
---|
94 | widget_modify(widget, hpos, vpos, width, height);
|
---|
95 | paint_internal(widget);
|
---|
96 | }
|
---|
97 |
|
---|
98 | static void minimal_repaint(widget_t *widget)
|
---|
99 | {
|
---|
100 | paint_internal(widget);
|
---|
101 | window_damage(widget->window);
|
---|
102 | }
|
---|
103 |
|
---|
104 | static void minimal_handle_keyboard_event(widget_t *widget, kbd_event_t event)
|
---|
105 | {
|
---|
106 | /* no-op */
|
---|
107 | }
|
---|
108 |
|
---|
109 | static void minimal_handle_position_event(widget_t *widget, pos_event_t event)
|
---|
110 | {
|
---|
111 | /* no-op */
|
---|
112 | }
|
---|
113 |
|
---|
114 | bool init_minimal(minimal_t *min, widget_t *parent, pixel_t a, pixel_t b)
|
---|
115 | {
|
---|
116 | widget_init(&min->widget, parent);
|
---|
117 |
|
---|
118 | min->widget.destroy = minimal_destroy;
|
---|
119 | min->widget.reconfigure = minimal_reconfigure;
|
---|
120 | min->widget.rearrange = minimal_rearrange;
|
---|
121 | min->widget.repaint = minimal_repaint;
|
---|
122 | min->widget.handle_keyboard_event = minimal_handle_keyboard_event;
|
---|
123 | min->widget.handle_position_event = minimal_handle_position_event;
|
---|
124 |
|
---|
125 | min->pix_a = a;
|
---|
126 | min->pix_b = b;
|
---|
127 |
|
---|
128 | return true;
|
---|
129 | }
|
---|
130 |
|
---|
131 | minimal_t *create_minimal(widget_t *parent, pixel_t a, pixel_t b)
|
---|
132 | {
|
---|
133 | minimal_t *min = (minimal_t *) malloc(sizeof(minimal_t));
|
---|
134 | if (!min) {
|
---|
135 | return NULL;
|
---|
136 | }
|
---|
137 |
|
---|
138 | if (init_minimal(min, parent, a, b)) {
|
---|
139 | return min;
|
---|
140 | } else {
|
---|
141 | free(min);
|
---|
142 | return NULL;
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | /** @}
|
---|
147 | */
|
---|