blob: 7e0827a33726c35838fbb62d17a6e70830eb06eb [file] [log] [blame]
adamdunkelsa2f3c422004-09-12 20:24:53 +00001/*
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 *
oliverschmidtadf27db2005-03-15 15:51:17 +000033 * $Id: ctk-draw.c,v 1.5 2005/03/15 15:51:17 oliverschmidt Exp $
adamdunkelsa2f3c422004-09-12 20:24:53 +000034 */
adamdunkels074dd972004-07-04 11:39:43 +000035
36#include "ek-service.h"
37
38#include "ctk-draw.h"
39#include "ctk.h"
40
41#include "ctk-draw-service.h"
42
43
adamdunkels72a46212004-08-09 20:22:24 +000044unsigned char ctk_draw_windowborder_width = 1,
45 ctk_draw_windowborder_height = 1,
46 ctk_draw_windowtitle_height = 1;
adamdunkels074dd972004-07-04 11:39:43 +000047
48EK_SERVICE(service, CTK_DRAW_SERVICE_NAME);
49
50/*---------------------------------------------------------------------------*/
51static struct ctk_draw_service_interface *
52find_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/*---------------------------------------------------------------------------*/
64void
65ctk_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/*---------------------------------------------------------------------------*/
77void
78ctk_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/*---------------------------------------------------------------------------*/
87void
88ctk_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/*---------------------------------------------------------------------------*/
100void
101ctk_draw_window(struct ctk_window *window,
102 unsigned char focus,
103 unsigned char clipy1,
oliverschmidtadf27db2005-03-15 15:51:17 +0000104 unsigned char clipy2,
105 unsigned char draw_borders)
adamdunkels074dd972004-07-04 11:39:43 +0000106{
107 struct ctk_draw_service_interface *interface;
108
109 if((interface = find_interface()) != NULL) {
oliverschmidtadf27db2005-03-15 15:51:17 +0000110 interface->draw_window(window, focus, clipy1, clipy2, draw_borders);
adamdunkels074dd972004-07-04 11:39:43 +0000111 }
112}
113/*---------------------------------------------------------------------------*/
114void
115ctk_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/*---------------------------------------------------------------------------*/
124void
125ctk_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/*---------------------------------------------------------------------------*/
137void
138ctk_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/*---------------------------------------------------------------------------*/
147unsigned char
148ctk_draw_width(void)
149{
150 struct ctk_draw_service_interface *interface;
151
152 if((interface = find_interface()) != NULL) {
153 return interface->width();
154 }
adamdunkels72a46212004-08-09 20:22:24 +0000155 return 40;
adamdunkels074dd972004-07-04 11:39:43 +0000156}
157/*---------------------------------------------------------------------------*/
158unsigned char
159ctk_draw_height(void)
160{
161 struct ctk_draw_service_interface *interface;
162
163 if((interface = find_interface()) != NULL) {
164 return interface->height();
165 }
adamdunkels72a46212004-08-09 20:22:24 +0000166 return 24;
adamdunkels074dd972004-07-04 11:39:43 +0000167}
168/*---------------------------------------------------------------------------*/
169unsigned short
170ctk_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/*---------------------------------------------------------------------------*/
180unsigned short
181ctk_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/*---------------------------------------------------------------------------*/
adamdunkelsccdcba22004-09-12 07:21:08 +0000191void
192ctk_draw_quit(void)
193{
194 ek_post(service.id, EK_EVENT_REQUEST_EXIT, NULL);
195 ek_service_reset(&service);
196}
197/*---------------------------------------------------------------------------*/