[prev in list] [next in list] [prev in thread] [next in thread]
List: moblin-commits
Subject: [Moblin-Commits] sample_apps: Changes to 'master'
From: deckerf () moblin ! org (Felicia E ! Decker)
Date: 2008-09-09 19:28:47
Message-ID: 20080909192847.69D7592C146 () moblin ! org
[Download RAW message or body]
This email list is read-only. Emails sent to this list will be discarded
----------------------------------
ChangeLog | 3 +-
Makefile.am | 2 +-
button/Makefile.am | 12 ++
button/arrow.png | Bin 0 -> 1131 bytes
button/button.c | 296 ++++++++++++++++++++++++++++++++++++++++++++++++
button/darkbutton.png | Bin 0 -> 5042 bytes
button/lightbutton.png | Bin 0 -> 4687 bytes
button/swirl.png | Bin 0 -> 5844 bytes
configure.ac | 4 +
9 files changed, 315 insertions(+), 2 deletions(-)
New commits:
commit 03e26b23e95b691b6b30c2ff336a65b1324e4aee
Author: Felicia Decker <felicia.e.decker@intel.com>
Date: Tue Sep 9 12:26:33 2008 -0700
Added button app
Diff in this email is a maximum of 400 lines.
diff --git a/ChangeLog b/ChangeLog
index 7e7a775..f8756e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
-
+Sept 9: Added button
+Aug 28: Added tictactoe
Aug 12: First drop includes 4 apps: helloworld, apples, colortext, and
rotating squares.
diff --git a/Makefile.am b/Makefile.am
index 182fe23..51d23db 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = helloworld apple colortext squares tictactoe
+SUBDIRS = helloworld apple button colortext squares tictactoe
MAINTAINERCLEANFILES = aclocal.m4 compile config.guess config.sub configure depcomp \
install-sh ltmain.sh Makefile.in missing
diff --git a/button/Makefile.am b/button/Makefile.am
new file mode 100644
index 0000000..f0293d3
--- /dev/null
+++ b/button/Makefile.am
@@ -0,0 +1,12 @@
+noinst_PROGRAMS = button
+
+AM_CFLAGS = $(CLUTTER_CFLAGS) \
+ $(GCC_CFLAGS) \
+ -D_GNU_SOURCE
+
+button_LDADD = $(CLUTTER_LIBS)
+button_SOURCES = button.c
+
+buttondir = $(datadir)/button
+button_DATA = arrow.png lightbutton.png darkbutton.png swirl.png
+
diff --git a/button/arrow.png b/button/arrow.png
new file mode 100644
index 0000000..dbe4dd8
Binary files /dev/null and b/button/arrow.png differ
diff --git a/button/button.c b/button/button.c
new file mode 100644
index 0000000..368e433
--- /dev/null
+++ b/button/button.c
@@ -0,0 +1,296 @@
+#include <clutter/clutter.h>
+#include <sys/stat.h>
+
+/* Clutter Button Sept 3 08
+ Read the comments right before main(), and then
+ go through main and read those comments, and then come
+ back to the top and read through.
+ */
+
+
+#define SCN_WIDTH 800
+#define SCN_HEIGHT 480
+#define NUM_SWIRLS 8
+
+ClutterActor *stage, *arrow;
+ClutterActor *swirls[NUM_SWIRLS], *overlay;
+ClutterEffectTemplate *effect_template;
+ClutterTimeline *effect_timeline, *timelines[NUM_SWIRLS];
+ClutterColor stage_color = { 0xff, 0xff, 0xff, 0xff };
+ClutterColor button_color = { 0x1e, 0x90, 0xff, 0xff };
+int swirl_pos[16];
+
+
+
+/*
+ Load image and return clutter actor; included
+ for robustness
+*/
+ClutterActor *get_actor_from_image (const char *file_name)
+{
+ GError **error = 0;
+ ClutterActor *actor;
+
+ //look in 3 spots for file
+ struct stat statbuf;
+ char path [256];
+
+ sprintf (path, "./%s", file_name);
+ int rval = stat (path, &statbuf);
+ if (rval < 0) {
+ sprintf (path, "/usr/local/share/button/%s", file_name);
+ rval = stat (path, &statbuf);
+ }
+ if (rval < 0) {
+ sprintf (path, "/usr/share/button/%s", file_name);
+ rval = stat (path, &statbuf);
+ }
+ if (rval >= 0) {
+ actor = clutter_texture_new_from_file(path, error);
+ }
+ if (!actor) {
+ fprintf(stderr, "Error: %s failed to load.\n", file_name);
+ }
+ return actor;
+}//end_get_actor_from_image
+
+
+
+void init_swirls(ClutterActor *actor)
+{
+ //swirl_pos[]: I put the x, y positions for
+ // each swirl into an array so it would be easier
+ // to initialize them within a for loop.
+ swirl_pos[0] = 89; swirl_pos[1] = 72;
+ swirl_pos[2] = 137; swirl_pos[3] = 73;
+ swirl_pos[4] = 189; swirl_pos[5] = 72;
+ swirl_pos[6] = 91; swirl_pos[7] = 105;
+ swirl_pos[8] = 190; swirl_pos[9] = 99;
+ swirl_pos[10] = 93; swirl_pos[11] = 135;
+ swirl_pos[12] = 145; swirl_pos[13] = 135;
+ swirl_pos[14] = 192; swirl_pos[15] = 133;
+
+ //Some additional positioning
+ int k;
+ for (k = 0; k < 16; ++k)
+ {
+ swirl_pos[k] += 133;
+ if (k % 2 == 0)
+ swirl_pos[k] += 127;
+ }
+
+ //The anchor point for each swirl is set to the middle -
+ //this is necessary for the rotate to work properly.
+ //Rotation happens about the z-axis
+ /* Add first actor */
+ int swirl_w = 78;
+ int swirl_h = 73;
+ swirls[0] = get_actor_from_image("swirl.png");
+ clutter_actor_set_size(swirls[0], swirl_w, swirl_h);
+ clutter_actor_set_position(swirls[0], swirl_pos[0], swirl_pos[1]);
+ clutter_actor_set_anchor_point(swirls[0], 39, 36);
+ clutter_container_add_actor(CLUTTER_CONTAINER(stage), swirls[0]);
+ clutter_actor_set_opacity(swirls[0], 0);
+ clutter_actor_show(swirls[0]);
+
+ int i, count;
+ count = 2;
+ for (i = 1; i < NUM_SWIRLS; ++i)
+ {
+ swirls[i] = clutter_clone_texture_new((ClutterTexture*)swirls[0]);
+ clutter_actor_set_size(swirls[i], swirl_w, swirl_h);
+ clutter_actor_set_position(swirls[i],
+ swirl_pos[count], swirl_pos[count + 1]);
+ clutter_actor_set_anchor_point(swirls[i], 39, 36);
+ clutter_container_add_actor(CLUTTER_CONTAINER(stage), swirls[i]);
+ clutter_actor_set_opacity(swirls[i], 0);
+ clutter_actor_show(swirls[i]);
+ count += 2;
+ }
+ return;
+
+}//end init_swirls
+
+
+
+/* A function called on the completion of the
+ clutter_effect_depth in the function below.
+ Returns the arrow back to its original scale.
+ */
+void shrink(ClutterActor *actor, gpointer data)
+{
+ clutter_effect_depth(effect_template, actor, 1, NULL, NULL);
+ return;
+}
+
+
+
+/* Callback function for signal "button-press-event".
+ overlay is passed in as data.
+ We increase overlay's opacity to 100% and fade-in
+ the arrow before increasing it's size.
+ */
+gboolean button_press(ClutterActor *actor, ClutterEvent *event, gpointer data)
+{
+ ClutterActor *tmp = (ClutterActor*)data;
+ clutter_actor_set_opacity(tmp, 0xff);
+
+ clutter_effect_fade(effect_template, arrow, 0xff, NULL, NULL);
+ clutter_effect_depth(effect_template, arrow, 200,
+ (ClutterEffectCompleteFunc)shrink, NULL);
+
+ return TRUE;
+}
+
+
+
+/* Callback function for signal "enter-event".
+ When button is entered by the cursor, all swirls
+ fade-in.
+ */
+gboolean on_enter(ClutterActor *actor, ClutterEvent *event, gpointer data)
+{
+ int i;
+ for (i = 0; i < NUM_SWIRLS; ++i) {
+ clutter_effect_fade(effect_template, swirls[i], 0xff, NULL, NULL);
+ }
+ return TRUE;
+}
+
+
+
+/* Callback function for signal "leave-event".
+ When cursor leaves button, all swirls and the overlay
+ fade-out.
+ */
+gboolean on_leave(ClutterActor *actor, ClutterEvent *event, gpointer data)
+{
+ int i;
+ for (i = 0; i < NUM_SWIRLS; ++i) {
+ clutter_effect_fade(effect_template, swirls[i], 0, NULL, NULL);
+ clutter_effect_fade(effect_template, overlay, 0, NULL, NULL);
+ }
+ return TRUE;
+}
+
+
+
+/*
+/-----------------------------------------------------------------
+ Overview:
+ The first thing I do in main is setup the stage.
+ Then I start adding my actors. If I don't want them to show up
+ at the start of the program, I can either hide them or set
+ their opacity to 0. (0xff for 100% opacity).
+
+ Then I create, setup and start my timeline.
+ Then I connect signal handlers.
+ And then I apply a rotate behaviour to each swirl, controlling
+ each swirl's start/end angle.
+
+ Finally, clutter_main is called and the fun begins!
+ After clutter_main is where I unref any objects that need it,
+ particualarly the timelines...
+
+/-----------------------------------------------------------------
+ Here are the clutter actors I need for the actual button:
+ ClutterActor: button, overlay, arrow, swirls[NUM_SWIRLS]
+ button: This is the dark blue button you first see
+ overlay: This is the light blue button that appears when you
+ click button and fades when your mouse leaves the
+ button.
+ arrow: This arrow appears over the arrows on button and overlay.
+ It is a deeper color and the arrow grows/shrinks when
+ you press button.
+ swirls[]: This is an array of swirls. The first swirl is
+ loaded, and the rest of the swirls are cloned from
+ swirls[0]. These swirls are set behind button and
+ rotate forever. On button-mouse-enter the swirls
+ fade in, and fade out on button-mouse-exit.
+
+/-----------------------------------------------------------------
+
+ */
+int main(int argc, char *argv[])
+{
+ //init everything needed to operate Clutter
+ clutter_init(&argc, &argv);
+
+ //init the stage
+ stage = clutter_stage_get_default();
+ clutter_actor_set_size(stage, SCN_WIDTH, SCN_HEIGHT);
+ clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color);
+ clutter_stage_set_title(CLUTTER_STAGE(stage), "Clutter Button");
+ clutter_actor_show(stage);
+
+ //bit of simple math to find middle of screen
+ int scn_mid_x = 0, scn_mid_y = 0;
+ scn_mid_x = SCN_WIDTH / 2;
+ scn_mid_y = SCN_HEIGHT / 2;
+
+ //more simple math to figure the correct position of button
+ int button_width = 125, button_height = 80;
+ int pos_x = scn_mid_x - (button_width / 2);
+ int pos_y = scn_mid_y - (button_height / 2);
+
+ // - init button
+ // - because we want our swirls to appear behind button, we
+ // init the swirls before we add/show button
+ // - make button reactive to *receive* signals
+ ClutterActor *button = get_actor_from_image("darkbutton.png");
+ clutter_actor_set_size(button, button_width, button_height);
+ clutter_actor_set_position(button, pos_x, pos_y);
+ init_swirls(button);
+ clutter_container_add_actor(CLUTTER_CONTAINER(stage), button);
+ clutter_actor_set_reactive(button, TRUE);
+ clutter_actor_show(button);
+
+ //init overlay
+ overlay = get_actor_from_image("lightbutton.png");
+ clutter_actor_set_size(overlay, button_width, button_height);
+ clutter_actor_set_position(overlay, pos_x, pos_y);
+ clutter_actor_set_opacity(overlay, 0);
+ clutter_container_add_actor(CLUTTER_CONTAINER(stage), overlay);
+
+ //init arrow
+ arrow = get_actor_from_image("arrow.png");
+ clutter_actor_set_size(arrow, button_width, button_height);
+ clutter_actor_set_position(arrow, pos_x, pos_y);
+ clutter_actor_set_opacity(arrow, 0);
+ clutter_container_add_actor(CLUTTER_CONTAINER(stage), arrow);
+
+ //connect signal handlers
+ //see function-name G_CALLBACK( <function-name> ) for further
+ //explanation of what is going on for this signal
+ g_signal_connect(button, "button-press-event",
+ G_CALLBACK(button_press), (gpointer)overlay);
+ g_signal_connect(button, "enter-event", G_CALLBACK(on_enter), NULL);
+ g_signal_connect(button, "leave-event", G_CALLBACK(on_leave), NULL);
+
+ //init timeline
+ effect_timeline = clutter_timeline_new(30, 30);
+ clutter_timeline_set_loop(effect_timeline, TRUE);
+ clutter_timeline_start(effect_timeline);
+ effect_template = clutter_effect_template_new(effect_timeline,
+ CLUTTER_ALPHA_RAMP_INC);
+
+ ClutterAlpha *alpha = clutter_alpha_new_full(effect_timeline,
+ CLUTTER_ALPHA_RAMP_INC,
+ NULL, NULL);
+ //apply rotate behaviour to each swirl, staggering their start
+ //angles by 45 degrees.
+ int i, angle = 0, step = 45;
+ ClutterBehaviour *rotate;
+ for (i = 0; i < NUM_SWIRLS; ++i)
+ {
+ rotate = clutter_behaviour_rotate_new(alpha, CLUTTER_Z_AXIS,
+ CLUTTER_ROTATE_CW,
+ angle, angle);
+ angle += step;
+ clutter_behaviour_apply(rotate, swirls[i]);
+ }
+
+ clutter_main();
+ g_object_unref(effect_timeline);
+ return 0;
+}
diff --git a/button/darkbutton.png b/button/darkbutton.png
new file mode 100644
index 0000000..3343842
Binary files /dev/null and b/button/darkbutton.png differ
diff --git a/button/lightbutton.png b/button/lightbutton.png
new file mode 100644
index 0000000..2e4da78
Binary files /dev/null and b/button/lightbutton.png differ
diff --git a/button/swirl.png b/button/swirl.png
new file mode 100644
index 0000000..a8f92c9
Binary files /dev/null and b/button/swirl.png differ
diff --git a/configure.ac b/configure.ac
index dd3c067..4c0207e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,9 @@ AC_SUBST(helloworlddir)
appledir = ${datadir}/apple
AC_SUBST(appledir)
+buttondir = ${datadir}/button
+AC_SUBST(buttondir)
+
colortextdir = ${datadir}/colortext
AC_SUBST(colorttextdir)
@@ -54,6 +57,7 @@ AC_OUTPUT([
Makefile
helloworld/Makefile
apple/Makefile
+button/Makefile
colortext/Makefile
squares/Makefile
tictactoe/Makefile
_______________________________________________
Commits mailing list
Commits@moblin.org
https://www.moblin.org/mailman/listinfo/commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic