nux-1.14.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: Jay Taoko <jaytaoko@inalogic.com> 00018 * 00019 */ 00020 00021 #include "Nux/Nux.h" 00022 #include "Nux/VLayout.h" 00023 #include "Nux/WindowThread.h" 00024 #include "Nux/TextureArea.h" 00025 #include "Nux/TimerProc.h" 00026 00027 nux::TimerFunctor *timer_functor = 0; 00028 nux::TimerHandle timer_handle; 00029 float angle = 0.0f; 00030 00031 void UpdateAngle (void *v) 00032 { 00033 angle += 0.1f; 00034 if (angle >= nux::Const::pi) 00035 { 00036 angle = 0.0f; 00037 } 00038 00039 nux::TextureArea* texture_area = NUX_STATIC_CAST (nux::TextureArea*, v); 00040 if (texture_area) 00041 { 00042 texture_area->Set2DRotation (angle); 00043 timer_handle = nux::GetTimer().AddTimerHandler (10, timer_functor, texture_area); 00044 if (angle == 0) 00045 { 00046 nux::ColorLayer color_layer (nux::color::RandomColor ()); 00047 texture_area->SetPaintLayer (&color_layer); 00048 } 00049 } 00050 } 00051 00052 void UserInterfaceInitialization(nux::NThread* thread, void* init_data) 00053 { 00054 // Create a vertical Layout 00055 nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION); 00056 00057 //Create a button of type PushButton 00058 nux::TextureArea* texture_area = new nux::TextureArea(NUX_TRACKER_LOCATION); 00059 00060 // Set the button maximum width/height 00061 texture_area->SetMaximumWidth (160); 00062 texture_area->SetMaximumHeight (80); 00063 texture_area->SetTextColor (nux::color::Pink); 00064 texture_area->Set2DRotation (0.0); 00065 00066 // Add the button to the layout 00067 layout->AddView ( 00068 texture_area, 00069 1, 00070 nux::MINOR_POSITION_CENTER, 00071 nux::MINOR_SIZE_FULL); 00072 00073 // Control the position of elements inside the layout 00074 layout->SetContentDistribution (nux::MAJOR_POSITION_CENTER); 00075 00076 // Set the layout as the container of the window thread 00077 nux::GetWindowThread ()->SetLayout (layout); 00078 00079 // Set the background color of the window 00080 nux::ColorLayer background (nux::Color (0xFF222222)); 00081 static_cast<nux::WindowThread*> (thread)->SetWindowBackgroundPaintLayer(&background); 00082 00083 timer_functor = new nux::TimerFunctor; 00084 timer_functor->OnTimerExpired.connect (sigc::ptr_fun (&UpdateAngle)); 00085 timer_handle = nux::GetTimer().AddTimerHandler (5, timer_functor, texture_area); 00086 00087 } 00088 00089 int main(int argc, char **argv) 00090 { 00091 // Initialize Nux subsystem 00092 nux::NuxInitialize (0); 00093 00094 // Create a Window thread 00095 nux::WindowThread* wt = nux::CreateGUIThread( 00096 TEXT("Rotate Texture Area"), 00097 400, 00098 300, 00099 0, 00100 &UserInterfaceInitialization, 00101 0); 00102 00103 // Start the main loop 00104 wt->Run (0); 00105 00106 delete wt; 00107 return 0; 00108 }