blob: e36137d9fd38d9dd133a9620634807835956f23d [file] [log] [blame]
oliverschmidt35973512006-04-09 15:34:11 +00001/*
2 * Copyright (c) 2003, 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
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior
16 * written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * This file is part of the "ctk" GUI toolkit for cc65
31 *
oliverschmidt80725612006-05-07 23:05:57 +000032 * $Id: ctk-mouse.c,v 1.2 2006/05/07 23:05:57 oliverschmidt Exp $
oliverschmidt35973512006-04-09 15:34:11 +000033 *
34 */
35
oliverschmidt80725612006-05-07 23:05:57 +000036#include <stdlib.h>
oliverschmidt35973512006-04-09 15:34:11 +000037#include <mouse.h>
38
39#include "ctk.h"
40#include "ctk-mouse.h"
41#include "ctk-conf.h"
42
43#include "ctk-mouse-conf.h"
44
45#if CTK_CONF_MOUSE_SUPPORT
46
47/* These two are defined in loader-arch.c */
48extern struct mod_ctrl ctrl;
49extern unsigned char load(const char *name);
50
51static struct mouse_pos pos;
52static unsigned char okay;
53
54/*-----------------------------------------------------------------------------------*/
55void
56ctk_mouse_init(void)
57{
58 okay = load(MOUSE_CONF_DRIVER) == LOADER_OK;
59 if(okay) {
60 okay = mouse_install(&mouse_def_callbacks, ctrl.module) == MOUSE_ERR_OK;
oliverschmidt80725612006-05-07 23:05:57 +000061 if(okay) {
62 atexit((void (*)(void))mouse_uninstall);
63 } else {
oliverschmidt35973512006-04-09 15:34:11 +000064 mod_free(ctrl.module);
65 }
66 }
67}
68/*-----------------------------------------------------------------------------------*/
69unsigned short
70ctk_mouse_x(void)
71{
72 if(okay) {
73 mouse_pos(&pos);
74 }
75 return pos.x;
76}
77/*-----------------------------------------------------------------------------------*/
78unsigned short
79ctk_mouse_y(void)
80{
81 if(okay) {
82 mouse_pos(&pos);
83 }
84 return pos.y;
85}
86/*-----------------------------------------------------------------------------------*/
87unsigned char
88ctk_mouse_button(void)
89{
90 if(okay) {
91 return mouse_buttons();
92 }
93 return 0;
94}
95/*-----------------------------------------------------------------------------------*/
96unsigned char
97ctk_mouse_xtoc(unsigned short x)
98{
99 return MOUSE_CONF_XTOC(x);
100}
101/*-----------------------------------------------------------------------------------*/
102unsigned char
103ctk_mouse_ytoc(unsigned short y)
104{
105 return MOUSE_CONF_YTOC(y);
106}
107/*-----------------------------------------------------------------------------------*/
108void
109ctk_mouse_hide(void)
110{
111 if(okay) {
112 mouse_hide();
113 }
114}
115/*-----------------------------------------------------------------------------------*/
116void
117ctk_mouse_show(void)
118{
119 if(okay) {
120 mouse_show();
121 }
122}
123/*-----------------------------------------------------------------------------------*/
124#endif /* CTK_CONF_MOUSE_SUPPORT */