Search
lxdream.org :: lxdream/src/display.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/display.c
changeset 271:2ec052d24881
prev166:8aa70cf503a2
next327:00d55a462af3
author nkeynes
date Thu Jan 25 08:21:56 2007 +0000 (17 years ago)
permissions -rw-r--r--
last change Remove cached BSC values (wasn't being saved, and is rarely used anyway)
view annotate diff log raw
     1 /**
     2  * $Id: display.c,v 1.3 2007-01-11 06:51:52 nkeynes Exp $
     3  *
     4  * Generic support for keyboard and other input sources. The active display
     5  * driver is expected to deliver events here, where they're translated and
     6  * passed to the appropriate dreamcast controllers (if any).
     7  *
     8  * Copyright (c) 2005 Nathan Keynes.
     9  *
    10  * This program is free software; you can redistribute it and/or modify
    11  * it under the terms of the GNU General Public License as published by
    12  * the Free Software Foundation; either version 2 of the License, or
    13  * (at your option) any later version.
    14  *
    15  * This program is distributed in the hope that it will be useful,
    16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  * GNU General Public License for more details.
    19  */
    21 #include <stdint.h>
    22 #include <assert.h>
    23 #include "dream.h"
    24 #include "display.h"
    26 typedef struct keymap_entry {
    27     uint16_t keycode;
    28     input_key_callback_t callback;
    29     void *data;
    30     uint32_t value;
    31 } *keymap_entry_t;
    33 /**
    34  * FIXME: make this more memory efficient
    35  */
    36 struct keymap_entry *keymap[65536];
    39 static struct keymap_entry *input_create_key( uint16_t keycode )
    40 {
    41     struct keymap_entry *key = keymap[ keycode ];
    42     if( key == NULL ) {
    43 	key = malloc( sizeof( struct keymap_entry ) );
    44 	assert( key != NULL );
    45 	keymap[ keycode ] = key;
    46 	key->keycode = keycode;
    47     }
    48     return key;
    49 }
    51 static void input_delete_key( uint16_t keycode )
    52 {
    53     struct keymap_entry *key = keymap[keycode];
    54     if( key != NULL ) {
    55 	free( key );
    56 	keymap[keycode] = NULL;
    57     }
    58 }
    60 static struct keymap_entry *input_get_key( uint16_t keycode )
    61 {
    62     return keymap[ keycode ];
    63 }
    65 gboolean input_register_key( const gchar *keysym, input_key_callback_t callback,
    66 			     void *data, uint32_t value )
    67 {
    68     int i;
    69     if( display_driver == NULL || keysym == NULL )
    70 	return FALSE; /* No display driver */
    71     gchar **strv = g_strsplit(keysym, ",", 16);
    72     gchar **s = strv;
    73     while( *s != NULL ) {
    74 	uint16_t keycode = display_driver->resolve_keysym(g_strstrip(*s));
    75 	if( keycode == 0 )
    76 	    return FALSE; /* Invalid keysym */
    78 	struct keymap_entry *key = input_create_key( keycode );
    79 	key->callback = callback;
    80 	key->data = data;
    81 	key->value = value;
    82 	s++;
    83     }
    84     g_strfreev(strv);
    85     return TRUE;
    86 }
    88 void input_unregister_key( const gchar *keysym )
    89 {
    90     if( display_driver == NULL || keysym == NULL )
    91 	return;
    92     uint16_t keycode = display_driver->resolve_keysym(keysym);
    93     if( keycode == 0 )
    94 	return;
    95     input_delete_key( keycode );
    96 }
    99 gboolean input_is_key_valid( const gchar *keysym )
   100 {
   101     if( display_driver == NULL )
   102 	return FALSE; /* No display driver */
   103     return display_driver->resolve_keysym(keysym) != 0;
   104 }
   106 gboolean input_is_key_registered( const gchar *keysym )
   107 {
   108     if( display_driver == NULL )
   109 	return FALSE;
   110     uint16_t keycode = display_driver->resolve_keysym(keysym);
   111     if( keycode == 0 )
   112 	return FALSE;
   113     return input_get_key( keycode ) != NULL;
   114 }
   116 void input_event_keydown( uint16_t keycode )
   117 {
   118     struct keymap_entry *key = input_get_key(keycode);
   119     if( key != NULL ) {
   120 	key->callback( key->data, key->value, TRUE );
   121     }	
   122 }
   124 void input_event_keyup( uint16_t keycode )
   125 {
   126     struct keymap_entry *key = input_get_key(keycode);
   127     if( key != NULL ) {
   128 	key->callback( key->data, key->value, FALSE );
   129     }
   130 }
   134 void display_set_driver( display_driver_t driver )
   135 {
   136     if( display_driver != NULL && display_driver->shutdown_driver != NULL )
   137 	display_driver->shutdown_driver();
   139     display_driver = driver;
   140     if( driver->init_driver != NULL )
   141 	driver->init_driver();
   142     driver->set_display_format( 640, 480, COLFMT_ARGB8888 );
   143     driver->set_render_format( 640, 480, COLFMT_ARGB8888, FALSE );
   144     texcache_gl_init();
   145 }
.