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