The Pedigree Project  0.1
user/applications/uitest/main.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "pedigree/native/graphics/Graphics.h"
21 #include "pedigree/native/types.h"
22 #include <Widget.h>
23 
24 #include <iostream>
25 
26 using namespace PedigreeGraphics;
27 
28 class TestWidget : public Widget
29 {
30  public:
31  TestWidget(uint32_t rgb) : Widget(), m_Rgb(rgb){};
32  virtual ~TestWidget()
33  {
34  }
35 
36  virtual bool render(Rect &rt, Rect &dirty)
37  {
38  std::cout << "uitest: rendering widget." << std::endl;
39 
40  void *pFramebuffer = getRawFramebuffer();
41  uint32_t *buffer = (uint32_t *) pFramebuffer;
42  for (size_t y = 0; y < rt.getH(); ++y)
43  {
44  for (size_t x = 0; x < rt.getW(); ++x)
45  buffer[y * rt.getW() + x] = m_Rgb;
46  }
47 
48  dirty.update(0, 0, rt.getW(), rt.getH());
49 
50  return true;
51  }
52 
53  private:
54  uint32_t m_Rgb;
55 };
56 
57 volatile bool bRun = true;
58 
59 bool callback(WidgetMessages message, size_t msgSize, const void *msgData)
60 {
61  std::cout << "uitest: callback for '" << static_cast<int>(message) << "'."
62  << std::endl;
63 
64  if (message == Terminate)
65  {
66  bRun = false;
67  }
68 
69  return true;
70 }
71 
72 int main(int argc, char *argv[])
73 {
74  std::cout << "uitest: starting up" << std::endl;
75 
76  Rect rt(20, 20, 20, 20);
77 
78  Widget *pWidgetA = new TestWidget(createRgb(0xFF, 0, 0));
79  if (!pWidgetA->construct("uitest.A", "UI Test A", callback, rt))
80  {
81  std::cerr << "uitest: widget A construction failed" << std::endl;
82  delete pWidgetA;
83  return 1;
84  }
85 
86  Widget *pWidgetB = new TestWidget(createRgb(0, 0xFF, 0));
87  if (!pWidgetB->construct("uitest.B", "UI Test B", callback, rt))
88  {
89  std::cerr << "uitest: widget B construction failed" << std::endl;
90  delete pWidgetA;
91  delete pWidgetB;
92  return 1;
93  }
94 
95  std::cout << "uitest: widgets created (handles are "
96  << pWidgetA->getHandle() << ", " << pWidgetB->getHandle() << ")."
97  << std::endl;
98 
99  pWidgetA->visibility(true);
100  pWidgetB->visibility(true);
101 
102  std::cout << "Widgets are visible!" << std::endl;
103 
104  Rect dirtyA, dirtyB;
105  pWidgetA->render(rt, dirtyA);
106  pWidgetB->render(rt, dirtyB);
107  pWidgetA->redraw(dirtyA);
108  pWidgetB->redraw(dirtyB);
109 
110  // Main loop
111  while (bRun)
112  {
114  }
115 
116  delete pWidgetB;
117  delete pWidgetA;
118 
119  return 0;
120 }
virtual bool render(PedigreeGraphics::Rect &rt, PedigreeGraphics::Rect &dirty)=0
uint64_t getHandle() const
Definition: Widget.h:79
static void checkForEvents(bool bAsync=false)
Definition: Widget.cc:339
bool redraw(PedigreeGraphics::Rect &rt)
Definition: Widget.cc:225
bool visibility(bool vis)
Definition: Widget.cc:269
virtual bool render(Rect &rt, Rect &dirty)
Definition: Widget.h:63
bool construct(const char *endpoint, const char *title, widgetCallback_t cb, PedigreeGraphics::Rect &dimensions)
Definition: Widget.cc:90