summaryrefslogtreecommitdiff
path: root/project
diff options
context:
space:
mode:
Diffstat (limited to 'project')
-rw-r--r--project/data/nofile.dummy0
-rw-r--r--project/inc/DrawingBoard.h68
-rw-r--r--project/manifest.xml25
-rw-r--r--project/res/tizen.pngbin0 -> 21322 bytes
-rw-r--r--project/shared/data/nofile.dummy0
-rw-r--r--project/shared/res/screen-density-xhigh/mainmenu.pngbin0 -> 57662 bytes
-rw-r--r--project/shared/trusted/nofile.dummy0
-rw-r--r--project/src/DrawingBoard.cpp1278
-rw-r--r--project/src/DrawingBoardEntry.cpp65
9 files changed, 1436 insertions, 0 deletions
diff --git a/project/data/nofile.dummy b/project/data/nofile.dummy
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/project/data/nofile.dummy
diff --git a/project/inc/DrawingBoard.h b/project/inc/DrawingBoard.h
new file mode 100644
index 0000000..b6303fe
--- /dev/null
+++ b/project/inc/DrawingBoard.h
@@ -0,0 +1,68 @@
+//
+// Tizen C++ SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.1 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef _DRAWING_BOARD_H_
+#define _DRAWING_BOARD_H_
+
+
+#include <FBase.h>
+#include <FGraphics.h>
+#include <FMedia.h>
+#include <FApp.h>
+#include <FUi.h>
+#include <FSystem.h>
+
+class Painter;
+
+class DrawingBoard
+ : public Tizen::App::Application
+ , public Tizen::System::IScreenEventListener
+ , public Tizen::Base::Runtime::ITimerEventListener
+ , public Tizen::Ui::IKeyEventListener
+{
+public:
+ static Tizen::App::Application* CreateInstance(void);
+
+ DrawingBoard();
+ ~DrawingBoard();
+
+ virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry);
+ virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);
+ virtual void OnForeground(void);
+ virtual void OnBackground(void);
+ virtual void OnLowMemory(void);
+ virtual void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
+ virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
+ virtual void OnScreenOn(void);
+ virtual void OnScreenOff(void);
+
+ virtual void OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
+ virtual void OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
+ virtual void OnKeyLongPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
+
+ void ChangePainter(void);
+ void Draw(void);
+
+private:
+ Tizen::Ui::Controls::Form* __pForm;
+ Painter* __pPainter;
+ Tizen::Base::Runtime::Timer* __pTimer;
+ int __scenarioIndex;
+};
+
+#endif
+
diff --git a/project/manifest.xml b/project/manifest.xml
new file mode 100644
index 0000000..3cdb4dc
--- /dev/null
+++ b/project/manifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<Manifest xmlns="http://schemas.tizen.org/2012/12/manifest">
+ <Id>$(manifestAppId)</Id>
+ <Version>2.2.0</Version>
+ <Type>C++App</Type>
+ <Requirements>
+ <Feature Name="http://tizen.org/feature/screen.size.all">true</Feature>
+ </Requirements>
+ <Apps>
+ <ApiVersion>2.2</ApiVersion>
+ <Privileges/>
+ <UiApp Main="True" MenuIconVisible="True" Name="$(projectName)">
+ <UiScalability BaseScreenSize="Normal" CoordinateSystem="Logical" LogicalCoordinate="720"/>
+ <UiTheme SystemTheme="Black"/>
+ <DisplayNames>
+ <DisplayName Locale="eng-GB">$(projectName)</DisplayName>
+ </DisplayNames>
+ <Icons>
+ <Icon Section="MainMenu" Type="Xhigh">mainmenu.png</Icon>
+ </Icons>
+ <LaunchConditions/>
+ <Notifications/>
+ </UiApp>
+ </Apps>
+</Manifest>
diff --git a/project/res/tizen.png b/project/res/tizen.png
new file mode 100644
index 0000000..d72552f
--- /dev/null
+++ b/project/res/tizen.png
Binary files differ
diff --git a/project/shared/data/nofile.dummy b/project/shared/data/nofile.dummy
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/project/shared/data/nofile.dummy
diff --git a/project/shared/res/screen-density-xhigh/mainmenu.png b/project/shared/res/screen-density-xhigh/mainmenu.png
new file mode 100644
index 0000000..9765b1b
--- /dev/null
+++ b/project/shared/res/screen-density-xhigh/mainmenu.png
Binary files differ
diff --git a/project/shared/trusted/nofile.dummy b/project/shared/trusted/nofile.dummy
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/project/shared/trusted/nofile.dummy
diff --git a/project/src/DrawingBoard.cpp b/project/src/DrawingBoard.cpp
new file mode 100644
index 0000000..462cb2e
--- /dev/null
+++ b/project/src/DrawingBoard.cpp
@@ -0,0 +1,1278 @@
+//
+// Tizen C++ SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.1 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "DrawingBoard.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Runtime;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Graphics;
+using namespace Tizen::Media;
+using namespace Tizen::System;
+using namespace Tizen::Ui;
+using namespace Tizen::Ui::Controls;
+
+
+#define RED32(color32) static_cast<byte>(0x00F8 & ((color32) >> 16))
+#define GREEN32(color32) static_cast<byte>(0x00FC & ((color32) >> 8))
+#define BLUE32(color32) static_cast<byte>(0x00F8 & (color32))
+
+#define RGB888ToCOLOR16(red, green, blue) (static_cast<unsigned short>((static_cast<byte>((blue) >> 3)) | (static_cast<unsigned short>(static_cast<byte>((green) >> 2)) << 5)) | ((static_cast<unsigned short>(static_cast<byte>((red) >> 3)) << 11)))
+#define COLOR32ToCOLOR16(color32) RGB888ToCOLOR16(RED32(color32), GREEN32(color32), BLUE32(color32))
+
+
+const int REPEAT_COUNT = 100;
+const int TIME_OUT = 50;
+const int MAX_LINE_WIDTH = 10;
+const int MAX_FONT_SIZE = 50;
+
+
+class DrawingForm
+ : public Tizen::Ui::Controls::Form
+{
+public:
+ DrawingForm(DrawingBoard* pApp)
+ : __pApp(pApp)
+ {
+ }
+
+ virtual ~DrawingForm(void)
+ {
+ }
+
+public:
+ virtual result OnDraw(void)
+ {
+ if (__pApp)
+ {
+ __pApp->Draw();
+ }
+
+ return E_SUCCESS;
+ }
+
+private:
+ DrawingBoard* __pApp;
+};
+
+
+class Painter
+{
+public:
+ Painter(const Control& control)
+ {
+ _count = 0;
+ _pCanvas = control.GetCanvasN();
+ _pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
+ _pCanvas->Clear();
+ _pCanvas->Show();
+
+ _bounds = _pCanvas->GetBounds();
+ }
+
+ virtual ~Painter()
+ {
+ delete _pCanvas;
+ }
+
+ virtual bool Draw(void) = 0;
+
+protected:
+ Canvas* _pCanvas;
+ int _count;
+ Rectangle _bounds;
+};
+
+class PixelPainter
+ : public Painter
+{
+public:
+ PixelPainter(const Control& control)
+ : Painter(control)
+ {
+ }
+
+ virtual bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+
+ _pCanvas->SetForegroundColor(color);
+
+ int x = (Math::Rand() % (_bounds.width -2)) + 1;
+ int y = (Math::Rand() % (_bounds.height-2)) + 1;
+
+ _pCanvas->SetPixel(Point(x - 1, y - 1));
+ _pCanvas->SetPixel(Point(x + 1, y - 1));
+ _pCanvas->SetPixel(Point(x, y - 1));
+ _pCanvas->SetPixel(Point(x, y));
+ _pCanvas->SetPixel(Point(x - 1, y + 1));
+ _pCanvas->SetPixel(Point(x, y + 1));
+ _pCanvas->SetPixel(Point(x + 1, y + 1));
+
+ _pCanvas->Show();
+
+ return true;
+ }
+};
+
+
+class LinePainter
+ : public Painter
+{
+public:
+ LinePainter(const Control& control)
+ : Painter(control)
+ {
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ int lineWidth = (Math::Rand() % MAX_LINE_WIDTH) + 1;
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+ _pCanvas->SetForegroundColor(color);
+
+ Point point1(Math::Rand() % _bounds.width, Math::Rand() % _bounds.height);
+ Point point2(Math::Rand() % _bounds.width, Math::Rand() % _bounds.height);
+
+ _pCanvas->SetLineWidth(lineWidth);
+ _pCanvas->DrawLine(point1, point2);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+};
+
+
+class TrianglePainter
+ : public Painter
+{
+public:
+ TrianglePainter(const Control& control)
+ : Painter(control)
+ {
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ int lineWidth = (Math::Rand() % MAX_LINE_WIDTH) + 1;
+
+ _pCanvas->SetLineWidth(lineWidth);
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+
+ _pCanvas->SetForegroundColor(color);
+
+ Point point1;
+ Point point2;
+ Point point3;
+
+ point1.x = Math::Rand() % _bounds.width;
+ point1.y = Math::Rand() % _bounds.height;
+ point2.x = Math::Rand() % _bounds.width;
+ point2.y = Math::Rand() % _bounds.height;
+ point3.x = Math::Rand() % _bounds.width;
+ point3.y = Math::Rand() % _bounds.height;
+
+ _pCanvas->DrawTriangle(point1, point2, point3);
+
+ point1.x = Math::Rand() % _bounds.width;
+ point1.y = Math::Rand() % _bounds.height;
+ point2.x = Math::Rand() % _bounds.width;
+ point2.y = Math::Rand() % _bounds.height;
+ point3.x = Math::Rand() % _bounds.width;
+ point3.y = Math::Rand() % _bounds.height;
+
+ _pCanvas->FillTriangle(color, point1, point2, point3);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+};
+
+
+class RectanglePainter
+ : public Painter
+{
+public:
+ RectanglePainter(const Control& control)
+ : Painter(control)
+ {
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ int lineWidth = (Math::Rand() % MAX_LINE_WIDTH) + 1;
+
+ _pCanvas->SetLineWidth(lineWidth);
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+
+ _pCanvas->SetForegroundColor(color);
+
+ Rectangle rect;
+
+ rect.x = Math::Rand() % _bounds.width;
+ rect.y = Math::Rand() % _bounds.height;
+ rect.width = Math::Rand() % _bounds.width;
+ rect.height = Math::Rand() % _bounds.height;
+
+ _pCanvas->DrawRectangle(rect);
+
+ rect.x = Math::Rand() % _bounds.width;
+ rect.y = Math::Rand() % _bounds.height;
+ rect.width = Math::Rand() % _bounds.width;
+ rect.height = Math::Rand() % _bounds.height;
+
+ _pCanvas->FillRectangle(color, rect);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+};
+
+
+class RoundRectanglePainter
+ : public Painter
+{
+public:
+ RoundRectanglePainter(const Control& control)
+ : Painter(control)
+ {
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ int lineWidth = (Math::Rand() % MAX_LINE_WIDTH) + 1;
+
+ _pCanvas->SetLineWidth(lineWidth);
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+
+ _pCanvas->SetForegroundColor(color);
+
+ Rectangle rect;
+ Dimension round;
+
+ rect.x = Math::Rand() % _bounds.width;
+ rect.y = Math::Rand() % _bounds.height;
+ rect.width = Math::Rand() % _bounds.width;
+ rect.height = Math::Rand() % _bounds.height;
+
+ round.width = rect.width / MAX_LINE_WIDTH;
+ round.height = rect.height / MAX_LINE_WIDTH;
+
+ _pCanvas->DrawRoundRectangle(rect, round);
+
+ rect.x = Math::Rand() % _bounds.width;
+ rect.y = Math::Rand() % _bounds.height;
+ rect.width = Math::Rand() % _bounds.width;
+ rect.height = Math::Rand() % _bounds.height;
+
+ round.width = rect.width / MAX_LINE_WIDTH;
+ round.height = rect.height / MAX_LINE_WIDTH;
+
+ _pCanvas->FillRoundRectangle(color, rect, round);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+};
+
+
+class EllipsePainter
+ : public Painter
+{
+public:
+ EllipsePainter(const Control& control)
+ : Painter(control)
+ {
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ int lineWidth = (Math::Rand() % MAX_LINE_WIDTH) + 1;
+
+ _pCanvas->SetLineWidth(lineWidth);
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+
+ _pCanvas->SetForegroundColor(color);
+
+ Rectangle rect;
+
+ rect.x = Math::Rand() % _bounds.width;
+ rect.y = Math::Rand() % _bounds.height;
+ rect.width = Math::Rand() % _bounds.width;
+ rect.height = Math::Rand() % _bounds.height;
+
+ _pCanvas->DrawEllipse(rect);
+
+ rect.x = Math::Rand() % _bounds.width;
+ rect.y = Math::Rand() % _bounds.height;
+ rect.width = Math::Rand() % _bounds.width;
+ rect.height = Math::Rand() % _bounds.height;
+
+ _pCanvas->FillEllipse(color, rect);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+};
+
+
+class ArcPainter
+ : public Painter
+{
+public:
+ ArcPainter(const Control& control)
+ : Painter(control)
+ {
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ int lineWidth = (Math::Rand() % MAX_LINE_WIDTH) + 1;
+
+ _pCanvas->SetLineWidth(lineWidth);
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+ _pCanvas->SetForegroundColor(color);
+
+ Rectangle rect(Math::Rand() % _bounds.width, Math::Rand() % _bounds.height, Math::Rand() % _bounds.width, Math::Rand() % _bounds.height);
+
+ int startAngle = Math::Rand() % 360;
+ int endAngle = Math::Rand() % 360;
+
+ ArcStyle arcStyle = ARC_STYLE_ONLY;
+
+ switch (Math::Rand() % 3)
+ {
+ case 0:
+ arcStyle = ARC_STYLE_ONLY;
+ break;
+ case 1:
+ arcStyle = ARC_STYLE_CHORD;
+ break;
+ default:
+ arcStyle = ARC_STYLE_PIE;
+ break;
+ }
+
+ _pCanvas->DrawArc(rect, startAngle, endAngle, arcStyle);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+};
+
+
+class PolylinePainter
+ : public Painter
+{
+public:
+ PolylinePainter(const Control& control)
+ : Painter(control)
+ {
+ for (int i = 0; i < 6; i++)
+ {
+ __pointList.Add(*(new (std::nothrow) Point));
+ }
+ }
+
+ virtual ~PolylinePainter()
+ {
+ __pointList.RemoveAll(true);
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ int lineWidth = (Math::Rand() % MAX_LINE_WIDTH) + 1;
+
+ _pCanvas->SetLineWidth(lineWidth);
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+
+ _pCanvas->SetForegroundColor(color);
+
+ for (int i = 0; i < __pointList.GetCount(); i++)
+ {
+ Point* pPoint = dynamic_cast<Point*>(__pointList.GetAt(i));
+
+ if (pPoint)
+ {
+ pPoint->x = Math::Rand() % _bounds.width;
+ pPoint->y = Math::Rand() % _bounds.height;
+ }
+ }
+
+ _pCanvas->DrawPolyline(__pointList);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+
+private:
+ Tizen::Base::Collection::ArrayList __pointList;
+};
+
+
+class PolygonPainter
+ : public Painter
+{
+public:
+ PolygonPainter(const Control& control)
+ : Painter(control)
+ {
+ for (int i = 0; i < 6; i++)
+ {
+ __pointList.Add(*(new (std::nothrow) Point));
+ }
+ }
+
+ virtual ~PolygonPainter()
+ {
+ __pointList.RemoveAll(true);
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ int lineWidth = (Math::Rand() % MAX_LINE_WIDTH) + 1;
+
+ _pCanvas->SetLineWidth(lineWidth);
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+
+ _pCanvas->SetForegroundColor(color);
+
+ for (int i = 0; i < __pointList.GetCount(); i++)
+ {
+ Point* pPoint = dynamic_cast<Point*>(__pointList.GetAt(i));
+
+ if (pPoint)
+ {
+ pPoint->x = Math::Rand() % _bounds.width;
+ pPoint->y = Math::Rand() % _bounds.height;
+ }
+ }
+
+ _pCanvas->DrawPolygon(__pointList);
+
+ for (int i = 0; i < __pointList.GetCount(); i++)
+ {
+ Point* pPoint = dynamic_cast<Point*>(__pointList.GetAt(i));
+
+ if (pPoint)
+ {
+ pPoint->x = Math::Rand() % _bounds.width;
+ pPoint->y = Math::Rand() % _bounds.height;
+ }
+ }
+
+ _pCanvas->FillPolygon(color, __pointList);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+
+private:
+ Tizen::Base::Collection::ArrayList __pointList;
+};
+
+
+class TextPainter
+ : public Painter
+{
+public:
+ TextPainter(const Control& control)
+ : Painter(control)
+ {
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ int fontStyle = FONT_STYLE_PLAIN;
+
+ switch (Math::Rand() % 3)
+ {
+ case 0:
+ fontStyle = FONT_STYLE_PLAIN;
+ break;
+ case 1:
+ fontStyle = FONT_STYLE_BOLD;
+ break;
+ default:
+ fontStyle = FONT_STYLE_ITALIC;
+ break;
+ }
+
+ int fontSize = Math::Rand() % MAX_FONT_SIZE;
+
+ if (fontSize < 10)
+ {
+ fontSize = 10;
+ }
+
+ Font font;
+
+ result r = font.Construct(fontStyle, fontSize);
+
+ if (IsFailed(r))
+ {
+ AppLog("Fails to construct font.\n");
+ return false;
+ }
+
+ _pCanvas->SetFont(font);
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+
+ _pCanvas->SetForegroundColor(color);
+
+ Point point(Math::Rand() % _bounds.width, Math::Rand() % _bounds.height);
+
+ Tizen::Base::String text(L"DrawingBoard Sample");
+
+ _pCanvas->DrawText(point, text);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+};
+
+
+class BitmapPainter
+ : public Painter
+{
+public:
+ BitmapPainter(const Control& control)
+ : Painter(control)
+ , __pBitmap16(null)
+ , __pBitmap32(null)
+ {
+ Image imageDecoder;
+
+ imageDecoder.Construct();
+
+ __pBitmap16 = imageDecoder.DecodeN(App::GetInstance()->GetAppRootPath() + L"res/tizen.png", BITMAP_PIXEL_FORMAT_RGB565);
+ __pBitmap32 = imageDecoder.DecodeN(App::GetInstance()->GetAppRootPath() + L"res/tizen.png", BITMAP_PIXEL_FORMAT_ARGB8888);
+ }
+
+ virtual ~BitmapPainter()
+ {
+ delete __pBitmap16;
+ delete __pBitmap32;
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ Point pos(Math::Rand() % _bounds.width, Math::Rand() % _bounds.height);
+
+ _pCanvas->DrawBitmap(pos, *__pBitmap16);
+
+ pos.x = Math::Rand() % _bounds.width;
+ pos.y = Math::Rand() % _bounds.height;
+
+ _pCanvas->DrawBitmap(pos, *__pBitmap32);
+
+ Rectangle rect;
+
+ rect.x = Math::Rand() % _bounds.width;
+ rect.y = Math::Rand() % _bounds.height;
+ rect.width = (Math::Rand() % (_bounds.width - 1)) + 1;
+ rect.height = (Math::Rand() % (_bounds.height- 1)) + 1;
+
+
+ _pCanvas->DrawBitmap(rect, *__pBitmap16);
+
+ rect.x = Math::Rand() % _bounds.width;
+ rect.y = Math::Rand() % _bounds.height;
+ rect.width = (Math::Rand() % (_bounds.width - 1)) + 1;
+ rect.height = (Math::Rand() % (_bounds.height- 1)) + 1;
+
+ _pCanvas->DrawBitmap(rect, *__pBitmap32);
+
+ rect.x = Math::Rand() % __pBitmap16->GetWidth();
+ rect.y = Math::Rand() % __pBitmap16->GetHeight();
+ rect.width = (Math::Rand() % (__pBitmap16->GetWidth() - 1)) + 1;
+ rect.height = (Math::Rand() % (__pBitmap16->GetHeight() - 1)) + 1;
+
+ if (rect.x + rect.width > __pBitmap16->GetWidth())
+ {
+ rect.width = __pBitmap16->GetWidth() - rect.x;
+ }
+
+ if (rect.y + rect.height > __pBitmap16->GetHeight())
+ {
+ rect.height = __pBitmap16->GetHeight() - rect.y;
+ }
+
+ Rectangle destRect;
+
+ destRect.x = Math::Rand() % _bounds.width;
+ destRect.y = Math::Rand() % _bounds.height;
+ destRect.width = (Math::Rand() % (_bounds.width - 1)) + 1;
+ destRect.height = (Math::Rand() % (_bounds.height- 1)) + 1;
+
+ _pCanvas->DrawBitmap(destRect, *__pBitmap16, rect);
+
+ rect.x = Math::Rand() % __pBitmap32->GetWidth();
+ rect.y = Math::Rand() % __pBitmap32->GetHeight();
+ rect.width = (Math::Rand() % (__pBitmap32->GetWidth() - 1)) + 1;
+ rect.height = (Math::Rand() % (__pBitmap32->GetHeight()- 1)) + 1;
+
+ if (rect.x + rect.width > __pBitmap32->GetWidth())
+ {
+ rect.width = __pBitmap32->GetWidth() - rect.x;
+ }
+
+ if (rect.y + rect.height > __pBitmap32->GetHeight())
+ {
+ rect.height = __pBitmap32->GetHeight() - rect.y;
+ }
+
+ destRect.x = Math::Rand() % _bounds.width;
+ destRect.y = Math::Rand() % _bounds.height;
+ destRect.width = (Math::Rand() % (_bounds.width - 1)) + 1;
+ destRect.height = (Math::Rand() % (_bounds.height- 1)) + 1;
+
+ _pCanvas->DrawBitmap(destRect, *__pBitmap32, rect);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+
+private:
+ Bitmap* __pBitmap16;
+ Bitmap* __pBitmap32;
+};
+
+
+class DirectBufferPainter
+ : public Painter
+{
+public:
+ DirectBufferPainter(const Control& control)
+ : Painter(control)
+ {
+ }
+
+ bool Draw(void)
+ {
+ if (REPEAT_COUNT < _count++)
+ {
+ return false;
+ }
+
+ byte red = Math::Rand() % 0xFF;
+ byte green = Math::Rand() % 0xFF;
+ byte blue = Math::Rand() % 0xFF;
+ byte alpha = Math::Rand() % 0xFF;
+
+ Color color(red, green, blue, alpha);
+
+ _pCanvas->SetForegroundColor(color);
+
+ Rectangle rect(Math::Rand() % _bounds.width, Math::Rand() % _bounds.height, Math::Rand() % _bounds.width, Math::Rand() % _bounds.height);
+
+ FillRectangle(*_pCanvas, color, rect);
+
+ _pCanvas->Show();
+
+ return true;
+ }
+
+ void FillRectangle(Canvas& canvas, const Color &color, const Rectangle &rect)
+ {
+ BufferInfo bufferInfo;
+ int x;
+ int y;
+ int offset;
+ byte srcR;
+ byte srcG;
+ byte srcB;
+ byte destR;
+ byte destG;
+ byte destB;
+ int alphaLevel;
+ int srcLevel;
+ int destLevel;
+ int r;
+ int g;
+ int b;
+ unsigned short color16;
+ unsigned short* pBuffer16;
+ unsigned long* pBuffer32;
+ int bufferWidth;
+ int bufferX1;
+ int bufferY1;
+ int bufferX2;
+ int bufferY2;
+ int x1;
+ int y1;
+ int x2;
+ int y2;
+ int width;
+ int height;
+
+ _pCanvas->Lock(bufferInfo);
+
+ x1 = rect.x;
+ y1 = rect.y;
+ width = rect.width;
+ height = rect.height;
+
+ x2 = x1 + width - 1;
+ y2 = y1 + height - 1;
+
+ bufferX1 = 0;
+ bufferY1 = 0;
+ bufferX2 = bufferX1 + bufferInfo.width - 1;
+ bufferY2 = bufferY1 + bufferInfo.height - 1;
+
+ if (x1 > bufferX2 || x2 < bufferX1)
+ {
+ return;
+ }
+
+ if (y1 > bufferY2 || y2 < bufferY1)
+ {
+ return;
+ }
+
+ if (x1 < bufferX1)
+ {
+ x1 = bufferX1;
+ }
+
+ if (x2 > bufferX2)
+ {
+ x2 = bufferX2;
+ }
+
+ if (y1 < bufferY1)
+ {
+ y1 = bufferY1;
+ }
+
+ if (y2 > bufferY2)
+ {
+ y2 = bufferY2;
+ }
+
+ width = x2 - x1 + 1;
+ height = y2 - y1 + 1;
+
+ bufferWidth = bufferInfo.width;
+
+ if (bufferInfo.bitsPerPixel == 16)
+ {
+
+ color16 = static_cast<unsigned short>(COLOR32ToCOLOR16(color.GetRGB32()));
+ pBuffer16 = static_cast<unsigned short*>(bufferInfo.pPixels);
+
+ alphaLevel = 100 - static_cast<int>(static_cast<float>(color.GetAlpha() / 2.56));
+ srcLevel = alphaLevel;
+ destLevel = 100 - alphaLevel;
+
+ srcR = static_cast<byte>(color16 >> 11);
+ srcG = static_cast<byte>((color16 >> 6) & 0x001F);
+ srcB = static_cast<byte>(color16 & 0x001F);
+
+ for (y = y1; y < y1 + height; y++)
+ {
+ for (x = x1; x < x1 + width; x++)
+ {
+ offset = bufferWidth * y + x;
+ destR = static_cast<byte>(pBuffer16[offset] >> 11);
+ destG = static_cast<byte>((pBuffer16[offset] >> 6) & 0x001F);
+ destB = static_cast<byte>(pBuffer16[offset] & 0x001F);
+
+ r = (destR * destLevel + srcR * srcLevel) / 100;
+ g = (destG * destLevel + srcG * srcLevel) / 100;
+ b = (destB * destLevel + srcB * srcLevel) / 100;
+
+ destR = static_cast<byte>(r);
+ destG = static_cast<byte>(g);
+ destB = static_cast<byte>(b);
+ pBuffer16[offset] = static_cast<unsigned short>((destR << 11) | (destG << 6) | (destB));
+ }
+ }
+ }
+ else if (bufferInfo.bitsPerPixel == 32)
+ {
+ pBuffer32 = static_cast<unsigned long*>(bufferInfo.pPixels);
+
+ for (y = y1; y < y1 + height; y++)
+ {
+ for (x = x1; x < x1 + width; x++)
+ {
+ offset = bufferWidth * y + x;
+ pBuffer32[offset] = color.GetRGB32();
+ }
+ }
+ }
+
+ _pCanvas->Unlock();
+ }
+};
+
+
+class ColorTablePainter
+ : public Painter
+{
+public:
+ ColorTablePainter(const Control& control)
+ : Painter(control)
+ , __x(0)
+ , __y(0)
+ , __width(25)
+ , __height(25)
+ , __red(0)
+ , __green(0)
+ , __blue(0)
+ , __alpha(0xFF)
+ {
+ }
+
+ bool Draw(void)
+ {
+ if (__y >= _bounds.height)
+ {
+ return false;
+ }
+
+ Color color(__red, __green, __blue, __alpha);
+
+ _pCanvas->FillRectangle(color, Rectangle(__x, __y, __width, __height));
+
+ _pCanvas->Show();
+
+ if (__red < 0xFF)
+ {
+ __red++;
+ }
+
+ if (__red >= 0xFF && __green < 0xFF)
+ {
+ __green++;
+ }
+
+ if (__green >= 0xFF && __blue < 0xFF)
+ {
+ __blue++;
+ }
+
+ __x += __width;
+
+ if (__x >= _bounds.width)
+ {
+ __x = 0;
+ __y += __height;
+ }
+
+ return true;
+ }
+
+private:
+ int __x;
+ int __y;
+ int __width;
+ int __height;
+ byte __red;
+ byte __green;
+ byte __blue;
+ byte __alpha;
+};
+
+
+DrawingBoard::DrawingBoard()
+ : __pForm(null)
+ , __pPainter(null)
+ , __pTimer(null)
+ , __scenarioIndex(0)
+{
+}
+
+
+DrawingBoard::~DrawingBoard()
+{
+}
+
+
+Application*
+DrawingBoard::CreateInstance(void)
+{
+ // You can create the instance through another constructor.
+ return new (std::nothrow) DrawingBoard();
+}
+
+bool
+DrawingBoard::OnAppInitializing(AppRegistry& appRegistry)
+{
+ Frame* pAppFrame = new (std::nothrow) Frame();
+
+ pAppFrame->Construct();
+
+ this->AddFrame(*pAppFrame);
+
+ result r = E_SUCCESS;
+
+ __pForm = new (std::nothrow) DrawingForm(this);
+ TryCatch(__pForm != null, , "Failed to allocate memory.");
+
+ r = __pForm->Construct(FORM_STYLE_NORMAL);
+ TryCatch(!IsFailed(r), , "__pForm->Construct(FORM_STYLE_NORMAL) failed.");
+
+ __pForm->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
+ r = this->GetAppFrame()->GetFrame()->AddControl(__pForm);
+ TryCatch(!IsFailed(r), , "__pForm->Construct(FORM_STYLE_NORMAL) failed.");
+
+ __pForm->AddKeyEventListener(*this);
+
+ __pTimer = new (std::nothrow) Timer;
+ TryCatch(__pTimer != null, , "Failed to allocate memory.");
+
+ r = __pTimer->Construct(*this);
+ TryCatch(!IsFailed(r), , "Failed to construct timer.");
+
+ return true;
+
+CATCH:
+ delete __pForm;
+ __pForm = null;
+
+ if (__pTimer != null)
+ {
+ __pTimer->Cancel();
+
+ delete __pTimer;
+ __pTimer = null;
+ }
+
+ return false;
+}
+
+
+bool
+DrawingBoard::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
+{
+ if (__pTimer != null)
+ {
+ __pTimer->Cancel();
+
+ delete __pTimer;
+ __pTimer = null;
+ }
+
+ if (__pPainter != null)
+ {
+ delete __pPainter;
+ __pPainter = null;
+ }
+
+ return true;
+}
+
+
+void
+DrawingBoard::OnForeground(void)
+{
+ if (__pTimer != null)
+ {
+ __pTimer->Start(TIME_OUT);
+ }
+}
+
+
+void
+DrawingBoard::OnBackground(void)
+{
+ if (__pTimer != null)
+ {
+ __pTimer->Cancel();
+ }
+
+ if (__pForm != null)
+ {
+ Canvas* pCanvas = __pForm->GetCanvasN();
+
+ pCanvas->SetBackgroundColor(Color(0x00000000));
+ pCanvas->Clear();
+
+ pCanvas->Show();
+
+ delete pCanvas;
+ }
+}
+
+
+void
+DrawingBoard::OnLowMemory(void)
+{
+}
+
+
+void
+DrawingBoard::OnBatteryLevelChanged(BatteryLevel batteryLevel)
+{
+}
+
+
+void
+DrawingBoard::OnTimerExpired(Timer& timer)
+{
+ if (__pTimer == null)
+ {
+ return;
+ }
+
+ if (__pPainter == null)
+ {
+ ChangePainter();
+ }
+ else
+ {
+ bool result = __pPainter->Draw();
+
+ if (!result)
+ {
+ ChangePainter();
+ }
+ }
+
+ __pTimer->Start(TIME_OUT);
+}
+
+void
+DrawingBoard::ChangePainter()
+{
+ if (__pForm == null)
+ {
+ return;
+ }
+
+ delete __pPainter;
+ __pPainter = null;
+
+ switch (__scenarioIndex)
+ {
+ case 0:
+ __pPainter = new (std::nothrow) PixelPainter(*__pForm);
+ break;
+ case 1:
+ __pPainter = new (std::nothrow) LinePainter(*__pForm);
+ break;
+ case 2:
+ __pPainter = new (std::nothrow) TrianglePainter(*__pForm);
+ break;
+ case 3:
+ __pPainter = new (std::nothrow) RectanglePainter(*__pForm);
+ break;
+ case 4:
+ __pPainter = new (std::nothrow) RoundRectanglePainter(*__pForm);
+ break;
+ case 5:
+ __pPainter = new (std::nothrow) EllipsePainter(*__pForm);
+ break;
+ case 6:
+ __pPainter = new (std::nothrow) ArcPainter(*__pForm);
+ break;
+ case 7:
+ __pPainter = new (std::nothrow) TextPainter(*__pForm);
+ break;
+ case 8:
+ __pPainter = new (std::nothrow) BitmapPainter(*__pForm);
+ break;
+ case 9:
+ __pPainter = new (std::nothrow) DirectBufferPainter(*__pForm);
+ break;
+ case 10:
+ __pPainter = new (std::nothrow) ColorTablePainter(*__pForm);
+ break;
+ case 11:
+ __pPainter = new (std::nothrow) PolylinePainter(*__pForm);
+ break;
+ case 12:
+ __pPainter = new (std::nothrow) PolygonPainter(*__pForm);
+ break;
+ default:
+ __scenarioIndex = 0;
+ break;
+ }
+
+ __scenarioIndex++;
+
+ if (__scenarioIndex > 12)
+ {
+ __scenarioIndex = 0;
+ }
+}
+
+void
+DrawingBoard::Draw(void)
+{
+ if (__pPainter != null)
+ {
+ __pPainter->Draw();
+ }
+}
+
+void
+DrawingBoard::OnScreenOn (void)
+{
+}
+
+void
+DrawingBoard::OnScreenOff (void)
+{
+}
+
+void
+DrawingBoard::OnKeyPressed(const Control& source, Tizen::Ui::KeyCode keyCode)
+{
+}
+
+void
+DrawingBoard::OnKeyReleased(const Control& source, Tizen::Ui::KeyCode keyCode)
+{
+ if (keyCode == Tizen::Ui::KEY_BACK || keyCode == Tizen::Ui::KEY_ESC)
+ {
+ Terminate();
+ }
+}
+
+void
+DrawingBoard::OnKeyLongPressed(const Control& source, Tizen::Ui::KeyCode keyCode)
+{
+}
diff --git a/project/src/DrawingBoardEntry.cpp b/project/src/DrawingBoardEntry.cpp
new file mode 100644
index 0000000..0b1438a
--- /dev/null
+++ b/project/src/DrawingBoardEntry.cpp
@@ -0,0 +1,65 @@
+//
+// Tizen C++ SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.1 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * This file contains the Tizen C++ application entry point.
+ */
+#include <new>
+#include "DrawingBoard.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+
+_EXPORT_ int OspMain(int argc, char* pArgv[]);
+
+
+/**
+ * The entry function of Tizen C++ application called by the operating system.
+ */
+int
+OspMain(int argc, char* pArgv[])
+{
+ AppLog("Application started.");
+ ArrayList args;
+ args.Construct();
+
+ for (int i = 0; i < argc; i++)
+ {
+ args.Add(*(new (std::nothrow) String(pArgv[i])));
+ }
+
+ result r = Tizen::App::Application::Execute(DrawingBoard::CreateInstance, &args);
+
+ if (IsFailed(r))
+ {
+ AppLogException("Application execution failed-[%s].", GetErrorMessage(r));
+ }
+
+ args.RemoveAll(true);
+ AppLog("Application finished.");
+
+ return static_cast<int>(r);
+}
+#ifdef __cplusplus
+}
+#endif // __cplusplus