a8a79e3ecbf790822238ef7312cd1e6e6779de19
[apps/native/sample/BasicApp.git] / project / src / ImagePanel.cpp
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 #include <FApp.h>
19 #include <FMedia.h>
20
21 #include "ImagePanel.h"
22
23 using namespace Tizen::App;
24 using namespace Tizen::Base;
25 using namespace Tizen::Io;
26 using namespace Tizen::Ui;
27 using namespace Tizen::Ui::Controls;
28 using namespace Tizen::Media;
29 using namespace Tizen::Graphics;
30
31 ImagePanel::ImagePanel(void)
32         : __pTizenBitmap(null)
33 {
34 }
35
36 ImagePanel::~ImagePanel(void)
37 {
38 }
39
40 result
41 ImagePanel::Initialize(Tizen::Graphics::Rectangle rect)
42 {
43         return Panel::Construct(rect);
44 }
45
46 result
47 ImagePanel::OnInitializing(void)
48 {
49         Image image;
50         result r = image.Construct();
51         String filepath = App::GetInstance()->GetAppResourcePath() + L"screen-density-xhigh/tizen.png";
52
53         __pTizenBitmap = image.DecodeN(filepath, BITMAP_PIXEL_FORMAT_ARGB8888);
54
55         return r;
56 }
57
58 result
59 ImagePanel::OnTerminating(void)
60 {
61         result r = E_SUCCESS;
62
63         delete __pTizenBitmap;
64         return r;
65 }
66
67 result
68 ImagePanel::OnDraw(void)
69 {
70         result r = E_SUCCESS;
71
72         Canvas* pCanvas = GetCanvasN();
73
74         if (pCanvas != null && __pTizenBitmap != null)
75         {
76                 Rectangle rect = GetBounds();
77
78                 float widthRatio = float(rect.width) / __pTizenBitmap->GetWidth();
79                 float heightRatio = float(rect.height) / __pTizenBitmap->GetHeight();
80                 float ratio = (widthRatio > heightRatio) ? heightRatio : widthRatio;
81
82                 int height = int(__pTizenBitmap->GetHeight() * ratio);
83                 int width = int(__pTizenBitmap->GetWidth() * ratio);
84
85                 r = pCanvas->DrawBitmap(Rectangle((rect.width - width) / 2, (rect.height - height) / 2, width, height), *__pTizenBitmap);
86         }
87
88         delete pCanvas;
89
90         return r;
91 }
92
93 void 
94 ImagePanel::OnOrientationChanged(const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
95 {
96         Form *pForm = static_cast<Form *>(GetParent());
97
98         if (pForm != null)
99         {
100                 Rectangle clientRect = pForm->GetClientAreaBounds();
101                 Rectangle rect(0, 0, clientRect.width, clientRect.height);
102
103                 SetBounds(rect);
104         }
105         Invalidate(true);
106 }