diff options
| author | Jay Taoko <jay.taoko@canonical.com> | 2010-01-15 12:39:26 -0500 |
|---|---|---|
| committer | Jay Taoko <jay.taoko@canonical.com> | 2010-01-15 12:39:26 -0500 |
| commit | 1edbb6b9cfd24b3ad34281424d26df84aefdb48b (patch) | |
| tree | dbd3e7877a482b1849894a6c32d574c2f522e185 /src | |
| parent | eafaf2e47ff181d7e97d63c6593e516d64fc1725 (diff) | |
| parent | 0ebeea044ffb573f68189a221fc83a773eebb857 (diff) | |
Improved Places bar code. Added code for the trash and devices icons.
Render Trash at the right location. [modified] src/places/bar-view.vala src/places/view.vala vapi/clutk-0.3.vapi (bzr r61)
Diffstat (limited to 'src')
| -rw-r--r-- | src/places/bar-view.vala | 304 | ||||
| -rw-r--r-- | src/places/view.vala | 139 |
2 files changed, 355 insertions, 88 deletions
diff --git a/src/places/bar-view.vala b/src/places/bar-view.vala index c81610436..e757d7436 100644 --- a/src/places/bar-view.vala +++ b/src/places/bar-view.vala @@ -31,91 +31,264 @@ namespace Unity.Places.Bar const string VIDEOS_FILE = Unity.PKGDATADIR + "/videos.png"; const string WEB_FILE = Unity.PKGDATADIR + "/web.png"; + + public class PlacesVSeparator : Ctk.Bin + { + public int Width = 0; + public int Height = 0; + + public Clutter.CairoTexture cairotxt; + public PlacesVSeparator () + { + } + + public void CreateSeparator (int W, int H) + { + Width = W; + Height = H; + + if (cairotxt != null) + this.remove_actor (cairotxt); + + cairotxt = new Clutter.CairoTexture(Width, Height); + Cairo.Context cairoctx = cairotxt.create(); + { + cairoctx.set_source_rgba (1, 1, 1, 1.0); + cairoctx.set_line_width (1.0); + + cairoctx.move_to (Width/2.0, 0); + cairoctx.line_to (Width/2.0, Height); + + cairoctx.stroke (); + cairoctx.set_source_rgba (1, 1, 1, 0.15); + } + + cairotxt.set_opacity (0xFF); + this.add_actor (cairotxt); + + Ctk.EffectGlow effect_glow = new Ctk.EffectGlow (); + Clutter.Color c = Clutter.Color () + { + red = 255, + green = 255, + blue = 255, + alpha = 255 + }; + + effect_glow.set_color (c); + effect_glow.set_factor (1.0f); + effect_glow.set_margin (5); + this.add_effect (effect_glow); + } + + construct + { + } + } + + + public class PlaceIcon + { + private Unity.Places.Bar.Model model; + public Ctk.Image view; + + public PlaceIcon (int width, /*int height,*/ string name, string icon_name, string tooltip) + { + model = new Unity.Places.Bar.Model (name, icon_name, tooltip); + view = new Ctk.Image.from_filename (width, icon_name); + view.set_reactive (true); + } + } + public class View : Ctk.Box { - private Gee.ArrayList<Unity.Places.Bar.Model> places; - private Gee.ArrayList<Ctk.Image> icon_view; + public int IconSize = 0; + public int FirstPlaceIconPosition = 0; + public int PlaceIconSpacing = 0; + public int SeparatorPosition = 0; + + public int FirstDevicePosition = 0; + public int DeviceIconSpacing = 0; + + public int TrashPosition = 0; + + private Gee.ArrayList<PlaceIcon> PlacesIconArray; + private Gee.ArrayList<PlaceIcon> DevicesIconArray; + private PlaceIcon TrashIcon; + + private PlacesVSeparator Separator; + + public signal void sig_places_active_icon_index (int i); + public signal void sig_devices_active_icon_index (int i); + public signal void sig_trash_active_icon_index (); + + public override void allocate (Clutter.ActorBox box, + Clutter.AllocationFlags flags) + { + Clutter.ActorBox base_box = {0, 0, 0, 0}; + base_box.x1 = box.x1; + base_box.x2 = box.x2; + base_box.y1 = box.y1; + base_box.y2 = box.y2; + base.allocate (base_box, flags); + + int i; + + base_box.x1 = FirstPlaceIconPosition; + for (i = 0; i < this.PlacesIconArray.size; i++) + { + base_box.x2 = base_box.x1 + IconSize; + base_box.y1 = 0; + base_box.y2 = IconSize; + + this.PlacesIconArray[i].view.allocate (base_box, flags); + + base_box.x1 += IconSize + PlaceIconSpacing; + } + + base_box.x1 = FirstDevicePosition; + for (i = 0; i < this.DevicesIconArray.size; i++) + { + base_box.x2 = base_box.x1 + IconSize; + base_box.y1 = 0; + base_box.y2 = IconSize; + + this.DevicesIconArray[i].view.allocate (base_box, flags); + + base_box.x1 += IconSize + PlaceIconSpacing; + } + + base_box.x1 = TrashPosition; + base_box.x2 = base_box.x1 + IconSize; + base_box.y1 = 0; + base_box.y2 = IconSize; - public signal void sig_active_icon_index (int i); + this.TrashIcon.view.allocate (base_box, flags); + + if (this.Separator.Height != 48) + { + this.Separator.CreateSeparator (5, 48); + } + + base_box.x1 = SeparatorPosition; + base_box.x2 = SeparatorPosition+5; + base_box.y1 = 4; + base_box.y2 = 44; + this.Separator.allocate (base_box, flags); + } public View () { - Unity.Places.Bar.Model place; + PlaceIcon place; int i; - Ctk.Image icon; int icon_size = 48; Ctk.EffectGlow glow; Clutter.Color white = {255, 255, 255, 255}; this.homogeneous = false; - this.spacing = icon_size/2; this.orientation = Ctk.Orientation.HORIZONTAL; // this sucks - this.places = new Gee.ArrayList<Unity.Places.Bar.Model> (); - this.icon_view = new Gee.ArrayList<Ctk.Image> (); + this.PlacesIconArray = new Gee.ArrayList<PlaceIcon> (); + this.DevicesIconArray = new Gee.ArrayList<PlaceIcon> (); // populate places-bar with hard-coded contents for the moment - place = new Unity.Places.Bar.Model ("Home", - HOME_FILE, - "Default View"); - this.places.add (place); - - place = new Unity.Places.Bar.Model ("Applications", - APPS_FILE, - "Programs installed locally"); - this.places.add (place); - - place = new Unity.Places.Bar.Model ("Files", - FILES_FILE, - "Your files stored locally"); - this.places.add (place); - - place = new Unity.Places.Bar.Model ("Music", - MUSIC_FILE, - "Soothing sounds and vibes"); - this.places.add (place); - - place = new Unity.Places.Bar.Model ("People", - PEOPLE_FILE, - "Friends, pals, mates and folks"); - this.places.add (place); - - place = new Unity.Places.Bar.Model ("Photos", - PHOTOS_FILE, - "Pretty pictures presented by pixels"); - this.places.add (place); - - place = new Unity.Places.Bar.Model ("Trash", - TRASH_FILE, - "Your piece of waste"); - this.places.add (place); + place = new PlaceIcon (icon_size, "Home", + HOME_FILE, + "Default View"); + this.PlacesIconArray.add (place); + + place = new PlaceIcon (icon_size, "Files", + FILES_FILE, + "Your files stored locally"); + this.PlacesIconArray.add (place); + + place = new PlaceIcon (icon_size, "Applications", + APPS_FILE, + "Programs installed locally"); + this.PlacesIconArray.add (place); + + place = new PlaceIcon (icon_size, "Music", + MUSIC_FILE, + "Soothing sounds and vibes"); + this.PlacesIconArray.add (place); + + place = new PlaceIcon (icon_size, "People", + PEOPLE_FILE, + "Friends, pals, mates and folks"); + this.PlacesIconArray.add (place); + + place = new PlaceIcon (icon_size, "Photos", + PHOTOS_FILE, + "Pretty pictures presented by pixels"); + this.PlacesIconArray.add (place); + + /*place = new PlaceIcon (icon_size, "Trash", + TRASH_FILE, + "Your piece of waste"); + this.PlacesIconArray.add (place);*/ /* create all image-actors for icons */ - for (i = 0; i < this.places.size ; i++) + for (i = 0; i < this.PlacesIconArray.size ; i++) + { + glow = new Ctk.EffectGlow (); + glow.set_color (white); + glow.set_factor (1.0f); + glow.set_margin (6); + this.PlacesIconArray[i].view.add_effect (glow); + + this.pack (this.PlacesIconArray[i].view, false, false); + this.PlacesIconArray[i].view.enter_event.connect (this.on_enter); + this.PlacesIconArray[i].view.leave_event.connect (this.on_leave); + this.PlacesIconArray[i].view.button_press_event.connect (this.on_button_press); + } + + for (i = 0; i < this.DevicesIconArray.size ; i++) { - icon = new Ctk.Image.from_filename (icon_size, this.places[i].icon_name); - icon.set_reactive (true); + glow = new Ctk.EffectGlow (); + glow.set_color (white); + glow.set_factor (1.0f); + glow.set_margin (6); + this.DevicesIconArray[i].view.add_effect (glow); + + this.pack (this.DevicesIconArray[i].view, false, false); + this.DevicesIconArray[i].view.enter_event.connect (this.on_enter); + this.DevicesIconArray[i].view.leave_event.connect (this.on_leave); + this.DevicesIconArray[i].view.button_press_event.connect (this.on_button_press); + } + { + TrashIcon = new PlaceIcon (icon_size, "Trash", + TRASH_FILE, + "Your piece of waste"); glow = new Ctk.EffectGlow (); glow.set_color (white); glow.set_factor (1.0f); - icon.add_effect (glow); + glow.set_margin (6); + this.TrashIcon.view.add_effect (glow); - this.icon_view.add (icon); - this.pack (icon, false, false); - icon.enter_event.connect (this.on_enter); - icon.leave_event.connect (this.on_leave); - icon.button_press_event.connect (this.on_button_press); + this.pack (this.TrashIcon.view, false, false); + this.TrashIcon.view.enter_event.connect (this.on_enter); + this.TrashIcon.view.leave_event.connect (this.on_leave); + this.TrashIcon.view.button_press_event.connect (this.on_button_press); } + Separator = new PlacesVSeparator (); + this.pack (this.Separator, false, false); + this.show_all (); } - public int get_number_of_items () + public int get_number_of_places () + { + return this.PlacesIconArray.size; + } + + public int get_number_of_devices () { - return this.places.size; + return this.DevicesIconArray.size; } + public bool on_enter () { /* stdout.printf ("on_enter() called\n"); */ @@ -134,11 +307,26 @@ namespace Unity.Places.Bar Clutter.Actor actor; actor = event.button.source; - for (i = 0; i < this.icon_view.size ; i++) - { - if (actor == this.icon_view[i]) - sig_active_icon_index(i); - } + for (i = 0; i < this.PlacesIconArray.size; i++) + { + if (actor == this.PlacesIconArray[i].view) + { + sig_places_active_icon_index (i); + return false; + } + } + + for (i = 0; i < this.DevicesIconArray.size; i++) + { + if (actor == this.DevicesIconArray[i].view) + { + sig_devices_active_icon_index (i); + return false; + } + } + + if (actor == this.TrashIcon.view) + sig_trash_active_icon_index (); return false; } diff --git a/src/places/view.vala b/src/places/view.vala index 782adf8b2..6941259af 100644 --- a/src/places/view.vala +++ b/src/places/view.vala @@ -19,6 +19,11 @@ namespace Unity.Places { + /* Margin outside of the cairo texture. We draw outside to complete the line loop + * and we don't want the line loop to be visible in some parts of the screen. + * */ + private int Margin = 5; + public class PlacesBackground : Ctk.Bin { public Clutter.CairoTexture cairotxt; @@ -35,11 +40,6 @@ namespace Unity.Places private int PlaceBottom; /* PlaceY + PlaceH */ - /* Margin outside of the cairo texture. We draw outside to complete the line loop - * and we don't want the line loop to be visible in some parts of the screen. - * */ - private int Margin = 20; - /* Menu area width and height */ private int MenuH = 22; private int MenuW = 216; @@ -136,7 +136,7 @@ namespace Unity.Places if (cairotxt != null) this.remove_actor (cairotxt); - cairotxt = new Clutter.CairoTexture(PlaceW, PlaceH); + cairotxt = new Clutter.CairoTexture(PlaceW, PlaceH + Margin); Cairo.Context cairoctx = cairotxt.create(); { cairoctx.set_source_rgba (1, 1, 1, 1.0); @@ -179,6 +179,7 @@ namespace Unity.Places effect_glow.set_color (c); effect_glow.set_factor (1.0f); + effect_glow.set_margin (5); this.add_effect (effect_glow); } @@ -191,7 +192,10 @@ namespace Unity.Places { private Unity.Places.Bar.View bar_view; private Unity.Places.Default.View default_view; - private Gee.ArrayList<PlacesBackground> background_array; + private Gee.ArrayList<PlacesBackground> PlacesBackgroundArray; + private Gee.ArrayList<PlacesBackground> DevicesBackgroundArray; + PlacesBackground TrashBackground; + private int current_tab_index; /* These parameters are temporary until we get the right metrics for the places bar */ @@ -203,16 +207,25 @@ namespace Unity.Places Clutter.ActorBox child_box = { 0.0f, 0.0f, 0.0f, 0.0f }; int bar_icon_size = 48; /* HARDCODED: height of icons in places bar */ int icon_margin = 4; - int offset = 94; /* offset to first icon */ + int PlacesPosition = 0; /* HARDCODED: Places X origin. Should be 0 in practice. */ int NewPlaceWidth = (int) (box.x2 - box.x1); - child_box.x1 = offset; //this.padding.left; - child_box.x2 = box.x2 - box.x1 - this.padding.left - this.padding.right; + this.bar_view.IconSize = bar_icon_size; + this.bar_view.FirstPlaceIconPosition = 100; /* HARDCODED: Offset from the left of the Places bar to the first Icon */ + this.bar_view.PlaceIconSpacing = 24; + + child_box.x1 = PlacesPosition; + child_box.x2 = box.x2 - box.x1; child_box.y1 = this.padding.top + 8; child_box.y2 = child_box.y1 + bar_icon_size; + + this.bar_view.TrashPosition = (int)(box.x2 - 216 - bar_icon_size - 80); /* HARDCODED: Menu width in the places bar */ + this.bar_view.SeparatorPosition = (int)(this.bar_view.TrashPosition - 20); /* HARDCODED: Menu width in the places bar */ + this.bar_view.allocate (child_box, flags); + child_box.x1 = box.x1 + 58 /* HARDCODED: width of quicklauncher */; child_box.x2 = box.x2; child_box.y1 = box.y1 + 55 /* HARDCODED: height of Places bar */; @@ -223,46 +236,72 @@ namespace Unity.Places child_box.x1 = 0; child_box.x2 = NewPlaceWidth; child_box.y1 = 0; - child_box.y2 = 55; + child_box.y2 = 55 + Margin; /* HARDCODED: height of Places bar */; - int spacing = this.bar_view.spacing; + int spacing = this.bar_view.PlaceIconSpacing; int i; - for (i = 0; i < this.background_array.size; i++) + for (i = 0; i < this.PlacesBackgroundArray.size; i++) { - if (this.background_array[i].PlaceWidth != NewPlaceWidth) + if (this.PlacesBackgroundArray[i].PlaceWidth != NewPlaceWidth) { - this.background_array[i].CreatePlacesBackground (NewPlaceWidth, 55, - offset + i*(bar_icon_size + spacing) - icon_margin, + this.PlacesBackgroundArray[i].CreatePlacesBackground (NewPlaceWidth, 55, + PlacesPosition + this.bar_view.FirstPlaceIconPosition + i*(bar_icon_size + spacing) - icon_margin, 2*icon_margin + bar_icon_size); } - this.background_array[i].allocate (child_box, flags); + this.PlacesBackgroundArray[i].allocate (child_box, flags); + } + + if (this.TrashBackground.PlaceWidth != NewPlaceWidth) + { + this.TrashBackground.CreatePlacesBackground (NewPlaceWidth, 55, + PlacesPosition + this.bar_view.TrashPosition - icon_margin, + 2*icon_margin + bar_icon_size); } + this.TrashBackground.allocate (child_box, flags); + } public View () { int i; int NunItems; - PlacesBackground placesbackground; + PlacesBackground background; - this.background_array = new Gee.ArrayList<PlacesBackground> (); + this.PlacesBackgroundArray = new Gee.ArrayList<PlacesBackground> (); + this.DevicesBackgroundArray = new Gee.ArrayList<PlacesBackground> (); this.current_tab_index = 0; this.orientation = Ctk.Orientation.VERTICAL; this.bar_view = new Unity.Places.Bar.View (); - this.bar_view.sig_active_icon_index.connect(this.on_signal_active_icon); - + this.bar_view.sig_places_active_icon_index.connect(this.on_signal_active_icon); + this.bar_view.sig_devices_active_icon_index.connect(this.on_signal_device_active_icon); + this.bar_view.sig_trash_active_icon_index.connect(this.on_signal_trash_active_icon); + this.default_view = new Unity.Places.Default.View (); - NunItems = this.bar_view.get_number_of_items (); + NunItems = this.bar_view.get_number_of_places (); + for (i = 0; i < NunItems; i++) + { + background = new PlacesBackground (); + this.add_actor (background); + this.PlacesBackgroundArray.add (background); + background.hide (); + } + this.PlacesBackgroundArray[0].show (); + + NunItems = this.bar_view.get_number_of_devices (); for (i = 0; i < NunItems; i++) { - placesbackground = new PlacesBackground (); - this.add_actor (placesbackground); - this.background_array.add (placesbackground); - placesbackground.hide (); + background = new PlacesBackground (); + this.add_actor (background); + this.DevicesBackgroundArray.add (background); + background.hide (); } - this.background_array[0].show (); + + TrashBackground = new PlacesBackground (); + this.add_actor (TrashBackground); + TrashBackground.hide (); + this.add_actor (this.bar_view); this.add_actor (this.default_view); @@ -297,13 +336,53 @@ namespace Unity.Places public void on_signal_active_icon (int i) { - if (i >= this.background_array.size) + if (i >= this.PlacesBackgroundArray.size) + return; + + int j; + for (j = 0; j < this.DevicesBackgroundArray.size; j++) + { + this.DevicesBackgroundArray[j].hide (); + } + TrashBackground.hide (); + + this.PlacesBackgroundArray[this.current_tab_index].hide (); + this.current_tab_index = i; + this.PlacesBackgroundArray[this.current_tab_index].show (); + } + + public void on_signal_device_active_icon (int i) + { + if (i >= this.DevicesBackgroundArray.size) return; - this.background_array[this.current_tab_index].hide (); + int j; + for (j = 0; j < this.PlacesBackgroundArray.size; j++) + { + this.PlacesBackgroundArray[j].hide (); + } + TrashBackground.hide (); + + this.DevicesBackgroundArray[this.current_tab_index].hide (); this.current_tab_index = i; - this.background_array[this.current_tab_index].show (); + this.DevicesBackgroundArray[this.current_tab_index].show (); + } + + public void on_signal_trash_active_icon () + { + int j; + for (j = 0; j < this.PlacesBackgroundArray.size; j++) + { + this.PlacesBackgroundArray[j].hide (); + } + for (j = 0; j < this.DevicesBackgroundArray.size; j++) + { + this.DevicesBackgroundArray[j].hide (); + } + + TrashBackground.show (); } + } } |
