3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.tizenopensource.org/license
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
22 using namespace Osp::Base;
23 using namespace Osp::Ui;
24 using namespace Osp::Ui::Controls;
25 using namespace Osp::App;
26 using namespace Osp::Graphics;
28 MainForm::MainForm(void)
32 MainForm::~MainForm(void)
37 MainForm::Initialize(void)
39 Form::Construct(FORM_STYLE_NORMAL|FORM_STYLE_HEADER|FORM_STYLE_INDICATOR);
43 Header* pHeader = this->GetHeader();
44 pHeader->SetTitleText(L"RockPaperScissors");
50 MainForm::OnInitializing(void)
54 Button *pBtnStart = new (std::nothrow) Button();
55 TryReturn(pBtnStart != null, E_FAILURE, "[Fail]Button Create");
57 Rectangle clientAreaBound = GetClientAreaBounds();
58 int buttonX = static_cast<int>(clientAreaBound.width * 0.33); // 1/3 Down
59 int buttonY = static_cast<int>(clientAreaBound.height * 0.75); // 3/4
60 int buttonWidth = static_cast<int>(clientAreaBound.width * 0.34); // 1/3 Up
61 int buttonHeight = static_cast<int>(clientAreaBound.height * 0.14); // 1/7
63 pBtnStart->Construct(Rectangle(buttonX, buttonY, buttonWidth, buttonHeight));
64 pBtnStart->SetText(L"Start");
65 pBtnStart->SetActionId(IDC_BTN_START);
66 pBtnStart->AddActionEventListener(*this);
67 AddControl(*pBtnStart);
73 MainForm::OnTerminating(void)
79 MainForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
81 Frame *pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
87 FormMgr *pFormMgr = static_cast<FormMgr *>(pFrame->GetControl("FormMgr"));
91 pFormMgr->SendUserEvent(FormMgr::REQUEST_ROCKPAPERSCISSORSFORM , null);
102 MainForm::OnDraw(void)
104 result r = E_SUCCESS;
106 Osp::Graphics::Canvas* __pCanvas = GetCanvasN();
108 if(__pCanvas != null)
112 static Rectangle clientAreaBound = GetClientAreaBounds();
113 static int rectMarginX = static_cast<int>(clientAreaBound.width * 0.03); // 1/32 Down
114 static int rectMarginY = static_cast<int>(clientAreaBound.height * 0.25); // 1/3 Down
115 static int rectX = clientAreaBound.x + rectMarginX;
116 static int rectY = clientAreaBound.y + rectMarginY;
117 static int rectWidth = clientAreaBound.width - (rectMarginX * 2);
118 static int rectHeight = static_cast<int>(clientAreaBound.height * 0.45); // 1/2
119 static int titleHeight = static_cast<int>(rectHeight * 0.167); // rectHeight/6
121 static int HEAD_FONT_SIZE = static_cast<int>(titleHeight * 0.7);
122 static int BODY_FONT_SIZE = static_cast<int>(titleHeight * 0.45);
124 static int lineStartX = rectX;
125 static int lineEndX = lineStartX + rectWidth;
126 static int lineY = rectY + titleHeight;
128 static int headX = rectX;
129 static int headY = rectY;
131 static int textX = headX + rectMarginX;
132 static int textY = lineY + rectMarginX;
133 static int textGapY = BODY_FONT_SIZE + rectMarginX;
134 static String text0(L"<How to play this game>");
135 static String text1(L"This game can join up to 4 people.");
136 static String text2(L"1. Choose the number.");
137 static String text3(L"2. Press the start button.");
138 static String text4(L"3. To stop, place a hand");
139 static String text5(L"across & near the top of the phone.");
141 __pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
142 __pCanvas->SetForegroundColor(Color::GetColor(COLOR_ID_YELLOW));
145 font.Construct(FONT_STYLE_PLAIN || FONT_STYLE_BOLD, HEAD_FONT_SIZE);
146 __pCanvas->SetFont(font);
147 __pCanvas->DrawRectangle(Rectangle(rectX, rectY, rectWidth, rectHeight));
148 __pCanvas->DrawText(Point(headX, headY), text0);
149 __pCanvas->DrawLine(Point(lineStartX, lineY), Point(lineEndX, lineY));
151 font.Construct(FONT_STYLE_PLAIN, BODY_FONT_SIZE);
152 __pCanvas->SetFont(font);
153 __pCanvas->DrawText(Point(headX, textY), text1);
154 __pCanvas->DrawText(Point(textX, textY + textGapY), text2);
155 __pCanvas->DrawText(Point(textX, textY + (textGapY * 2)), text3);
156 __pCanvas->DrawText(Point(textX, textY + (textGapY * 3)), text4);
157 __pCanvas->DrawText(Point(textX, textY + (textGapY * 4)), text5);