source: mainline/uspace/lib/gui/minimal.c@ cd9531d3

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

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 3.7 KB
Line 
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 <stdlib.h>
37#include <surface.h>
38
39#include "window.h"
40#include "minimal.h"
41
42static 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
72void deinit_minimal(minimal_t *min)
73{
74 widget_deinit(&min->widget);
75}
76
77static 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
86static void minimal_reconfigure(widget_t *widget)
87{
88 /* no-op */
89}
90
91static 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
98static void minimal_repaint(widget_t *widget)
99{
100 paint_internal(widget);
101 window_damage(widget->window);
102}
103
104static void minimal_handle_keyboard_event(widget_t *widget, kbd_event_t event)
105{
106 /* no-op */
107}
108
109static void minimal_handle_position_event(widget_t *widget, pos_event_t event)
110{
111 /* no-op */
112}
113
114bool init_minimal(minimal_t *min, widget_t *parent, const void *data, pixel_t a,
115 pixel_t b)
116{
117 widget_init(&min->widget, parent, data);
118
119 min->widget.destroy = minimal_destroy;
120 min->widget.reconfigure = minimal_reconfigure;
121 min->widget.rearrange = minimal_rearrange;
122 min->widget.repaint = minimal_repaint;
123 min->widget.handle_keyboard_event = minimal_handle_keyboard_event;
124 min->widget.handle_position_event = minimal_handle_position_event;
125
126 min->pix_a = a;
127 min->pix_b = b;
128
129 return true;
130}
131
132minimal_t *create_minimal(widget_t *parent, const void *data, pixel_t a,
133 pixel_t b)
134{
135 minimal_t *min = (minimal_t *) malloc(sizeof(minimal_t));
136 if (!min) {
137 return NULL;
138 }
139
140 if (init_minimal(min, parent, data, a, b)) {
141 return min;
142 } else {
143 free(min);
144 return NULL;
145 }
146}
147
148/** @}
149 */
Note: See TracBrowser for help on using the repository browser.