mirror of
https://github.com/brl/mutter.git
synced 2024-12-25 12:32:05 +00:00
e82f656590
This is the result of running a number of sed and perl scripts over the code to do 90% of the work in converting from 16.16 fixed to single precision floating point. Note: A pristine cogl-fixed.c has been maintained as a standalone utility API so that applications may still take advantage of fixed point if they desire for certain optimisations where lower precision may be acceptable. Note: no API changes were made in Clutter, only in Cogl. Overview of changes: - Within clutter/* all usage of the COGL_FIXED_ macros have been changed to use the CLUTTER_FIXED_ macros. - Within cogl/* all usage of the COGL_FIXED_ macros have been completly stripped and expanded into code that works with single precision floats instead. - Uses of cogl_fixed_* have been replaced with single precision math.h alternatives. - Uses of COGL_ANGLE_* and cogl_angle_* have been replaced so we use a float for angles and math.h replacements.
118 lines
3.6 KiB
C
118 lines
3.6 KiB
C
#include <stdlib.h>
|
|
#include <gmodule.h>
|
|
#include <clutter/clutter.h>
|
|
|
|
#define FONT "Mono Bold 14px"
|
|
|
|
static void
|
|
on_entry_paint (ClutterActor *actor,
|
|
gpointer data)
|
|
{
|
|
ClutterActorBox allocation = { 0, };
|
|
ClutterUnit width, height;
|
|
|
|
clutter_actor_get_allocation_box (actor, &allocation);
|
|
width = allocation.x2 - allocation.x1;
|
|
height = allocation.y2 - allocation.y1;
|
|
|
|
cogl_set_source_color4ub (255, 255, 255, 255);
|
|
cogl_path_round_rectangle (0, 0,
|
|
CLUTTER_UNITS_TO_FIXED (width),
|
|
CLUTTER_UNITS_TO_FIXED (height),
|
|
(float)(4),
|
|
COGL_ANGLE_FROM_DEG (1.0));
|
|
cogl_path_stroke ();
|
|
}
|
|
|
|
static void
|
|
on_entry_activate (ClutterText *text,
|
|
gpointer data)
|
|
{
|
|
g_print ("Text activated: %s\n", clutter_text_get_text (text));
|
|
}
|
|
|
|
static ClutterActor *
|
|
create_label (const ClutterColor *color,
|
|
const gchar *text)
|
|
{
|
|
ClutterActor *retval = clutter_text_new_full (FONT, text, color);
|
|
|
|
clutter_text_set_editable (CLUTTER_TEXT (retval), FALSE);
|
|
clutter_text_set_selectable (CLUTTER_TEXT (retval), FALSE);
|
|
|
|
return retval;
|
|
}
|
|
|
|
static ClutterActor *
|
|
create_entry (const ClutterColor *color,
|
|
const gchar *text,
|
|
gunichar password_char,
|
|
gint max_length)
|
|
{
|
|
ClutterActor *retval = clutter_text_new_full (FONT, text, color);
|
|
ClutterColor selection = { 0, };
|
|
|
|
clutter_actor_set_width (retval, 200);
|
|
clutter_actor_set_reactive (retval, TRUE);
|
|
|
|
clutter_color_darken (color, &selection);
|
|
|
|
clutter_text_set_editable (CLUTTER_TEXT (retval), TRUE);
|
|
clutter_text_set_selectable (CLUTTER_TEXT (retval), TRUE);
|
|
clutter_text_set_activatable (CLUTTER_TEXT (retval), TRUE);
|
|
clutter_text_set_single_line_mode (CLUTTER_TEXT (retval), TRUE);
|
|
clutter_text_set_password_char (CLUTTER_TEXT (retval), password_char);
|
|
clutter_text_set_cursor_color (CLUTTER_TEXT (retval), &selection);
|
|
clutter_text_set_max_length (CLUTTER_TEXT (retval), max_length);
|
|
|
|
g_signal_connect (retval, "activate",
|
|
G_CALLBACK (on_entry_activate),
|
|
NULL);
|
|
g_signal_connect (retval, "paint",
|
|
G_CALLBACK (on_entry_paint),
|
|
NULL);
|
|
|
|
return retval;
|
|
}
|
|
|
|
G_MODULE_EXPORT gint
|
|
test_text_field_main (gint argc,
|
|
gchar **argv)
|
|
{
|
|
ClutterActor *stage;
|
|
ClutterActor *text;
|
|
ClutterColor entry_color = {0x33, 0xff, 0x33, 0xff};
|
|
ClutterColor label_color = {0xff, 0xff, 0xff, 0xff};
|
|
ClutterColor background_color = {0x00, 0x00, 0x00, 0xff};
|
|
gint height;
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
stage = clutter_stage_get_default ();
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &background_color);
|
|
|
|
text = create_label (&label_color, "Input field: ");
|
|
clutter_actor_set_position (text, 10, 10);
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
|
|
|
height = clutter_actor_get_height (text);
|
|
|
|
text = create_entry (&entry_color, "some text", 0, 0);
|
|
clutter_actor_set_position (text, 200, 10);
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
|
|
|
text = create_label (&label_color, "Password field: ");
|
|
clutter_actor_set_position (text, 10, height + 12);
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
|
|
|
text = create_entry (&entry_color, "password", '*', 8);
|
|
clutter_actor_set_position (text, 200, height + 12);
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), text);
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
clutter_main ();
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|