~ubuntu-branches/ubuntu/oneiric/nux/oneiric

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright 2010 Inalogic Inc.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the  Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
 *
 */

#include "Nux/Nux.h"
#include "Nux/WindowThread.h"
#include "NuxGraphics/GraphicsEngine.h"

#include "Nux/TextureArea.h"
#include "Nux/HLayout.h"
#include "Nux/VLayout.h"
#include "Nux/LayeredLayout.h"
#include "Nux/ToggleButton.h"
#include "Nux/ComboBoxSimple.h"

class Foo
{
public:
  Foo ()
  {
    nux::VLayout *main_layout((new nux::VLayout(NUX_TRACKER_LOCATION)));
    nux::ComboBoxSimple *combo = new nux::ComboBoxSimple (NUX_TRACKER_LOCATION);

    combo->SetMinimumWidth (150);
    combo->sigTriggered.connect (sigc::mem_fun (this, &Foo::OnComboChangedFoRealz));
    main_layout->AddView (combo, 0, nux::eCenter, nux::eFix);

    layered_layout = new nux::LayeredLayout (NUX_TRACKER_LOCATION);
    for (int i = 0; i < 10; i++)
    {
      gchar *text = g_strdup_printf ("Button %d", i);
      nux::LayeredLayout *layered = new nux::LayeredLayout (NUX_TRACKER_LOCATION);

      nux::ColorLayer color (nux::color::RandomColor ());
      nux::TextureArea* texture_area = new nux::TextureArea ();
      texture_area->SetPaintLayer (&color);
      layered->AddLayer (texture_area);

      nux::HLayout *hori = new nux::HLayout (NUX_TRACKER_LOCATION);
      nux::Button* button = new nux::Button ("Big Button", NUX_TRACKER_LOCATION);
      button->SetMinMaxSize (200, 100);
      hori->AddView (button, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
      hori->SetContentDistribution (nux::MAJOR_POSITION_CENTER);
      layered->AddLayer (hori);

      hori = new nux::HLayout (NUX_TRACKER_LOCATION);
      button = new nux::ToggleButton (text, NUX_TRACKER_LOCATION);
      button->SetMinMaxSize (100, 50);
      hori->AddView (button, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
      hori->SetContentDistribution (nux::MAJOR_POSITION_CENTER);
      layered->AddLayout (hori);

      button = new nux::ToggleButton ("This button is insensitive", NUX_TRACKER_LOCATION);
      button->SetSensitive (false);
      layered->AddLayer (button, false, 10, 10, 180, 40);

      button = new nux::ToggleButton ("This button has x, y, w, h set", NUX_TRACKER_LOCATION);
      layered->AddLayer (button, false, 400, 10, 180, 40);

      nux::ROPConfig rop;
      rop.Blend = true;
      rop.SrcBlend = GL_ONE;
      rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
      nux::Color col (0x55005500);
      nux::ColorLayer c (col, true, rop);
      texture_area = new nux::TextureArea ();
      texture_area->SetPaintLayer (&c);
      layered->AddLayer (texture_area, false, 0, 100, 600, 200);

      button = new nux::ToggleButton ("YOU CANT SEE ME!!!!!", NUX_TRACKER_LOCATION);
      layered->AddLayer (button, true);
      button->SetVisible (false);

      layered->SetPaintAll (true);
      layered->SetInputMode (nux::LayeredLayout::INPUT_MODE_COMPOSITE);

      layered->Raise (hori, texture_area);

      button = new nux::ToggleButton ("YOU CANT SEE ME!!!!!", NUX_TRACKER_LOCATION);
      layered->AddLayer (button, true);
      layered->RemoveLayer (button);

      layered_layout->AddLayout (layered);
      combo->AddItem (text);

      g_free (text);
    }

    main_layout->AddLayout (layered_layout, 1);

    nux::GetWindowThread ()->SetLayout(main_layout);
  }

  ~Foo ()
  {

  }

  void OnComboChangedFoRealz (nux::ComboBoxSimple *simple)
  {
    g_debug ("Active: %d", simple->GetSelectionIndex ());
    layered_layout->SetActiveLayerN (simple->GetSelectionIndex ());
  }

  nux::LayeredLayout *layered_layout;
};

void LayeredLayoutInit(nux::NThread* thread, void* InitData)
{
}

int main(int argc, char **argv)
{
  Foo *foo;

  nux::NuxInitialize(0);

  nux::WindowThread* wt = nux::CreateGUIThread(TEXT("Layered Layout"), 600, 400, 0, &LayeredLayoutInit, 0);
  foo = new Foo ();

  wt->Run(NULL);

  delete wt;
  delete foo;

  return 0;
}