nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic Inc. 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: Neil Jagdish Patel <neil.patel@canonical.com> 00018 * 00019 */ 00020 00021 #include "Nux/Nux.h" 00022 #include "Nux/WindowThread.h" 00023 #include "NuxGraphics/GraphicsEngine.h" 00024 00025 #include "Nux/TextureArea.h" 00026 #include "Nux/HLayout.h" 00027 #include "Nux/VLayout.h" 00028 #include "Nux/LayeredLayout.h" 00029 #include "Nux/ToggleButton.h" 00030 #include "Nux/ComboBoxSimple.h" 00031 00032 class Foo 00033 { 00034 public: 00035 Foo () 00036 { 00037 nux::VLayout *main_layout((new nux::VLayout(NUX_TRACKER_LOCATION))); 00038 nux::ComboBoxSimple *combo = new nux::ComboBoxSimple (NUX_TRACKER_LOCATION); 00039 00040 combo->SetMinimumWidth (150); 00041 combo->sigTriggered.connect (sigc::mem_fun (this, &Foo::OnComboChangedFoRealz)); 00042 main_layout->AddView (combo, 0, nux::eCenter, nux::eFix); 00043 00044 layered_layout = new nux::LayeredLayout (NUX_TRACKER_LOCATION); 00045 for (int i = 0; i < 10; i++) 00046 { 00047 gchar *text = g_strdup_printf ("Button %d", i); 00048 nux::LayeredLayout *layered = new nux::LayeredLayout (NUX_TRACKER_LOCATION); 00049 00050 nux::ColorLayer color (nux::color::RandomColor ()); 00051 nux::TextureArea* texture_area = new nux::TextureArea (); 00052 texture_area->SetPaintLayer (&color); 00053 layered->AddLayer (texture_area); 00054 00055 nux::HLayout *hori = new nux::HLayout (NUX_TRACKER_LOCATION); 00056 nux::Button* button = new nux::Button ("Big Button", NUX_TRACKER_LOCATION); 00057 button->SetMinMaxSize (200, 100); 00058 hori->AddView (button, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); 00059 hori->SetContentDistribution (nux::MAJOR_POSITION_CENTER); 00060 layered->AddLayer (hori); 00061 00062 hori = new nux::HLayout (NUX_TRACKER_LOCATION); 00063 button = new nux::ToggleButton (text, NUX_TRACKER_LOCATION); 00064 button->SetMinMaxSize (100, 50); 00065 hori->AddView (button, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); 00066 hori->SetContentDistribution (nux::MAJOR_POSITION_CENTER); 00067 layered->AddLayout (hori); 00068 00069 button = new nux::ToggleButton ("This button is insensitive", NUX_TRACKER_LOCATION); 00070 button->SetSensitive (false); 00071 layered->AddLayer (button, false, 10, 10, 180, 40); 00072 00073 button = new nux::ToggleButton ("This button has x, y, w, h set", NUX_TRACKER_LOCATION); 00074 layered->AddLayer (button, false, 400, 10, 180, 40); 00075 00076 nux::ROPConfig rop; 00077 rop.Blend = true; 00078 rop.SrcBlend = GL_ONE; 00079 rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; 00080 nux::Color col (0x55005500); 00081 nux::ColorLayer c (col, true, rop); 00082 texture_area = new nux::TextureArea (); 00083 texture_area->SetPaintLayer (&c); 00084 layered->AddLayer (texture_area, false, 0, 100, 600, 200); 00085 00086 button = new nux::ToggleButton ("YOU CANT SEE ME!!!!!", NUX_TRACKER_LOCATION); 00087 layered->AddLayer (button, true); 00088 button->SetVisible (false); 00089 00090 layered->SetPaintAll (true); 00091 layered->SetInputMode (nux::LayeredLayout::INPUT_MODE_COMPOSITE); 00092 00093 layered->Raise (hori, texture_area); 00094 00095 button = new nux::ToggleButton ("YOU CANT SEE ME!!!!!", NUX_TRACKER_LOCATION); 00096 layered->AddLayer (button, true); 00097 layered->RemoveLayer (button); 00098 00099 layered_layout->AddLayout (layered); 00100 combo->AddItem (text); 00101 00102 g_free (text); 00103 } 00104 00105 main_layout->AddLayout (layered_layout, 1); 00106 00107 nux::GetWindowThread ()->SetLayout(main_layout); 00108 } 00109 00110 ~Foo () 00111 { 00112 00113 } 00114 00115 void OnComboChangedFoRealz (nux::ComboBoxSimple *simple) 00116 { 00117 g_debug ("Active: %d", simple->GetSelectionIndex ()); 00118 layered_layout->SetActiveLayerN (simple->GetSelectionIndex ()); 00119 } 00120 00121 nux::LayeredLayout *layered_layout; 00122 }; 00123 00124 void LayeredLayoutInit(nux::NThread* thread, void* InitData) 00125 { 00126 } 00127 00128 int main(int argc, char **argv) 00129 { 00130 Foo *foo; 00131 00132 nux::NuxInitialize(0); 00133 00134 nux::WindowThread* wt = nux::CreateGUIThread(TEXT("Layered Layout"), 600, 400, 0, &LayeredLayoutInit, 0); 00135 foo = new Foo (); 00136 00137 wt->Run(NULL); 00138 00139 delete wt; 00140 delete foo; 00141 00142 return 0; 00143 }