filename | src/gtkui/main_win.c |
changeset | 561:533f6b478071 |
prev | 545:fdcdcd8b9fd1 |
next | 606:23029426ab8f |
author | nkeynes |
date | Mon Jan 14 10:23:49 2008 +0000 (16 years ago) |
branch | lxdream-mmu |
permissions | -rw-r--r-- |
last change | Remove asm file and convert to inline (easier to cope with platform conventions) Add breakpoint support Add MMU store-queue support |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Define the main (emu) GTK window, along with its menubars,
5 * toolbars, etc.
6 *
7 * Copyright (c) 2005 Nathan Keynes.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
20 #include <assert.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include <stdlib.h>
28 #include <gtk/gtk.h>
29 #include <gdk/gdkx.h>
30 #include <X11/Xutil.h>
32 #include "dream.h"
33 #include "gtkui/gtkui.h"
34 #include "drivers/video_glx.h"
37 struct main_window_info {
38 GtkWidget *window;
39 GtkWidget *video;
40 GtkWidget *menubar;
41 GtkWidget *toolbar;
42 GtkWidget *statusbar;
43 GtkActionGroup *actions;
44 };
46 static gboolean on_main_window_deleted( GtkWidget *widget, GdkEvent event, gpointer user_data )
47 {
48 exit(0);
49 }
51 static void on_main_window_state_changed( GtkWidget *widget, GdkEventWindowState *state,
52 gpointer userdata )
53 {
54 main_window_t win = (main_window_t)userdata;
55 if( state->changed_mask & GDK_WINDOW_STATE_FULLSCREEN ) {
56 gboolean fs = (state->new_window_state & GDK_WINDOW_STATE_FULLSCREEN);
57 GtkWidget *frame = gtk_widget_get_parent(win->video);
58 if( frame->style == NULL ) {
59 gtk_widget_set_style( frame, gtk_style_new() );
60 }
61 if( fs ) {
62 gtk_widget_hide( win->menubar );
63 gtk_widget_hide( win->toolbar );
64 gtk_widget_hide( win->statusbar );
66 frame->style->xthickness = 0;
67 frame->style->ythickness = 0;
68 } else {
69 frame->style->xthickness = 2;
70 frame->style->ythickness = 2;
71 gtk_widget_show( win->menubar );
72 gtk_widget_show( win->toolbar );
73 gtk_widget_show( win->statusbar );
74 }
75 gtk_widget_queue_draw( win->window );
76 }
77 }
79 main_window_t main_window_new( const gchar *title, GtkWidget *menubar, GtkWidget *toolbar,
80 GtkAccelGroup *accel_group )
81 {
82 GtkWidget *vbox;
83 GtkWidget *frame;
84 main_window_t win = g_malloc0( sizeof(struct main_window_info) );
86 win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
87 win->menubar = menubar;
88 win->toolbar = toolbar;
89 gtk_window_set_title( GTK_WINDOW(win->window), title );
90 gtk_window_add_accel_group (GTK_WINDOW (win->window), accel_group);
92 gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
94 Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(win->window));
95 Screen *screen = gdk_x11_screen_get_xscreen( gtk_widget_get_screen(win->window));
96 int screen_no = XScreenNumberOfScreen(screen);
97 video_glx_init(display, screen_no);
99 XVisualInfo *visual = video_glx_get_visual();
100 GdkVisual *gdkvis = gdk_x11_screen_lookup_visual( gtk_widget_get_screen(win->window), visual->visualid );
101 GdkColormap *colormap = gdk_colormap_new( gdkvis, FALSE );
102 win->video = gtk_drawing_area_new();
103 gtk_widget_set_colormap( win->video, colormap );
104 GTK_WIDGET_SET_FLAGS(win->video, GTK_CAN_FOCUS|GTK_CAN_DEFAULT);
105 gtk_widget_set_size_request( win->video, 640, 480 );
106 frame = gtk_frame_new(NULL);
107 gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
108 gtk_container_add( GTK_CONTAINER(frame), win->video );
110 win->statusbar = gtk_statusbar_new();
112 vbox = gtk_vbox_new(FALSE, 0);
113 gtk_container_add( GTK_CONTAINER(win->window), vbox );
114 gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
115 gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
116 gtk_box_pack_start( GTK_BOX(vbox), frame, TRUE, TRUE, 0 );
117 gtk_box_pack_start( GTK_BOX(vbox), win->statusbar, FALSE, FALSE, 0 );
118 gtk_widget_show_all( win->window );
119 gtk_widget_grab_focus( win->video );
121 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, "Stopped" );
122 g_signal_connect( win->window, "delete_event",
123 G_CALLBACK(on_main_window_deleted), win );
124 g_signal_connect( win->window, "window-state-event",
125 G_CALLBACK(on_main_window_state_changed), win );
126 return win;
127 }
129 void main_window_set_running( main_window_t win, gboolean running )
130 {
131 gtk_gui_enable_action( "Pause", running );
132 gtk_gui_enable_action( "Run", !running && dreamcast_can_run() );
133 gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
134 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, running ? "Running" : "Stopped" );
135 }
137 void main_window_set_framerate( main_window_t win, float rate )
138 {
141 }
143 void main_window_set_speed( main_window_t win, double speed )
144 {
145 char buf[32];
147 snprintf( buf, 32, "Running (%2.4f%%)", speed );
148 gtk_statusbar_pop( GTK_STATUSBAR(win->statusbar), 1 );
149 gtk_statusbar_push( GTK_STATUSBAR(win->statusbar), 1, buf );
152 }
154 GtkWidget *main_window_get_renderarea( main_window_t win )
155 {
156 return win->video;
157 }
159 GtkWindow *main_window_get_frame( main_window_t win )
160 {
161 return GTK_WINDOW(win->window);
162 }
164 void main_window_set_fullscreen( main_window_t win, gboolean fullscreen )
165 {
166 if( fullscreen ) {
167 gtk_window_fullscreen( GTK_WINDOW(win->window) );
168 } else {
169 gtk_window_unfullscreen( GTK_WINDOW(win->window) );
170 }
171 }
.