New helper include for gtk for use in plugins. Mostly based on the gtk 2/3 helper functions I added to spu2-x for the moment.

This commit is contained in:
Shanoah Alkire 2018-10-02 01:20:54 -07:00
parent 08a270a429
commit 7641d6726f
7 changed files with 149 additions and 57 deletions

View File

@ -0,0 +1,133 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
// ----------------------------------------------------------------------------
// gtkGuiTools.h
//
// This file is meant to contain utility classes for users of GTK, for purposes
// of GTK 2/3 compatibility, and other helpful routines to help avoid repeatedly
// implementing the same code.
//
// ----------------------------------------------------------------------------
#include <gtk/gtk.h>
#include <cstring>
// They've gotten rid of the GtkHBox and GtkVBox in GTK3 in favor of using the
// more general GtkBox and supplying an orientation. While this is probably a
// move in the right direction, for compatability, it's easier to define our
// own hbox and vbox routines that invoke the old or the new version, depending
// on what it's built for.
//
static GtkWidget *ps_gtk_hbox_new(int padding = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_hbox_new(false, padding);
#else
return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, padding);
#endif
}
static GtkWidget *ps_gtk_vbox_new(int padding = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_vbox_new(false, padding);
#else
return gtk_box_new(GTK_ORIENTATION_VERTICAL, padding);
#endif
}
// Similarly, GtkHScale and GtkVScale make way for GtkScale.
static GtkWidget *ps_gtk_hscale_new_with_range(double g_min, double g_max, int g_step = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_hscale_new_with_range(g_min, g_max, g_step);
#else
return gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, g_min, g_max, g_step);
#endif
}
static GtkWidget *ps_gtk_vscale_new_with_range(double g_min, double g_max, int g_step = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_vscale_new_with_range(g_min, g_max, g_step);
#else
return gtk_scale_new_with_range(GTK_ORIENTATION_VERTICAL, g_min, g_max, g_step);
#endif
}
// And so on and so forth...
static GtkWidget *ps_gtk_hseparator_new()
{
#if GTK_MAJOR_VERSION < 3
return gtk_hseparator_new();
#else
return gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
#endif
}
static GtkWidget *ps_gtk_vseparator_new()
{
#if GTK_MAJOR_VERSION < 3
return gtk_vseparator_new();
#else
return gtk_separator_new(GTK_ORIENTATION_VERTICAL);
#endif
}
// These two routines have been rewritten over and over. May as well include a copy.
// Renaming so as not to interfere with existing versions.
static void pcsx2_message(const char *fmt, ...)
{
va_list list;
char msg[512];
va_start(list, fmt);
vsprintf(msg, fmt, list);
va_end(list);
if (msg[strlen(msg) - 1] == '\n')
msg[strlen(msg) - 1] = 0;
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s", msg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
static void pcsx2_message(const wchar_t *fmt, ...)
{
va_list list;
va_start(list, fmt);
wxString msg;
msg.PrintfV(fmt, list);
va_end(list);
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s", msg.ToUTF8().data());
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}

View File

@ -55,6 +55,7 @@ set(UtilitiesHeaders
../../include/Utilities/EventSource.h
../../include/Utilities/Exceptions.h
../../include/Utilities/FixedPointTypes.h
../../include/Utilities/gtkGuiTools.h
../../include/Utilities/General.h
../../include/Utilities/MakeUnique.h
../../include/Utilities/MemcpyFast.h

View File

@ -333,12 +333,12 @@ void DisplayDialog()
latency_label = gtk_label_new("Latency:");
const int min_latency = SynchMode == 0 ? LATENCY_MIN_TIMESTRETCH : LATENCY_MIN;
latency_slide = spu2x_gtk_hscale_new_with_range(min_latency, LATENCY_MAX, 5);
latency_slide = ps_gtk_hscale_new_with_range(min_latency, LATENCY_MAX, 5);
gtk_range_set_value(GTK_RANGE(latency_slide), SndOutLatencyMS);
volume_label = gtk_label_new("Volume:");
volume_slide = spu2x_gtk_hscale_new_with_range(0, 100, 5);
volume_slide = ps_gtk_hscale_new_with_range(0, 100, 5);
gtk_range_set_value(GTK_RANGE(volume_slide), FinalVolume * 100);
sync_label = gtk_label_new("Synchronization Mode:");
@ -350,17 +350,17 @@ void DisplayDialog()
advanced_button = gtk_button_new_with_label("Advanced...");
main_box = spu2x_gtk_hbox_new(5);
main_box = ps_gtk_hbox_new(5);
mixing_box = spu2x_gtk_vbox_new(5);
mixing_box = ps_gtk_vbox_new(5);
mixing_frame = gtk_frame_new("Mixing Settings:");
gtk_container_add(GTK_CONTAINER(mixing_frame), mixing_box);
output_box = spu2x_gtk_vbox_new(5);
output_box = ps_gtk_vbox_new(5);
output_frame = gtk_frame_new("Output Settings:");
debug_box = spu2x_gtk_vbox_new(5);
debug_box = ps_gtk_vbox_new(5);
debug_frame = gtk_frame_new("Debug Settings:");
gtk_container_add(GTK_CONTAINER(debug_box), debug_check);

View File

@ -180,10 +180,10 @@ void DisplayDialog()
"OK", GTK_RESPONSE_ACCEPT,
NULL);
main_box = spu2x_gtk_hbox_new(5);
main_box = ps_gtk_hbox_new(5);
// Message Section
msg_box = spu2x_gtk_vbox_new(5);
msg_box = ps_gtk_vbox_new(5);
msg_console_check = gtk_check_button_new_with_label("Show In Console");
msg_key_check = gtk_check_button_new_with_label("KeyOn/Off Events");
@ -213,7 +213,7 @@ void DisplayDialog()
gtk_container_add(GTK_CONTAINER(msg_frame), msg_box);
// Log Section
log_box = spu2x_gtk_vbox_new(5);
log_box = ps_gtk_vbox_new(5);
log_access_check = gtk_check_button_new_with_label("Log Register/DMA Actions");
log_dma_check = gtk_check_button_new_with_label("Log DMA Writes");
@ -231,7 +231,7 @@ void DisplayDialog()
gtk_container_add(GTK_CONTAINER(log_frame), log_box);
// Dump Section
dump_box = spu2x_gtk_vbox_new(5);
dump_box = ps_gtk_vbox_new(5);
dump_core_check = gtk_check_button_new_with_label("Dump Core and Voice State");
dump_mem_check = gtk_check_button_new_with_label("Dump Memory Contents");

View File

@ -107,18 +107,18 @@ void DisplayDialog()
default_button = gtk_button_new_with_label("Reset to Defaults");
seq_label = gtk_label_new("Sequence Length");
seq_slide = spu2x_gtk_hscale_new_with_range(SequenceLen_Min, SequenceLen_Max, 2);
seq_slide = ps_gtk_hscale_new_with_range(SequenceLen_Min, SequenceLen_Max, 2);
gtk_range_set_value(GTK_RANGE(seq_slide), SequenceLenMS);
seek_label = gtk_label_new("Seek Window Size");
seek_slide = spu2x_gtk_hscale_new_with_range(SeekWindow_Min, SeekWindow_Max, 2);
seek_slide = ps_gtk_hscale_new_with_range(SeekWindow_Min, SeekWindow_Max, 2);
gtk_range_set_value(GTK_RANGE(seek_slide), SeekWindowMS);
over_label = gtk_label_new("Overlap");
over_slide = spu2x_gtk_hscale_new_with_range(Overlap_Min, Overlap_Max, 2);
over_slide = ps_gtk_hscale_new_with_range(Overlap_Min, Overlap_Max, 2);
gtk_range_set_value(GTK_RANGE(over_slide), OverlapMS);
adv_box = spu2x_gtk_vbox_new(5);
adv_box = ps_gtk_vbox_new(5);
gtk_box_pack_start(GTK_BOX(adv_box), main_label, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(adv_box), default_button, TRUE, TRUE, 5);

View File

@ -64,42 +64,6 @@ void SysMessage(const wchar_t *fmt, ...)
}
#endif
GtkWidget *spu2x_gtk_hbox_new(int padding = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_hbox_new(false, padding);
#else
return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, padding);
#endif
}
GtkWidget *spu2x_gtk_vbox_new(int padding = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_vbox_new(false, padding);
#else
return gtk_box_new(GTK_ORIENTATION_VERTICAL, padding);
#endif
}
GtkWidget *spu2x_gtk_hscale_new_with_range(double g_min, double g_max, int g_step = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_hscale_new_with_range(g_min, g_max, g_step);
#else
return gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, g_min, g_max, g_step);
#endif
}
GtkWidget *spu2x_gtk_vscale_new_with_range(double g_min, double g_max, int g_step = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_vscale_new_with_range(g_min, g_max, g_step);
#else
return gtk_scale_new_with_range(GTK_ORIENTATION_VERTICAL, g_min, g_max, g_step);
#endif
}
void DspUpdate()
{
}

View File

@ -20,6 +20,7 @@
#include "../Global.h"
#include "../Config.h"
#include "Utilities/gtkGuiTools.h"
namespace DebugConfig
{
@ -42,11 +43,4 @@ extern void CfgReadStr(const wchar_t *Section, const wchar_t *Name, wxString &Da
extern int CfgReadInt(const wchar_t *Section, const wchar_t *Name, int Default);
extern float CfgReadFloat(const wchar_t *Section, const wchar_t *Name, float Default);
#if defined(__unix__)
extern GtkWidget *spu2x_gtk_hbox_new(int padding);
extern GtkWidget *spu2x_gtk_vbox_new(int padding);
extern GtkWidget *spu2x_gtk_hscale_new_with_range(double g_min, double g_max, int g_step);
extern GtkWidget *spu2x_gtk_vscale_new_with_range(double g_min, double g_max, int g_step);
#endif
#endif