Search
lxdream.org :: lxdream/src/gui/gtkui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkui.c
changeset 435:7a5d71e8560b
next437:2c259474b474
author nkeynes
date Wed Oct 10 11:02:04 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change First cut of new GUI
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@435
     2
 * $Id: gtkui.c,v 1.1 2007-10-10 11:02:04 nkeynes Exp $
nkeynes@435
     3
 *
nkeynes@435
     4
 * Core GTK-based user interface
nkeynes@435
     5
 *
nkeynes@435
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@435
     7
 *
nkeynes@435
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@435
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@435
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@435
    11
 * (at your option) any later version.
nkeynes@435
    12
 *
nkeynes@435
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@435
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@435
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@435
    16
 * GNU General Public License for more details.
nkeynes@435
    17
 */
nkeynes@435
    18
nkeynes@435
    19
#include "dream.h"
nkeynes@435
    20
#include "dreamcast.h"
nkeynes@435
    21
#include "gui/gtkui.h"
nkeynes@435
    22
nkeynes@435
    23
nkeynes@435
    24
void gtk_gui_update( void );
nkeynes@435
    25
void gtk_gui_start( void );
nkeynes@435
    26
void gtk_gui_stop( void );
nkeynes@435
    27
void gtk_gui_alloc_resources ( void );
nkeynes@435
    28
uint32_t gtk_gui_run_slice( uint32_t nanosecs );
nkeynes@435
    29
nkeynes@435
    30
struct dreamcast_module gtk_gui_module = { "gui", NULL,
nkeynes@435
    31
					   gtk_gui_update, 
nkeynes@435
    32
					   gtk_gui_start, 
nkeynes@435
    33
					   gtk_gui_run_slice, 
nkeynes@435
    34
					   gtk_gui_stop, 
nkeynes@435
    35
					   NULL, NULL };
nkeynes@435
    36
nkeynes@435
    37
/**
nkeynes@435
    38
 * Single-instance windows (at most one)
nkeynes@435
    39
 */
nkeynes@435
    40
static main_window_t main_win = NULL;
nkeynes@435
    41
static debug_window_t debug_win = NULL;
nkeynes@435
    42
static mmio_window_t mmio_win = NULL;
nkeynes@435
    43
nkeynes@435
    44
/**
nkeynes@435
    45
 * Count of running nanoseconds - used to cut back on the GUI runtime
nkeynes@435
    46
 */
nkeynes@435
    47
static uint32_t gtk_gui_nanos = 0;
nkeynes@435
    48
nkeynes@435
    49
nkeynes@435
    50
gboolean gui_parse_cmdline( int *argc, char **argv[] )
nkeynes@435
    51
{
nkeynes@435
    52
    return gtk_init_check( argc, argv );
nkeynes@435
    53
}
nkeynes@435
    54
nkeynes@435
    55
gboolean gui_init( gboolean withDebug )
nkeynes@435
    56
{
nkeynes@435
    57
    dreamcast_register_module( &gtk_gui_module );
nkeynes@435
    58
    gtk_gui_alloc_resources();
nkeynes@435
    59
    if( withDebug ) {
nkeynes@435
    60
	debug_win = debug_window_new();
nkeynes@435
    61
    }
nkeynes@435
    62
    main_win = main_window_new( APP_NAME " " APP_VERSION );
nkeynes@435
    63
    return TRUE;
nkeynes@435
    64
}
nkeynes@435
    65
nkeynes@435
    66
void gui_main_loop(void)
nkeynes@435
    67
{
nkeynes@435
    68
    gtk_main();
nkeynes@435
    69
}
nkeynes@435
    70
nkeynes@435
    71
void gui_update_io_activity( io_activity_type io, gboolean active )
nkeynes@435
    72
{
nkeynes@435
    73
nkeynes@435
    74
}
nkeynes@435
    75
nkeynes@435
    76
void gtk_gui_show_debugger()
nkeynes@435
    77
{
nkeynes@435
    78
    if( debug_win ) {
nkeynes@435
    79
	debug_window_show(debug_win, TRUE);
nkeynes@435
    80
    } else {
nkeynes@435
    81
	debug_win = debug_window_new();
nkeynes@435
    82
    }
nkeynes@435
    83
}    
nkeynes@435
    84
nkeynes@435
    85
GtkWidget *gtk_gui_get_renderarea()
nkeynes@435
    86
{
nkeynes@435
    87
    return main_window_get_renderarea(main_win);
nkeynes@435
    88
}
nkeynes@435
    89
nkeynes@435
    90
/**
nkeynes@435
    91
 * Hook called when DC starts running. Just disables the run/step buttons
nkeynes@435
    92
 * and enables the stop button.
nkeynes@435
    93
 */
nkeynes@435
    94
void gtk_gui_start( void )
nkeynes@435
    95
{
nkeynes@435
    96
    main_window_set_running( main_win, TRUE );
nkeynes@435
    97
    if( debug_win != NULL ) {
nkeynes@435
    98
	debug_window_set_running( debug_win, TRUE );
nkeynes@435
    99
    }
nkeynes@435
   100
}
nkeynes@435
   101
nkeynes@435
   102
/**
nkeynes@435
   103
 * Hook called when DC stops running. Enables the run/step buttons
nkeynes@435
   104
 * and disables the stop button.
nkeynes@435
   105
 */
nkeynes@435
   106
void gtk_gui_stop( void )
nkeynes@435
   107
{
nkeynes@435
   108
    main_window_set_running( main_win, FALSE );
nkeynes@435
   109
    gtk_gui_update();
nkeynes@435
   110
}
nkeynes@435
   111
nkeynes@435
   112
void gtk_gui_update( void )
nkeynes@435
   113
{
nkeynes@435
   114
    if( debug_win ) {
nkeynes@435
   115
	debug_window_set_running( debug_win, FALSE );
nkeynes@435
   116
	debug_window_update(debug_win);
nkeynes@435
   117
    }
nkeynes@435
   118
    if( mmio_win ) {
nkeynes@435
   119
	mmio_win_update(mmio_win);
nkeynes@435
   120
    }
nkeynes@435
   121
    dump_win_update_all();
nkeynes@435
   122
}
nkeynes@435
   123
nkeynes@435
   124
/**
nkeynes@435
   125
 * Module run-slice. Because UI processing is fairly expensive, only 
nkeynes@435
   126
 * run the processing about 10 times a second while we're emulating.
nkeynes@435
   127
 */
nkeynes@435
   128
uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
nkeynes@435
   129
{
nkeynes@435
   130
    gtk_gui_nanos += nanosecs;
nkeynes@435
   131
    if( gtk_gui_nanos > 100000000 ) { 
nkeynes@435
   132
	gtk_gui_nanos = 0;
nkeynes@435
   133
	while( gtk_events_pending() )
nkeynes@435
   134
	    gtk_main_iteration();
nkeynes@435
   135
	//	main_window_set_framerate( main_win, pvr2_get_frame_rate() );
nkeynes@435
   136
    }
nkeynes@435
   137
    return nanosecs;
nkeynes@435
   138
}
nkeynes@435
   139
nkeynes@435
   140
nkeynes@435
   141
PangoFontDescription *gui_fixed_font;
nkeynes@435
   142
GdkColor gui_colour_normal, gui_colour_changed, gui_colour_error;
nkeynes@435
   143
GdkColor gui_colour_warn, gui_colour_pc, gui_colour_debug;
nkeynes@435
   144
GdkColor gui_colour_trace, gui_colour_break, gui_colour_temp_break;
nkeynes@435
   145
GdkColor gui_colour_white;
nkeynes@435
   146
nkeynes@435
   147
void gtk_gui_alloc_resources() {
nkeynes@435
   148
    GdkColormap *map;
nkeynes@435
   149
nkeynes@435
   150
    gui_colour_normal.red = gui_colour_normal.green = gui_colour_normal.blue = 0;
nkeynes@435
   151
    gui_colour_changed.red = gui_colour_changed.green = 64*256;
nkeynes@435
   152
    gui_colour_changed.blue = 154*256;
nkeynes@435
   153
    gui_colour_error.red = 65535;
nkeynes@435
   154
    gui_colour_error.green = gui_colour_error.blue = 64*256;
nkeynes@435
   155
    gui_colour_pc.red = 32*256;
nkeynes@435
   156
    gui_colour_pc.green = 170*256;
nkeynes@435
   157
    gui_colour_pc.blue = 52*256;
nkeynes@435
   158
    gui_colour_warn = gui_colour_changed;
nkeynes@435
   159
    gui_colour_trace.red = 156*256;
nkeynes@435
   160
    gui_colour_trace.green = 78*256;
nkeynes@435
   161
    gui_colour_trace.blue = 201*256;
nkeynes@435
   162
    gui_colour_debug = gui_colour_pc;
nkeynes@435
   163
    gui_colour_break.red = 65535;
nkeynes@435
   164
    gui_colour_break.green = gui_colour_break.blue = 192*256;
nkeynes@435
   165
    gui_colour_temp_break.red = gui_colour_temp_break.green = 128*256;
nkeynes@435
   166
    gui_colour_temp_break.blue = 32*256;
nkeynes@435
   167
    gui_colour_white.red = gui_colour_white.green = gui_colour_white.blue = 65535;
nkeynes@435
   168
nkeynes@435
   169
    map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
nkeynes@435
   170
    gdk_colormap_alloc_color(map, &gui_colour_normal, TRUE, TRUE);
nkeynes@435
   171
    gdk_colormap_alloc_color(map, &gui_colour_changed, TRUE, TRUE);
nkeynes@435
   172
    gdk_colormap_alloc_color(map, &gui_colour_error, TRUE, TRUE);
nkeynes@435
   173
    gdk_colormap_alloc_color(map, &gui_colour_warn, TRUE, TRUE);
nkeynes@435
   174
    gdk_colormap_alloc_color(map, &gui_colour_pc, TRUE, TRUE);
nkeynes@435
   175
    gdk_colormap_alloc_color(map, &gui_colour_debug, TRUE, TRUE);
nkeynes@435
   176
    gdk_colormap_alloc_color(map, &gui_colour_trace, TRUE, TRUE);
nkeynes@435
   177
    gdk_colormap_alloc_color(map, &gui_colour_break, TRUE, TRUE);
nkeynes@435
   178
    gdk_colormap_alloc_color(map, &gui_colour_temp_break, TRUE, TRUE);
nkeynes@435
   179
    gdk_colormap_alloc_color(map, &gui_colour_white, TRUE, TRUE);
nkeynes@435
   180
    gui_fixed_font = pango_font_description_from_string("Courier 10");
nkeynes@435
   181
}
.