/[pcsx2_0.9.7]/trunk/common/include/PS2Eext.h
ViewVC logotype

Contents of /trunk/common/include/PS2Eext.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 6748 byte(s)
committing r3113 initial commit again...
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #ifndef PS2EEXT_H_INCLUDED
17 #define PS2EEXT_H_INCLUDED
18
19 #include <stdio.h>
20 #include <string>
21 #include <cstdarg>
22
23 #ifdef _MSC_VER
24 #include <windows.h>
25 #include <windowsx.h>
26 #include <commctrl.h>
27
28 #define EXPORT_C_(type) extern "C" type CALLBACK
29 #else
30 #include <gtk/gtk.h>
31 #include <cstring>
32
33 #define EXPORT_C_(type) extern "C" type
34 #endif
35
36 //#include "PS2Edefs.h"
37
38 static void SysMessage(const char *fmt, ...);
39 static void __forceinline PluginNullConfigure(std::string desc, s32 &log);
40 static void __forceinline PluginNullAbout(const char *aboutText);
41
42 enum FileMode
43 {
44 READ_FILE = 0,
45 WRITE_FILE
46 };
47
48 struct PluginLog
49 {
50 bool WriteToFile, WriteToConsole;
51 FILE *LogFile;
52
53 bool Open(std::string logname)
54 {
55 LogFile = fopen(logname.c_str(), "w");
56
57 if (LogFile)
58 {
59 setvbuf(LogFile, NULL, _IONBF, 0);
60 return true;
61 }
62 return false;
63 }
64
65 void Close()
66 {
67 if (LogFile) fclose(LogFile);
68 }
69
70 void Write(const char *fmt, ...)
71 {
72 va_list list;
73
74 if (LogFile == NULL) return;
75
76 va_start(list, fmt);
77 if (WriteToFile) vfprintf(LogFile, fmt, list);
78 if (WriteToConsole) vfprintf(stdout, fmt, list);
79 va_end(list);
80 }
81
82 void WriteLn(const char *fmt, ...)
83 {
84 va_list list;
85
86 if (LogFile == NULL) return;
87
88 va_start(list, fmt);
89 if (WriteToFile) vfprintf(LogFile, fmt, list);
90 if (WriteToConsole) vfprintf(stdout, fmt, list);
91 va_end(list);
92
93 if (WriteToFile) fprintf(LogFile, "\n");
94 if (WriteToConsole) fprintf(stdout, "\n");
95 }
96
97 void Message(const char *fmt, ...)
98 {
99 va_list list;
100 char buf[256];
101
102 if (LogFile == NULL) return;
103
104 va_start(list, fmt);
105 vsprintf(buf, fmt, list);
106 va_end(list);
107
108 SysMessage(buf);
109 }
110 };
111
112 struct PluginConf
113 {
114 FILE *ConfFile;
115 char *PluginName;
116
117 bool Open(std::string name, FileMode mode = READ_FILE)
118 {
119 if (mode == READ_FILE)
120 {
121 ConfFile = fopen(name.c_str(), "r");
122 }
123 else
124 {
125 ConfFile = fopen(name.c_str(), "w");
126 }
127
128 if (ConfFile == NULL) return false;
129
130 return true;
131 }
132
133 void Close()
134 {
135 fclose(ConfFile);
136 }
137
138 int ReadInt(const std::string& item, int defval)
139 {
140 int value = defval;
141 std::string buf = item + " = %d\n";
142
143 if (ConfFile) fscanf(ConfFile, buf.c_str(), &value);
144
145 return value;
146 }
147
148 void WriteInt(std::string item, int value)
149 {
150 std::string buf = item + " = %d\n";
151
152 if (ConfFile) fprintf(ConfFile, buf.c_str(), value);
153 }
154 };
155
156 #ifdef __LINUX__
157
158 static void SysMessage(const char *fmt, ...)
159 {
160 va_list list;
161 char msg[512];
162
163 va_start(list, fmt);
164 vsprintf(msg, fmt, list);
165 va_end(list);
166
167 if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
168
169 GtkWidget *dialog;
170 dialog = gtk_message_dialog_new (NULL,
171 GTK_DIALOG_DESTROY_WITH_PARENT,
172 GTK_MESSAGE_INFO,
173 GTK_BUTTONS_OK,
174 "%s", msg);
175 gtk_dialog_run (GTK_DIALOG (dialog));
176 gtk_widget_destroy (dialog);
177 }
178
179 static bool loggingValue = false;
180
181 static void __forceinline set_logging(GtkToggleButton *check)
182 {
183 loggingValue = gtk_toggle_button_get_active(check);
184 }
185
186 static void __forceinline send_ok(GtkDialog *dialog)
187 {
188 int ret = (loggingValue) ? 1 : 0;
189 gtk_dialog_response (dialog, ret);
190 }
191
192 static void __forceinline PluginNullConfigure(std::string desc, int &log)
193 {
194 GtkWidget *dialog, *label, *okay_button, *check_box;
195
196 /* Create the widgets */
197 dialog = gtk_dialog_new();
198 label = gtk_label_new (desc.c_str());
199 okay_button = gtk_button_new_with_label("Ok");
200 check_box = gtk_check_button_new_with_label("Logging");
201
202 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), (log != 0));
203
204 /* Ensure that the dialog box is destroyed when the user clicks ok, and that we get the check box value. */
205 g_signal_connect_swapped(GTK_OBJECT (okay_button), "clicked", G_CALLBACK(send_ok), dialog);
206 g_signal_connect_swapped(GTK_OBJECT (check_box), "toggled", G_CALLBACK(set_logging), check_box);
207
208 /* Add all our widgets, and show everything we've added to the dialog. */
209 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area), okay_button);
210 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
211 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), check_box);
212 gtk_widget_show_all (dialog);
213
214 log = gtk_dialog_run (GTK_DIALOG (dialog));
215 gtk_widget_destroy (dialog);
216 }
217
218 static void __forceinline PluginNullAbout(const char *aboutText)
219 {
220 SysMessage(aboutText);
221 }
222
223 #define ENTRY_POINT /* We don't need no stinkin' entry point! */
224
225 #else
226
227 #define usleep(x) Sleep(x / 1000)
228
229 static void __forceinline SysMessage(const char *fmt, ...)
230 {
231 va_list list;
232 char tmp[512];
233 va_start(list,fmt);
234 vsprintf(tmp,fmt,list);
235 va_end(list);
236 MessageBox( GetActiveWindow(), tmp, "Message", MB_SETFOREGROUND | MB_OK );
237 }
238
239 static void __forceinline PluginNullConfigure(std::string desc, s32 &log)
240 {
241 /* To do: Write a dialog box that displays a dialog box with the text in desc,
242 and a check box that says "Logging", checked if log !=0, and set log to
243 1 if it is checked on return, and 0 if it isn't. */
244 SysMessage("This space intentionally left blank.");
245 }
246
247 static void __forceinline PluginNullAbout(const char *aboutText)
248 {
249 SysMessage(aboutText);
250 }
251
252 #define ENTRY_POINT \
253 HINSTANCE hInst; \
254 \
255 BOOL APIENTRY DllMain(HANDLE hModule, /* DLL INIT*/ \
256 DWORD dwReason, \
257 LPVOID lpReserved) \
258 { \
259 hInst = (HINSTANCE)hModule; \
260 return TRUE; /* very quick :)*/ \
261 }
262
263 #endif
264 #endif // PS2EEXT_H_INCLUDED

  ViewVC Help
Powered by ViewVC 1.1.22