diff options
Diffstat (limited to 'widget/src/scissorbox/ScissorBox.cpp')
-rwxr-xr-x | widget/src/scissorbox/ScissorBox.cpp | 1727 |
1 files changed, 1727 insertions, 0 deletions
diff --git a/widget/src/scissorbox/ScissorBox.cpp b/widget/src/scissorbox/ScissorBox.cpp new file mode 100755 index 0000000..6472842 --- /dev/null +++ b/widget/src/scissorbox/ScissorBox.cpp @@ -0,0 +1,1727 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.tizenopensource.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 "ScissorBox.h" + +#undef LOG_LVL +#define LOG_LVL DBG_MSG_LVL_HIGH + +#undef LOG_CAT +#define LOG_CAT "IV-SCISSOR" + +#define IMAGE_PATH PREFIX"/res/images/"PACKAGE + +#define CROP_POT_PATH IMAGE_PATH"/scissorbox/T01_CallerID_normal.png" +#define CROP_POT_HOLD_PATH IMAGE_PATH"/scissorbox/T01_CallerID_hold.png" +#define CROP_POT_PRESS_PATH IMAGE_PATH"/scissorbox/T01_CallerID_press.png" + +#define CROP_LINEW_PATH IMAGE_PATH"/scissorbox/T01_CallerID_line_W.png" +#define CROP_LINEH_PATH IMAGE_PATH"/scissorbox/T01_CallerID_line_h.png" +#define CROP_LINEW_PRESS_PATH IMAGE_PATH"/scissorbox/T01_CallerID_line_W_press.png" +#define CROP_LINEH_PRESS_PATH IMAGE_PATH"/scissorbox/T01_CallerID_line_h_press.png" + +#define DEFAULT_POT_NUM (4) +#define DEFAULT_DIM_BG_ALPHA (102) + +#undef ALLOW_RECT_TRACE + +class CSelectBox { +public: + enum eState { + NORMAL, + HOLD, + PRESS, + }; + + enum eGripType { + GRIP_LEFT = (1 << 0), + GRIP_RIGHT = (1 << 1), + GRIP_TOP = (1 << 2), + GRIP_BOTTOM = (1 << 3), + }; + +public: + CSelectBox() : m_state(NORMAL), m_ratio(0.0f), m_bPreserve(false), m_rect(), m_bound(0,0,720,1280) + { + }; + + virtual ~CSelectBox() {}; + + virtual void Create(Evas_Object *obj) {}; + + virtual void Move(int x, int y) { + m_rect.Left(x); + m_rect.Top(y); + }; + + virtual void Resize(int w, int h){ + MSG_HIGH("Box resized %dx%d ratio=%f", w, h, m_ratio); + + m_rect.Width(w); + + if ( m_bPreserve == true ) + { + m_rect.Height(w * m_ratio); + } + else + { + m_rect.Height(h); + } + }; + + virtual void SetState(eState state) { + m_state = state; + }; + + virtual eState GetState() const { + return m_state; + }; + + virtual void SetRatio(double ratio) { + m_bPreserve = true; + + m_ratio = ratio; // h / w + }; + + virtual double GetRatio() const { + if ( m_bPreserve == true ) + return m_ratio; + + return 0.0f; + }; + + virtual void SetBound(const CRect &rect) + { + m_bound = rect; + } + + virtual const CRect &GetBound() const { return m_bound; }; + virtual const CRect &GetRegion() const { return m_rect; }; + + virtual void Draw() = 0; +private: + eState m_state; + double m_ratio; + bool m_bPreserve; + +protected: + CRect m_rect; + CRect m_bound; +}; + + +class CBox : public CSelectBox { +public: + const int SHADOW_DEPTH; + const int EVENT_GRIP_SIZE; + const CSize POT_SIZE; + + static void _line_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) {}; + static void _line_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info) {}; + + static void _pot_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox *pBox = (CBox *)data; + +// Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down *) event_info; + + pBox->OnGripMouseDown(); + }; + static void _pot_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info) + { + CBox *pBox = (CBox *)data; + + Evas_Event_Mouse_Move *ev = (Evas_Event_Mouse_Move *) event_info; + + eGripType grip = static_cast<eGripType> (reinterpret_cast<int>
(evas_object_data_get(obj, "grip_type"))); + + if ( ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD ) + { + MSG_HIGH("On Hold"); + } + + if ( ev->event_flags & EVAS_EVENT_FLAG_ON_SCROLL ) + { + MSG_HIGH("On Scroller"); + } + + pBox->OnGripMouseMove(grip, ev->prev.output.x, ev->prev.output.y, ev->cur.output.x, ev->cur.output.y); + }; + + static void _pot_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox *pBox = (CBox *)data; + +// Evas_Event_Mouse_Up *ev = (Evas_Event_Mouse_Up *) event_info; + + pBox->OnGripMouseUp(); + }; + + + static void _selector_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox *pBox = (CBox *)data; + + Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down *) event_info; + + pBox->OnMouseDown(ev->output.x, ev->output.y); + + }; + + static void _selector_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox *pBox = (CBox *)data; + + Evas_Event_Mouse_Move *ev = (Evas_Event_Mouse_Move *) event_info; + + MSG_LOW("(%d,%d) --> (%d,%d)", ev->cur.output.x, ev->cur.output.y, ev->prev.output.x, ev->prev.output.y); + pBox->OnMouseMove(ev->prev.output.x, ev->prev.output.y, ev->cur.output.x, ev->cur.output.y); + }; + + static void _selector_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox *pBox = (CBox *)data; + + Evas_Event_Mouse_Up *ev = (Evas_Event_Mouse_Up *) event_info; + + pBox->OnMouseUp(ev->output.x, ev->output.y); + }; + +public: + CBox() : CSelectBox(), SHADOW_DEPTH(4), EVENT_GRIP_SIZE(60), POT_SIZE(18,18), m_bMouseDown(false), m_bGripMouseDown(false) { }; + + virtual ~CBox() { + MSG_HIGH("Remove CBox"); + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + evas_object_del(selector_line[i]); + evas_object_del(selector_pot[i]); + evas_object_del(event_pot[i]); + } + + evas_object_del(center); + }; + + void OnMouseDown(int x, int y) + { + MSG_HIGH("Mouse down XY(%d,%d)", x, y); + + SetState(PRESS); + m_bMouseDown = true; + } + + void OnMouseMove(int px, int py, int cx, int cy) + { + // Inform changes to parent. + if ( m_bMouseDown == false ) return; + + int dx, dy; + + dx = cx - px; + dy = cy - py; + + MSG_HIGH("Mouse move XY(%d,%d) -> XY(%d,%d)", px, py, cx, cy); + + if ( dx == 0 && dy == 0) { + return; + }; + + if ( m_rect.Left() + dx < m_bound.Left() ) + { + MSG_HIGH("Left bound"); + dx = m_bound.Left() - m_rect.Left(); + } + + if ( m_rect.Right() + dx > m_bound.Right() ) + { + MSG_HIGH("Right bound"); + dx = m_bound.Right() - m_rect.Right(); + } + + if ( m_rect.Top() + dy < m_bound.Top() ) + { + MSG_HIGH("Top bound"); + dy = m_bound.Top() - m_rect.Top(); + } + + if ( m_rect.Bottom() + dy > m_bound.Bottom() ) + { + MSG_HIGH("Bottom bound"); + dy = m_bound.Bottom() - m_rect.Bottom(); + } + + // Move rect + m_rect.MoveBy(dx, dy); + + evas_object_smart_changed(evas_object_smart_parent_get(center)); + + } + + void OnMouseUp(int x, int y) + { + MSG_HIGH("Mouse up XY(%d,%d)", x, y); + SetState(NORMAL); + + m_bMouseDown = false; +// evas_object_smart_callback_call(sd->obj, SIG_CHANGED, NULL); + } + + void OnGripMouseUp() + { + m_bGripMouseDown = false; + SetState(NORMAL); + } + + void OnGripMouseDown() + { + m_bGripMouseDown = true; + SetState(HOLD); + } + + void OnGripMouseMove(eGripType grip, int px, int py, int cx, int cy) + { + if ( m_bGripMouseDown == false ) return; + + int dx = cx - px; + int dy = cy - py; + + if ( dx == 0 && dy == 0) { + return; + }; + + if ( GetRatio() != 0.0f ) + { + _GripMovePreserve(grip, dx, dy); + } + else + { + _GripMove(grip, dx, dy); + } + + MSG_HIGH("New Rect %d,%d,%d,%d", m_rect.Left(), m_rect.Top(), m_rect.Width(), m_rect.Height()); + + evas_object_smart_changed(evas_object_smart_parent_get(center)); + } + + virtual void SetState(eState state) { + CSelectBox::SetState(state); + + _LoadImage(); + }; + +private: + void _GripMove(eGripType grip, int dx, int dy) { + const int min_size = EVENT_GRIP_SIZE; + CRect rect = m_rect; + + int X1 = rect.Left(), Y1 = rect.Top() ,X2 = rect.Right(), Y2 = rect.Bottom(); + + if ( grip & GRIP_LEFT ) + { + X1 = rect.Left() + dx; + + if ( X1 < m_bound.Left() ) + { + MSG_HIGH("Left bound"); + X1 = m_bound.Left(); + } + + if ( rect.Width() - dx < min_size ) + { + X1 = rect.Right() - min_size; + + MSG_HIGH("X1 = %d (%d,%d)", X1, rect.Left(), rect.Right()); + } + } + + if ( grip & GRIP_TOP ) + { + Y1 = rect.Top() + dy; + + if ( Y1 < m_bound.Top() ) + { + MSG_HIGH("Top bound"); + Y1 = m_bound.Top(); + } + + if ( rect.Height() - dy < min_size ) + { + Y1 = rect.Bottom() - min_size; + + MSG_HIGH("Y1 = %d B=%d", Y1, rect.Bottom()); + } + } + + if ( grip & GRIP_RIGHT ) + { + X2 = rect.Right() + dx; + + if ( X2 > m_bound.Right() ) + { + MSG_HIGH("Right bound"); + X2 = m_bound.Right() ; + } + + if ( rect.Width() + dx < min_size ) + { + X2 = rect.Left() + min_size; + } + } + + if ( grip & GRIP_BOTTOM ) + { + Y2 = rect.Bottom() + dy; + + if ( Y2 > m_bound.Bottom() ) + { + MSG_HIGH("Bottom bound"); + Y2 = m_bound.Bottom(); + } + + if ( rect.Height() + dy < min_size ) + { + Y2 = rect.Top() + min_size; + } + } + + m_rect = CRect(X1, Y1, X2 - X1, Y2 - Y1); + + }; + + void _GripMovePreserve(eGripType grip, int dx, int dy) { + const int min_size = EVENT_GRIP_SIZE; + CRect rect = m_rect; + + int X,Y,W,H; + + double ratio = GetRatio(); + + MSG_HIGH("Dx=%d Dy=%d Ratio=%f", dx, dy, ratio); + + enum eDominantDirection + { + Direction_X, + Direction_Y + } ; + + eDominantDirection dir = Direction_X; + int mov_dist; + if(abs(dx) < abs(dy)) + { + dir = Direction_Y; + mov_dist = dy; + } + else + { + mov_dist = dx; + } + + if ( (grip & GRIP_LEFT) && (grip & GRIP_TOP) ) + { + MSG_HIGH("LEFT,TOP"); + + if ( dir == Direction_X ) + { + W = rect.Width() - mov_dist; + H = W * ratio; + + X = m_rect.Right() - W; + Y = m_rect.Bottom() - H; + } + else + { + H = rect.Height() - mov_dist; + W = H / ratio; + + X = m_rect.Right() - W; + Y = m_rect.Bottom() - H; + } + + + } + + if ( (grip & GRIP_RIGHT) && (grip & GRIP_TOP) ) + { + MSG_HIGH("RIGHT,TOP"); + + if ( dir == Direction_X ) + { + W = rect.Width() + mov_dist; + H = W * ratio; + + X = m_rect.Left(); + Y = m_rect.Bottom() - H; + } + else + { + H = rect.Height() - mov_dist; + W = H / ratio; + + X = m_rect.Left(); + Y = m_rect.Bottom() - H; + } + + } + + if ( (grip & GRIP_RIGHT) && (grip & GRIP_BOTTOM) ) + { + MSG_HIGH("RIGHT,BOTTOM"); + if ( dir == Direction_X ) + { + W = rect.Width() + mov_dist; + H = W * ratio; + + X = m_rect.Left(); + Y = m_rect.Top(); + } + else + { + H = rect.Height() + mov_dist; + W = H / ratio; + + X = m_rect.Left(); + Y = m_rect.Top(); + + } + + } + + if ( (grip & GRIP_LEFT) && (grip & GRIP_BOTTOM) ) + { + MSG_HIGH("LEFT,BOTTOM"); + + if ( dir == Direction_X ) + { + W = rect.Width() - mov_dist; + H = W * ratio; + + X = m_rect.Right() - W; + Y = m_rect.Top(); + } + else + { + H = rect.Height() + mov_dist; + W = H / ratio; + + X = m_rect.Right() - W; + Y = m_rect.Top(); + } + + } + + if ( W < min_size || H < min_size) + { + return; + } + + if ( X < m_bound.Left() || Y < m_bound.Top() || + X
+ W > m_bound.Right() || Y+H > m_bound.Bottom() ) + { + return; + } + + m_rect = CRect(X,Y,W,H); + + } + + void _LoadImage() { + const char *line_w; + const char *line_h; + const char *pot; + + if ( GetState() == NORMAL ) + { + line_w = CROP_LINEW_PATH; + line_h = CROP_LINEH_PATH; + + pot = CROP_POT_PATH; + } + else if ( GetState() == PRESS ) + { + line_w = CROP_LINEW_PRESS_PATH; + line_h = CROP_LINEH_PRESS_PATH; + + pot = CROP_POT_PRESS_PATH; + } + else if ( GetState() == HOLD ) + { + line_w = CROP_LINEW_PATH; + line_h = CROP_LINEH_PATH; + + pot = CROP_POT_HOLD_PATH; + } + else + { + MSG_FATAL("Invalid state"); + return; + } + + Evas_Load_Error err; + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + if(i % 2) // 1, 3 + { + evas_object_image_file_set(selector_line[i], line_w, NULL); + err = evas_object_image_load_error_get(selector_line[i]); + if (err != EVAS_LOAD_ERROR_NONE) + { + MSG_ERROR("could not load image '%s'. %s", line_w, evas_load_error_str(err)); + } + } + else // 0, 2 + { + evas_object_image_file_set(selector_line[i], line_h, NULL); + err = evas_object_image_load_error_get(selector_line[i]); + if (err != EVAS_LOAD_ERROR_NONE) + { + MSG_ERROR("could not load image '%s'. %s", line_h, evas_load_error_str(err)); + } + } + + evas_object_show(selector_line[i]); + + } + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + evas_object_image_file_set(selector_pot[i], pot, NULL); + + err = evas_object_image_load_error_get(selector_line[i]); + if (err != EVAS_LOAD_ERROR_NONE) + { + MSG_ERROR("could not load image '%s'. %s", pot, evas_load_error_str(err)); + } + + evas_object_image_scale_hint_set(selector_pot[i], EVAS_IMAGE_SCALE_HINT_STATIC); + + evas_object_show(selector_pot[i]); + } + }; + +public: + + void Create(Evas_Object *obj) { + Evas *e = evas_object_evas_get(obj); + + center = evas_object_rectangle_add(e); + evas_object_color_set(center, 0, 0, 0, 0); + + evas_object_event_callback_add(center, EVAS_CALLBACK_MOUSE_DOWN, _selector_mouse_down, this); + evas_object_event_callback_add(center, EVAS_CALLBACK_MOUSE_UP, _selector_mouse_up, this); + evas_object_event_callback_add(center, EVAS_CALLBACK_MOUSE_MOVE, _selector_mouse_move, this); + + evas_object_smart_member_add(center, obj); + + evas_object_show(center); + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + selector_line[i] = evas_object_image_filled_add(e); + + evas_object_event_callback_add(selector_line[i], EVAS_CALLBACK_MOUSE_DOWN, _line_mouse_down, this); + evas_object_event_callback_add(selector_line[i], EVAS_CALLBACK_MOUSE_UP, _line_mouse_up, this); + + evas_object_smart_member_add(selector_line[i], obj); + } + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + /* Create image icon (pot) */ + selector_pot[i] = evas_object_image_filled_add(e); + + evas_object_image_scale_hint_set(selector_pot[i], EVAS_IMAGE_SCALE_HINT_STATIC); + + evas_object_smart_member_add(selector_pot[i], obj); + + /* Create event object above image icon (pot) */ + event_pot[i] = evas_object_rectangle_add(e); + evas_object_color_set(event_pot[i], 0, 0, 0, 0); + + evas_object_event_callback_add(event_pot[i], EVAS_CALLBACK_MOUSE_DOWN, _pot_mouse_down, this); + evas_object_event_callback_add(event_pot[i], EVAS_CALLBACK_MOUSE_UP, _pot_mouse_up, this); + evas_object_event_callback_add(event_pot[i], EVAS_CALLBACK_MOUSE_MOVE, _pot_mouse_move, this); + + evas_object_resize(event_pot[i], EVENT_GRIP_SIZE, EVENT_GRIP_SIZE); + + evas_object_smart_member_add(event_pot[i], obj); + + evas_object_show(event_pot[i]); + } + + evas_object_data_set(event_pot[0], "grip_type",(void *)(GRIP_LEFT | GRIP_TOP)); + evas_object_data_set(event_pot[1], "grip_type",(void *)(GRIP_RIGHT | GRIP_TOP)); + evas_object_data_set(event_pot[2], "grip_type",(void *)(GRIP_RIGHT | GRIP_BOTTOM)); + evas_object_data_set(event_pot[3], "grip_type",(void *)(GRIP_LEFT | GRIP_BOTTOM)); + + _LoadImage(); + }; + + void Draw() { +// Check bound. + if ( m_bound.Inside(m_rect) == false ) + { + MSG_ERROR("Out of bound region. Rect(%d,%d,%d,%d) Bound(%d,%d,%d,%d)", m_rect.Left(), m_rect.Top(), m_rect.Width(), m_rect.Height(), + m_bound.Left(), m_bound.Top(), m_bound.Width(), m_bound.Height()); + + // Reset Rect + } + + evas_object_move(center, m_rect.Left(), m_rect.Top()); + evas_object_resize(center, m_rect.Width(), m_rect.Height()); + // Horizontal + evas_object_move(selector_line[0], m_rect.Left(), m_rect.Top()); + evas_object_resize(selector_line[0], m_rect.Width() , 8); + + evas_object_move(selector_line[2], m_rect.Left(), m_rect.Bottom() - (SHADOW_DEPTH / 2)); + evas_object_resize(selector_line[2], m_rect.Width() , 8); + + // Vertical + evas_object_move(selector_line[1], m_rect.Left(), m_rect.Top()); + evas_object_resize(selector_line[1], 8, m_rect.Height() ); + + evas_object_move(selector_line[3], m_rect.Right() - (SHADOW_DEPTH / 2), m_rect.Top()); + evas_object_resize(selector_line[3], 8, m_rect.Height()); + + evas_object_move(event_pot[0], m_rect.Left() - ( EVENT_GRIP_SIZE / 2), m_rect.Top() - ( EVENT_GRIP_SIZE / 2)); + evas_object_move(event_pot[1], m_rect.Right() - ( EVENT_GRIP_SIZE / 2), m_rect.Top() - ( EVENT_GRIP_SIZE / 2)); + evas_object_move(event_pot[2], m_rect.Right() - ( EVENT_GRIP_SIZE / 2), m_rect.Bottom() - ( EVENT_GRIP_SIZE / 2)); + evas_object_move(event_pot[3], m_rect.Left() - ( EVENT_GRIP_SIZE / 2), m_rect.Bottom() - ( EVENT_GRIP_SIZE / 2)); + + // Pot + int w, h; + + w = POT_SIZE.Width(); + h = POT_SIZE.Height(); + + evas_object_move(selector_pot[0], m_rect.Left() - 4, m_rect.Top() - 4 ); + evas_object_resize(selector_pot[0], w, h); + + evas_object_move(selector_pot[1], m_rect.Right() - 8, m_rect.Top() - 4 ); + evas_object_resize(selector_pot[1], w, h); + + evas_object_move(selector_pot[2], m_rect.Right() - 8, m_rect.Bottom() - 8); + evas_object_resize(selector_pot[2], w, h); + + evas_object_move(selector_pot[3], m_rect.Left() - 4, m_rect.Bottom() - 8); + evas_object_resize(selector_pot[3], w, h); + + }; + +private: + Evas_Object *selector_line[4]; + Evas_Object *event_pot[4]; + Evas_Object *selector_pot[4]; + + Evas_Object *center; + + bool m_bMouseDown; + bool m_bGripMouseDown; + +}; + + +#define CROP_SELECT_PATH IMAGE_PATH"/crop/T06_selection.png" + +#define CROP_RESIZE_H_PATH IMAGE_PATH"/crop/T06_selection_Resizing_h.png" +#define CROP_RESIZE_W_PATH IMAGE_PATH"/crop/T06_selection_Resizing_V.png" + +#define CROP_ROTATE_PATH IMAGE_PATH"/crop/T06_selection_Rotate.png" + +class CBox1 : public CSelectBox { +public: + const int EVENT_GRIP_SIZE; + const CSize POT_SIZE; + + static void _line_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) {}; + static void _line_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info) {}; + + static void _pot_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox1 *pBox = (CBox1 *)data; + +// Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down *) event_info; + + pBox->OnGripMouseDown(); + }; + static void _pot_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info) + { + CBox1 *pBox = (CBox1 *)data; + + Evas_Event_Mouse_Move *ev = (Evas_Event_Mouse_Move *) event_info; + + eGripType grip = static_cast<eGripType> (reinterpret_cast<int>
(evas_object_data_get(obj, "grip_type"))); + + if ( ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD ) + { + MSG_HIGH("On Hold"); + } + + if ( ev->event_flags & EVAS_EVENT_FLAG_ON_SCROLL ) + { + MSG_HIGH("On Scroller"); + } + + pBox->OnGripMouseMove(grip, ev->prev.output.x, ev->prev.output.y, ev->cur.output.x, ev->cur.output.y); + }; + + static void _pot_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox1 *pBox = (CBox1 *)data; + +// Evas_Event_Mouse_Up *ev = (Evas_Event_Mouse_Up *) event_info; + + pBox->OnGripMouseUp(); + }; + + + static void _selector_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox1 *pBox = (CBox1 *)data; + + Evas_Event_Mouse_Down *ev = (Evas_Event_Mouse_Down *) event_info; + + pBox->OnMouseDown(ev->output.x, ev->output.y); + + }; + + static void _selector_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox1 *pBox = (CBox1 *)data; + + Evas_Event_Mouse_Move *ev = (Evas_Event_Mouse_Move *) event_info; + + MSG_LOW("(%d,%d) --> (%d,%d)", ev->cur.output.x, ev->cur.output.y, ev->prev.output.x, ev->prev.output.y); + pBox->OnMouseMove(ev->prev.output.x, ev->prev.output.y, ev->cur.output.x, ev->cur.output.y); + }; + + static void _selector_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info) { + CBox1 *pBox = (CBox1 *)data; + + Evas_Event_Mouse_Up *ev = (Evas_Event_Mouse_Up *) event_info; + + pBox->OnMouseUp(ev->output.x, ev->output.y); + }; + +public: + CBox1() : CSelectBox(), EVENT_GRIP_SIZE(60), POT_SIZE(56,56), m_bMouseDown(false), m_bGripMouseDown(false) { }; + + virtual ~CBox1() { + MSG_HIGH("Remove CBox1"); + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + evas_object_del(selector_pot[i]); + evas_object_del(event_pot[i]); + } + + evas_object_del(this->sel_rotate); + evas_object_del(select_rect); + }; + + void OnMouseDown(int x, int y) + { + MSG_HIGH("Mouse down XY(%d,%d)", x, y); + + SetState(PRESS); + m_bMouseDown = true; + } + + void OnMouseMove(int px, int py, int cx, int cy) + { + // Inform changes to parent. + if ( m_bMouseDown == false ) return; + + int dx, dy; + + dx = cx - px; + dy = cy - py; + + MSG_HIGH("Mouse move XY(%d,%d) -> XY(%d,%d)", px, py, cx, cy); + + if ( dx == 0 && dy == 0) { + return; + }; + + if ( m_rect.Left() + dx < m_bound.Left() ) + { + MSG_HIGH("Left bound"); + dx = m_bound.Left() - m_rect.Left(); + } + + if ( m_rect.Right() + dx > m_bound.Right() ) + { + MSG_HIGH("Right bound"); + dx = m_bound.Right() - m_rect.Right(); + } + + if ( m_rect.Top() + dy < m_bound.Top() ) + { + MSG_HIGH("Top bound"); + dy = m_bound.Top() - m_rect.Top(); + } + + if ( m_rect.Bottom() + dy > m_bound.Bottom() ) + { + MSG_HIGH("Bottom bound"); + dy = m_bound.Bottom() - m_rect.Bottom(); + } + + // Move rect + m_rect.MoveBy(dx, dy); + + evas_object_smart_changed(evas_object_smart_parent_get(select_rect)); + + } + + void OnMouseUp(int x, int y) + { + MSG_HIGH("Mouse up XY(%d,%d)", x, y); + SetState(NORMAL); + + m_bMouseDown = false; +// evas_object_smart_callback_call(sd->obj, SIG_CHANGED, NULL); + } + + void OnGripMouseUp() + { + m_bGripMouseDown = false; + SetState(NORMAL); + } + + void OnGripMouseDown() + { + m_bGripMouseDown = true; + SetState(HOLD); + } + + void OnGripMouseMove(eGripType grip, int px, int py, int cx, int cy) + { + if ( m_bGripMouseDown == false ) return; + + int dx = cx - px; + int dy = cy - py; + + if ( dx == 0 && dy == 0) { + return; + }; + + if ( GetRatio() != 0.0f ) + { + _GripMovePreserve(grip, dx, dy); + } + else + { + _GripMove(grip, dx, dy); + } + + MSG_HIGH("New Rect %d,%d,%d,%d", m_rect.Left(), m_rect.Top(), m_rect.Width(), m_rect.Height()); + + evas_object_smart_changed(evas_object_smart_parent_get(select_rect)); + } + +private: + void _GripMove(eGripType grip, int dx, int dy) { + const int min_size = EVENT_GRIP_SIZE; + CRect rect = m_rect; + + int X1 = rect.Left(), Y1 = rect.Top() ,X2 = rect.Right(), Y2 = rect.Bottom(); + + if ( grip & GRIP_LEFT ) + { + X1 = rect.Left() + dx; + + if ( X1 < m_bound.Left() ) + { + MSG_HIGH("Left bound"); + X1 = m_bound.Left(); + } + + if ( rect.Width() - dx < min_size ) + { + X1 = rect.Right() - min_size; + + MSG_HIGH("X1 = %d (%d,%d)", X1, rect.Left(), rect.Right()); + } + } + + if ( grip & GRIP_TOP ) + { + Y1 = rect.Top() + dy; + + if ( Y1 < m_bound.Top() ) + { + MSG_HIGH("Top bound"); + Y1 = m_bound.Top(); + } + + if ( rect.Height() - dy < min_size ) + { + Y1 = rect.Bottom() - min_size; + + MSG_HIGH("Y1 = %d B=%d", Y1, rect.Bottom()); + } + } + + if ( grip & GRIP_RIGHT ) + { + X2 = rect.Right() + dx; + + if ( X2 > m_bound.Right() ) + { + MSG_HIGH("Right bound"); + X2 = m_bound.Right() ; + } + + if ( rect.Width() + dx < min_size ) + { + X2 = rect.Left() + min_size; + } + } + + if ( grip & GRIP_BOTTOM ) + { + Y2 = rect.Bottom() + dy; + + if ( Y2 > m_bound.Bottom() ) + { + MSG_HIGH("Bottom bound"); + Y2 = m_bound.Bottom(); + } + + if ( rect.Height() + dy < min_size ) + { + Y2 = rect.Top() + min_size; + } + } + + m_rect = CRect(X1, Y1, X2 - X1, Y2 - Y1); + + }; + + void _GripMovePreserve(eGripType grip, int dx, int dy) { + const int min_size = EVENT_GRIP_SIZE; + CRect rect = m_rect; + + int X,Y,W,H; + + double ratio = GetRatio(); + + MSG_HIGH("Dx=%d Dy=%d Ratio=%f", dx, dy, ratio); + + enum eDominantDirection + { + Direction_X, + Direction_Y + } ; + + eDominantDirection dir = Direction_X; + int mov_dist; + if(abs(dx) < abs(dy)) + { + dir = Direction_Y; + mov_dist = dy; + } + else + { + mov_dist = dx; + } + + if ( (grip & GRIP_LEFT) || (grip & GRIP_TOP) ) + { + MSG_HIGH("LEFT,TOP"); + + if ( dir == Direction_X ) + { + W = rect.Width() - mov_dist; + H = W * ratio; + + X = m_rect.Right() - W; + Y = m_rect.Bottom() - H; + } + else + { + H = rect.Height() - mov_dist; + W = H / ratio; + + X = m_rect.Right() - W; + Y = m_rect.Bottom() - H; + } + + + } + + + if ( (grip & GRIP_RIGHT) || (grip & GRIP_BOTTOM) ) + { + MSG_HIGH("RIGHT,BOTTOM"); + if ( dir == Direction_X ) + { + W = rect.Width() + mov_dist; + H = W * ratio; + + X = m_rect.Left(); + Y = m_rect.Top(); + } + else + { + H = rect.Height() + mov_dist; + W = H / ratio; + + X = m_rect.Left(); + Y = m_rect.Top(); + + } + + } + + +#if 0 + if ( (grip & GRIP_RIGHT) && (grip & GRIP_TOP) ) + { + MSG_HIGH("RIGHT,TOP"); + + if ( dir == Direction_X ) + { + W = rect.Width() + mov_dist; + H = W * m_ratio; + + X = m_rect.Left(); + Y = m_rect.Bottom() - H; + } + else + { + H = rect.Height() - mov_dist; + W = H / m_ratio; + + X = m_rect.Left(); + Y = m_rect.Bottom() - H; + } + + } + + if ( (grip & GRIP_LEFT) && (grip & GRIP_BOTTOM) ) + { + MSG_HIGH("LEFT,BOTTOM"); + + if ( dir == Direction_X ) + { + W = rect.Width() - mov_dist; + H = W * m_ratio; + + X = m_rect.Right() - W; + Y = m_rect.Top(); + } + else + { + H = rect.Height() + mov_dist; + W = H / m_ratio; + + X = m_rect.Right() - W; + Y = m_rect.Top(); + } + + } +#endif + + if ( W < min_size || H < min_size) + { + return; + } + + if ( X < m_bound.Left() || Y < m_bound.Top() || + X
+ W > m_bound.Right() || Y+H > m_bound.Bottom() ) + { + return; + } + + m_rect = CRect(X,Y,W,H); + + } + + void _LoadImage() { + + Evas_Load_Error err; + + evas_object_image_file_set(select_rect, CROP_SELECT_PATH, NULL); + err = evas_object_image_load_error_get(select_rect); + if (err != EVAS_LOAD_ERROR_NONE) + { + MSG_ERROR("could not load image '%s'. %s", CROP_SELECT_PATH, evas_load_error_str(err)); + } + + evas_object_image_border_set(select_rect, 19, 18, 18, 18); + evas_object_show(select_rect); + + const char *szPot[] = { + CROP_RESIZE_H_PATH, + CROP_RESIZE_H_PATH, + CROP_RESIZE_W_PATH, + CROP_RESIZE_W_PATH + }; + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + evas_object_image_file_set(selector_pot[i], szPot[i], NULL); + + err = evas_object_image_load_error_get(selector_pot[i]); + if (err != EVAS_LOAD_ERROR_NONE) + { + MSG_ERROR("could not load image '%s'. %s", szPot[i], evas_load_error_str(err)); + } + + evas_object_image_scale_hint_set(selector_pot[i], EVAS_IMAGE_SCALE_HINT_STATIC); + + evas_object_show(selector_pot[i]); + } + + /*evas_object_image_file_set(sel_rotate, CROP_ROTATE_PATH, NULL); + + err = evas_object_image_load_error_get(sel_rotate); + if (err != EVAS_LOAD_ERROR_NONE) + { + MSG_ERROR("could not load image '%s'. %s", CROP_ROTATE_PATH, evas_load_error_str(err)); + } + + evas_object_image_scale_hint_set(sel_rotate, EVAS_IMAGE_SCALE_HINT_STATIC); + + evas_object_show(sel_rotate);*/ + + }; + +public: + virtual void SetState(eState state) { + CSelectBox::SetState(state); + + _LoadImage(); + }; + + void Create(Evas_Object *obj) { + Evas *e = evas_object_evas_get(obj); + + select_rect = evas_object_image_filled_add(e); + + evas_object_event_callback_add(select_rect, EVAS_CALLBACK_MOUSE_DOWN, _selector_mouse_down, this); + evas_object_event_callback_add(select_rect, EVAS_CALLBACK_MOUSE_UP, _selector_mouse_up, this); + evas_object_event_callback_add(select_rect, EVAS_CALLBACK_MOUSE_MOVE, _selector_mouse_move, this); + + evas_object_smart_member_add(select_rect, obj); + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + /* Create image icon (pot) */ + selector_pot[i] = evas_object_image_filled_add(e); + + evas_object_image_scale_hint_set(selector_pot[i], EVAS_IMAGE_SCALE_HINT_STATIC); + + evas_object_smart_member_add(selector_pot[i], obj); + + /* Create event object above image icon (pot) */ + event_pot[i] = evas_object_rectangle_add(e); + evas_object_color_set(event_pot[i], 0, 0, 0, 0); + + evas_object_event_callback_add(event_pot[i], EVAS_CALLBACK_MOUSE_DOWN, _pot_mouse_down, this); + evas_object_event_callback_add(event_pot[i], EVAS_CALLBACK_MOUSE_UP, _pot_mouse_up, this); + evas_object_event_callback_add(event_pot[i], EVAS_CALLBACK_MOUSE_MOVE, _pot_mouse_move, this); + + evas_object_smart_member_add(event_pot[i], obj); + + evas_object_show(event_pot[i]); + } + + + evas_object_data_set(event_pot[0], "grip_type",(void *)GRIP_LEFT); + evas_object_data_set(event_pot[1], "grip_type",(void *)GRIP_RIGHT); + evas_object_data_set(event_pot[2], "grip_type",(void *)GRIP_TOP); + evas_object_data_set(event_pot[3], "grip_type",(void *)GRIP_BOTTOM); + + sel_rotate = evas_object_image_filled_add(e); + evas_object_smart_member_add(sel_rotate, obj); + + _LoadImage(); + }; + + void Draw() { +// Check bound. + if ( m_bound.Inside(m_rect) == false ) + { + MSG_ERROR("Out of bound region. Rect(%d,%d,%d,%d) Bound(%d,%d,%d,%d)", m_rect.Left(), m_rect.Top(), m_rect.Width(), m_rect.Height(), + m_bound.Left(), m_bound.Top(), m_bound.Width(), m_bound.Height()); + } + + MSG_HIGH("Rect. %d,%d,%d,%d", m_rect.Left(), m_rect.Top(), m_rect.Width(), m_rect.Height()); + + const int margin_l = -10; + const int margin_r = -1; + const int margin_t = -1; + const int margin_b = -9; + + int mx, my, mw, mh; + + mx = m_rect.Left() + margin_l; + my = m_rect.Top() + margin_t; + mw = m_rect.Width() - margin_l - margin_r; + mh = m_rect.Height() - margin_t - margin_b; + + evas_object_move(select_rect, mx, my); + evas_object_resize(select_rect, mw, mh); + +// Event handle. + evas_object_resize(event_pot[0], EVENT_GRIP_SIZE, EVENT_GRIP_SIZE * 2); + evas_object_move(event_pot[0], m_rect.Left() - ( EVENT_GRIP_SIZE / 2), m_rect.Top() + m_rect.Height() / 2 - ( EVENT_GRIP_SIZE )); // Left + + evas_object_resize(event_pot[1], EVENT_GRIP_SIZE, EVENT_GRIP_SIZE * 2); + evas_object_move(event_pot[1], m_rect.Right() - ( EVENT_GRIP_SIZE / 2), m_rect.Top() + m_rect.Height() / 2 - ( EVENT_GRIP_SIZE )); // Right + + evas_object_resize(event_pot[2], EVENT_GRIP_SIZE * 2, EVENT_GRIP_SIZE); + evas_object_move(event_pot[2], m_rect.Left() + m_rect.Width() / 2 - ( EVENT_GRIP_SIZE ), m_rect.Top() - ( EVENT_GRIP_SIZE / 2)); // Top + + evas_object_resize(event_pot[3], EVENT_GRIP_SIZE * 2, EVENT_GRIP_SIZE); + evas_object_move(event_pot[3], m_rect.Left() + m_rect.Width() / 2 - ( EVENT_GRIP_SIZE ), m_rect.Bottom() - ( EVENT_GRIP_SIZE / 2)); // Bottom + + // Pot + const int lw = 4; + const int lh = 4; + + int w, h; + + w = POT_SIZE.Width(); + h = POT_SIZE.Height(); +// L + evas_object_resize(selector_pot[0], w, h); + evas_object_move(selector_pot[0], m_rect.Left() - w / 2 + lw, m_rect.Top() + m_rect.Height() / 2 - h / 2 ); +// R + evas_object_move(selector_pot[1], m_rect.Right() - w / 2 -lw, m_rect.Top() + m_rect.Height() / 2 - h / 2 ); + evas_object_resize(selector_pot[1], w, h); +// T + evas_object_move(selector_pot[2], m_rect.Left() + m_rect.Width() / 2 - w / 2 , m_rect.Top() - h / 2 + lh); + evas_object_resize(selector_pot[2], w, h); +// B + evas_object_move(selector_pot[3], m_rect.Left() + m_rect.Width() / 2 - w / 2, m_rect.Bottom() - h / 2 - lh); + evas_object_resize(selector_pot[3], w, h); + + evas_object_move(sel_rotate, m_rect.Right() - w / 2 - lw , m_rect.Top() - h / 2 + lh); + evas_object_resize(sel_rotate, w, h); + + }; + +private: + Evas_Object *select_rect; // Center rect + + Evas_Object *event_pot[4]; + Evas_Object *selector_pot[4]; + + Evas_Object *sel_rotate; + + bool m_bMouseDown; + bool m_bGripMouseDown; +}; + + +template<> +const Evas_Smart_Cb_Description CEvasSmartObject<CScissorBox>::_signals[] = { + {NULL, NULL}, +}; + +Evas_Object *CScissorBox::CreateObject(Evas_Object *parent) { + CEvasSmartObject<CScissorBox>::CreateObject(parent); + + evas_object_smart_callbacks_descriptions_set(GetObject(), _signals); + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + m_opaque[i] = evas_object_rectangle_add(evas_object_evas_get(parent)); + + evas_object_color_set(m_opaque[i], 0, 0, 0, DEFAULT_DIM_BG_ALPHA); + evas_object_smart_member_add(m_opaque[i], GetObject()); + evas_object_repeat_events_set(m_opaque[i], EINA_TRUE); + } + + m_box = new CBox(); + + m_box->Create( GetObject() ); + + m_parent = parent; + + MSG_HIGH("Scissorbox created"); + return GetObject(); +}; + +void CScissorBox::remove() +{ + MSG_HIGH("Destroy ScissorBox. m_box=0x%08x", m_box); + + if ( m_target ) + { + UnRegisterCB(); + m_target = NULL; + } + + m_parent = NULL; + + for (int i = 0; i < DEFAULT_POT_NUM; i++) + { + evas_object_hide(m_opaque[i]); + evas_object_del(m_opaque[i]); + } + + if ( m_job ) + { + ecore_job_del(m_job); + m_job = NULL; + } + + delete m_box; + + delete this; +} + + +void CScissorBox::SetOpaque(bool bOpaque) +{ +#if 0 + // Determine whether BG is drawn or not. + if ( bOpaque == m_bOpaque ) + { + return; + } +#endif + + +/* +m_rect +------------------------------ +| m_opaque[0] | +| ___________________________ | +| ---- | +| m_opaque[3] |bg | m_opaque[1] | +|_______________----___________ | +| | +| m_opaque[2] | +------------------------------ +*/ + if ( bOpaque == true ) + { + evas_object_show(m_opaque[0]); + evas_object_show(m_opaque[1]); + evas_object_show(m_opaque[2]); + evas_object_show(m_opaque[3]); + } + else + { + evas_object_hide(m_opaque[0]); + evas_object_hide(m_opaque[1]); + evas_object_hide(m_opaque[2]); + evas_object_hide(m_opaque[3]); + } + + m_bOpaque = bOpaque; + +} + + +void CScissorBox::SetPreserveRatio(bool bPreserveRatio) +{ + m_bPreserveRatio = bPreserveRatio; + + if ( m_bPreserveRatio == true ) + { + CRect rect = m_box->GetRegion(); + + if ( rect.Width() != 0 ) + { + MSG_HIGH("Set to preserve ratio"); + m_box->SetRatio((double)rect.Height() / rect.Width()); + } + } + +} + +void CScissorBox::SetRegion(int x, int y, int w, int h) +{ + MSG_HIGH("Set Region(%d,%d,%d,%d)", x, y, w, h); + + m_box->Move(x,y); + + if ( m_bPreserveRatio == true ) + { + m_box->SetRatio((double)h / w); + } + + m_box->Resize(w,h); + m_bSetRegion = true; + + evas_object_smart_changed(GetObject()); +} + +void CScissorBox::SetBound(int x, int y, int w, int h) +{ + MSG_HIGH("Set Bound(%d,%d,%d,%d)", x, y, w, h); + + CRect rect(x, y, w, h); + m_box->SetBound(rect); + + + evas_object_smart_changed(GetObject()); +} + +void CScissorBox::SetBoxType(eType type) +{ +// Remove old one and reload + if ( m_boxtype != type ) + { + // Load again + if ( m_box ) + { + const CRect &bound = m_box->GetBound(); + const CRect ®ion = m_box->GetRegion(); + double ratio = m_box->GetRatio(); + + delete m_box; + m_box = NULL; + + if ( type == IMAGE_VIEW ) + { + m_box = new CBox; + } + else + { + m_box = new CBox1; + } + + m_box->Create( GetObject() ); + + m_box->SetBound(bound); + m_box->Move(region.Left(), region.Top()); + m_box->Resize(region.Width(), region.Height()); + + if ( m_bPreserveRatio == true ) + { + m_box->SetRatio(ratio); + } + + } + } + + m_boxtype = type; +} + + +const CRect &CScissorBox::GetRegion() const +{ + return m_box->GetRegion(); +} + + +void CScissorBox::Attach(Evas_Object *obj) +{ + MSG_HIGH("Attach client! obj=%s", evas_object_type_get(obj)); + + if ( m_target ) + UnRegisterCB(); + + m_target = obj; + + RegisterCB(); + + SetOpaque(true); + + OnTargetChanged(); +} + + +void CScissorBox::draw() +{ + if ( m_box == NULL ) return; + + if ( m_bOpaque == true) + { + const CRect &box_rect = m_box->GetRegion(); + + if ( box_rect != CRect::Zero ) + { + int x, y, w, h; + evas_output_viewport_get(evas_object_evas_get(GetObject()), &x, &y, &w, &h); + + MSG_LOW("Evas View port Output : %d,%d,%d,%d", x,y,w, h); + + evas_object_move(m_opaque[0], x, y); + evas_object_resize(m_opaque[0], w, box_rect.Top()); + + evas_object_move(m_opaque[1], box_rect.Right(), box_rect.Top()); + evas_object_resize(m_opaque[1], w - box_rect.Right() , box_rect.Height() ); + + evas_object_move(m_opaque[2], x, box_rect.Bottom()); + evas_object_resize(m_opaque[2], w , h - box_rect.Bottom() ); + + evas_object_move(m_opaque[3], x, box_rect.Top()); + evas_object_resize(m_opaque[3], box_rect.Left() , box_rect.Height() ); + } + } + + m_box->Draw(); +} + +void CScissorBox::OnTargetChanged() +{ + if ( m_job ) + { + ecore_job_del(m_job); + } + + m_job = ecore_job_add(_OnChangedJob, this); + +} + +void CScissorBox::ApplyChanges() +{ + int x, y, w, h; + + int lcd_x, lcd_y, lcd_w, lcd_h; + + evas_object_geometry_get(m_parent, &lcd_x, &lcd_y, &lcd_w, &lcd_h); + MSG_HIGH("LCD size (%d,%d,%d,%d)", lcd_x, lcd_y, lcd_w, lcd_h); + + double lcd_ratio = (double)lcd_h/lcd_w; + + if ( m_target == NULL ) + { + x = 0; + y = 0; + w = lcd_w; + h = lcd_h; + } + else + { + evas_object_geometry_get(m_target, &x, &y, &w, &h); + } + + // evas_object_geometry_get is not corret when image loaded before show effect ended + if(lcd_ratio > (double)h/w) + { + x = 0; + } + else + { + x = (lcd_w - w)/2; + } + + MSG_HIGH("Target Changed (%d,%d,%d,%d)->(%d,%d,%d,%d)", tRect.Left(), tRect.Top(), tRect.Width(), tRect.Height(), x, y, w, h); + + if ( w == 0 || h == 0 ) + { + MSG_WARN("Size does not changed"); + return; + } + + CRect bound(x,y,w,h); // Boundary size is same as target + m_box->SetBound(bound); + + MSG_HIGH("Set Bound rect(%d,%d,%d,%d)", bound.Left(), bound.Top(), bound.Width(), bound.Height() ); + + if ( m_bSetRegion == false ) + { + int nW = w / 2; + int nH = h / 2; + + m_box->Move(x + (w - nW) / 2, y + (h - nH) / 2 ); + m_box->Resize(nW, nH); + + MSG_HIGH("Region is not set yet. BoxRegion(%d,%d,%d,%d)", x + (w - nW) / 2, y + (h - nH) / 2, nW, nH); + evas_object_smart_changed(GetObject()); + + return; + } + +#ifdef ALLOW_RECT_TRACE + if ( tRect.Width() == 0 || tRect.Height() == 0 ) + { + MSG_WARN("First time"); + tRect = CRect(x,y,w,h); + return; + } + + double zRatio = (double)w / tRect.Width(); + + const CRect &box_rect = m_box->GetRegion(); + +// Convert to rect on image; + int ix = box_rect.Left() - tRect.Left(); + int iy = box_rect.Top() - tRect.Top(); + + int rx = ix * zRatio; + int ry = iy * zRatio; + int rw = box_rect.Width() * zRatio; + int rh = box_rect.Height() * zRatio; + + m_box->Move(rx + x, ry + y); + m_box->Resize(rw, rh); + + MSG_HIGH("%d,%d %d,%d,%d,%d", ix, iy, rx, ry, rw, rh); +#endif + tRect = CRect(x,y,w,h); + +#ifndef ALLOW_RECT_TRACE + const CRect &box_rect = m_box->GetRegion(); + + if ( bound.Inside(box_rect) == false ) + { + MSG_ERROR("Out of bound region. Rect(%d,%d,%d,%d) Bound(%d,%d,%d,%d)", box_rect.Left(), box_rect.Top(), box_rect.Width(), box_rect.Height(), + bound.Left(), bound.Top(), bound.Width(), bound.Height()); + + int ph, pw; + + ph = (box_rect.Height() * bound.Width()) / box_rect.Width(); + + if (ph > bound.Height()) + { + pw = (box_rect.Width() * bound.Height()) / box_rect.Height(); + ph = bound.Height(); + } + else + { + pw = bound.Width(); + } + + pw = pw / 2; + ph = ph / 2; + + MSG_ERROR("New WH(%d,%d)", pw, ph); + + m_box->Move(bound.Left() + (bound.Width() - pw ) / 2, bound.Top() + (bound.Height() - ph) / 2 ); + m_box->Resize(pw , ph); + +#if 0 + // Reset Rect + int nW = bound.Width() / 2; + int nH = bound.Height() / 2; + + if ( nW > nH ) + { + nW = bound.Width() / 2; + nH = bound.Height() / 2; + } + else + { + nW = bound.Width() / 2; + nH = bound.Height() / 2; + } + + m_box->Move(bound.Left() + (bound.Width() - nW) / 2, bound.Top() + (bound.Height() - nH) / 2 ); + m_box->Resize(nW, nH); +#endif + + } + +#endif // ALLOW_RECT_TRACE + + evas_object_smart_changed(GetObject()); + +} + + |