oliverschmidt | 3597351 | 2006-04-09 15:34:11 +0000 | [diff] [blame] | 1 | /* |
| 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 | * |
oliverschmidt | 8072561 | 2006-05-07 23:05:57 +0000 | [diff] [blame] | 32 | * $Id: ctk-mouse.c,v 1.2 2006/05/07 23:05:57 oliverschmidt Exp $ |
oliverschmidt | 3597351 | 2006-04-09 15:34:11 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
| 35 | |
oliverschmidt | 8072561 | 2006-05-07 23:05:57 +0000 | [diff] [blame] | 36 | #include <stdlib.h> |
oliverschmidt | 3597351 | 2006-04-09 15:34:11 +0000 | [diff] [blame] | 37 | #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 */ |
| 48 | extern struct mod_ctrl ctrl; |
| 49 | extern unsigned char load(const char *name); |
| 50 | |
| 51 | static struct mouse_pos pos; |
| 52 | static unsigned char okay; |
| 53 | |
| 54 | /*-----------------------------------------------------------------------------------*/ |
| 55 | void |
| 56 | ctk_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; |
oliverschmidt | 8072561 | 2006-05-07 23:05:57 +0000 | [diff] [blame] | 61 | if(okay) { |
| 62 | atexit((void (*)(void))mouse_uninstall); |
| 63 | } else { |
oliverschmidt | 3597351 | 2006-04-09 15:34:11 +0000 | [diff] [blame] | 64 | mod_free(ctrl.module); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | /*-----------------------------------------------------------------------------------*/ |
| 69 | unsigned short |
| 70 | ctk_mouse_x(void) |
| 71 | { |
| 72 | if(okay) { |
| 73 | mouse_pos(&pos); |
| 74 | } |
| 75 | return pos.x; |
| 76 | } |
| 77 | /*-----------------------------------------------------------------------------------*/ |
| 78 | unsigned short |
| 79 | ctk_mouse_y(void) |
| 80 | { |
| 81 | if(okay) { |
| 82 | mouse_pos(&pos); |
| 83 | } |
| 84 | return pos.y; |
| 85 | } |
| 86 | /*-----------------------------------------------------------------------------------*/ |
| 87 | unsigned char |
| 88 | ctk_mouse_button(void) |
| 89 | { |
| 90 | if(okay) { |
| 91 | return mouse_buttons(); |
| 92 | } |
| 93 | return 0; |
| 94 | } |
| 95 | /*-----------------------------------------------------------------------------------*/ |
| 96 | unsigned char |
| 97 | ctk_mouse_xtoc(unsigned short x) |
| 98 | { |
| 99 | return MOUSE_CONF_XTOC(x); |
| 100 | } |
| 101 | /*-----------------------------------------------------------------------------------*/ |
| 102 | unsigned char |
| 103 | ctk_mouse_ytoc(unsigned short y) |
| 104 | { |
| 105 | return MOUSE_CONF_YTOC(y); |
| 106 | } |
| 107 | /*-----------------------------------------------------------------------------------*/ |
| 108 | void |
| 109 | ctk_mouse_hide(void) |
| 110 | { |
| 111 | if(okay) { |
| 112 | mouse_hide(); |
| 113 | } |
| 114 | } |
| 115 | /*-----------------------------------------------------------------------------------*/ |
| 116 | void |
| 117 | ctk_mouse_show(void) |
| 118 | { |
| 119 | if(okay) { |
| 120 | mouse_show(); |
| 121 | } |
| 122 | } |
| 123 | /*-----------------------------------------------------------------------------------*/ |
| 124 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |