Search
lxdream.org :: lxdream/src/gui/gtkui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkui.c
changeset 437:2c259474b474
prev435:7a5d71e8560b
next447:3e095bfcb476
author nkeynes
date Thu Oct 11 08:22:03 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add speed meter to main window
Add sunken border around video area
Add debugger menu item
Move logging out to util.c
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@437
     2
 * $Id: gtkui.c,v 1.2 2007-10-11 08:22:03 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@437
    19
#include <sys/time.h>
nkeynes@437
    20
#include <time.h>
nkeynes@435
    21
#include "dream.h"
nkeynes@435
    22
#include "dreamcast.h"
nkeynes@435
    23
#include "gui/gtkui.h"
nkeynes@435
    24
nkeynes@435
    25
nkeynes@435
    26
void gtk_gui_update( void );
nkeynes@435
    27
void gtk_gui_start( void );
nkeynes@435
    28
void gtk_gui_stop( void );
nkeynes@435
    29
void gtk_gui_alloc_resources ( void );
nkeynes@435
    30
uint32_t gtk_gui_run_slice( uint32_t nanosecs );
nkeynes@435
    31
nkeynes@435
    32
struct dreamcast_module gtk_gui_module = { "gui", NULL,
nkeynes@435
    33
					   gtk_gui_update, 
nkeynes@435
    34
					   gtk_gui_start, 
nkeynes@435
    35
					   gtk_gui_run_slice, 
nkeynes@435
    36
					   gtk_gui_stop, 
nkeynes@435
    37
					   NULL, NULL };
nkeynes@435
    38
nkeynes@435
    39
/**
nkeynes@435
    40
 * Single-instance windows (at most one)
nkeynes@435
    41
 */
nkeynes@435
    42
static main_window_t main_win = NULL;
nkeynes@435
    43
static debug_window_t debug_win = NULL;
nkeynes@435
    44
static mmio_window_t mmio_win = NULL;
nkeynes@435
    45
nkeynes@435
    46
/**
nkeynes@435
    47
 * Count of running nanoseconds - used to cut back on the GUI runtime
nkeynes@435
    48
 */
nkeynes@435
    49
static uint32_t gtk_gui_nanos = 0;
nkeynes@437
    50
static struct timeval gtk_gui_lasttv;
nkeynes@435
    51
nkeynes@435
    52
gboolean gui_parse_cmdline( int *argc, char **argv[] )
nkeynes@435
    53
{
nkeynes@435
    54
    return gtk_init_check( argc, argv );
nkeynes@435
    55
}
nkeynes@435
    56
nkeynes@435
    57
gboolean gui_init( gboolean withDebug )
nkeynes@435
    58
{
nkeynes@435
    59
    dreamcast_register_module( &gtk_gui_module );
nkeynes@435
    60
    gtk_gui_alloc_resources();
nkeynes@435
    61
    if( withDebug ) {
nkeynes@435
    62
	debug_win = debug_window_new();
nkeynes@435
    63
    }
nkeynes@435
    64
    main_win = main_window_new( APP_NAME " " APP_VERSION );
nkeynes@435
    65
    return TRUE;
nkeynes@435
    66
}
nkeynes@435
    67
nkeynes@435
    68
void gui_main_loop(void)
nkeynes@435
    69
{
nkeynes@435
    70
    gtk_main();
nkeynes@435
    71
}
nkeynes@435
    72
nkeynes@435
    73
void gui_update_io_activity( io_activity_type io, gboolean active )
nkeynes@435
    74
{
nkeynes@435
    75
nkeynes@435
    76
}
nkeynes@435
    77
nkeynes@435
    78
void gtk_gui_show_debugger()
nkeynes@435
    79
{
nkeynes@435
    80
    if( debug_win ) {
nkeynes@435
    81
	debug_window_show(debug_win, TRUE);
nkeynes@435
    82
    } else {
nkeynes@435
    83
	debug_win = debug_window_new();
nkeynes@435
    84
    }
nkeynes@435
    85
}    
nkeynes@435
    86
nkeynes@435
    87
GtkWidget *gtk_gui_get_renderarea()
nkeynes@435
    88
{
nkeynes@435
    89
    return main_window_get_renderarea(main_win);
nkeynes@435
    90
}
nkeynes@435
    91
nkeynes@435
    92
/**
nkeynes@435
    93
 * Hook called when DC starts running. Just disables the run/step buttons
nkeynes@435
    94
 * and enables the stop button.
nkeynes@435
    95
 */
nkeynes@435
    96
void gtk_gui_start( void )
nkeynes@435
    97
{
nkeynes@435
    98
    main_window_set_running( main_win, TRUE );
nkeynes@435
    99
    if( debug_win != NULL ) {
nkeynes@435
   100
	debug_window_set_running( debug_win, TRUE );
nkeynes@435
   101
    }
nkeynes@437
   102
    gtk_gui_nanos = 0;
nkeynes@437
   103
    gettimeofday(&gtk_gui_lasttv,NULL);
nkeynes@435
   104
}
nkeynes@435
   105
nkeynes@435
   106
/**
nkeynes@435
   107
 * Hook called when DC stops running. Enables the run/step buttons
nkeynes@435
   108
 * and disables the stop button.
nkeynes@435
   109
 */
nkeynes@435
   110
void gtk_gui_stop( void )
nkeynes@435
   111
{
nkeynes@435
   112
    main_window_set_running( main_win, FALSE );
nkeynes@435
   113
    gtk_gui_update();
nkeynes@435
   114
}
nkeynes@435
   115
nkeynes@435
   116
void gtk_gui_update( void )
nkeynes@435
   117
{
nkeynes@435
   118
    if( debug_win ) {
nkeynes@435
   119
	debug_window_set_running( debug_win, FALSE );
nkeynes@435
   120
	debug_window_update(debug_win);
nkeynes@435
   121
    }
nkeynes@435
   122
    if( mmio_win ) {
nkeynes@435
   123
	mmio_win_update(mmio_win);
nkeynes@435
   124
    }
nkeynes@435
   125
    dump_win_update_all();
nkeynes@435
   126
}
nkeynes@435
   127
nkeynes@435
   128
/**
nkeynes@435
   129
 * Module run-slice. Because UI processing is fairly expensive, only 
nkeynes@435
   130
 * run the processing about 10 times a second while we're emulating.
nkeynes@435
   131
 */
nkeynes@435
   132
uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
nkeynes@435
   133
{
nkeynes@435
   134
    gtk_gui_nanos += nanosecs;
nkeynes@435
   135
    if( gtk_gui_nanos > 100000000 ) { 
nkeynes@437
   136
	struct timeval tv;
nkeynes@435
   137
	while( gtk_events_pending() )
nkeynes@435
   138
	    gtk_main_iteration();
nkeynes@437
   139
	
nkeynes@437
   140
	gettimeofday(&tv,NULL);
nkeynes@437
   141
	double ns = ((tv.tv_sec - gtk_gui_lasttv.tv_sec) * 1000000000.0) +
nkeynes@437
   142
	    ((tv.tv_usec - gtk_gui_lasttv.tv_usec)*1000.0);
nkeynes@437
   143
	double speed = (float)( (double)gtk_gui_nanos * 100.0 / ns );
nkeynes@437
   144
	gtk_gui_lasttv.tv_sec = tv.tv_sec;
nkeynes@437
   145
	gtk_gui_lasttv.tv_usec = tv.tv_usec;
nkeynes@437
   146
	main_window_set_speed( main_win, speed );
nkeynes@437
   147
	gtk_gui_nanos = 0;
nkeynes@435
   148
    }
nkeynes@435
   149
    return nanosecs;
nkeynes@435
   150
}
nkeynes@435
   151
nkeynes@435
   152
nkeynes@435
   153
PangoFontDescription *gui_fixed_font;
nkeynes@435
   154
GdkColor gui_colour_normal, gui_colour_changed, gui_colour_error;
nkeynes@435
   155
GdkColor gui_colour_warn, gui_colour_pc, gui_colour_debug;
nkeynes@435
   156
GdkColor gui_colour_trace, gui_colour_break, gui_colour_temp_break;
nkeynes@435
   157
GdkColor gui_colour_white;
nkeynes@435
   158
nkeynes@435
   159
void gtk_gui_alloc_resources() {
nkeynes@435
   160
    GdkColormap *map;
nkeynes@435
   161
nkeynes@435
   162
    gui_colour_normal.red = gui_colour_normal.green = gui_colour_normal.blue = 0;
nkeynes@435
   163
    gui_colour_changed.red = gui_colour_changed.green = 64*256;
nkeynes@435
   164
    gui_colour_changed.blue = 154*256;
nkeynes@435
   165
    gui_colour_error.red = 65535;
nkeynes@435
   166
    gui_colour_error.green = gui_colour_error.blue = 64*256;
nkeynes@435
   167
    gui_colour_pc.red = 32*256;
nkeynes@435
   168
    gui_colour_pc.green = 170*256;
nkeynes@435
   169
    gui_colour_pc.blue = 52*256;
nkeynes@435
   170
    gui_colour_warn = gui_colour_changed;
nkeynes@435
   171
    gui_colour_trace.red = 156*256;
nkeynes@435
   172
    gui_colour_trace.green = 78*256;
nkeynes@435
   173
    gui_colour_trace.blue = 201*256;
nkeynes@435
   174
    gui_colour_debug = gui_colour_pc;
nkeynes@435
   175
    gui_colour_break.red = 65535;
nkeynes@435
   176
    gui_colour_break.green = gui_colour_break.blue = 192*256;
nkeynes@435
   177
    gui_colour_temp_break.red = gui_colour_temp_break.green = 128*256;
nkeynes@435
   178
    gui_colour_temp_break.blue = 32*256;
nkeynes@435
   179
    gui_colour_white.red = gui_colour_white.green = gui_colour_white.blue = 65535;
nkeynes@435
   180
nkeynes@435
   181
    map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
nkeynes@435
   182
    gdk_colormap_alloc_color(map, &gui_colour_normal, TRUE, TRUE);
nkeynes@435
   183
    gdk_colormap_alloc_color(map, &gui_colour_changed, TRUE, TRUE);
nkeynes@435
   184
    gdk_colormap_alloc_color(map, &gui_colour_error, TRUE, TRUE);
nkeynes@435
   185
    gdk_colormap_alloc_color(map, &gui_colour_warn, TRUE, TRUE);
nkeynes@435
   186
    gdk_colormap_alloc_color(map, &gui_colour_pc, TRUE, TRUE);
nkeynes@435
   187
    gdk_colormap_alloc_color(map, &gui_colour_debug, TRUE, TRUE);
nkeynes@435
   188
    gdk_colormap_alloc_color(map, &gui_colour_trace, TRUE, TRUE);
nkeynes@435
   189
    gdk_colormap_alloc_color(map, &gui_colour_break, TRUE, TRUE);
nkeynes@435
   190
    gdk_colormap_alloc_color(map, &gui_colour_temp_break, TRUE, TRUE);
nkeynes@435
   191
    gdk_colormap_alloc_color(map, &gui_colour_white, TRUE, TRUE);
nkeynes@435
   192
    gui_fixed_font = pango_font_description_from_string("Courier 10");
nkeynes@435
   193
}
.