/** * clutter_shader_set_uniform: * @shader: a #ClutterShader. * @name: name of uniform in GLSL shader program to set. * @value: a #ClutterShaderFloat, #ClutterShaderInt or #ClutterShaderMatrix * #GValue. * * Sets a user configurable variable in the GLSL shader programs attached to * a #ClutterShader. * * Since: 1.0 */ void clutter_shader_set_uniform (ClutterShader *shader, const gchar *name, const GValue *value) { ClutterShaderPrivate *priv; GLint location = 0; gsize size; g_return_if_fail (CLUTTER_IS_SHADER (shader)); g_return_if_fail (name != NULL); g_return_if_fail (value != NULL); g_return_if_fail (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (value) || CLUTTER_VALUE_HOLDS_SHADER_INT (value) || CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value) || G_VALUE_HOLDS_FLOAT (value) || G_VALUE_HOLDS_INT (value)); priv = shader->priv; g_return_if_fail (priv->program != COGL_INVALID_HANDLE); location = cogl_program_get_uniform_location (priv->program, name); if (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (value)) { const GLfloat *floats; floats = clutter_value_get_shader_float (value, &size); cogl_program_uniform_float (location, size, 1, floats); } else if (CLUTTER_VALUE_HOLDS_SHADER_INT (value)) { const int *ints; ints = clutter_value_get_shader_int (value, &size); cogl_program_uniform_int (location, size, 1, ints); } else if (CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value)) { const GLfloat *matrix; matrix = clutter_value_get_shader_matrix (value, &size); cogl_program_uniform_matrix (location, size, 1, FALSE, matrix); } else if (G_VALUE_HOLDS_FLOAT (value)) { GLfloat float_val = g_value_get_float (value); cogl_program_uniform_float (location, 1, 1, &float_val); } else if (G_VALUE_HOLDS_INT (value)) { int int_val = g_value_get_int (value); cogl_program_uniform_int (location, 1, 1, &int_val); } else g_assert_not_reached (); }
/** * g_value_get_float: * @value: a valid #GValue of type %G_TYPE_FLOAT * * Get the contents of a %G_TYPE_FLOAT #GValue. * * Returns: float contents of @value */ gfloat g_value_get_float (const GValue *value) { g_return_val_if_fail (G_VALUE_HOLDS_FLOAT (value), 0); return value->data[0].v_float; }
double AccessibilityUIElement::intValue() const { if (!ATK_IS_OBJECT(m_element.get())) return 0; if (ATK_IS_VALUE(m_element.get())) { GValue value = G_VALUE_INIT; atk_value_get_current_value(ATK_VALUE(m_element.get()), &value); if (!G_VALUE_HOLDS_FLOAT(&value)) return 0; return g_value_get_float(&value); } // Consider headings as an special case when returning the "int value" of // an AccessibilityUIElement, so we can reuse some tests to check the level // both for HTML headings and objects with the aria-level attribute. if (atk_object_get_role(ATK_OBJECT(m_element.get())) == ATK_ROLE_HEADING) { String headingLevel = getAttributeSetValueForId(ATK_OBJECT(m_element.get()), ObjectAttributeType, "level"); bool ok; double headingLevelValue = headingLevel.toDouble(&ok); if (ok) return headingLevelValue; } return 0; }
static gpointer value_as_pointer (GValue *value) { if (g_value_fits_pointer (value)) return g_value_peek_pointer (value); if (G_VALUE_HOLDS_BOOLEAN (value)) return (void*) g_value_get_boolean (value); if (G_VALUE_HOLDS_CHAR (value)) return (void*) (gssize) g_value_get_char (value); if (G_VALUE_HOLDS_UCHAR (value)) return (void*) (gsize) g_value_get_uchar (value); if (G_VALUE_HOLDS_INT (value)) return (void*) g_value_get_int (value); if (G_VALUE_HOLDS_UINT (value)) return (void*) g_value_get_uint (value); if (G_VALUE_HOLDS_LONG (value)) return (void*) g_value_get_long (value); if (G_VALUE_HOLDS_ULONG (value)) return (void*) g_value_get_ulong (value); if (G_VALUE_HOLDS_FLOAT (value)) return (void*) (gssize) g_value_get_float (value); if (G_VALUE_HOLDS_DOUBLE (value)) return (void*) (gssize) g_value_get_double (value); if (G_VALUE_HOLDS_ENUM (value)) return (void*) (gssize) g_value_get_enum (value); if (G_VALUE_HOLDS_FLAGS (value)) return (void*) (gsize) g_value_get_flags (value); return (void*) 0x1373babe; }
void LayoutTestController::overridePreference(JSStringRef key, JSStringRef value) { GOwnPtr<gchar> originalName(JSStringCopyUTF8CString(key)); GOwnPtr<gchar> valueAsString(JSStringCopyUTF8CString(value)); WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); ASSERT(view); // This transformation could be handled by a hash table (and it once was), but // having it prominent, makes it easier for people from other ports to keep the // list up to date. const gchar* propertyName = 0; if (g_str_equal(originalName.get(), "WebKitJavaScriptEnabled")) propertyName = "enable-scripts"; else if (g_str_equal(originalName.get(), "WebKitDefaultFontSize")) propertyName = "default-font-size"; else if (g_str_equal(originalName.get(), "WebKitEnableCaretBrowsing")) propertyName = "enable-caret-browsing"; else if (g_str_equal(originalName.get(), "WebKitUsesPageCachePreferenceKey")) propertyName = "enable-page-cache"; else if (g_str_equal(originalName.get(), "WebKitPluginsEnabled")) propertyName = "enable-plugins"; else if (g_str_equal(originalName.get(), "WebKitHyperlinkAuditingEnabled")) propertyName = "enable-hyperlink-auditing"; else if (g_str_equal(originalName.get(), "WebKitWebGLEnabled")) propertyName = "enable-webgl"; else if (g_str_equal(originalName.get(), "WebKitWebAudioEnabled")) propertyName = "enable-webaudio"; else if (g_str_equal(originalName.get(), "WebKitTabToLinksPreferenceKey")) { DumpRenderTreeSupportGtk::setLinksIncludedInFocusChain(!g_ascii_strcasecmp(valueAsString.get(), "true") || !g_ascii_strcasecmp(valueAsString.get(), "1")); return; } else if (g_str_equal(originalName.get(), "WebKitHixie76WebSocketProtocolEnabled")) { DumpRenderTreeSupportGtk::setHixie76WebSocketProtocolEnabled(webkit_web_frame_get_web_view(mainFrame), !g_ascii_strcasecmp(valueAsString.get(), "true") || !g_ascii_strcasecmp(valueAsString.get(), "1")); return; } else { fprintf(stderr, "LayoutTestController::overridePreference tried to override " "unknown preference '%s'.\n", originalName.get()); return; } WebKitWebSettings* settings = webkit_web_view_get_settings(view); GParamSpec* pspec = g_object_class_find_property(G_OBJECT_CLASS( WEBKIT_WEB_SETTINGS_GET_CLASS(settings)), propertyName); GValue currentPropertyValue = { 0, { { 0 } } }; g_value_init(¤tPropertyValue, pspec->value_type); if (G_VALUE_HOLDS_STRING(¤tPropertyValue)) g_object_set(settings, propertyName, valueAsString.get(), NULL); else if (G_VALUE_HOLDS_BOOLEAN(¤tPropertyValue)) g_object_set(G_OBJECT(settings), propertyName, !g_ascii_strcasecmp(valueAsString.get(), "true") || !g_ascii_strcasecmp(valueAsString.get(), "1"), NULL); else if (G_VALUE_HOLDS_INT(¤tPropertyValue)) g_object_set(G_OBJECT(settings), propertyName, atoi(valueAsString.get()), NULL); else if (G_VALUE_HOLDS_FLOAT(¤tPropertyValue)) { gfloat newValue = g_ascii_strtod(valueAsString.get(), 0); g_object_set(G_OBJECT(settings), propertyName, newValue, NULL); } else fprintf(stderr, "LayoutTestController::overridePreference failed to override " "preference '%s'.\n", originalName.get()); }
/* A helper funtion which is registered as string to float * convertion one. GGtype system doesn't support such conversion, * and what is more, such convesrion must be done using plain C locale * for SQL safety. */ static void __transform_string_to_float (const GValue *src_val, GValue *dest_val) { g_assert (src_val != NULL); g_assert (dest_val != NULL); g_assert (G_VALUE_HOLDS_FLOAT (dest_val)); gchar *lstring = setlocale (LC_NUMERIC, "0"); setlocale (LC_NUMERIC, "C"); const gchar *string_float = g_value_get_string (src_val); if (!string_float) { g_value_set_float (dest_val, 0.00); } else { g_value_set_float (dest_val, atof (string_float)); } setlocale (LC_ALL, lstring); return; }
/** * g_value_set_float: * @value: a valid #GValue of type %G_TYPE_FLOAT * @v_float: float value to be set * * Set the contents of a %G_TYPE_FLOAT #GValue to @v_float. */ void g_value_set_float (GValue *value, gfloat v_float) { g_return_if_fail (G_VALUE_HOLDS_FLOAT (value)); value->data[0].v_float = v_float; }
double AccessibilityUIElement::maxValue() { if (!ATK_IS_VALUE(m_element)) return 0; GValue value = G_VALUE_INIT; atk_value_get_maximum_value(ATK_VALUE(m_element), &value); if (!G_VALUE_HOLDS_FLOAT(&value)) return 0; return g_value_get_float(&value); }
double AccessibilityUIElement::intValue() const { GValue value = { 0, { { 0 } } }; if (!ATK_IS_VALUE(m_element)) return 0.0f; atk_value_get_current_value(ATK_VALUE(m_element), &value); if (!G_VALUE_HOLDS_FLOAT(&value)) return 0.0f; return g_value_get_float(&value); }
double AccessibilityUIElement::maxValue() { if (!m_element || !ATK_IS_OBJECT(m_element.get())) return 0.0f; GValue value = G_VALUE_INIT; atk_value_get_maximum_value(ATK_VALUE(m_element.get()), &value); if (!G_VALUE_HOLDS_FLOAT(&value)) return 0.0f; return g_value_get_float(&value); }
double AccessibilityUIElement::minValue() { GValue value = { 0, { { 0 } } }; if (!ATK_IS_VALUE(m_element)) return 0.0f; atk_value_get_minimum_value(ATK_VALUE(m_element), &value); if (!G_VALUE_HOLDS_FLOAT(&value)) return 0.0f; return g_value_get_float(&value); }
/** * clutter_actor_set_shader_param: * @self: a #ClutterActor * @param: the name of the parameter * @value: the value of the parameter * * Sets the value for a named parameter of the shader applied * to @actor. * * Since: 1.0 * * Deprecated: 1.8: Use clutter_shader_effect_set_uniform_value() instead */ void clutter_actor_set_shader_param (ClutterActor *self, const gchar *param, const GValue *value) { g_return_if_fail (CLUTTER_IS_ACTOR (self)); g_return_if_fail (param != NULL); g_return_if_fail (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (value) || CLUTTER_VALUE_HOLDS_SHADER_INT (value) || CLUTTER_VALUE_HOLDS_SHADER_MATRIX (value) || G_VALUE_HOLDS_FLOAT (value) || G_VALUE_HOLDS_INT (value)); clutter_actor_set_shader_param_internal (self, param, value); }
/** * grl_related_keys_get_float: * @relkeys: set of related keys to inspect * @key: (type GrlKeyID): key to use * * Returns the value associated with @key from @relkeys. If @key has no value, * or value is not a gfloat, or @key is not in @relkeys, then 0 is returned. * * Returns: float value associated with @key, or 0 in other case. * * Since: 0.1.10 **/ gfloat grl_related_keys_get_float (GrlRelatedKeys *relkeys, GrlKeyID key) { const GValue *value; g_return_val_if_fail (GRL_IS_RELATED_KEYS (relkeys), 0.0); value = grl_related_keys_get (relkeys, key); if (!value || !G_VALUE_HOLDS_FLOAT (value)) { return 0; } else { return g_value_get_float (value); } }
/** * Get a float property * @param filter_param A RSFilterParam * @param name The name of the property * @param value A pointer to a gfloat where the value will be stored * @return TRUE if the property was found, FALSE otherwise */ gboolean rs_filter_param_get_float(const RSFilterParam *filter_param, const gchar *name, gfloat *value) { GValue *val; g_return_val_if_fail(RS_IS_FILTER_PARAM(filter_param), FALSE); g_return_val_if_fail(name != NULL, FALSE); g_return_val_if_fail(name[0] != '\0', FALSE); g_return_val_if_fail(value != NULL, FALSE); val = rs_filter_param_get_gvalue(filter_param, name); if (val && G_VALUE_HOLDS_FLOAT(val)) *value = g_value_get_float(val); return (val != NULL); }
static gboolean string_to_num (GBinding *binding, const GValue *source_value, GValue *target_value, gpointer userdata) { if (G_VALUE_HOLDS_INT (target_value)) g_value_set_int (target_value, atoi (g_value_get_string (source_value))); else if (G_VALUE_HOLDS_UINT (target_value)) g_value_set_uint (target_value, atoi (g_value_get_string (source_value))); else if (G_VALUE_HOLDS_DOUBLE (target_value)) g_value_set_double (target_value, strtod (g_value_get_string (source_value), NULL)); else if (G_VALUE_HOLDS_FLOAT (target_value)) g_value_set_float (target_value, strtof (g_value_get_string (source_value), NULL)); else return FALSE; return TRUE; }
static gboolean num_to_string (GBinding *binding, const GValue *source_value, GValue *target_value, gpointer userdata) { gchar *string; if (G_VALUE_HOLDS_INT (source_value)) string = g_strdup_printf ("%d", g_value_get_int (source_value)); else if (G_VALUE_HOLDS_UINT (source_value)) string = g_strdup_printf ("%d", g_value_get_uint (source_value)); else if (G_VALUE_HOLDS_DOUBLE (source_value)) string = g_strdup_printf ("%.2f", g_value_get_double (source_value)); else if (G_VALUE_HOLDS_FLOAT (source_value)) string = g_strdup_printf ("%.2f", g_value_get_float (source_value)); else return FALSE; g_value_take_string (target_value, string); return TRUE; }
/** * Implements * org.gnome.glib.GValue.g_value_get_float(long value) * called from * org.gnome.glib.GValue.getFloat(Value value) * called from * org.gnome.glib.Object.getPropertyFloat(String name) * * Extract the gfloat value from a GValue of G_TYPE_FLOAT, returning the * primitive. */ JNIEXPORT jfloat JNICALL Java_org_gnome_glib_GValue_g_1value_1get_1float ( JNIEnv* env, jclass cls, jlong _value ) { GValue* value; gfloat result; // translate value value = (GValue*) _value; if (!G_VALUE_HOLDS_FLOAT(value)) { bindings_java_throw(env, "You've asked for the float value of a GValue, but it's not a G_TYPE_FLOAT!"); return 0.0f; } // call function result = g_value_get_float(value); // and return return (jfloat) result; }
static void clutter_shader_effect_update_uniforms (ClutterShaderEffect *effect) { ClutterShaderEffectPrivate *priv = effect->priv; GHashTableIter iter; gpointer key, value; gsize size; if (priv->program == COGL_INVALID_HANDLE) return; if (priv->uniforms == NULL) return; key = value = NULL; g_hash_table_iter_init (&iter, priv->uniforms); while (g_hash_table_iter_next (&iter, &key, &value)) { ShaderUniform *uniform = value; if (uniform->location == -1) uniform->location = cogl_program_get_uniform_location (priv->program, uniform->name); if (CLUTTER_VALUE_HOLDS_SHADER_FLOAT (&uniform->value)) { const GLfloat *floats; floats = clutter_value_get_shader_float (&uniform->value, &size); cogl_program_set_uniform_float (priv->program, uniform->location, size, 1, floats); } else if (CLUTTER_VALUE_HOLDS_SHADER_INT (&uniform->value)) { const GLint *ints; ints = clutter_value_get_shader_int (&uniform->value, &size); cogl_program_set_uniform_int (priv->program, uniform->location, size, 1, ints); } else if (CLUTTER_VALUE_HOLDS_SHADER_MATRIX (&uniform->value)) { const GLfloat *matrix; matrix = clutter_value_get_shader_matrix (&uniform->value, &size); cogl_program_set_uniform_matrix (priv->program, uniform->location, size, 1, FALSE, matrix); } else if (G_VALUE_HOLDS_FLOAT (&uniform->value)) { const GLfloat float_val = g_value_get_float (&uniform->value); cogl_program_set_uniform_float (priv->program, uniform->location, 1, 1, &float_val); } else if (G_VALUE_HOLDS_DOUBLE (&uniform->value)) { const GLfloat float_val = (GLfloat) g_value_get_double (&uniform->value); cogl_program_set_uniform_float (priv->program, uniform->location, 1, 1, &float_val); } else if (G_VALUE_HOLDS_INT (&uniform->value)) { const GLint int_val = g_value_get_int (&uniform->value); cogl_program_set_uniform_int (priv->program, uniform->location, 1, 1, &int_val); } else g_warning ("Invalid uniform of type '%s' for name '%s'", g_type_name (G_VALUE_TYPE (&uniform->value)), uniform->name); } }
std::string get_property_with_node_name( GParamSpec* pParamSpec, const std::string& strObjectName, const std::string& strNodeName) { std::string strResult; // Name and type: const std::string strName = g_param_spec_get_name(pParamSpec); const std::string strTypeName = G_PARAM_SPEC_TYPE_NAME(pParamSpec); const gchar* pchBlurb = g_param_spec_get_blurb(pParamSpec); std::string strDocs = (pchBlurb) ? pchBlurb : ""; // Quick hack to get rid of nested double quotes: std::replace(strDocs.begin(), strDocs.end(), '"', '\''); strResult += "(" + strNodeName + " " + strName + "\n"; strResult += " (of-object \"" + strObjectName + "\")\n"; strResult += " (prop-type \"" + strTypeName + "\")\n"; strResult += " (docs \"" + strDocs + "\")\n"; // Flags: GParamFlags flags = pParamSpec->flags; bool bReadable = (flags & G_PARAM_READABLE) == G_PARAM_READABLE; bool bWritable = (flags & G_PARAM_WRITABLE) == G_PARAM_WRITABLE; bool bConstructOnly = (flags & G_PARAM_CONSTRUCT_ONLY) == G_PARAM_CONSTRUCT_ONLY; bool bDeprecated = (flags & G_PARAM_DEPRECATED) == G_PARAM_DEPRECATED; //#t and #f aren't documented, but I guess that it's correct based on the example in the .defs // spec. const std::string strTrue = "#t"; const std::string strFalse = "#f"; strResult += " (readable " + (bReadable ? strTrue : strFalse) + ")\n"; strResult += " (writable " + (bWritable ? strTrue : strFalse) + ")\n"; strResult += " (construct-only " + (bConstructOnly ? strTrue : strFalse) + ")\n"; if (bDeprecated) strResult += " (deprecated #t)\n"; // Default: not deprecated // Default value: const GValue* defValue = g_param_spec_get_default_value(pParamSpec); std::string defString; bool defValueExists = false; if (G_VALUE_HOLDS_STRING(defValue)) { defValueExists = true; const char* defCString = g_value_get_string(defValue); if (defCString) { // Replace newlines with \n. // A string default value can contain newline characters. // gmmproc removes all newlines when it reads .defs files. defString = std::regex_replace(defCString, std::regex("\n"), "\\n"); } else defString = ""; // A NULL string pointer becomes an empty string. } else if (G_VALUE_HOLDS_FLOAT(defValue) || G_VALUE_HOLDS_DOUBLE(defValue)) { // g_value_transform() can transform a floating point value to a terrible // string, especially if the value is huge. defValueExists = true; const double defDouble = G_VALUE_HOLDS_FLOAT(defValue) ? g_value_get_float(defValue) : g_value_get_double(defValue); std::ostringstream defStringStream; defStringStream << defDouble; defString = defStringStream.str(); } else { GValue defStringValue = G_VALUE_INIT; g_value_init(&defStringValue, G_TYPE_STRING); if (g_value_transform(defValue, &defStringValue)) { const char* defCString = g_value_get_string(&defStringValue); if (defCString) { defValueExists = true; defString = defCString; } } g_value_unset(&defStringValue); } if (defValueExists) strResult += " (default-value \"" + defString + "\")\n"; strResult += ")\n\n"; // close (strNodeName return strResult; }