snes9x/gtk/src/gtk_builder_window.cpp

156 lines
3.8 KiB
C++
Raw Normal View History

/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
2010-09-26 11:19:15 +02:00
#include <stdlib.h>
#include <string.h>
#include "gtk_builder_window.h"
extern const unsigned char snes9x_ui[];
extern const int snes9x_ui_size;
2010-09-26 11:19:15 +02:00
Glib::RefPtr<Gtk::Builder> global_builder;
bool global_builder_created = false;
2010-09-26 11:19:15 +02:00
GtkBuilderWindow::GtkBuilderWindow(const char *root)
2010-09-26 11:19:15 +02:00
{
if (!global_builder_created)
2010-09-26 11:19:15 +02:00
{
global_builder = Gtk::Builder::create();
global_builder->add_from_string((const gchar *)snes9x_ui, snes9x_ui_size);
global_builder_created = true;
2010-09-26 11:19:15 +02:00
}
window = get_object<Gtk::Window>(root);
2010-09-26 11:19:15 +02:00
}
GtkBuilderWindow::~GtkBuilderWindow()
2010-09-26 11:19:15 +02:00
{
}
void GtkBuilderWindow::enable_widget(const char *name, bool state)
2010-09-26 11:19:15 +02:00
{
auto widget = get_object<Gtk::Widget>(name);
widget->set_sensitive(state);
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::show_widget(const char *name, bool state)
2010-09-26 11:19:15 +02:00
{
auto widget = get_object<Gtk::Widget>(name);
widget->set_visible(state);
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::resize(int width, int height)
2010-09-26 11:19:15 +02:00
{
window->resize(width, height);
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::refresh()
2010-09-26 11:19:15 +02:00
{
window->queue_draw();
2010-09-26 11:19:15 +02:00
}
int GtkBuilderWindow::get_width()
2010-09-26 11:19:15 +02:00
{
return window->get_width();
}
2010-09-26 11:19:15 +02:00
int GtkBuilderWindow::get_height()
{
return window->get_height();
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::set_button_label(const char *name, const char *label)
2010-09-26 11:19:15 +02:00
{
get_object<Gtk::Button>(name)->set_label(label);
2010-09-26 11:19:15 +02:00
}
bool GtkBuilderWindow::get_check(const char *name)
2010-09-26 11:19:15 +02:00
{
return get_object<Gtk::ToggleButton>(name)->get_active();
2010-09-26 11:19:15 +02:00
}
int GtkBuilderWindow::get_entry_value(const char *name)
2010-09-26 11:19:15 +02:00
{
auto text = get_object<Gtk::Entry>(name)->get_text();
return std::stoi(text);
2010-09-26 11:19:15 +02:00
}
std::string GtkBuilderWindow::get_entry_text(const char *name)
2010-09-26 11:19:15 +02:00
{
return get_object<Gtk::Entry>(name)->get_text();
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::set_entry_value(const char *name, unsigned int value)
2010-09-26 11:19:15 +02:00
{
get_object<Gtk::Entry>(name)->set_text(std::to_string(value));
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::set_entry_text(const char *name, const char *text)
2010-09-26 11:19:15 +02:00
{
get_object<Gtk::Entry>(name)->set_text(text);
2010-09-26 11:19:15 +02:00
}
float GtkBuilderWindow::get_slider(const char *name)
2010-09-26 11:19:15 +02:00
{
return get_object<Gtk::Range>(name)->get_value();
2010-09-26 11:19:15 +02:00
}
int GtkBuilderWindow::get_combo(const char *name)
2010-09-26 11:19:15 +02:00
{
return get_object<Gtk::ComboBox>(name)->get_active_row_number();
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::set_slider(const char *name, float value)
2010-09-26 11:19:15 +02:00
{
get_object<Gtk::Range>(name)->set_value(value);
}
2010-09-26 11:19:15 +02:00
void GtkBuilderWindow::set_check(const char *name, bool value)
{
get_object<Gtk::ToggleButton>(name)->set_active(value);
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::set_combo(const char *name, unsigned char value)
2010-09-26 11:19:15 +02:00
{
get_object<Gtk::ComboBox>(name)->set_active(value);
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::set_spin(const char *name, double value)
2010-09-26 11:19:15 +02:00
{
get_object<Gtk::SpinButton>(name)->set_value(value);
2010-09-26 11:19:15 +02:00
}
double GtkBuilderWindow::get_spin(const char *name)
2010-09-26 11:19:15 +02:00
{
return get_object<Gtk::SpinButton>(name)->get_value();
2010-09-26 11:19:15 +02:00
}
void GtkBuilderWindow::combo_box_append(const char *name, const char *value)
{
return combo_box_append(get_object<Gtk::ComboBox>(name).get(), value);
}
void GtkBuilderWindow::combo_box_append(Gtk::ComboBox *combo, const char *value)
{
GtkListStore *store;
GtkTreeIter iter;
store = GTK_LIST_STORE(combo->get_model()->gobj());
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, value, -1);
2010-09-26 11:19:15 +02:00
}
GtkWindow *GtkBuilderWindow::get_window()
2010-09-26 11:19:15 +02:00
{
return window->gobj();
2010-09-26 11:19:15 +02:00
}
bool GtkBuilderWindow::has_focus(const char *widget)
2010-09-26 11:19:15 +02:00
{
return get_object<Gtk::Widget>(widget)->is_focus();
2010-09-26 11:19:15 +02:00
}