Add Crop opeation
[apps/osp/ImageViewer.git] / src / IvImageCropForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (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 /**
18  * @file                IvImageCrop.cpp
19  * @brief               This is the implementation file for Image Crop.
20  */
21
22 #include <FApp.h>
23 #include <FMedia.h>
24 #include "IvImageCropForm.h"
25 #include "IvImageViewerPresentationModel.h"
26 #include "IvResourceManager.h"
27 #include "IvTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Content;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Io;
35 using namespace Tizen::Media;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
38
39 static const unsigned int CROP_BOX_RECTANGLE_COLOR = Color32<199, 110, 6>::Value;
40 static const int CROP_BOX_LINE_WIDTH = 5;
41
42 ImageCropForm::ImageCropForm(void)
43         : __imageHeight(0)
44         , __imageWidth(0)
45         , __isOrientationChanged(false)
46         , __pCanvas(null)
47         , __pCurrentBitmap(null)
48         , __pRectangleBitmap(null)
49         , __pointLocation(OUTSIDE_CROPBOX)
50         , __pPresentationModel(null)
51 {
52 }
53
54 ImageCropForm::~ImageCropForm(void)
55 {
56         if (__pCurrentBitmap != null)
57         {
58                 delete __pCurrentBitmap;
59         }
60         if (__pRectangleBitmap != null)
61         {
62                 delete __pRectangleBitmap;
63         }
64         if (__pCanvas != null)
65         {
66                 delete __pCanvas;
67         }
68 }
69
70 bool
71 ImageCropForm::Initialize(void)
72 {
73         Form::Construct(IDL_FORM_IMAGE_CROP);
74         Form::SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR);
75
76         __pPresentationModel = ImageViewerPresentationModel::GetInstance();
77
78         return true;
79 }
80
81 result
82 ImageCropForm::OnInitializing(void)
83 {
84         result r = E_SUCCESS;
85
86         AppResource* pAppResource = null;
87         Bitmap* pSaveButtonBitmap = null;
88         Bitmap* pCancelButtonBitmap  = null;
89         Bitmap* pCWRotationButtonBitmap  = null;
90         Bitmap* pCCWRotationButtonBitmap  = null;
91         Panel* pPanel = null;
92         Button* pSaveButton = null;
93         Button* pCancelButton = null;
94         pAppResource = UiApp::App::GetInstance()->GetAppResource();
95         if (pAppResource != null)
96         {
97                 pSaveButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_SAVE_ICON);
98                 pCancelButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CANCEL_ICON);
99                 pCWRotationButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CW_ROTATION_ICON);
100                 pCCWRotationButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CCW_ROTATION_ICON);
101                 __pRectangleBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_RECTANGLE);
102         }
103
104         pPanel = static_cast<Panel*>(GetControl(L"IDC_FOOTER_PANEL"));
105         if (pPanel != null)
106         {
107                 pSaveButton = static_cast<Button*>(pPanel->GetControl(L"IDC_SAVE_BUTTON"));
108                 if (pSaveButton != null)
109                 {
110                         Point startPoint((pSaveButton->GetWidth() - pSaveButtonBitmap->GetWidth()) / 2,
111                                         (pSaveButton->GetHeight() - pSaveButtonBitmap->GetHeight()) / 2);
112                         pSaveButton->SetNormalBitmap(startPoint, *pSaveButtonBitmap);
113                         pSaveButton->AddActionEventListener(*this);
114                         pSaveButton->SetActionId(IDA_BUTTON_SAVE);
115                 }
116
117                 pCancelButton = static_cast<Button*>(pPanel->GetControl(L"IDC_CANCEL_BUTTON"));
118                 if (pCancelButton != null)
119                 {
120                         Point startPoint((pCancelButton->GetWidth() - pCancelButtonBitmap->GetWidth()) / 2,
121                                         (pCancelButton->GetHeight() - pCancelButtonBitmap->GetHeight()) / 2);
122                         pCancelButton->SetNormalBitmap(startPoint, *pCancelButtonBitmap);
123                         pCancelButton->AddActionEventListener(*this);
124                         pCancelButton->SetActionId(IDA_BUTTON_CANCEL);
125                 }
126                 Label* pLabel = static_cast<Label*>(pPanel->GetControl(L"IDC_PANEL_LABEL"));
127                 if (pLabel != null)
128                 {
129                         SetControlAlwaysOnTop(*pPanel, true);
130                 }
131                 SetControlAlwaysAtBottom(*pLabel, true);
132         }
133         AddTouchEventListener(*this);
134         AddOrientationEventListener(*this);
135
136         delete pSaveButtonBitmap;
137         delete pCancelButtonBitmap;
138         delete pCWRotationButtonBitmap;
139         delete pCCWRotationButtonBitmap;
140         return r;
141 }
142
143 void
144 ImageCropForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
145 {
146         AppLogDebug("ENTER pArgs(%x)", pArgs);
147         String filePath;
148         if (pArgs != null)
149         {
150                 filePath = *(static_cast<String*>(pArgs->GetAt(0)));
151                 delete pArgs;
152         }
153         else
154         {
155                 filePath = __pPresentationModel->GetFilePathAt(0);
156         }
157
158         if (filePath.IsEmpty() == false)
159         {
160                 __sourceFilePath.Append(filePath);
161                 result r = __imageBuffer.Construct(__sourceFilePath.GetPointer());
162                 if (r == E_SUCCESS)
163                 {
164                         __imageWidth = __imageBuffer.GetWidth();
165                         __imageHeight = __imageBuffer.GetHeight();
166                         __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO);
167                 }
168                 Image img;
169                 __imageFormat = img.GetImageFormat(__sourceFilePath);
170         }
171         SetValue();
172         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
173 }
174
175 void
176 ImageCropForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
177 {
178         AppLogDebug("ENTER");
179         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
180 }
181
182 result
183 ImageCropForm::OnDraw(void)
184 {
185         result r = E_SUCCESS;
186         AppLogDebug("ENTER");
187         if (__pCanvas != null)
188         {
189                 r = __pCanvas->SetLineWidth(CROP_BOX_LINE_WIDTH);
190                 r = __pCanvas->DrawBitmap(Rectangle(__imageBox.x, __imageBox.y, __imageBox.width, __imageBox.height), *__pCurrentBitmap);
191                 r = __pCanvas->DrawRectangle(Rectangle(__cropBox.x, __cropBox.y, __cropBox.width, __cropBox.height));
192                 r = __pCanvas->DrawBitmap(Rectangle((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2), __cropBox.y - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Top Rectangle
193                 r = __pCanvas->DrawBitmap(Rectangle((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Bottom Rectangle
194                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); //Left Rectangle
195                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); //Right Rectangle
196                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2), __cropBox.y - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Top Left Rectangle
197                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2), __cropBox.y - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Top Right Rectangle
198                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Bottom Right Rectangle
199                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Bottom Left Rectangle
200         }
201         AppLogDebug("EXIT");
202         return r;
203 }
204
205 void
206 ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
207 {
208         SceneManager* pSceneManager = SceneManager::GetInstance();
209         switch(actionId)
210         {
211         case IDA_BUTTON_CANCEL:
212                 pSceneManager->GoBackward(BackwardSceneTransition());
213                 break;
214         case IDA_BUTTON_SAVE:
215         {
216                 ImageBuffer* pCropBuffer = null;
217                 int count = 1;
218                 int index = 0;
219                 String destFilePath;
220                 String stringToInsert = L"_";
221                 String delimiter = L".";
222                 if (__sourceFilePath.IsEmpty() == false)
223                 {
224                         __sourceFilePath.Reverse();
225                         __sourceFilePath.IndexOf(delimiter, 0, index);
226                         __sourceFilePath.Reverse();
227                         __sourceFilePath.Insert(stringToInsert, __sourceFilePath.GetLength() - index - 1);
228                         destFilePath.Append(__sourceFilePath);
229                         destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
230                         while (File::IsFileExist(destFilePath) == true)
231                         {
232                                 count++;
233                                 destFilePath.Clear();
234                                 destFilePath.Append(__sourceFilePath);
235                                 destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
236                         }
237                         pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
238                                                 (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
239                         pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
240                         ContentManager::ScanFile(destFilePath);
241                         delete pCropBuffer;
242                 }
243                 pSceneManager->GoBackward(BackwardSceneTransition());
244                 AppLog("Exit");
245         }
246         break;
247         }
248 }
249
250 void
251 ImageCropForm::OnOrientationChanged(const Control &source, OrientationStatus orientationStatus)
252 {
253         AppLogDebug("ENTER");
254         __isOrientationChanged = true;
255         SetValue();
256         __pCanvas->Clear();
257         AppLogDebug("EXIT");
258 }
259
260 void
261 ImageCropForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
262 {
263         AppLogDebug("ENTER");
264         __touchStart = currentPosition;
265         CheckCurrentPosition(currentPosition);
266         AppLogDebug("EXIT");
267 }
268
269 void
270 ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
271 {
272         AppLogDebug("ENTER");
273         int deltaX = currentPosition.x - __touchStart.x;
274         int deltaY = currentPosition.y - __touchStart.y;
275         switch(__pointLocation)
276         {
277         case INSIDE_TOP_RECTANGLE:
278         {
279                 if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3)))
280                 {
281                         __cropBox.y += deltaY;
282                         __cropBox.height -= deltaY;
283                 }
284         }
285         break;
286
287         case INSIDE_BOTTOM_RECTANGLE:
288         {
289                 if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height)
290                         && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
291                 {
292                         __cropBox.height += deltaY;
293                 }
294         }
295         break;
296
297         case INSIDE_LEFT_RECTANGLE:
298         {
299                 if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
300                 {
301                         __cropBox.x += deltaX;
302                         __cropBox.width -= deltaX;
303                 }
304         }
305         break;
306
307         case INSIDE_RIGHT_RECTANGLE:
308         {
309                 if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width)
310                         && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
311                 {
312                         __cropBox.width += deltaX;
313                 }
314         }
315         break;
316
317         case INSIDE_TOP_LEFT_RECTANGLE:
318         {
319                 if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
320                                 && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
321                 {
322                         __cropBox.y += deltaY;
323                         __cropBox.height -= deltaY;
324                         __cropBox.x += deltaX;
325                         __cropBox.width -= deltaX;
326                 }
327         }
328         break;
329
330         case INSIDE_TOP_RIGHT_RECTANGLE:
331         {
332                 if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
333                                 && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
334                 {
335                         __cropBox.width += deltaX;
336                         __cropBox.y += deltaY;
337                         __cropBox.height -= deltaY;
338                 }
339         }
340         break;
341
342         case INSIDE_BOTTOM_LEFT_RECTANGLE:
343         {
344                 if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3)
345                         && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
346                 {
347                         __cropBox.x += deltaX;
348                         __cropBox.width -= deltaX;
349                         __cropBox.height += deltaY;
350                 }
351         }
352         break;
353
354         case INSIDE_BOTTOM_RIGHT_RECTANGLE:
355         {
356                 if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3)
357                         && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
358                 {
359                         __cropBox.width += deltaX;
360                         __cropBox.height += deltaY;
361                 }
362         }
363         break;
364
365         case INSIDE_CROPBOX:
366         {
367                 if ((__cropBox.x + deltaX) > __imageBox.x)
368                 {
369                         __cropBox.x += deltaX;
370                 }
371                 else
372                 {
373                         __cropBox.x = __imageBox.x;
374                 }
375                 if ((__cropBox.y + deltaY) > __imageBox.y)
376                 {
377                         __cropBox.y += deltaY;
378                 }
379                 else
380                 {
381                         __cropBox.y = __imageBox.y;
382                 }
383                 if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
384                 {
385                         __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
386                 }
387                 if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
388                 {
389                         __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
390                 }
391         }
392         break;
393
394         default:
395                 break;
396         }
397         RequestRedraw(false);
398         __touchStart = currentPosition;
399         AppLogDebug("EXIT");
400 }
401
402 void
403 ImageCropForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
404 {
405         AppLogDebug("ENTER");
406         __pointLocation = OUTSIDE_CROPBOX;
407         AppLogDebug("EXIT");
408 }
409
410 void
411 ImageCropForm::CheckCurrentPosition(const Point currentPosition)
412 {
413         AppLogDebug("ENTER");
414         if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
415                 && currentPosition.y >  (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + (CROP_RECTANGLE_HEIGHT / 2)))
416         {
417                 __pointLocation = INSIDE_TOP_RECTANGLE;
418         }
419         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
420                 && currentPosition.y >  ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
421         {
422                 __pointLocation = INSIDE_LEFT_RECTANGLE;
423         }
424         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
425                 && currentPosition.y > ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
426         {
427                 __pointLocation = INSIDE_RIGHT_RECTANGLE;
428         }
429         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
430                 && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
431         {
432                 __pointLocation = INSIDE_BOTTOM_RECTANGLE;
433         }
434         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
435                          && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
436         {
437                 __pointLocation = INSIDE_TOP_LEFT_RECTANGLE;
438         }
439         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
440                         && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
441         {
442                 __pointLocation = INSIDE_TOP_RIGHT_RECTANGLE;
443         }
444         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
445                         && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
446         {
447                 __pointLocation = INSIDE_BOTTOM_RIGHT_RECTANGLE;
448         }
449         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
450                         && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
451         {
452                 __pointLocation = INSIDE_BOTTOM_LEFT_RECTANGLE;
453         }
454         else if (currentPosition.x > __cropBox.x && currentPosition.x < (__cropBox.x + __cropBox.width) && currentPosition.y > __cropBox.y && currentPosition.y < (__cropBox.y + __cropBox.height))
455         {
456                 __pointLocation = INSIDE_CROPBOX;
457         }
458         else
459         {
460                 __pointLocation = OUTSIDE_CROPBOX;
461         }
462         AppLogDebug("EXIT");
463         return;
464 }
465
466 void
467 ImageCropForm::SetValue(void)
468 {
469         int prevHeight = __imageBox.height;
470         int prevWidth = __imageBox.width;
471         int prevImageboxX = __imageBox.x;
472         int prevImageBoxY = __imageBox.y;
473         int indicatorBarHeight = 0;
474
475         if (GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
476         {
477                 indicatorBarHeight = 21;
478         }
479         else
480         {
481                 indicatorBarHeight = 60;
482         }
483
484         if (__imageWidth > GetClientAreaBounds().width && __imageHeight > GetClientAreaBounds().height)
485         {
486                 if (__imageHeight > __imageWidth)
487                 {
488                         __imageBox.height = GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT;
489                         __imageBox.width = (__imageWidth * GetClientAreaBounds().height) / __imageHeight;
490                         __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
491                         __imageBox.y = indicatorBarHeight;
492                 }
493                 else
494                 {
495                         __imageBox.width = GetClientAreaBounds().width;
496                         __imageBox.height = (GetClientAreaBounds().width * __imageHeight) / __imageWidth;
497                         __imageBox.x = 0;
498                         __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2;
499                 }
500         }
501         else if (__imageWidth > GetClientAreaBounds().width)
502         {
503                 __imageBox.width = GetClientAreaBounds().width;
504                 __imageBox.height = (__imageHeight * GetClientAreaBounds().width) / __imageWidth;
505                 __imageBox.x = 0;
506                 __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2;
507
508         }
509         else if (__imageHeight > GetClientAreaBounds().height)
510         {
511                 __imageBox.height = GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT;
512                 __imageBox.width = (__imageWidth * GetClientAreaBounds().height) / __imageHeight;
513                 __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
514                 __imageBox.y = indicatorBarHeight;
515         }
516         else
517         {
518                 __imageBox.height = __imageHeight;
519                 __imageBox.width = __imageWidth;
520                 __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
521                 __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2 ;
522         }
523         if (__isOrientationChanged == false)
524         {
525                 if (__imageHeight >= __imageWidth)
526                 {
527                         __cropBox.height = __imageBox.height / 2;
528                         __cropBox.width = __imageBox.width / 2;
529                         __cropBox.y =  __imageBox.y + (__imageBox.height / 4);
530                         __cropBox.x = __imageBox.x + (__imageBox.width / 4);
531                 }
532                 else
533                 {
534                         __cropBox.height = (2 * __imageBox.height) / 3;
535                         __cropBox.width = (2 * __imageBox.width) / 3;
536                         __cropBox.y = __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
537                         __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
538                 }
539         }
540         else
541         {
542                 float temp = __imageBox.x + ((__cropBox.x - prevImageboxX) * __imageBox.width) / (float)prevWidth;
543                 __cropBox.x = (temp + 0.5);
544                 temp = __imageBox.y + ((__cropBox.y - prevImageBoxY) * __imageBox.height) / (float)prevHeight;
545                 __cropBox.y = (temp + 0.5);
546                 temp = (__cropBox.height * __imageBox.height) / (float)prevHeight;
547                 __cropBox.height = (temp + 0.5);
548                 temp = (__cropBox.width * __imageBox.width) / (float)prevWidth;
549                 __cropBox.width = (temp + 0.5);
550         }
551         __pCanvas = GetCanvasN();
552         __pCanvas->SetForegroundColor(CROP_BOX_RECTANGLE_COLOR);
553 }