~mike82/netbook-remix-launcher/fixes

« back to all changes in this revision

Viewing changes to src/launcher-catbar.c

  • Committer: Neil J. Patel
  • Date: 2008-04-16 13:50:57 UTC
  • Revision ID: njpatel@gmail.com-20080416135057-uwf4gyqvdmn9xnpu
* Inital check-in of the category bar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Canonical Ltd
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * Authored by Neil Jagdish Patel <neil.patel@canonical.com>
 
20
 *
 
21
 */
 
22
 
 
23
#include "launcher-catbar.h"
 
24
#include "launcher-defines.h"
 
25
 
 
26
#include "tidy-texture-frame.h"
 
27
 
 
28
G_DEFINE_TYPE (LauncherCatbar, launcher_catbar, CLUTTER_TYPE_GROUP);
 
29
 
 
30
#define LAUNCHER_CATBAR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
 
31
  LAUNCHER_TYPE_CATBAR, \
 
32
  LauncherCatbarPrivate))
 
33
 
 
34
struct _LauncherCatbarPrivate
 
35
{
 
36
  ClutterActor *bg_texture;
 
37
  ClutterActor *bg;
 
38
 
 
39
  ClutterActor *hilight_texture;
 
40
  ClutterActor *hilight;
 
41
};
 
42
 
 
43
enum
 
44
{
 
45
  CAT_SELECTED,
 
46
 
 
47
  LAST_SIGNAL
 
48
};
 
49
static guint _catbar_signals[LAST_SIGNAL] = { 0 };
 
50
 
 
51
 
 
52
/* GObject stuff */
 
53
static void
 
54
launcher_catbar_class_init (LauncherCatbarClass *klass)
 
55
{
 
56
  GObjectClass        *obj_class = G_OBJECT_CLASS (klass);
 
57
 
 
58
        _catbar_signals[CAT_SELECTED] =
 
59
                g_signal_new ("categroy-selected",
 
60
                              G_OBJECT_CLASS_TYPE (obj_class),
 
61
                              G_SIGNAL_RUN_LAST,
 
62
                              G_STRUCT_OFFSET (LauncherCatbarClass, category_selected),
 
63
                              NULL, NULL,
 
64
                              g_cclosure_marshal_VOID__POINTER, 
 
65
                              G_TYPE_NONE,0);
 
66
 
 
67
  g_type_class_add_private (obj_class, sizeof (LauncherCatbarPrivate));
 
68
}
 
69
 
 
70
static void
 
71
_append_category (LauncherCatbar       *bar, 
 
72
                  LauncherMenuCategory *category,
 
73
                  gint                  size,
 
74
                  gint                  offset)
 
75
{
 
76
  GdkPixbuf *icon;
 
77
  ClutterActor *texture;
 
78
  ClutterActor *label;
 
79
  ClutterColor color = { 0xff, 0xff, 0xff, 0xff };
 
80
 
 
81
  icon = launcher_menu_category_get_icon (category);
 
82
  texture = clutter_texture_new_from_pixbuf (icon);
 
83
  clutter_actor_set_size (texture, size -(4*CAT_PADDING), size-(4*CAT_PADDING));
 
84
  clutter_actor_set_anchor_point_from_gravity (texture, CLUTTER_GRAVITY_NORTH);
 
85
  clutter_actor_set_position (texture, 
 
86
                              size/2,
 
87
                              offset + CAT_PADDING);
 
88
  clutter_container_add_actor (CLUTTER_CONTAINER (bar), texture);
 
89
  clutter_actor_show (texture);
 
90
 
 
91
  label = clutter_label_new_full (CAT_FONT, 
 
92
                                  launcher_menu_category_get_name (category),
 
93
                                  &color);
 
94
  clutter_container_add_actor (CLUTTER_CONTAINER (bar), label);
 
95
  clutter_actor_set_anchor_point_from_gravity (label, CLUTTER_GRAVITY_NORTH);
 
96
  clutter_actor_set_position (label, 
 
97
                              size/2,
 
98
                              clutter_actor_get_y (texture) + CAH(texture)
 
99
                                + (CAT_PADDING/2));
 
100
  clutter_actor_show (label);
 
101
}
 
102
      
 
103
static void
 
104
launcher_catbar_init (LauncherCatbar *catbar)
 
105
{
 
106
  LauncherCatbarPrivate *priv;
 
107
  LauncherMenu *menu = launcher_menu_get_default ();
 
108
  GdkPixbuf *temp;
 
109
  gint bar_width = CAT_SIZE();
 
110
  gint bar_height = CAT_SIZE() * N_CATS;
 
111
        GList *l;
 
112
  gint i = 0;
 
113
 
 
114
  priv = catbar->priv = LAUNCHER_CATBAR_GET_PRIVATE (catbar);
 
115
 
 
116
  temp = gdk_pixbuf_new_from_file (PKGDATADIR"/sidebar.png", NULL);
 
117
  priv->bg_texture = clutter_texture_new_from_pixbuf (temp);
 
118
  clutter_actor_realize (priv->bg_texture);
 
119
  g_object_unref (temp);
 
120
 
 
121
  priv->bg = tidy_texture_frame_new (CLUTTER_TEXTURE (priv->bg_texture),
 
122
                                     2, 35, 10,10);
 
123
  clutter_container_add_actor (CLUTTER_CONTAINER (catbar), priv->bg);
 
124
  clutter_actor_set_size (priv->bg, bar_width, bar_height);
 
125
  clutter_actor_set_position (priv->bg, 0,
 
126
                              ((CSH()/2)-(bar_height/2))+PANEL_HEIGHT);
 
127
  clutter_actor_show (priv->bg);
 
128
 
 
129
  for (l = launcher_menu_get_categories (menu); l; l = l->next)
 
130
  {
 
131
    LauncherMenuCategory *cat = l->data;
 
132
 
 
133
    _append_category (catbar, cat, bar_width, 
 
134
                      (bar_width * i)+ clutter_actor_get_y (priv->bg));
 
135
    i++;
 
136
  }
 
137
}
 
138
 
 
139
ClutterActor *
 
140
launcher_catbar_get_default (void)
 
141
 
 
142
{
 
143
  static ClutterActor *catbar = NULL;
 
144
 
 
145
  if (!catbar)
 
146
    catbar = g_object_new (LAUNCHER_TYPE_CATBAR, 
 
147
                       NULL);
 
148
 
 
149
  return catbar;
 
150
}