adamdunkels | a2f3c42 | 2004-09-12 20:24:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004, Adam Dunkels. |
| 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 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. Neither the name of the Institute nor the names of its contributors |
| 14 | * may be used to endorse or promote products derived from this software |
| 15 | * without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | * |
| 29 | * This file is part of the Contiki operating system. |
| 30 | * |
| 31 | * Author: Adam Dunkels <adam@sics.se> |
| 32 | * |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 33 | * $Id: ctk-draw.c,v 1.5 2005/03/15 15:51:17 oliverschmidt Exp $ |
adamdunkels | a2f3c42 | 2004-09-12 20:24:53 +0000 | [diff] [blame] | 34 | */ |
adamdunkels | 074dd97 | 2004-07-04 11:39:43 +0000 | [diff] [blame] | 35 | |
| 36 | #include "ek-service.h" |
| 37 | |
| 38 | #include "ctk-draw.h" |
| 39 | #include "ctk.h" |
| 40 | |
| 41 | #include "ctk-draw-service.h" |
| 42 | |
| 43 | |
adamdunkels | 72a4621 | 2004-08-09 20:22:24 +0000 | [diff] [blame] | 44 | unsigned char ctk_draw_windowborder_width = 1, |
| 45 | ctk_draw_windowborder_height = 1, |
| 46 | ctk_draw_windowtitle_height = 1; |
adamdunkels | 074dd97 | 2004-07-04 11:39:43 +0000 | [diff] [blame] | 47 | |
| 48 | EK_SERVICE(service, CTK_DRAW_SERVICE_NAME); |
| 49 | |
| 50 | /*---------------------------------------------------------------------------*/ |
| 51 | static struct ctk_draw_service_interface * |
| 52 | find_interface(void) |
| 53 | { |
| 54 | struct ctk_draw_service_interface *interface; |
| 55 | interface = (struct ctk_draw_service_interface *)ek_service_state(&service); |
| 56 | if(interface != NULL && |
| 57 | interface->version == CTK_DRAW_SERVICE_VERSION) { |
| 58 | return interface; |
| 59 | } else { |
| 60 | return NULL; |
| 61 | } |
| 62 | } |
| 63 | /*---------------------------------------------------------------------------*/ |
| 64 | void |
| 65 | ctk_draw_init(void) |
| 66 | { |
| 67 | struct ctk_draw_service_interface *interface; |
| 68 | |
| 69 | if((interface = find_interface()) != NULL) { |
| 70 | interface->draw_init(); |
| 71 | ctk_draw_windowborder_width = interface->windowborder_width; |
| 72 | ctk_draw_windowborder_height = interface->windowborder_height; |
| 73 | ctk_draw_windowtitle_height = interface->windowtitle_height; |
| 74 | } |
| 75 | } |
| 76 | /*---------------------------------------------------------------------------*/ |
| 77 | void |
| 78 | ctk_draw_clear(unsigned char clipy1, unsigned char clipy2) |
| 79 | { |
| 80 | struct ctk_draw_service_interface *interface; |
| 81 | |
| 82 | if((interface = find_interface()) != NULL) { |
| 83 | interface->draw_clear(clipy1, clipy2); |
| 84 | } |
| 85 | } |
| 86 | /*---------------------------------------------------------------------------*/ |
| 87 | void |
| 88 | ctk_draw_clear_window(struct ctk_window *window, |
| 89 | unsigned char focus, |
| 90 | unsigned char clipy1, |
| 91 | unsigned char clipy2) |
| 92 | { |
| 93 | struct ctk_draw_service_interface *interface; |
| 94 | |
| 95 | if((interface = find_interface()) != NULL) { |
| 96 | interface->draw_clear_window(window, focus, clipy1, clipy2); |
| 97 | } |
| 98 | } |
| 99 | /*---------------------------------------------------------------------------*/ |
| 100 | void |
| 101 | ctk_draw_window(struct ctk_window *window, |
| 102 | unsigned char focus, |
| 103 | unsigned char clipy1, |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 104 | unsigned char clipy2, |
| 105 | unsigned char draw_borders) |
adamdunkels | 074dd97 | 2004-07-04 11:39:43 +0000 | [diff] [blame] | 106 | { |
| 107 | struct ctk_draw_service_interface *interface; |
| 108 | |
| 109 | if((interface = find_interface()) != NULL) { |
oliverschmidt | adf27db | 2005-03-15 15:51:17 +0000 | [diff] [blame] | 110 | interface->draw_window(window, focus, clipy1, clipy2, draw_borders); |
adamdunkels | 074dd97 | 2004-07-04 11:39:43 +0000 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | /*---------------------------------------------------------------------------*/ |
| 114 | void |
| 115 | ctk_draw_dialog(struct ctk_window *dialog) |
| 116 | { |
| 117 | struct ctk_draw_service_interface *interface; |
| 118 | |
| 119 | if((interface = find_interface()) != NULL) { |
| 120 | interface->draw_dialog(dialog); |
| 121 | } |
| 122 | } |
| 123 | /*---------------------------------------------------------------------------*/ |
| 124 | void |
| 125 | ctk_draw_widget(struct ctk_widget *widget, |
| 126 | unsigned char focus, |
| 127 | unsigned char clipy1, |
| 128 | unsigned char clipy2) |
| 129 | { |
| 130 | struct ctk_draw_service_interface *interface; |
| 131 | |
| 132 | if((interface = find_interface()) != NULL) { |
| 133 | interface->draw_widget(widget, focus, clipy1, clipy2); |
| 134 | } |
| 135 | } |
| 136 | /*---------------------------------------------------------------------------*/ |
| 137 | void |
| 138 | ctk_draw_menus(struct ctk_menus *menus) |
| 139 | { |
| 140 | struct ctk_draw_service_interface *interface; |
| 141 | |
| 142 | if((interface = find_interface()) != NULL) { |
| 143 | interface->draw_menus(menus); |
| 144 | } |
| 145 | } |
| 146 | /*---------------------------------------------------------------------------*/ |
| 147 | unsigned char |
| 148 | ctk_draw_width(void) |
| 149 | { |
| 150 | struct ctk_draw_service_interface *interface; |
| 151 | |
| 152 | if((interface = find_interface()) != NULL) { |
| 153 | return interface->width(); |
| 154 | } |
adamdunkels | 72a4621 | 2004-08-09 20:22:24 +0000 | [diff] [blame] | 155 | return 40; |
adamdunkels | 074dd97 | 2004-07-04 11:39:43 +0000 | [diff] [blame] | 156 | } |
| 157 | /*---------------------------------------------------------------------------*/ |
| 158 | unsigned char |
| 159 | ctk_draw_height(void) |
| 160 | { |
| 161 | struct ctk_draw_service_interface *interface; |
| 162 | |
| 163 | if((interface = find_interface()) != NULL) { |
| 164 | return interface->height(); |
| 165 | } |
adamdunkels | 72a4621 | 2004-08-09 20:22:24 +0000 | [diff] [blame] | 166 | return 24; |
adamdunkels | 074dd97 | 2004-07-04 11:39:43 +0000 | [diff] [blame] | 167 | } |
| 168 | /*---------------------------------------------------------------------------*/ |
| 169 | unsigned short |
| 170 | ctk_mouse_xtoc(unsigned short x) |
| 171 | { |
| 172 | struct ctk_draw_service_interface *interface; |
| 173 | |
| 174 | if((interface = find_interface()) != NULL) { |
| 175 | return interface->mouse_xtoc(x); |
| 176 | } |
| 177 | return 0; |
| 178 | } |
| 179 | /*---------------------------------------------------------------------------*/ |
| 180 | unsigned short |
| 181 | ctk_mouse_ytoc(unsigned short y) |
| 182 | { |
| 183 | struct ctk_draw_service_interface *interface; |
| 184 | |
| 185 | if((interface = find_interface()) != NULL) { |
| 186 | return interface->mouse_ytoc(y); |
| 187 | } |
| 188 | return 0; |
| 189 | } |
| 190 | /*---------------------------------------------------------------------------*/ |
adamdunkels | ccdcba2 | 2004-09-12 07:21:08 +0000 | [diff] [blame] | 191 | void |
| 192 | ctk_draw_quit(void) |
| 193 | { |
| 194 | ek_post(service.id, EK_EVENT_REQUEST_EXIT, NULL); |
| 195 | ek_service_reset(&service); |
| 196 | } |
| 197 | /*---------------------------------------------------------------------------*/ |