[BasicApp] Change license statements
[apps/native/sample/BasicApp.git] / project / src / ImagePanel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include <FApp.h>
18 #include <FMedia.h>
19
20 #include "ImagePanel.h"
21
22 using namespace Tizen::App;
23 using namespace Tizen::Base;
24 using namespace Tizen::Io;
25 using namespace Tizen::Ui;
26 using namespace Tizen::Ui::Controls;
27 using namespace Tizen::Media;
28 using namespace Tizen::Graphics;
29
30 ImagePanel::ImagePanel(void)
31         : __pTizenBitmap(null)
32 {
33 }
34
35 ImagePanel::~ImagePanel(void)
36 {
37 }
38
39 result
40 ImagePanel::Initialize(Tizen::Graphics::Rectangle rect)
41 {
42         return Panel::Construct(rect);
43 }
44
45 result
46 ImagePanel::OnInitializing(void)
47 {
48         Image image;
49         result r = image.Construct();
50         String filepath = App::GetInstance()->GetAppResourcePath() + L"screen-density-xhigh/tizen.png";
51
52         __pTizenBitmap = image.DecodeN(filepath, BITMAP_PIXEL_FORMAT_ARGB8888);
53
54         return r;
55 }
56
57 result
58 ImagePanel::OnTerminating(void)
59 {
60         result r = E_SUCCESS;
61
62         delete __pTizenBitmap;
63         return r;
64 }
65
66 result
67 ImagePanel::OnDraw(void)
68 {
69         result r = E_SUCCESS;
70
71         Canvas* pCanvas = GetCanvasN();
72
73         if (pCanvas != null && __pTizenBitmap != null)
74         {
75                 Rectangle rect = GetBounds();
76
77                 float widthRatio = float(rect.width) / __pTizenBitmap->GetWidth();
78                 float heightRatio = float(rect.height) / __pTizenBitmap->GetHeight();
79                 float ratio = (widthRatio > heightRatio) ? heightRatio : widthRatio;
80
81                 int height = int(__pTizenBitmap->GetHeight() * ratio);
82                 int width = int(__pTizenBitmap->GetWidth() * ratio);
83
84                 r = pCanvas->DrawBitmap(Rectangle((rect.width - width) / 2, (rect.height - height) / 2, width, height), *__pTizenBitmap);
85         }
86
87         delete pCanvas;
88
89         return r;
90 }
91
92 void 
93 ImagePanel::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
94 {
95         Form *pForm = static_cast<Form *>(GetParent());
96
97         if (pForm != null)
98         {
99                 Rectangle clientRect = pForm->GetClientAreaBounds();
100                 Rectangle rect(0, 0, clientRect.width, clientRect.height);
101
102                 SetBounds(rect);
103         }
104         Invalidate(true);
105 }