Sun, 17 Jan 2016 19:19:28 +0100
improved gtk2 implementation of grid container
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2012 Olaf Wintermann. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <stdio.h> #include <stdlib.h> #include "graphics.h" #include "container.h" #include "../common/object.h" UIWIDGET ui_drawingarea(UiObject *obj, ui_drawfunc f, void *userdata) { GtkWidget *widget = gtk_drawing_area_new(); if(f) { UiDrawEvent *event = malloc(sizeof(UiDrawEvent)); event->obj = obj; event->callback = f; event->userdata = userdata; ui_connect_draw_handler(widget, event); } UiContainer *ct = uic_get_current_container(obj); ct->add(ct, widget, TRUE); return widget; } // text layout UiTextLayout* ui_text(UiGraphics *g) { UiTextLayout *layout = malloc(sizeof(UiTextLayout)); PangoContext *pc = ui_get_pango_context(g); layout->layout = pango_layout_new(pc); return layout; } void ui_text_setstring(UiTextLayout *layout, char *str) { pango_layout_set_text(layout->layout, str, -1); } void ui_text_setstringl(UiTextLayout *layout, char *str, int len) { pango_layout_set_text(layout->layout, str, len); } void ui_text_setfont(UiTextLayout *layout, char *font, int size) { PangoFontDescription *fontDesc; fontDesc = pango_font_description_from_string(font); pango_font_description_set_size(fontDesc, size * PANGO_SCALE); pango_layout_set_font_description(layout->layout, fontDesc); pango_font_description_free(fontDesc); } void ui_text_getsize(UiTextLayout *layout, int *width, int *height) { pango_layout_get_size(layout->layout, width, height); *width = *width / PANGO_SCALE; *height = *height / PANGO_SCALE; } void ui_text_setwidth(UiTextLayout *layout, int width) { pango_layout_set_width(layout->layout, width * PANGO_SCALE); pango_layout_set_ellipsize(layout->layout, PANGO_ELLIPSIZE_END); //pango_layout_set_wrap(layout->layout, PANGO_WRAP_WORD_CHAR); } void ui_text_free(UiTextLayout *text) { g_object_unref(text->layout); free(text); }