~smspillaz/unity/untiy.less-paint-insanity

« back to all changes in this revision

Viewing changes to standalone-clients/nux_test_framework.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * version 3 along with this program.  If not, see
 
15
 * <http://www.gnu.org/licenses/>
 
16
 *
 
17
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 
18
 *
 
19
 */
 
20
 
 
21
#include "Nux/Nux.h"
 
22
#include "Nux/VLayout.h"
 
23
#include "Nux/HLayout.h"
 
24
#include "Nux/WindowThread.h"
 
25
#include "Nux/TextEntry.h"
 
26
#include "nux_test_framework.h"
 
27
 
 
28
 
 
29
NuxTestFramework::NuxTestFramework(const char* program_name,
 
30
  int window_width,
 
31
  int window_height,
 
32
  int program_life_span)
 
33
{
 
34
  ready_to_go_ = false;
 
35
  window_width_ = window_width;
 
36
  window_height_ = window_height;
 
37
 
 
38
  if (window_width_ < 100)
 
39
    window_width_ = 100;
 
40
 
 
41
  if (window_height_ < 100)
 
42
    window_height_ = 100;
 
43
 
 
44
  timeout_signal_ = NULL;
 
45
  window_thread_ = NULL;
 
46
  program_name_ = program_name;
 
47
  program_life_span_ = program_life_span;
 
48
 
 
49
  if (program_life_span_ > 0 && program_life_span_ < 1000)
 
50
  {
 
51
    // Minimum life span is 1 second.
 
52
    program_life_span_ = 1000;
 
53
  }
 
54
}
 
55
 
 
56
NuxTestFramework::~NuxTestFramework()
 
57
{
 
58
  if (window_thread_)
 
59
    delete window_thread_;
 
60
}
 
61
 
 
62
void NuxTestFramework::Startup()
 
63
{
 
64
  nux::NuxInitialize(0);
 
65
  window_thread_ = nux::CreateGUIThread(program_name_.c_str(), window_width_, window_height_, NULL, NULL, NULL);
 
66
 
 
67
  window_thread_->window_configuration.connect(sigc::mem_fun(this, &NuxTestFramework::WaitForConfigureEvent));
 
68
}
 
69
 
 
70
void NuxTestFramework::UserInterfaceSetup()
 
71
{
 
72
  // nux::VLayout *MainVLayout = new nux::VLayout(NUX_TRACKER_LOCATION);
 
73
  // nux::TextEntry *text_entry_0 = new nux::TextEntry(TEXT("0123456789abcdefghij"), NUX_TRACKER_LOCATION);
 
74
 
 
75
  // MainVLayout->AddView(text_entry_0, 0, nux::eCenter, nux::eFull);
 
76
  // MainVLayout->SetVerticalInternalMargin(10);
 
77
  // MainVLayout->SetContentDistribution(nux::eStackCenter);
 
78
 
 
79
  // nux::GetWindowThread()->SetLayout(MainVLayout);
 
80
  // nux::ColorLayer background(nux::Color(0xFF4D4D4D));
 
81
  // window_thread_->SetWindowBackgroundPaintLayer(&background);
 
82
}
 
83
 
 
84
void NuxTestFramework::Run()
 
85
{
 
86
  if (window_thread_ == NULL)
 
87
    return;
 
88
 
 
89
  if (program_life_span_ > 0)
 
90
  {
 
91
    timeout_signal_ = new nux::TimeOutSignal();
 
92
    timeout_signal_->time_expires.connect(sigc::mem_fun(this, &NuxTestFramework::ProgramExitCall));
 
93
    window_thread_->GetTimerHandler().AddTimerHandler(program_life_span_, timeout_signal_, NULL, NULL);
 
94
  }
 
95
 
 
96
  window_thread_->Run(NULL);
 
97
}
 
98
 
 
99
bool NuxTestFramework::ReadyToGo()
 
100
{
 
101
  return window_thread_;
 
102
}
 
103
 
 
104
nux::WindowThread* NuxTestFramework::GetWindowThread()
 
105
{
 
106
  return window_thread_;
 
107
}
 
108
 
 
109
void NuxTestFramework::ProgramExitCall(void *data)
 
110
{
 
111
  if (window_thread_)
 
112
    window_thread_->ExitMainLoop();
 
113
}
 
114
 
 
115
void NuxTestFramework::WaitForConfigureEvent(int x, int y, int width, int height)
 
116
{
 
117
  ready_to_go_ = true;
 
118
}
 
119
 
 
120
 
 
121
// int main(int argc, char **argv)
 
122
// {
 
123
//     NuxTestFramework test("Text Entry", 300, 300, 3000);
 
124
//     test.Startup();
 
125
//     test.UserInterfaceSetup();
 
126
//     test.Run();
 
127
 
 
128
//     return 0;
 
129
// }