some gtk_render_* blank?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

some gtk_render_* blank?

The Devils Jester

Hello, I am wondering if anyone here has experience with the gtk_render_* set of functions.  

I have had mixed results:
gtk_render_background and gtk_render_frame work pretty well with gtk_button and gtk_window (but not with most other widgets)

gtk_render_extension, gtk_render_focus, and gtk_render_frame_gap do not seem to produce any output, no matter which widget's style I pass in, or which flags I set. 

gtk_render_check (and gtk_render_option) does render, with the wrong color, a check mark or a circle, but no background or frame (gtk_render_frame and gtk_render_background do nothing on these widgets)

With all of the above, I have tried setting various states, and using many different widgets as the style base without any success.  I have also made sure to use widgets that are parented and have been realized.

I am doing something wrong, I am just not sure what.  My process is simple:

1. Get a (realized) widget
2. Get a cairo_t
3. Get a GtkStateFlags
4. Get style context for widget
5. Save context
6. Set State
7. gtk_render_* . (may have more than one render call, like background & frame)
8. Restore context

An example where this works perfectly is the GtkButton.    Is there some simple step I am missing to get these other render functions to work correctly?

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: some gtk_render_* blank?

adlo
I am also experiencing this issue, and have tried the same things. How can I get gtk_render_frame to render on a no-visible-window GtkEventBox?

Regards

adlo

> On 2 Feb 2017, at 03:35, The Devils Jester <[hidden email]> wrote:
>
>
> Hello, I am wondering if anyone here has experience with the gtk_render_* set of functions.  
>
> I have had mixed results:
> gtk_render_background and gtk_render_frame work pretty well with gtk_button and gtk_window (but not with most other widgets)
>
> gtk_render_extension, gtk_render_focus, and gtk_render_frame_gap do not seem to produce any output, no matter which widget's style I pass in, or which flags I set.
>
> gtk_render_check (and gtk_render_option) does render, with the wrong color, a check mark or a circle, but no background or frame (gtk_render_frame and gtk_render_background do nothing on these widgets)
>
> With all of the above, I have tried setting various states, and using many different widgets as the style base without any success.  I have also made sure to use widgets that are parented and have been realized.
>
> I am doing something wrong, I am just not sure what.  My process is simple:
>
> 1. Get a (realized) widget
> 2. Get a cairo_t
> 3. Get a GtkStateFlags
> 4. Get style context for widget
> 5. Save context
> 6. Set State
> 7. gtk_render_* . (may have more than one render call, like background & frame)
> 8. Restore context
>
> An example where this works perfectly is the GtkButton.    Is there some simple step I am missing to get these other render functions to work correctly?
> _______________________________________________
> gtk-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-list
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: some gtk_render_* blank?

Gtk+ - General mailing list

Hi adlo,

With the event box you can draw with transparency. If you want to get the CSS and combine that with a cairo drawing and have transparency so that you can see the background window through the event box window, all that can be done.

Eric

//gcc -Wall render_css1.c -o render_css1 `pkg-config --cflags --libs gtk+-3.0`

//Tested with GTK3.18 and GTK3.22

#include<gtk/gtk.h>

static gboolean draw_event_box(GtkWidget *event_box, cairo_t *cr, gpointer user_data)
  {
    gint width=gtk_widget_get_allocated_width(event_box);
    gint height=gtk_widget_get_allocated_height(event_box);

    //Draw from CSS.
    GtkStyleContext *context=gtk_widget_get_style_context(event_box);
    gtk_render_background(context, cr, 0, 0, width, height);
    gtk_render_frame(context, cr, 0, 0, width, height);

    //Draw with cairo also.
    cairo_set_source_rgba(cr, 0.0, 1.0, 1.0, 1.0);
    cairo_set_line_width(cr, 10);
    cairo_translate(cr, width/2, height/2);
    cairo_arc(cr, 0, 0, 0.3*width, 0.0, 2.0*G_PI);
    cairo_stroke(cr);

    return FALSE;
  }
int main(int argc, char *argv[])
  {
    gtk_init(&argc, &argv);

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Event Box");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget *event_box=gtk_event_box_new();
    gtk_widget_set_app_paintable(event_box, TRUE);
    gtk_widget_set_hexpand(event_box, TRUE);
    gtk_widget_set_vexpand(event_box, TRUE);
    gtk_widget_set_name(event_box, "event1");
    g_signal_connect(event_box, "draw", G_CALLBACK(draw_event_box), NULL);

    GtkWidget *label=gtk_label_new("Label");
    gtk_container_add(GTK_CONTAINER(event_box), label);

    GtkWidget *grid=gtk_grid_new();
    gtk_grid_attach(GTK_GRID(grid), event_box, 0, 0, 1, 1);
    gtk_container_add(GTK_CONTAINER(window), grid);

    GError *css_error=NULL;
    gchar *css_string=NULL;
    //Set background alpha.
    css_string=g_strdup("#event1{background: rgba(255,0,255,0.3); border: solid 20px yellow;}");
    GtkCssProvider *provider=gtk_css_provider_new();
    GdkDisplay *display=gdk_display_get_default();
    GdkScreen *screen=gdk_display_get_default_screen(display);
    gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
    gtk_css_provider_load_from_data(provider, css_string, -1, &css_error);
    if(css_error!=NULL)
      {
        g_print("CSS loader error %s\n", css_error->message);
        g_error_free(css_error);
      }
    g_object_unref(provider);
    if(css_string!=NULL) g_free(css_string);
  
    gtk_widget_show_all(window);
    gtk_main();
    return 0;  
  }




_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list