Search
lxdream.org :: lxdream/src/display.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/display.c
changeset 144:7f0714e89aaa
next166:8aa70cf503a2
author nkeynes
date Mon May 15 08:28:52 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Rename video_driver to display_driver
Add input source to display
Implement configuration file support
Hook controllers up to configuration
view annotate diff log raw
     1 /**
     2  * $Id: display.c,v 1.1 2006-05-15 08:28:48 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     if( display_driver == NULL || keysym == NULL )
    69 	return FALSE; /* No display driver */
    70     uint16_t keycode = display_driver->resolve_keysym(keysym);
    71     if( keycode == 0 )
    72 	return FALSE; /* Invalid keysym */
    74     struct keymap_entry *key = input_create_key( keycode );
    75     key->callback = callback;
    76     key->data = data;
    77     key->value = value;
    78     INFO( "Registered key '%s' (%4x)", keysym, keycode );
    79     return TRUE;
    80 }
    82 void input_unregister_key( const gchar *keysym )
    83 {
    84     if( display_driver == NULL || keysym == NULL )
    85 	return;
    86     uint16_t keycode = display_driver->resolve_keysym(keysym);
    87     if( keycode == 0 )
    88 	return;
    89     input_delete_key( keycode );
    90 }
    93 gboolean input_is_key_valid( const gchar *keysym )
    94 {
    95     if( display_driver == NULL )
    96 	return FALSE; /* No display driver */
    97     return display_driver->resolve_keysym(keysym) != 0;
    98 }
   100 gboolean input_is_key_registered( const gchar *keysym )
   101 {
   102     if( display_driver == NULL )
   103 	return FALSE;
   104     uint16_t keycode = display_driver->resolve_keysym(keysym);
   105     if( keycode == 0 )
   106 	return FALSE;
   107     return input_get_key( keycode ) != NULL;
   108 }
   110 void input_event_keydown( uint16_t keycode )
   111 {
   112     struct keymap_entry *key = input_get_key(keycode);
   113     if( key != NULL ) {
   114 	key->callback( key->data, key->value, TRUE );
   115     }	
   116 }
   118 void input_event_keyup( uint16_t keycode )
   119 {
   120     struct keymap_entry *key = input_get_key(keycode);
   121     if( key != NULL ) {
   122 	key->callback( key->data, key->value, FALSE );
   123     }
   124 }
   128 void display_set_driver( display_driver_t driver )
   129 {
   130     if( display_driver != NULL && display_driver->shutdown_driver != NULL )
   131 	display_driver->shutdown_driver();
   133     display_driver = driver;
   134     if( driver->init_driver != NULL )
   135 	driver->init_driver();
   136     driver->set_display_format( 640, 480, COLFMT_ARGB8888 );
   137     driver->set_render_format( 640, 480, COLFMT_ARGB8888, FALSE );
   138     texcache_gl_init();
   139 }
.