~asac/clutk/gles-support

« back to all changes in this revision

Viewing changes to tests/test-ctk-menu-expandable.c

  • Committer: Jay Taoko
  • Date: 2010-07-22 16:33:53 UTC
  • mfrom: (237.1.2 clutk.menu-expandable)
  • Revision ID: jay.taoko@canonical.com-20100722163353-jospaxvda2ih8b4p
CtkMenuExpandable: Added an Expandable Menu. Compute correct size
and position with regard to the anchor and the special item inside the menu.

[modified]
  clutk/Makefile.am
  clutk/clutk.h
  clutk/ctk-arb-asm-private.c
  clutk/ctk-arb-asm-private.h
  clutk/ctk-layer-actor.c
  clutk/ctk-main.c
  clutk/ctk-menu.c
  clutk/ctk-menu.h
  data/shaders/Makefile.am
  data/shaders/shaders.h
  gtk-doc.make
  tests/Makefile.am
  tests/test-clutk.c
  vapi/clutk-0.3.gi
  vapi/clutk-0.3.vapi

[added]
  clutk/ctk-menu-expandable.c
  clutk/ctk-menu-expandable.h
  data/shaders/TextureColorMask.fparb
  tests/test-ctk-menu-expandable.c
  tests/test-menu-expandable.c

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 
 
3
//      10        20        30        40        50        60        70        80         
 
4
//
 
5
// Copyright 2010 Canonical Ltd.
 
6
//
 
7
// This program is free software: you can redistribute it and/or modify it
 
8
// under the terms of either or both of the following licenses:
 
9
//
 
10
// 1) the GNU Lesser General Public License version 3, as published by the
 
11
// Free Software Foundation; and/or
 
12
// 2) the GNU Lesser General Public License version 2.1, as published by
 
13
// the Free Software Foundation.
 
14
//
 
15
// This program is distributed in the hope that it will be useful, but
 
16
// WITHOUT ANY WARRANTY; without even the implied warranties of
 
17
// MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
18
// PURPOSE.  See the applicable version of the GNU Lesser General Public
 
19
// License for more details.
 
20
//
 
21
// You should have received a copy of both the GNU Lesser General Public
 
22
// License version 3 and version 2.1 along with this program.  If not, see
 
23
// <http://www.gnu.org/licenses/>
 
24
//
 
25
// Authored by: Mirco Müller <mirco.mueller@canonical.com>
 
26
//
 
27
////////////////////////////////////////////////////////////////////////////////
 
28
 
 
29
//
 
30
// how to compile:
 
31
//   gcc -Wall -Werror -g -std=c99 `pkg-config --cflags --libs gtk+-2.0
 
32
//   clutter-1.0 clutter-gtk-0.10 clutk-0.3` test-ctk-menu-expandable.c
 
33
//   -o test-ctk-menu-expandable
 
34
//
 
35
 
 
36
#include <clutter/clutter.h>
 
37
#include <clutk/clutk.h>
 
38
 
 
39
 
 
40
gboolean
 
41
anim_func (gpointer data)
 
42
{
 
43
  CtkMenuExpandable* menu   = NULL;
 
44
  static gfloat      factor = 0.0f;
 
45
  static gfloat      step   = 1.0f / 60.0f;
 
46
 
 
47
  menu = CTK_MENU_EXPANDABLE (data);
 
48
 
 
49
  if (factor + step > 1.0f)
 
50
    step = -1.0f / 60.0f;
 
51
 
 
52
  if (factor + step < 0.0f)
 
53
    step = 1.0f / 60.0f;
 
54
 
 
55
  factor += step;
 
56
 
 
57
  ctk_menu_expandable_set_expansion_size_factor (menu, factor);
 
58
 
 
59
  clutter_actor_queue_redraw (CLUTTER_ACTOR (menu));
 
60
 
 
61
  return TRUE;
 
62
}
 
63
 
 
64
int
 
65
main (int    argc,
 
66
      char** argv)
 
67
{
 
68
  ClutterActor*      stage;
 
69
  gint               dummy          = 0;
 
70
  ClutterColor       green          = {0, 128, 0, 255};
 
71
  ClutterColor       white          = {255, 255, 255, 255};
 
72
  ClutterActor*      item_1         = NULL;
 
73
  ClutterActor*      item_2         = NULL;
 
74
  ClutterActor*      item_3         = NULL;
 
75
  ClutterActor*      item_4         = NULL;
 
76
  ClutterActor*      item_5         = NULL;
 
77
  CtkMenuExpandable* menu           = NULL;
 
78
  CtkMenuSeperator*  separator_1    = NULL;
 
79
  CtkMenuSeperator*  separator_2    = NULL;
 
80
  CtkPadding         padding;
 
81
  cairo_surface_t*   surf           = NULL;
 
82
  gfloat             rgba[4]        = {0.25f, 0.5f, 1.0f, 1.0f};
 
83
  //gfloat             rgba2[4]       = {1.0f, 0.5f, 0.25f, 0.5f};
 
84
  gfloat             rgba_tint[4]   = {0.2f, 0.2f, 0.2f, 1.0f};
 
85
  gfloat             rgba_hl[4]     = {1.0f, 1.0f, 1.0f, 0.65f};
 
86
  gfloat             rgba_line[4]   = {0.8f, 0.8f, 0.8f, 1.0f};
 
87
  gfloat             rgba_shadow[4] = {0.0f, 0.0f, 0.0f, 0.75f};
 
88
  gfloat             menu_width;
 
89
  gfloat             menu_height;
 
90
  gfloat             tooltip_width;
 
91
  gfloat             tooltip_height;
 
92
 
 
93
 
 
94
 
 
95
  // don't sync to vblank, needs to be _before_ clutter_init () !!!
 
96
  g_setenv ("CLUTTER_VBLANK", "none", FALSE);
 
97
 
 
98
  clutter_init (&dummy, NULL);
 
99
  ctk_init (&dummy, NULL);
 
100
 
 
101
  stage = clutter_stage_get_default ();
 
102
  clutter_stage_set_color (CLUTTER_STAGE (stage), &green);
 
103
 
 
104
  item_1 = clutter_text_new_full ("Coconut Medium 9", "Open...", &white);
 
105
  clutter_actor_set_reactive (item_1, TRUE);
 
106
  item_2 = clutter_text_new_full ("Coconut Medium 9", "Save...", &white);
 
107
  clutter_actor_set_reactive (item_2, TRUE);
 
108
  item_3 = clutter_text_new_full ("Coconut Medium 9", "Info...", &white);
 
109
  clutter_actor_set_reactive (item_3, TRUE);
 
110
  item_4 = clutter_text_new_full ("Coconut Medium 9", "Settings...", &white);
 
111
  clutter_actor_set_reactive (item_4, TRUE);
 
112
  item_5 = clutter_text_new_full ("Coconut Medium 9", "Quit", &white);
 
113
  clutter_actor_set_reactive (item_5, TRUE);
 
114
 
 
115
  menu = ctk_menu_expandable_new ();
 
116
  clutter_actor_set_reactive (CLUTTER_ACTOR (menu), TRUE);
 
117
 
 
118
  ctk_menu_append (CTK_MENU (menu), item_1, FALSE);
 
119
  ctk_menu_append (CTK_MENU (menu), item_2, FALSE);
 
120
  separator_1 = ctk_menu_seperator_new ();
 
121
  ctk_menu_append (CTK_MENU (menu), CLUTTER_ACTOR (separator_1), FALSE);
 
122
  ctk_menu_append (CTK_MENU (menu), item_3, FALSE);
 
123
  ctk_menu_append (CTK_MENU (menu), item_4, FALSE);
 
124
  separator_2 = ctk_menu_seperator_new ();
 
125
  ctk_menu_append (CTK_MENU (menu), CLUTTER_ACTOR (separator_2), FALSE);
 
126
  ctk_menu_append (CTK_MENU (menu), item_5, FALSE);
 
127
  clutter_container_add_actor (CLUTTER_CONTAINER (stage),
 
128
                               CLUTTER_ACTOR (menu));
 
129
 
 
130
 
 
131
  ctk_menu_set_spacing (CTK_MENU (menu), 2);
 
132
  ctk_menu_expandable_set_content_padding (menu, 4);
 
133
  ctk_menu_expandable_set_padding (menu, 16);
 
134
  ctk_menu_expandable_compute_style_textures (menu);
 
135
  
 
136
  ctk_menu_expandable_set_anchor_position (menu, 0, 100, 40);
 
137
      
 
138
  ctk_menu_expandable_set_expansion_size_factor (menu, 1.0f);
 
139
 
 
140
  g_timeout_add (1000/100, anim_func, (gpointer) menu);
 
141
 
 
142
  clutter_actor_show_all (stage);
 
143
 
 
144
  clutter_main ();
 
145
 
 
146
  return 0;
 
147
}
 
 
b'\\ No newline at end of file'