/* input handler */ void input_cb (ClutterStage *stage, ClutterEvent *event, gpointer data) { if (event->type == CLUTTER_BUTTON_PRESS) { ClutterActor *a; gfloat x, y; clutter_event_get_coords (event, &x, &y); a = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, x, y); if (a && (CLUTTER_IS_TEXTURE (a) || CLUTTER_IS_CLONE (a))) clutter_actor_hide (a); } else if (event->type == CLUTTER_KEY_PRESS) { g_print ("*** key press event (key:%c) ***\n", clutter_event_get_key_symbol (event)); if (clutter_event_get_key_symbol (event) == CLUTTER_q) gtk_main_quit (); } }
static void toggle_texture_quality (ClutterActor *actor) { if (CLUTTER_IS_CONTAINER (actor)) clutter_container_foreach (CLUTTER_CONTAINER (actor), (ClutterCallback) toggle_texture_quality, NULL); if (CLUTTER_IS_TEXTURE (actor)) { ClutterTextureQuality quality; quality = clutter_texture_get_filter_quality (CLUTTER_TEXTURE (actor)); if (quality == CLUTTER_TEXTURE_QUALITY_HIGH) quality = CLUTTER_TEXTURE_QUALITY_MEDIUM; else quality = CLUTTER_TEXTURE_QUALITY_HIGH; g_print ("switching to quality %s for %p\n", quality == CLUTTER_TEXTURE_QUALITY_HIGH ? "high" : "medium", actor); clutter_texture_set_filter_quality (CLUTTER_TEXTURE (actor), quality); } }
CoglHandle _st_create_shadow_material_from_actor (StShadow *shadow_spec, ClutterActor *actor) { CoglHandle shadow_material = COGL_INVALID_HANDLE; if (CLUTTER_IS_TEXTURE (actor)) { CoglHandle texture; texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor)); shadow_material = _st_create_shadow_material (shadow_spec, texture); } else { CoglHandle buffer, offscreen; ClutterActorBox box; CoglColor clear_color; float width, height; clutter_actor_get_allocation_box (actor, &box); clutter_actor_box_get_size (&box, &width, &height); if (width == 0 || height == 0) return COGL_INVALID_HANDLE; buffer = st_cogl_texture_new_with_size_wrapper (width, height, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_ANY); if (buffer == COGL_INVALID_HANDLE) return COGL_INVALID_HANDLE; offscreen = cogl_offscreen_new_to_texture (buffer); if (offscreen == COGL_INVALID_HANDLE) { cogl_handle_unref (buffer); return COGL_INVALID_HANDLE; } cogl_color_set_from_4ub (&clear_color, 0, 0, 0, 0); cogl_push_framebuffer (offscreen); cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR); cogl_translate (-box.x1, -box.y1, 0); cogl_ortho (0, width, height, 0, 0, 1.0); clutter_actor_paint (actor); cogl_pop_framebuffer (); cogl_handle_unref (offscreen); shadow_material = _st_create_shadow_material (shadow_spec, buffer); cogl_handle_unref (buffer); } return shadow_material; }
/** * gtk_clutter_texture_set_from_icon_name: * @texture: a #GtkClutterTexture * @widget: (allow-none): a #GtkWidget or %NULL * @icon_name: the name of the icon * @icon_size: the icon size or -1 * @error: a return location for errors, or %NULL * * Sets the contents of @texture using the @icon_name from the * current icon theme. * * Return value: %TRUE on success, %FALSE on failure * * Since: 1.0 */ gboolean gtk_clutter_texture_set_from_icon_name (GtkClutterTexture *texture, GtkWidget *widget, const gchar *icon_name, GtkIconSize icon_size, GError **error) { GError *local_error = NULL; GtkSettings *settings; GtkIconTheme *icon_theme; gboolean returnval; gint width, height; GdkPixbuf *pixbuf; g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), FALSE); g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); g_return_val_if_fail (icon_name != NULL, FALSE); g_return_val_if_fail ((icon_size > GTK_ICON_SIZE_INVALID) || (icon_size == -1), FALSE); if (widget && gtk_widget_has_screen (widget)) { GdkScreen *screen; screen = gtk_widget_get_screen (widget); settings = gtk_settings_get_for_screen (screen); icon_theme = gtk_icon_theme_get_for_screen (screen); } else { settings = gtk_settings_get_default (); icon_theme = gtk_icon_theme_get_default (); } G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (icon_size == -1 || !gtk_icon_size_lookup_for_settings (settings, icon_size, &width, &height)) { width = height = 48; } G_GNUC_END_IGNORE_DEPRECATIONS pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, MIN (width, height), 0, &local_error); if (local_error) { g_propagate_error (error, local_error); return FALSE; } returnval = gtk_clutter_texture_set_from_pixbuf (texture, pixbuf, error); g_object_unref (pixbuf); return returnval; }
/** * clutter_reflect_texture_new: * @texture: a #ClutterTexture or %NULL * * Creates an efficient 'reflect' of a pre-existing texture if which it * shares the underlying pixbuf data. * * You can use clutter_reflect_texture_set_parent_texture() to change the * parent texture to be reflectd. * * Return value: the newly created #ClutterReflectTexture */ ClutterActor * clutter_reflect_texture_new (ClutterTexture *texture, gint reflection_height) { g_return_val_if_fail (texture == NULL || CLUTTER_IS_TEXTURE (texture), NULL); return g_object_new (CLUTTER_TYPE_REFLECT_TEXTURE, "parent-texture", texture, "reflection-height", reflection_height, NULL); }
/* input handler */ static gboolean input_cb (ClutterActor *stage, ClutterEvent *event, gpointer data) { SuperOH *oh = data; if (event->type == CLUTTER_BUTTON_PRESS) { ClutterButtonEvent *button_event; ClutterActor *e; gint x, y; clutter_event_get_coords (event, &x, &y); button_event = (ClutterButtonEvent *) event; g_print ("*** button press event (button:%d) ***\n", button_event->button); e = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage), x, y); if (e && (CLUTTER_IS_TEXTURE (e) || CLUTTER_IS_CLONE_TEXTURE (e))) { clutter_actor_hide (e); return TRUE; } } else if (event->type == CLUTTER_KEY_RELEASE) { ClutterKeyEvent *kev = (ClutterKeyEvent *) event; g_print ("*** key press event (key:%c) ***\n", clutter_key_event_symbol (kev)); if (clutter_key_event_symbol (kev) == CLUTTER_q) { clutter_main_quit (); return TRUE; } else if (clutter_key_event_symbol (kev) == CLUTTER_r) { gint i; for (i = 0; i < n_hands; i++) clutter_actor_show (oh->hand[i]); return TRUE; } } return FALSE; }
static void mnb_spinner_paint (ClutterActor *self) { MnbSpinnerPrivate *priv = MNB_SPINNER (self)->priv; MxWidget *widget = MX_WIDGET (self); ClutterTexture *background; /* * This paints border-image. */ CLUTTER_ACTOR_CLASS (mnb_spinner_parent_class)->paint (self); if ((background = (ClutterTexture *) mx_widget_get_background_image (widget))) { gint tx_w, tx_h; gfloat tf_x, tf_y, tf_w, tf_h; guint8 opacity; ClutterActorBox box = { 0, }; CoglHandle material; if (!CLUTTER_IS_TEXTURE (background)) return; opacity = clutter_actor_get_paint_opacity (self); if (opacity == 0) return; clutter_texture_get_base_size (background, &tx_w, &tx_h); material = clutter_texture_get_cogl_material (background); cogl_material_set_color4ub (material, opacity, opacity, opacity, opacity); clutter_actor_get_allocation_box (self, &box); tf_x = (gfloat)priv->frame / (gfloat) priv->n_frames; tf_y = 0.0; tf_w = tf_x + 1.0 / priv->n_frames; tf_h = 1.0; /* Paint will have translated us */ cogl_set_source (material); cogl_rectangle_with_texture_coords (0.0, 0.0, box.x2 - box.x1, box.y2 - box.y1, tf_x, tf_y, tf_w, tf_h); } }
static void _lambda23_ (GObject* obj, GParamSpec* spec, Block7Data* _data7_) { #line 167 "ease-image-actor.c" EaseImageActor * self; ClutterActor* _tmp0_; char* _tmp1_; self = _data7_->self; #line 57 "ease-image-actor.vala" g_return_if_fail (obj != NULL); #line 57 "ease-image-actor.vala" g_return_if_fail (spec != NULL); #line 58 "ease-image-actor.vala" g_object_set ((_tmp0_ = ((EaseActor*) self)->contents, CLUTTER_IS_TEXTURE (_tmp0_) ? ((ClutterTexture*) _tmp0_) : NULL), "filename", _tmp1_ = ease_media_element_get_full_filename ((EaseMediaElement*) _data7_->e), NULL); #line 178 "ease-image-actor.c" _g_free0 (_tmp1_); }
/** * tidy_texture_frame_new: * @texture: a #ClutterTexture or %NULL * * FIXME * * Return value: the newly created #TidyTextureFrame */ ClutterActor* tidy_texture_frame_new (ClutterTexture *texture, gint left, gint top, gint right, gint bottom) { g_return_val_if_fail (texture == NULL || CLUTTER_IS_TEXTURE (texture), NULL); return g_object_new (TIDY_TYPE_TEXTURE_FRAME, "parent-texture", texture, "left", left, "top", top, "right", right, "bottom", bottom, NULL); }
ClutterActor * mnb_toolbar_shadow_new (MnbToolbar *toolbar, ClutterTexture *texture, gfloat top, gfloat right, gfloat bottom, gfloat left) { g_return_val_if_fail (texture == NULL || CLUTTER_IS_TEXTURE (texture), NULL); return g_object_new (MNB_TYPE_TOOLBAR_SHADOW, "toolbar", toolbar, "parent-texture", texture, "top", top, "right", right, "bottom", bottom, "left", left, NULL); }
static void mnb_spinner_get_preferred_height (ClutterActor *self, gfloat for_width, gfloat *min_height_p, gfloat *natural_height_p) { MxWidget *widget = MX_WIDGET (self); ClutterTexture *background; if ((background = (ClutterTexture *) mx_widget_get_background_image (widget))) { gint tx_w, tx_h; if (!CLUTTER_IS_TEXTURE (background)) return; /* * The background texture is a strip of squares making up the individual * frames in the animation, so the width matches the height of the * texture. */ clutter_texture_get_base_size (background, &tx_w, &tx_h); if (min_height_p) *min_height_p = tx_h; if (natural_height_p) *natural_height_p = tx_h; return; } if (min_height_p) *min_height_p = 0.0; if (natural_height_p) *natural_height_p = 0.0; }
static void astro_applet_init (AstroApplet *applet) { AstroAppletPrivate *priv; priv = applet->priv = ASTRO_APPLET_GET_PRIVATE (applet); if (!CLUTTER_IS_TEXTURE (texture)) { applet_bg = gdk_pixbuf_new_from_file (PKGDATADIR "/applet_bg.png", NULL); texture = g_object_new (CLUTTER_TYPE_TEXTURE, "pixbuf", applet_bg, "tiled", FALSE, NULL); } priv->texture = tidy_texture_frame_new (CLUTTER_TEXTURE (texture), 15, 15, 15, 15); clutter_container_add_actor (CLUTTER_CONTAINER (applet), priv->texture); clutter_actor_show_all (CLUTTER_ACTOR (applet)); }
/* input handler */ static gboolean input_cb (ClutterStage *stage, ClutterEvent *event, gpointer data) { ClutterEventType event_type = clutter_event_type (event); SuperOH *oh = data; if (event_type == CLUTTER_BUTTON_PRESS) { ClutterActor *a; gfloat x, y; clutter_event_get_coords (event, &x, &y); a = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, x, y); if (a != NULL && (CLUTTER_IS_TEXTURE (a) || CLUTTER_IS_CLONE (a))) clutter_actor_hide (a); } else if (event->type == CLUTTER_KEY_PRESS) { g_print ("*** key press event (key:%c) ***\n", clutter_event_get_key_symbol (event)); if (clutter_event_get_key_symbol (event) == CLUTTER_KEY_q) gtk_main_quit (); else if (clutter_event_get_key_symbol (event) == CLUTTER_KEY_r) { int i; for (i = 0; i < NHANDS; i++) clutter_actor_show (oh->hand[i]); } } return TRUE; }
static void set_shader_num (ClutterActor *actor, gint new_no) { int tex_width; int tex_height; if (new_no >= 0 && shaders[new_no].name) { ClutterShader *shader; GError *error; shader_no = new_no; g_print ("setting shaders[%i] named '%s'\n", shader_no, shaders[shader_no].name); shader = clutter_shader_new (); error = NULL; g_object_set (G_OBJECT (shader), "fragment-source", shaders[shader_no].source, NULL); /* try to bind the shader, provoking an error we catch if there is issues * with the shader sources we've provided. At a later stage it should be * possible to iterate through a set of alternate shader sources (glsl -> * asm -> cg?) and the one that succesfully compiles is used. */ clutter_shader_compile (shader, &error); if (error) { g_print ("unable to set shaders[%i] named '%s': %s", shader_no, shaders[shader_no].name, error->message); g_error_free (error); clutter_actor_set_shader (actor, NULL); } else { clutter_actor_set_shader (actor, NULL); clutter_actor_set_shader (actor, shader); clutter_actor_set_shader_param_int (actor, "tex", 0); clutter_actor_set_shader_param_float (actor, "radius", 3.0); clutter_actor_set_shader_param_float (actor, "brightness", 0.4); clutter_actor_set_shader_param_float (actor, "contrast", -1.9); if (CLUTTER_IS_TEXTURE (actor)) { /* XXX - this assumes *a lot* about how things are done * internally on *some* hardware and driver */ tex_width = clutter_actor_get_width (actor); tex_width = next_p2 (tex_width); tex_height = clutter_actor_get_height (actor); tex_height = next_p2 (tex_height); clutter_actor_set_shader_param_float (actor, "x_step", 1.0f / tex_width); clutter_actor_set_shader_param_float (actor, "y_step", 1.0f / tex_height); } } g_object_unref (shader); } }
static void mnb_spinner_constructed (GObject *self) { MnbSpinnerPrivate *priv = MNB_SPINNER (self)->priv; MxWidget *widget = MX_WIDGET (self); ClutterTexture *background; ClutterTimeline *timeline; /* * Mx does not seem to load the style info until the first show, but we want * to get hold of the background asset here to work out the frame count, so * we need to force the style loading. * * NB: mx_widget_ensure_style() does not work here, because the MxWidget * is_style_dirty flag is cleared at this point. */ mx_stylable_style_changed (MX_STYLABLE (widget), MX_STYLE_CHANGED_FORCE); if ((background = (ClutterTexture *) mx_widget_get_background_image (widget))) { gint tx_w, tx_h; guint duration; if (!CLUTTER_IS_TEXTURE (background)) { g_critical ("Expected ClutterTexture, but got %s", G_OBJECT_TYPE_NAME (background)); return; } /* * The background texture is a strip of squares making up the individual * frames in the animation, so the width matches the height of the * texture. */ clutter_texture_get_base_size (background, &tx_w, &tx_h); priv->n_frames = tx_w / tx_h; if (tx_w % tx_h) g_warning (G_STRLOC ": Expected texture size %d x %d, got %d x %d", tx_h * priv->n_frames, tx_h, tx_w, tx_h); /* * Setup a looped timeline with a marker that fires everytime we should * advance to a new frame. * * Assume the whole animation is to last 1s. */ duration = 1000/ priv->n_frames; timeline = priv->timeline = clutter_timeline_new (duration); clutter_timeline_set_loop (timeline, TRUE); clutter_timeline_add_marker_at_time (timeline, "next", duration); clutter_timeline_stop (timeline); g_signal_connect (timeline, "marker-reached", G_CALLBACK (mnb_spinner_marker_reached_cb), self); } else g_warning ("%s did not have background-image set in style !!!", G_OBJECT_TYPE_NAME (self)); }
CoglPipeline * _st_create_shadow_pipeline_from_actor (StShadow *shadow_spec, ClutterActor *actor) { CoglPipeline *shadow_pipeline = NULL; if (CLUTTER_IS_TEXTURE (actor)) { CoglTexture *texture; texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor)); shadow_pipeline = _st_create_shadow_pipeline (shadow_spec, texture); } else { CoglTexture *buffer; CoglOffscreen *offscreen; CoglFramebuffer *fb; ClutterActorBox box; CoglColor clear_color; float width, height; CoglError *catch_error = NULL; clutter_actor_get_allocation_box (actor, &box); clutter_actor_box_get_size (&box, &width, &height); if (width == 0 || height == 0) return NULL; buffer = cogl_texture_new_with_size (width, height, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_ANY); if (buffer == NULL) return NULL; offscreen = cogl_offscreen_new_with_texture (buffer); fb = COGL_FRAMEBUFFER (offscreen); if (!cogl_framebuffer_allocate (fb, &catch_error)) { cogl_error_free (catch_error); cogl_object_unref (buffer); return NULL; } cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0); /* XXX: There's no way to render a ClutterActor to an offscreen * as it uses the implicit API. */ G_GNUC_BEGIN_IGNORE_DEPRECATIONS; cogl_push_framebuffer (fb); G_GNUC_END_IGNORE_DEPRECATIONS; cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color); cogl_framebuffer_translate (fb, -box.x1, -box.y1, 0); cogl_framebuffer_orthographic (fb, 0, 0, width, height, 0, 1.0); clutter_actor_set_opacity_override (actor, 255); clutter_actor_paint (actor); clutter_actor_set_opacity_override (actor, -1); G_GNUC_BEGIN_IGNORE_DEPRECATIONS; cogl_pop_framebuffer (); G_GNUC_END_IGNORE_DEPRECATIONS; cogl_object_unref (fb); shadow_pipeline = _st_create_shadow_pipeline (shadow_spec, buffer); cogl_object_unref (buffer); } return shadow_pipeline; }
Context::Context( ClutterActor * actor ) : unpack_flip_y( false ), unpack_premultiply_alpha( false ), unpack_colorspace_conversion( GL_BROWSER_DEFAULT_WEBGL ), have_depth( false ), have_stencil( false ), acquisitions( 0 ), texture( 0 ), texture_target( 0 ), framebuffer( 0 ) { g_assert( CLUTTER_IS_TEXTURE( actor ) ); // Make sure we are in the clutter context context_op( SWITCH_TO_CLUTTER_CONTEXT ); // Get the Clutter GL texture id and target #ifdef CLUTTER_VERSION_1_10 CoglTexture * th = COGL_TEXTURE( clutter_texture_get_cogl_texture( CLUTTER_TEXTURE( actor ) ) ); #else CoglHandle th = clutter_texture_get_cogl_texture( CLUTTER_TEXTURE( actor ) ); #endif if ( ! cogl_texture_get_gl_texture( th , & texture , & texture_target ) ) { tpwarn( "FAILED TO GET GL TEXTURE HANDLE" ); } // Now, create our context and switch to it context_op( CREATE_CONTEXT ); context_op( SWITCH_TO_MY_CONTEXT ); // Get the width and height of the actor gfloat width; gfloat height; clutter_actor_get_size( actor , & width , & height ); // Try to create the frame buffer in different ways until one // succeeds (or all fail). const int try_flags[] = { #if defined(CLUTTER_WINDOWING_GLX) || defined(CLUTTER_WINDOWING_OSX) FBO_TRY_DEPTH_STENCIL , #endif FBO_TRY_DEPTH | FBO_TRY_STENCIL , FBO_TRY_DEPTH , FBO_TRY_STENCIL , 0 }; for ( size_t i = 0; i < sizeof( try_flags ) / sizeof( int ); ++i ) { if ( try_create_fbo( width , height , try_flags[ i ] ) ) { break; } } if ( ! framebuffer ) { tpwarn( "UNABLE TO CREATE FRAMEBUFFER" ); } else { tplog2( "FRAMEBUFFER READY : DEPTH = %s : STENCIL = %s" , have_depth ? "YES" : "NO" , have_stencil ? "YES" : "NO" ); } context_op( SWITCH_TO_CLUTTER_CONTEXT ); }