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: 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/TimeGraph.h" 00025 #include "Nux/TimerProc.h" 00026 #include "Nux/FloatingWindow.h" 00027 00028 nux::TimerFunctor *timer_functor; 00029 nux::TimerHandle timer_handler; 00030 float time_value = 0; 00031 00032 nux::FloatingWindow* moveable_view = NULL; 00033 00034 void GraphTimerInterrupt (void *data) 00035 { 00036 time_value += 0.001f; 00037 nux::TimeGraph* timegraph = NUX_STATIC_CAST (nux::TimeGraph*, data); 00038 00039 for (int i = 0; i < 3; i++) 00040 { 00041 if (i == 0) 00042 timegraph->UpdateGraph (i, nux::GetWindowThread ()->GetFrameRate() ); 00043 00044 if (i == 1) 00045 timegraph->UpdateGraph (i, nux::RandomUInt (25) + 25); 00046 00047 if (i == 2) 00048 timegraph->UpdateGraph (i, 30 * (std::sin (time_value) + 1) + nux::RandomUInt (10) ); 00049 } 00050 00051 timer_handler = nux::GetTimer().AddTimerHandler (100, timer_functor, timegraph); 00052 } 00053 00054 void UserInterfaceInitialization(nux::NThread* thread, void* init_data) 00055 { 00056 // Create a vertical Layout 00057 nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION); 00058 00059 nux::TimeGraph* timegraph = new nux::TimeGraph(TEXT("Graph")); 00060 timegraph->ShowColumnStyle (); 00061 timegraph->SetYAxisBounds (0.0, 200.0f); 00062 00063 timegraph->AddGraph (nux::Color (0xFF9AD61F), nux::Color (0x50191919) ); 00064 timegraph->AddGraph (nux::Color (0xFF00FF00), nux::Color (0x5000FF00) ); 00065 timegraph->AddGraph (nux::Color (0xFFFF0022), nux::Color (0x50BB0022) ); 00066 00067 timer_functor = new nux::TimerFunctor (); 00068 timer_functor->OnTimerExpired.connect (sigc::ptr_fun (&GraphTimerInterrupt)); 00069 timer_handler = nux::GetTimer ().AddTimerHandler (1000, timer_functor, timegraph); 00070 00071 // Add the timegraph to the layout 00072 layout->AddView ( 00073 timegraph, 00074 1, 00075 nux::MINOR_POSITION_CENTER, 00076 nux::MINOR_SIZE_FULL); 00077 00078 // Control the position of elements inside the layout 00079 layout->SetContentDistribution (nux::MAJOR_POSITION_CENTER); 00080 00081 layout->SetHorizontalExternalMargin (4); 00082 layout->SetVerticalExternalMargin (4); 00083 00084 moveable_view = new nux::FloatingWindow(TEXT("Moveable View"), NUX_TRACKER_LOCATION); 00085 00086 moveable_view->SetLayout(layout); 00087 00088 moveable_view->ShowWindow(true); 00089 moveable_view->SetBaseXY(10, 10); 00090 00091 00092 // Set the layout as the container of the window thread 00093 //nux::GetWindowThread ()->SetLayout (layout); 00094 00095 // Set the background color of the window 00096 nux::ColorLayer background (nux::Color (0xFF202020)); 00097 static_cast<nux::WindowThread*> (thread)->SetWindowBackgroundPaintLayer(&background); 00098 } 00099 00100 int main(int argc, char **argv) 00101 { 00102 // Initialize Nux subsystem 00103 nux::NuxInitialize (0); 00104 00105 // Create a Window thread 00106 nux::WindowThread* wt = nux::CreateGUIThread( 00107 TEXT("Moveable View"), 00108 600, 00109 400, 00110 0, 00111 &UserInterfaceInitialization, 00112 0); 00113 00114 // Start the main loop 00115 wt->Run (0); 00116 00117 00118 moveable_view->Dispose(); 00119 00120 delete timer_functor; 00121 delete wt; 00122 return 0; 00123 }