Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
emutools_gui.c
Go to the documentation of this file.
1 /* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
2  Copyright (C)2016,2019-2022 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17 
18 #include "xemu/emutools.h"
19 #include "xemu/emutools_gui.h"
20 #include <string.h>
21 
22 int is_xemugui_ok = 0;
23 
24 
25 #if defined(XEMU_HAS_GTK3) || defined(XEMU_ARCH_MAC) || defined(XEMU_ARCH_WIN)
26 static void store_dir_from_file_selection ( char *store_dir, const char *filename, int dialog_mode )
27 {
28  if (store_dir && (dialog_mode & XEMUGUI_FSEL_FLAG_STORE_DIR)) {
29  if ((dialog_mode & 0xFF) == XEMUGUI_FSEL_DIRECTORY)
30  strcpy(store_dir, filename);
31  else {
32  char *p = strrchr(filename, DIRSEP_CHR);
33  if (p) {
34  memcpy(store_dir, filename, p - filename + 1);
35  store_dir[p - filename + 1] = '\0';
36  }
37  }
38  }
39 }
40 #endif
41 
43 
45  const char *name;
46  const char *description;
47  int (*init)(void);
48  void (*shutdown)(void);
49  int (*iteration)(void);
50  int (*file_selector)( int dialog_mode, const char *dialog_title, char *default_dir, char *selected, int path_max_size );
51  int (*popup)( const struct menu_st desc[] );
52  int (*info)(int sdl_class, const char *msg);
53 };
54 
55 #if defined(XEMU_HAS_GTK3)
56 # include "xemu/gui/gui_gtk.c"
57 #elif defined(XEMU_ARCH_MAC)
58 # include "xemu/gui/gui_osx.c"
59 #elif defined(XEMU_ARCH_WIN)
60 # include "xemu/gui/gui_win.c"
61 #endif
62 #include "xemu/gui/gui_nogui.c"
63 #include "xemu/gui/gui_osd.c"
64 
65 static const struct xemugui_descriptor_st *current_gui = NULL;
66 
67 static const struct xemugui_descriptor_st *xemugui_descriptor_list[] = {
68 #if defined(XEMU_ARCH_MAC)
69  &xemuosxgui_descriptor,
70 #endif
71 #if defined (XEMU_ARCH_WIN)
72  &xemuwingui_descriptor,
73 #endif
74 #if defined(XEMU_HAS_GTK3)
75  &xemugtkgui_descriptor,
76 #endif
77 // &xemuosdgui_descriptor,
78  &xemunullgui_descriptor // THIS MUST BE THE LAST ENTRY
79 };
80 
81 
82 int xemugui_init ( const char *name )
83 {
84  char avail[256]; // "should be enough" (yeah, I know, the 640K ...) for some names ...
85  avail[0] = 0;
86  is_xemugui_ok = 0;
87  if (name && name[0] == '\0') // make sure that empty string means the same as NULL pointer passed
88  name = NULL;
89  for (int a = 0 ;; a++) {
90  strcat(avail, " ");
91  strcat(avail, xemugui_descriptor_list[a]->name);
92  if (name && !strcasecmp(xemugui_descriptor_list[a]->name, name)) {
93  current_gui = xemugui_descriptor_list[a];
94  break;
95  }
96  if (xemugui_descriptor_list[a] == &xemunullgui_descriptor) {
97  current_gui = xemugui_descriptor_list[0];
98  if (name)
100  "Requested GUI (\"%s\") cannot be found, using \"%s\" instead.\nAvailable GUI implementations:%s",
101  name, current_gui->name, avail
102  );
103  else
104  DEBUGPRINT("GUI: no GUI was specified, using the first available one from this list:%s" NL, avail);
105  break;
106  }
107  }
108  DEBUGPRINT("GUI: using \"%s\" (%s)" NL, current_gui->name, current_gui->description);
109  return current_gui->init ? current_gui->init() : 1;
110 }
111 
112 
113 void xemugui_shutdown ( void )
114 {
115  if (current_gui && current_gui->shutdown)
116  current_gui->shutdown();
117 }
118 
119 
120 int xemugui_iteration ( void )
121 {
122  return (current_gui && current_gui->iteration) ? current_gui->iteration() : 0;
123 }
124 
125 
126 int xemugui_file_selector ( int dialog_mode, const char *dialog_title, char *default_dir, char *selected, int path_max_size )
127 {
128  if (current_gui && current_gui->file_selector)
129  return current_gui->file_selector(dialog_mode, dialog_title, default_dir, selected, path_max_size);
130  else
131  return 1;
132 }
133 
134 
135 int xemugui_popup ( const struct menu_st desc[] )
136 {
137  if (!current_gui) {
138  ERROR_WINDOW("GUI hasn't been initialized yet, cannot pop menu.");
139  return 1;
140  }
141  if (!current_gui->popup) {
142 #ifndef GUI_HAS_POPUP
143  ERROR_WINDOW("GUI support is not compiled for this Xemu build for any GUI backend which can pop menu");
144  return 1;
145 #endif
146  if (current_gui == &xemunullgui_descriptor)
147  ERROR_WINDOW("The 'none' GUI is used. It does not support popping menu");
148  else
149  ERROR_WINDOW("Current GUI backend (%s) does not support popping menu", current_gui->name);
150  return 1;
151  }
152  return current_gui->popup(desc);
153 }
154 
155 
156 int xemugui_info ( int sdl_class, const char *msg )
157 {
158  if (current_gui && current_gui->info)
159  return current_gui->info(sdl_class, msg);
160  else
161  return 1;
162 }
xemugui_descriptor_st::init
int(* init)(void)
Definition: emutools_gui.c:47
menu_st
Definition: emutools_gui.h:65
emutools.h
xemugui_descriptor_st::shutdown
void(* shutdown)(void)
Definition: emutools_gui.c:48
xemugui_descriptor_st::file_selector
int(* file_selector)(int dialog_mode, const char *dialog_title, char *default_dir, char *selected, int path_max_size)
Definition: emutools_gui.c:50
xemugui_info
int xemugui_info(int sdl_class, const char *msg)
Definition: emutools_gui.c:156
xemugui_descriptor_st::description
const char * description
Definition: emutools_gui.c:46
xemugui_file_selector
int xemugui_file_selector(int dialog_mode, const char *dialog_title, char *default_dir, char *selected, int path_max_size)
Definition: emutools_gui.c:126
xemugui_popup
int xemugui_popup(const struct menu_st desc[])
Definition: emutools_gui.c:135
gui_osx.c
gui_nogui.c
gui_gtk.c
emutools_gui.h
xemugui_descriptor_st::info
int(* info)(int sdl_class, const char *msg)
Definition: emutools_gui.c:52
XEMUGUI_FSEL_FLAG_STORE_DIR
#define XEMUGUI_FSEL_FLAG_STORE_DIR
Definition: emutools_gui.h:28
xemugui_descriptor_st::popup
int(* popup)(const struct menu_st desc[])
Definition: emutools_gui.c:51
xemugui_init
int xemugui_init(const char *name)
Definition: emutools_gui.c:82
xemugui_descriptor_st::name
const char * name
Definition: emutools_gui.c:45
popular_user_funcs.c
DEBUGPRINT
#define DEBUGPRINT(...)
Definition: emutools_basicdefs.h:171
ERROR_WINDOW
#define ERROR_WINDOW(...)
Definition: xep128.h:116
NL
#define NL
Definition: fat32.c:37
xemugui_descriptor_st::iteration
int(* iteration)(void)
Definition: emutools_gui.c:49
xemugui_descriptor_st
Definition: emutools_gui.c:44
xemugui_shutdown
void xemugui_shutdown(void)
Definition: emutools_gui.c:113
gui_win.c
xemugui_iteration
int xemugui_iteration(void)
Definition: emutools_gui.c:120
name
const char * name
Definition: joystick.c:46
XEMUGUI_FSEL_DIRECTORY
#define XEMUGUI_FSEL_DIRECTORY
Definition: emutools_gui.h:25
is_xemugui_ok
int is_xemugui_ok
Definition: emutools_gui.c:22
gui_osd.c
DIRSEP_CHR
#define DIRSEP_CHR
Definition: emutools_basicdefs.h:142