blob: 33af1e2e26d11a4c78da653f479a0361bc72af6c [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 *
33 * $Id: ctk-draw.c,v 1.4 2004/09/12 20:24:55 adamdunkels Exp $
34 */
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,
104 unsigned char clipy2)
105{
106 struct ctk_draw_service_interface *interface;
107
108 if((interface = find_interface()) != NULL) {
109 interface->draw_window(window, focus, clipy1, clipy2);
110 }
111}
112/*---------------------------------------------------------------------------*/
113void
114ctk_draw_dialog(struct ctk_window *dialog)
115{
116 struct ctk_draw_service_interface *interface;
117
118 if((interface = find_interface()) != NULL) {
119 interface->draw_dialog(dialog);
120 }
121}
122/*---------------------------------------------------------------------------*/
123void
124ctk_draw_widget(struct ctk_widget *widget,
125 unsigned char focus,
126 unsigned char clipy1,
127 unsigned char clipy2)
128{
129 struct ctk_draw_service_interface *interface;
130
131 if((interface = find_interface()) != NULL) {
132 interface->draw_widget(widget, focus, clipy1, clipy2);
133 }
134}
135/*---------------------------------------------------------------------------*/
136void
137ctk_draw_menus(struct ctk_menus *menus)
138{
139 struct ctk_draw_service_interface *interface;
140
141 if((interface = find_interface()) != NULL) {
142 interface->draw_menus(menus);
143 }
144}
145/*---------------------------------------------------------------------------*/
146unsigned char
147ctk_draw_width(void)
148{
149 struct ctk_draw_service_interface *interface;
150
151 if((interface = find_interface()) != NULL) {
152 return interface->width();
153 }
adamdunkels72a46212004-08-09 20:22:24 +0000154 return 40;
adamdunkels074dd972004-07-04 11:39:43 +0000155}
156/*---------------------------------------------------------------------------*/
157unsigned char
158ctk_draw_height(void)
159{
160 struct ctk_draw_service_interface *interface;
161
162 if((interface = find_interface()) != NULL) {
163 return interface->height();
164 }
adamdunkels72a46212004-08-09 20:22:24 +0000165 return 24;
adamdunkels074dd972004-07-04 11:39:43 +0000166}
167/*---------------------------------------------------------------------------*/
168unsigned short
169ctk_mouse_xtoc(unsigned short x)
170{
171 struct ctk_draw_service_interface *interface;
172
173 if((interface = find_interface()) != NULL) {
174 return interface->mouse_xtoc(x);
175 }
176 return 0;
177}
178/*---------------------------------------------------------------------------*/
179unsigned short
180ctk_mouse_ytoc(unsigned short y)
181{
182 struct ctk_draw_service_interface *interface;
183
184 if((interface = find_interface()) != NULL) {
185 return interface->mouse_ytoc(y);
186 }
187 return 0;
188}
189/*---------------------------------------------------------------------------*/
adamdunkelsccdcba22004-09-12 07:21:08 +0000190void
191ctk_draw_quit(void)
192{
193 ek_post(service.id, EK_EVENT_REQUEST_EXIT, NULL);
194 ek_service_reset(&service);
195}
196/*---------------------------------------------------------------------------*/