Back to index

unity  6.0.0
StandaloneSwitcher.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Canonical Ltd.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License version 3, as published
00006  * by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * version 3 along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>
00016  *
00017  * Authored by: Jason Smith <jason.smith@canonical.com>
00018  *
00019  */
00020 
00021 #include "Nux/Nux.h"
00022 #include "Nux/Button.h"
00023 #include "Nux/VLayout.h"
00024 #include "Nux/HLayout.h"
00025 #include "Nux/WindowThread.h"
00026 #include "Nux/CheckBox.h"
00027 #include "Nux/SpinBox.h"
00028 #include "Nux/EditTextBox.h"
00029 #include "Nux/StaticText.h"
00030 #include "Nux/RangeValueInteger.h"
00031 #include "NuxGraphics/GraphicsEngine.h"
00032 #include <gtk/gtk.h>
00033 
00034 #include "SwitcherController.h"
00035 #include "MockLauncherIcon.h"
00036 #include "unity-shared/BackgroundEffectHelper.h"
00037 #include <dbus/dbus-glib.h>
00038 
00039 using namespace unity::switcher;
00040 using namespace unity::ui;
00041 using unity::launcher::AbstractLauncherIcon;
00042 using unity::launcher::MockLauncherIcon;
00043 
00044 static bool enable_flipping = false;
00045 
00046 static Controller *view;
00047 
00048 static gboolean on_timeout(gpointer data)
00049 {
00050   if (!enable_flipping)
00051     return TRUE;
00052 
00053   Controller* self = static_cast<Controller*>(data);
00054   self->Next();
00055 
00056   return TRUE;
00057 }
00058 
00059 void OnFlippingChanged (bool value)
00060 {
00061   enable_flipping = value;
00062 }
00063 
00064 void OnBorderSizeChanged (nux::RangeValueInteger *self)
00065 {
00066   view->GetView ()->border_size = self->GetValue ();
00067   view->GetView ()->QueueDraw ();
00068 }
00069 
00070 void OnFlatSpacingSizeChanged (nux::RangeValueInteger *self)
00071 {
00072   view->GetView ()->flat_spacing = self->GetValue ();
00073   view->GetView ()->QueueDraw ();
00074 }
00075 
00076 void OnTextSizeChanged (nux::RangeValueInteger *self)
00077 {
00078   view->GetView ()->text_size = self->GetValue ();
00079   view->GetView ()->QueueDraw ();
00080 }
00081 
00082 void OnIconSizeChanged (nux::RangeValueInteger *self)
00083 {
00084   view->GetView ()->icon_size = self->GetValue ();
00085   view->GetView ()->QueueDraw ();
00086 }
00087 
00088 void OnTileSizeChanged (nux::RangeValueInteger *self)
00089 {
00090   view->GetView ()->tile_size = self->GetValue ();
00091   view->GetView ()->QueueDraw ();
00092 }
00093 
00094 void OnAnimationLengthChanged (nux::RangeValueInteger *self)
00095 {
00096   view->GetView ()->animation_length = self->GetValue ();
00097   view->GetView ()->QueueDraw ();
00098 }
00099 
00100 void OnNumIconsChanged (nux::SpinBox *self)
00101 {
00102   view->Hide();
00103 
00104   std::vector<nux::ObjectPtr<AbstractLauncherIcon>> icons;
00105   for (int i = 0; i < self->GetValue (); i++)
00106     icons.push_back(nux::ObjectPtr<AbstractLauncherIcon>(new MockLauncherIcon()));
00107 
00108   view->Show(ShowMode::ALL, SortMode::FOCUS_ORDER, false, icons);
00109 }
00110 
00111 void OnNextClicked (nux::View *sender)
00112 {
00113   view->Next ();
00114 }
00115 
00116 void OnDetailClicked (nux::View *sender)
00117 {
00118   view->NextDetail ();
00119 }
00120 
00121 void OnPreviousClicked (nux::View *sender)
00122 {
00123   view->Prev();
00124 }
00125 
00126 void ThreadWidgetInit(nux::NThread* thread, void* InitData)
00127 {
00128   nux::VLayout* layout = new nux::VLayout(TEXT(""), NUX_TRACKER_LOCATION);
00129 
00130   view = new Controller();
00131   view->timeout_length = 0;
00132   view->SetWorkspace(nux::Geometry(0, 0, 900, 600), 0);
00133 
00134   layout->SetContentDistribution(nux::eStackCenter);
00135   layout->SetHorizontalExternalMargin (10);
00136   nux::GetWindowThread()->SetLayout(layout);
00137 
00138   std::vector<nux::ObjectPtr<AbstractLauncherIcon>> icons;
00139   for (int i = 0; i < 9; i++)
00140     icons.push_back(nux::ObjectPtr<AbstractLauncherIcon>(new MockLauncherIcon()));
00141 
00142   view->Show(ShowMode::ALL, SortMode::FOCUS_ORDER, false, icons);
00143 
00144   view->GetView ()->render_boxes = true;
00145 
00146   nux::CheckBox* flipping_check = new nux::CheckBox(TEXT("Enable Automatic Flipping"), false, NUX_TRACKER_LOCATION);
00147   flipping_check->SetMaximumWidth(250);
00148   flipping_check->state_change.connect (sigc::ptr_fun (OnFlippingChanged));
00149   layout->AddView(flipping_check, 1, nux::eRight, nux::eFull);
00150 
00151 
00152   nux::HLayout* num_icons_layout = new nux::HLayout("", NUX_TRACKER_LOCATION);
00153   num_icons_layout->SetMaximumWidth(250);
00154   num_icons_layout->SetMaximumHeight(30);
00155   num_icons_layout->SetHorizontalInternalMargin (10);
00156 
00157   nux::StaticText* num_icons_label = new nux::StaticText(TEXT("Num Icons:"), NUX_TRACKER_LOCATION);
00158   num_icons_layout->AddView(num_icons_label, 1, nux::eLeft, nux::eFull);
00159 
00160   nux::SpinBox * num_icons_spin = new nux::SpinBox (icons.size (), 1, 2, 100, NUX_TRACKER_LOCATION);
00161   num_icons_spin->sigValueChanged.connect (sigc::ptr_fun (OnNumIconsChanged));
00162   num_icons_layout->AddView(num_icons_spin, 1, nux::eRight, nux::eFix);
00163 
00164   layout->AddView(num_icons_layout, 1, nux::eRight, nux::eFull);
00165 
00166 
00167 
00168   nux::HLayout* border_layout = new nux::HLayout("", NUX_TRACKER_LOCATION);
00169   border_layout->SetMaximumWidth(250);
00170   border_layout->SetMaximumHeight(30);
00171   border_layout->SetHorizontalInternalMargin (10);
00172 
00173   nux::StaticText* border_label = new nux::StaticText(TEXT("Border Size:"), NUX_TRACKER_LOCATION);
00174   border_layout->AddView(border_label, 1, nux::eLeft, nux::eFull);
00175 
00176   nux::RangeValueInteger * border_size_range = new nux::RangeValueInteger (view->GetView ()->border_size, 0, 200, NUX_TRACKER_LOCATION);
00177   border_size_range->sigValueChanged.connect (sigc::ptr_fun (OnBorderSizeChanged));
00178   border_layout->AddView(border_size_range, 1, nux::eRight, nux::eFix);
00179 
00180   layout->AddView(border_layout, 1, nux::eRight, nux::eFull);
00181 
00182 
00183 
00184   nux::HLayout* flat_spacing_layout = new nux::HLayout("", NUX_TRACKER_LOCATION);
00185   flat_spacing_layout->SetMaximumWidth(250);
00186   flat_spacing_layout->SetMaximumHeight(30);
00187   flat_spacing_layout->SetHorizontalInternalMargin (10);
00188 
00189   nux::StaticText* flat_spacing_label = new nux::StaticText(TEXT("Flat Spacing:"), NUX_TRACKER_LOCATION);
00190   flat_spacing_layout->AddView(flat_spacing_label, 1, nux::eLeft, nux::eFull);
00191 
00192   nux::RangeValueInteger * flat_spacing_size_range = new nux::RangeValueInteger (view->GetView ()->flat_spacing, 0, 200, NUX_TRACKER_LOCATION);
00193   flat_spacing_size_range->sigValueChanged.connect (sigc::ptr_fun (OnFlatSpacingSizeChanged));
00194   flat_spacing_layout->AddView(flat_spacing_size_range, 1, nux::eRight, nux::eFix);
00195 
00196   layout->AddView(flat_spacing_layout, 1, nux::eRight, nux::eFull);
00197   
00198 
00199   nux::HLayout* text_size_layout = new nux::HLayout("", NUX_TRACKER_LOCATION);
00200   text_size_layout->SetMaximumWidth(250);
00201   text_size_layout->SetMaximumHeight(30);
00202   text_size_layout->SetHorizontalInternalMargin (10);
00203 
00204   nux::StaticText* text_size_label = new nux::StaticText(TEXT("Text Size:"), NUX_TRACKER_LOCATION);
00205   text_size_layout->AddView(text_size_label, 1, nux::eLeft, nux::eFull);
00206 
00207   nux::RangeValueInteger * text_size_size_range = new nux::RangeValueInteger (view->GetView ()->text_size, 0, 200, NUX_TRACKER_LOCATION);
00208   text_size_size_range->sigValueChanged.connect (sigc::ptr_fun (OnTextSizeChanged));
00209   text_size_layout->AddView(text_size_size_range, 1, nux::eRight, nux::eFix);
00210 
00211   layout->AddView(text_size_layout, 1, nux::eRight, nux::eFull);
00212 
00213 
00214   nux::HLayout* icon_size_layout = new nux::HLayout("", NUX_TRACKER_LOCATION);
00215   icon_size_layout->SetMaximumWidth(250);
00216   icon_size_layout->SetMaximumHeight(30);
00217   icon_size_layout->SetHorizontalInternalMargin (10);
00218 
00219   nux::StaticText* icon_size_label = new nux::StaticText(TEXT("Icon Size:"), NUX_TRACKER_LOCATION);
00220   icon_size_layout->AddView(icon_size_label, 1, nux::eLeft, nux::eFull);
00221 
00222   nux::RangeValueInteger * icon_size_size_range = new nux::RangeValueInteger (view->GetView ()->icon_size, 0, 200, NUX_TRACKER_LOCATION);
00223   icon_size_size_range->sigValueChanged.connect (sigc::ptr_fun (OnIconSizeChanged));
00224   icon_size_layout->AddView(icon_size_size_range, 1, nux::eRight, nux::eFix);
00225 
00226   layout->AddView(icon_size_layout, 1, nux::eRight, nux::eFull);
00227 
00228 
00229   nux::HLayout* tile_size_layout = new nux::HLayout("", NUX_TRACKER_LOCATION);
00230   tile_size_layout->SetMaximumWidth(250);
00231   tile_size_layout->SetMaximumHeight(30);
00232   tile_size_layout->SetHorizontalInternalMargin (10);
00233 
00234   nux::StaticText* tile_size_label = new nux::StaticText(TEXT("Tile Size:"), NUX_TRACKER_LOCATION);
00235   tile_size_layout->AddView(tile_size_label, 1, nux::eLeft, nux::eFull);
00236 
00237   nux::RangeValueInteger * tile_size_size_range = new nux::RangeValueInteger (view->GetView ()->tile_size, 0, 200, NUX_TRACKER_LOCATION);
00238   tile_size_size_range->sigValueChanged.connect (sigc::ptr_fun (OnTileSizeChanged));
00239   tile_size_layout->AddView(tile_size_size_range, 1, nux::eRight, nux::eFix);
00240 
00241   layout->AddView(tile_size_layout, 1, nux::eRight, nux::eFull);
00242 
00243 
00244   nux::HLayout* animation_length_layout = new nux::HLayout("", NUX_TRACKER_LOCATION);
00245   animation_length_layout->SetMaximumWidth(250);
00246   animation_length_layout->SetMaximumHeight(30);
00247   animation_length_layout->SetHorizontalInternalMargin (10);
00248 
00249   nux::StaticText* animation_length_label = new nux::StaticText(TEXT("Animation Length:"), NUX_TRACKER_LOCATION);
00250   animation_length_layout->AddView(animation_length_label, 1, nux::eLeft, nux::eFull);
00251 
00252   nux::RangeValueInteger * animation_length_size_range = new nux::RangeValueInteger (view->GetView ()->animation_length, 0, 2000, NUX_TRACKER_LOCATION);
00253   animation_length_size_range->sigValueChanged.connect (sigc::ptr_fun (OnAnimationLengthChanged));
00254   animation_length_layout->AddView(animation_length_size_range, 1, nux::eRight, nux::eFix);
00255 
00256   layout->AddView(animation_length_layout, 1, nux::eRight, nux::eFull);
00257 
00258 
00259   nux::HLayout* control_buttons_layout = new nux::HLayout("", NUX_TRACKER_LOCATION);
00260   control_buttons_layout->SetMaximumWidth(250);
00261   control_buttons_layout->SetMaximumHeight(30);
00262   control_buttons_layout->SetHorizontalInternalMargin (10);
00263 
00264   nux::Button* prev_button = new nux::Button ("Previous", NUX_TRACKER_LOCATION);
00265   prev_button->state_change.connect (sigc::ptr_fun (OnPreviousClicked));
00266   control_buttons_layout->AddView(prev_button, 1, nux::eLeft, nux::eFull);
00267 
00268   nux::Button* next_button = new nux::Button ("Next", NUX_TRACKER_LOCATION);
00269   next_button->state_change.connect (sigc::ptr_fun (OnNextClicked));
00270   control_buttons_layout->AddView(next_button, 1, nux::eRight, nux::eFull);
00271 
00272   nux::Button* detail_button = new nux::Button ("Detail", NUX_TRACKER_LOCATION);
00273   detail_button->state_change.connect (sigc::ptr_fun (OnDetailClicked));
00274   control_buttons_layout->AddView(detail_button, 1, nux::eRight, nux::eFull);
00275 
00276   layout->AddView(control_buttons_layout, 1, nux::eRight, nux::eFull);
00277 
00278 
00279   layout->SetContentDistribution(nux::eStackCenter);
00280 
00281   nux::BaseTexture *background = nux::CreateTexture2DFromFile("/usr/share/backgrounds/Grey_day_by_Drew__.jpg", -1, true);
00282   nux::GetGraphicsDisplay()->GetGpuDevice()->backup_texture0_ = background->GetDeviceTexture();
00283 
00284 
00285   g_timeout_add(1500, on_timeout, view);
00286 }
00287 
00288 int main(int argc, char** argv)
00289 {
00290   g_type_init();
00291   
00292   gtk_init(&argc, &argv);
00293 
00294   nux::NuxInitialize(0);
00295 
00296   BackgroundEffectHelper::blur_type = unity::BLUR_ACTIVE;
00297   nux::WindowThread* wt = nux::CreateGUIThread(TEXT("Unity Switcher"), 1200, 600, 0, &ThreadWidgetInit, 0);
00298 
00299   wt->Run(NULL);
00300   delete wt;
00301   return 0;
00302 }