Back to index

nux  3.0.0
ProgramTemplate.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 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.h"
00022 #include "VLayout.h"
00023 #include "HLayout.h"
00024 #include "WindowThread.h"
00025 #include "TextEntry.h"
00026 #include "ProgramTemplate.h"
00027 
00028 
00029 ProgramTemplate::ProgramTemplate(const char* program_name,
00030   int window_width,
00031   int window_height,
00032   int program_life_span)
00033 {
00034   ready_to_go_ = false;
00035   window_width_ = window_width;
00036   window_height_ = window_height;
00037 
00038   if (window_width_ < 100)
00039     window_width_ = 100;
00040 
00041   if (window_height_ < 100)
00042     window_height_ = 100;
00043 
00044   timeout_signal_ = NULL;
00045   window_thread_ = NULL;
00046   program_name_ = program_name;
00047   program_life_span_ = program_life_span;
00048 
00049   if (program_life_span_ > 0 && program_life_span_ < 1000)
00050   {
00051     // Minimum life span is 1 second.
00052     program_life_span_ = 1000;
00053   }
00054 }
00055 
00056 ProgramTemplate::~ProgramTemplate()
00057 {
00058   if (window_thread_)
00059     delete window_thread_;
00060 }
00061 
00062 void ProgramTemplate::Startup()
00063 {
00064   nux::NuxInitialize(0);
00065   window_thread_ = nux::CreateGUIThread(program_name_.c_str(), window_width_, window_height_, NULL, NULL, NULL);
00066 
00067   window_thread_->window_configuration.connect(sigc::mem_fun(this, &ProgramTemplate::WaitForConfigureEvent));
00068 }
00069 
00070 void ProgramTemplate::UserInterfaceSetup()
00071 {
00072   // nux::VLayout *MainVLayout = new nux::VLayout(NUX_TRACKER_LOCATION);
00073   // nux::TextEntry *text_entry_0 = new nux::TextEntry(TEXT("0123456789abcdefghij"), NUX_TRACKER_LOCATION);
00074 
00075   // MainVLayout->AddView(text_entry_0, 0, nux::eCenter, nux::eFull);
00076   // MainVLayout->SetVerticalInternalMargin(10);
00077   // MainVLayout->SetContentDistribution(nux::eStackCenter);
00078 
00079   // nux::GetWindowThread()->SetLayout(MainVLayout);
00080   // nux::ColorLayer background(nux::Color(0xFF4D4D4D));
00081   // window_thread_->SetWindowBackgroundPaintLayer(&background);
00082 }
00083 
00084 void ProgramTemplate::Run()
00085 {
00086   if (window_thread_ == NULL)
00087     return;
00088 
00089   if (program_life_span_ > 0)
00090   {
00091     timeout_signal_ = new nux::TimeOutSignal();
00092     timeout_signal_->time_expires.connect(sigc::mem_fun(this, &ProgramTemplate::ProgramExitCall));
00093     window_thread_->GetTimerHandler().AddTimerHandler(program_life_span_, timeout_signal_, NULL, NULL);
00094   }
00095 
00096   window_thread_->Run(NULL);
00097 }
00098 
00099 bool ProgramTemplate::ReadyToGo()
00100 {
00101   return window_thread_;
00102 }
00103 
00104 nux::WindowThread* ProgramTemplate::GetWindowThread()
00105 {
00106   return window_thread_;
00107 }
00108 
00109 void ProgramTemplate::ProgramExitCall(void *data)
00110 {
00111   if (window_thread_)
00112     window_thread_->ExitMainLoop();
00113 }
00114 
00115 void ProgramTemplate::WaitForConfigureEvent(int x, int y, int width, int height)
00116 {
00117   ready_to_go_ = true;
00118 }
00119 
00120 
00121 // int main(int argc, char **argv)
00122 // {
00123 //     ProgramTemplate test("Text Entry", 300, 300, 3000);
00124 //     test.Startup();
00125 //     test.UserInterfaceSetup();
00126 //     test.Run();
00127 
00128 //     return 0;
00129 // }