X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=libs%2Fuilib%2Fuilib.cpp;h=72da1de0a652fbab16f82759326ae06bcce38db2;hb=66dab04732db09384c0031d3271a78533811a184;hp=a27d2d841a866cb875c72d684319128da54cf6e9;hpb=225950494a606af9aac2bc2f06ece70cb2146481;p=xonotic%2Fnetradiant.git diff --git a/libs/uilib/uilib.cpp b/libs/uilib/uilib.cpp index a27d2d84..72da1de0 100644 --- a/libs/uilib/uilib.cpp +++ b/libs/uilib/uilib.cpp @@ -11,10 +11,17 @@ namespace ui { - void init(int argc, char *argv[]) + bool init(int *argc, char **argv[], char const *parameter_string, char const **error) { gtk_disable_setlocale(); - gtk_init(&argc, &argv); + static GOptionEntry entries[] = {{NULL}}; + char const *translation_domain = NULL; + GError *gerror = NULL; + bool ret = gtk_init_with_args(argc, argv, parameter_string, entries, translation_domain, &gerror) != 0; + if (!ret) { + *error = gerror->message; + } + return ret; } void main() @@ -29,7 +36,7 @@ namespace ui { } } - Widget root{nullptr}; + Widget root; #define IMPL(T, F) template<> _IMPL(T, F) #define _IMPL(T, F) struct verify { using self = T; static self test(self it) { return self(F(it)); } } @@ -39,7 +46,7 @@ namespace ui { template _IMPL(T,); -#define this verify::test(*static_cast(this)) +#define this (verify::test(*static_cast(this))) IMPL(Editable, GTK_EDITABLE); @@ -85,11 +92,28 @@ namespace ui { return ::file_dialog(this, open, title, path, pattern, want_load, want_import, want_save); } + bool IWidget::visible() + { + return gtk_widget_get_visible(this) != 0; + } + void IWidget::show() { gtk_widget_show(this); } + Dimensions IWidget::dimensions() + { + GtkAllocation allocation; + gtk_widget_get_allocation(this, &allocation); + return Dimensions{allocation.width, allocation.height}; + } + + void IWidget::dimensions(int width, int height) + { + gtk_widget_set_size_request(this, width, height); + } + IMPL(Container, GTK_CONTAINER); void IContainer::add(Widget widget) @@ -97,13 +121,15 @@ namespace ui { gtk_container_add(this, widget); } + void IContainer::remove(Widget widget) + { + gtk_container_remove(this, widget); + } + IMPL(Bin, GTK_BIN); IMPL(Window, GTK_WINDOW); - Window::Window() : Window(nullptr) - {} - Window::Window(window_type type) : Window(GTK_WINDOW(gtk_window_new( type == window_type::TOP ? GTK_WINDOW_TOPLEVEL : type == window_type::POPUP ? GTK_WINDOW_POPUP : @@ -176,6 +202,9 @@ namespace ui { IMPL(CheckButton, GTK_CHECK_BUTTON); + CheckButton::CheckButton() : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new())) + {} + CheckButton::CheckButton(const char *label) : CheckButton(GTK_CHECK_BUTTON(gtk_check_button_new_with_label(label))) {} @@ -203,6 +232,11 @@ namespace ui { ScrolledWindow::ScrolledWindow() : ScrolledWindow(GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(nullptr, nullptr))) {} + void IScrolledWindow::overflow(Policy x, Policy y) + { + gtk_scrolled_window_set_policy(this, static_cast(x), static_cast(y)); + } + IMPL(VBox, GTK_VBOX); VBox::VBox(bool homogenous, int spacing) : VBox(GTK_VBOX(gtk_vbox_new(homogenous, spacing))) @@ -240,6 +274,12 @@ namespace ui { TextView::TextView() : TextView(GTK_TEXT_VIEW(gtk_text_view_new())) {} + void ITextView::text(char const *str) + { + GtkTextBuffer *buffer = gtk_text_view_get_buffer(this); + gtk_text_buffer_set_text(buffer, str, -1); + } + TreeView::TreeView() : TreeView(GTK_TREE_VIEW(gtk_tree_view_new())) {} @@ -251,6 +291,11 @@ namespace ui { Label::Label(const char *label) : Label(GTK_LABEL(gtk_label_new(label))) {} + void ILabel::text(char const *str) + { + gtk_label_set_text(this, str); + } + IMPL(Image, GTK_IMAGE); Image::Image() : Image(GTK_IMAGE(gtk_image_new())) @@ -266,6 +311,16 @@ namespace ui { gtk_entry_set_max_length(this, static_cast(max_length)); } + char const *IEntry::text() + { + return gtk_entry_get_text(this); + } + + void IEntry::text(char const *str) + { + return gtk_entry_set_text(this, str); + } + IMPL(SpinButton, GTK_SPIN_BUTTON); SpinButton::SpinButton(Adjustment adjustment, double climb_rate, std::size_t digits) : SpinButton( @@ -326,4 +381,16 @@ namespace ui { TreePath::TreePath(const char *path) : TreePath(gtk_tree_path_new_from_string(path)) {} + // Custom + + guint IGLArea::on_render(GCallback pFunction, void *data) + { +#if GTK_TARGET == 3 + return this.connect("render", pFunction, data); +#endif +#if GTK_TARGET == 2 + return this.connect("expose_event", pFunction, data); +#endif + }; + }