[6d5e378] | 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 |
|
---|
[38d150e] | 36 | #include <stdlib.h>
|
---|
[2bb6d04] | 37 | #include <draw/surface.h>
|
---|
[6d5e378] | 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 | }
|
---|
[a35b458] | 68 |
|
---|
[6d5e378] | 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 |
|
---|
[10cb47e] | 114 | bool init_minimal(minimal_t *min, widget_t *parent, const void *data, pixel_t a,
|
---|
| 115 | pixel_t b)
|
---|
[6d5e378] | 116 | {
|
---|
[10cb47e] | 117 | widget_init(&min->widget, parent, data);
|
---|
[6d5e378] | 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 |
|
---|
[10cb47e] | 132 | minimal_t *create_minimal(widget_t *parent, const void *data, pixel_t a,
|
---|
| 133 | pixel_t b)
|
---|
[6d5e378] | 134 | {
|
---|
| 135 | minimal_t *min = (minimal_t *) malloc(sizeof(minimal_t));
|
---|
| 136 | if (!min) {
|
---|
| 137 | return NULL;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[10cb47e] | 140 | if (init_minimal(min, parent, data, a, b)) {
|
---|
[6d5e378] | 141 | return min;
|
---|
| 142 | } else {
|
---|
| 143 | free(min);
|
---|
| 144 | return NULL;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | /** @}
|
---|
| 149 | */
|
---|