2 // Open Service Platform
3 // Copyright (c) 2012-2013 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://floralicense.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.
19 * @file FGrpCanvas.cpp
20 * @brief This is the implementation file for Canvas class.
26 #include <FGrpCanvas.h>
28 #include <FBaseSysLog.h>
30 #include "FGrp_CanvasImpl.h"
31 #include "util/FGrp_Util.h"
34 #define CHECK_INSTANCE \
35 SysTryReturnResult(NID_GRP, this->__pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Fails to allocate memory.")
37 #define CHECK_INSTANCE_EX(_result) \
38 SysTryReturn(NID_GRP, this->__pImpl, _result, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Fails to allocate memory.")
40 #define CHECK_INSTANCE_VOID \
41 SysTryReturnVoidResult(NID_GRP, this->__pImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Fails to allocate memory.")
44 #define CHECK_NOT_CONSTRUCTED \
47 SysAssertf(!this->__pImpl->IsConstructed(), \
48 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class");
50 #define CHECK_CONSTRUCTED \
52 SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
53 "Not yet constructed. Construct() should be called before use.");
55 #define CHECK_CONSTRUCTED_EX(_result) \
57 SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
58 "Not yet constructed. Construct() should be called before use.");
60 #define CHECK_CONSTRUCTED_VOID \
62 SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
63 "Not yet constructed. Construct() should be called before use.");
66 namespace Tizen { namespace Graphics
72 __pImpl = new (std::nothrow) _CanvasImpl;
81 Canvas::Construct(void)
83 CHECK_NOT_CONSTRUCTED;
85 result r = this->__pImpl->Construct();
87 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
93 Canvas::Construct(const Rectangle& vcRect)
95 CHECK_NOT_CONSTRUCTED;
97 result r = this->__pImpl->Construct(vcRect);
99 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
105 Canvas::Construct(const BufferInfo& bufferInfo)
107 CHECK_NOT_CONSTRUCTED;
109 result r = this->__pImpl->Construct(bufferInfo);
111 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121 result r = this->__pImpl->Clear();
123 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
129 Canvas::Clear(const Rectangle& vcRect)
133 result r = this->__pImpl->Clear(vcRect);
135 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
141 Canvas::Copy(const Point& vcDestPoint, const Canvas& canvas, const Rectangle& vcSrcRect)
145 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&canvas), E_INVALID_ARG, "The source canvas is invalid.\n");
147 const Tizen::Graphics::_CanvasImpl& impl = *canvas.__pImpl;
149 result r = this->__pImpl->Copy(vcDestPoint, impl, vcSrcRect);
151 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
157 Canvas::Copy(const Rectangle& vcDestRect, const Canvas& canvas, const Rectangle& vcSrcRect)
161 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&canvas), E_INVALID_ARG, "The source canvas is invalid.\n");
163 const Tizen::Graphics::_CanvasImpl& impl = *canvas.__pImpl;
165 result r = this->__pImpl->Copy(vcDestRect, impl, vcSrcRect);
167 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
173 Canvas::DrawArc(const Rectangle& vcBounds, int startAngle, int endAngle, ArcStyle arcStyle)
177 result r = this->__pImpl->DrawArc(vcBounds, startAngle, endAngle, arcStyle);
179 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
185 Canvas::DrawBitmap(const Rectangle& vcRect, const Bitmap& bitmap)
189 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&bitmap), E_INVALID_ARG, "The source bitmap is invalid.\n");
191 const Tizen::Graphics::_BitmapImpl& impl = *bitmap.__pImpl;
193 result r = this->__pImpl->DrawBitmap(vcRect, impl);
195 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
201 Canvas::DrawBitmap(const Point& vcPoint, const Bitmap& bitmap)
205 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&bitmap), E_INVALID_ARG, "The source bitmap is invalid.\n");
207 const Tizen::Graphics::_BitmapImpl& impl = *bitmap.__pImpl;
209 result r = this->__pImpl->DrawBitmap(vcPoint, impl);
211 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
217 Canvas::DrawBitmap(const Rectangle& vcDestRect, const Bitmap& srcBitmap, const Rectangle& vcSrcRect)
221 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&srcBitmap), E_INVALID_ARG, "The source bitmap is invalid.\n");
223 const Tizen::Graphics::_BitmapImpl& impl = *srcBitmap.__pImpl;
225 result r = this->__pImpl->DrawBitmap(vcDestRect, impl, vcSrcRect);
227 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
233 Canvas::DrawBitmap(const Point& vcPoint, const Bitmap& bitmap, FlipDirection dir)
237 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&bitmap), E_INVALID_ARG, "The source bitmap is invalid.\n");
239 const Tizen::Graphics::_BitmapImpl& impl = *bitmap.__pImpl;
241 result r = this->__pImpl->DrawBitmap(vcPoint, impl, dir);
243 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
249 Canvas::DrawBitmap(const Point& vcPoint, const Bitmap& bitmap, const Point& vcPivot, int degree)
253 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&bitmap), E_INVALID_ARG, "The source bitmap is invalid.\n");
255 const Tizen::Graphics::_BitmapImpl& impl = *bitmap.__pImpl;
257 result r = this->__pImpl->DrawBitmap(vcPoint, impl, vcPivot, degree);
259 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
265 Canvas::DrawNinePatchedBitmap(const Rectangle& vcRect, const Bitmap& bitmap)
269 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&bitmap), E_INVALID_ARG, "The source bitmap is invalid.\n");
271 const Tizen::Graphics::_BitmapImpl& impl = *bitmap.__pImpl;
273 result r = this->__pImpl->DrawNinePatchedBitmap(vcRect, impl);
275 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
281 Canvas::DrawEllipse(const Rectangle& vcBounds)
285 result r = this->__pImpl->DrawEllipse(vcBounds);
287 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
293 Canvas::DrawLine(const Point& vcPoint1, const Point& vcPoint2)
297 result r = this->__pImpl->DrawLine(vcPoint1, vcPoint2);
299 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
305 Canvas::DrawPolygon(const Tizen::Base::Collection::IList& vcPoints)
309 result r = this->__pImpl->DrawPolygon(vcPoints);
311 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
317 Canvas::DrawPolyline(const Tizen::Base::Collection::IList& vcPoints)
321 result r = this->__pImpl->DrawPolyline(vcPoints);
323 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
329 Canvas::DrawRectangle(const Rectangle& vcRect)
333 result r = this->__pImpl->DrawRectangle(vcRect);
335 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
341 Canvas::DrawRoundRectangle(const Rectangle& vcRect, const Dimension& vcArcDim)
345 result r = this->__pImpl->DrawRoundRectangle(vcRect, vcArcDim);
347 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
353 Canvas::DrawTriangle(const Point& vcPoint1, const Point& vcPoint2, const Point& vcPoint3)
357 result r = this->__pImpl->DrawTriangle(vcPoint1, vcPoint2, vcPoint3);
359 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
365 Canvas::FillEllipse(const Color& color, const Rectangle& vcBounds)
369 result r = this->__pImpl->FillEllipse(color, vcBounds);
371 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
377 Canvas::FillPolygon(const Color& color, const Tizen::Base::Collection::IList& vcPoints)
381 result r = this->__pImpl->FillPolygon(color, vcPoints);
383 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
389 Canvas::FillRectangle(const Color& color, const Rectangle& vcRect)
393 result r = this->__pImpl->FillRectangle(color, vcRect);
395 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
401 Canvas::FillRoundRectangle(const Color& color, const Rectangle& vcRect, const Dimension& vcArcDim)
405 result r = this->__pImpl->FillRoundRectangle(color, vcRect, vcArcDim);
407 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
413 Canvas::FillTriangle(const Color& color, const Point& vcPoint1, const Point& vcPoint2, const Point& vcPoint3)
417 result r = this->__pImpl->FillTriangle(color, vcPoint1, vcPoint2, vcPoint3);
419 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
425 Canvas::DrawText(const Point& vcPoint, const Tizen::Base::String& text)
429 result r = this->__pImpl->DrawText(vcPoint, text);
431 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
437 Canvas::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int length)
441 result r = this->__pImpl->DrawText(vcPoint, text, 0, length);
443 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
449 Canvas::DrawText(const Point& vcPoint, const Tizen::Base::String& text, const Color& outlineColor)
453 result r = this->__pImpl->DrawText(vcPoint, text, 0, outlineColor);
455 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
461 Canvas::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int length, const Color& outlineColor)
465 result r = this->__pImpl->DrawText(vcPoint, text, 0, length, outlineColor);
467 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
473 Canvas::DrawText(const Point& vcPoint, const EnrichedText& etext)
477 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&etext), E_INVALID_ARG, "The source enriched text is invalid.\n");
479 result r = this->__pImpl->DrawText(vcPoint, etext);
481 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
487 Canvas::GetBounds(void) const
489 CHECK_CONSTRUCTED_EX(Rectangle());
491 return this->__pImpl->GetBounds();
495 Canvas::GetLineStyle() const
497 CHECK_CONSTRUCTED_EX(LINE_STYLE_MAX);
499 return this->__pImpl->GetLineStyle();
503 Canvas::GetLineWidth() const
505 CHECK_CONSTRUCTED_EX(-1);
507 return this->__pImpl->GetLineWidth();
511 Canvas::SetLineStyle(LineStyle style)
515 result r = this->__pImpl->SetLineStyle(style);
517 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
523 Canvas::SetLineWidth(int vcWidth)
527 result r = this->__pImpl->SetLineWidth(vcWidth);
529 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
535 Canvas::GetDashPattern(Tizen::Base::Collection::IListT<int>& pattern, int& offset) const
539 result r = this->__pImpl->GetDashPattern(pattern, offset);
541 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
547 Canvas::SetDashPattern(const Tizen::Base::Collection::IListT<int>& pattern, int offset)
551 result r = this->__pImpl->SetDashPattern(pattern, offset);
553 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
558 #if 0 // Not public feature yet
561 Canvas::SetDrawingQuality(BitmapDrawingQuality quality)
565 result r = this->__pImpl->SetDrawingQuality(quality);
567 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r,"[%s] Propagating.", GetErrorMessage(r));
573 Canvas::GetDrawingQuality(void) const
575 CHECK_CONSTRUCTED_EX(BITMAP_DRAWING_QUALITY_LOW);
577 return this->__pImpl->GetDrawingQuality();
583 Canvas::GetPixel(const Point& vcPoint, Color& color) const
587 result r = this->__pImpl->GetPixel(vcPoint, color);
589 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
595 Canvas::SetPixel(const Point& vcPoint)
599 result r = this->__pImpl->SetPixel(vcPoint);
601 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
611 result r = this->__pImpl->Show();
613 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
619 Canvas::Show(const Rectangle& vcRect)
623 result r = this->__pImpl->Show(vcRect);
625 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
631 Canvas::SetFont(const Font& font)
635 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&font), E_INVALID_ARG, "The source font is invalid.\n");
637 result r = this->__pImpl->SetFont(font);
639 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
645 Canvas::GetFontN(void) const
647 CHECK_CONSTRUCTED_EX(null);
649 Font* pReturnFont = this->__pImpl->GetFontN();
651 if (pReturnFont == null)
653 result r = GetLastResult();
655 SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
664 Canvas::SetClipBounds(const Rectangle& vcRect)
668 result r = this->__pImpl->SetClipBounds(vcRect);
670 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
676 Canvas::GetClipBounds(void) const
678 CHECK_CONSTRUCTED_EX(Rectangle());
680 return this->__pImpl->GetClipBounds();
684 Canvas::Lock(BufferInfo& info, long timeout)
688 result r = this->__pImpl->Lock(info, timeout);
690 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
700 result r = this->__pImpl->Unlock();
702 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
708 Canvas::SetForegroundColor(const Color& fgColor)
710 CHECK_CONSTRUCTED_VOID;
712 return this->__pImpl->SetForegroundColor(fgColor);
716 Canvas::GetForegroundColor(void) const
718 CHECK_CONSTRUCTED_EX(Color::GetColor(COLOR_ID_BLACK));
720 return this->__pImpl->GetForegroundColor();
724 Canvas::SetBackgroundColor(const Color& bgColor)
726 CHECK_CONSTRUCTED_VOID;
728 return this->__pImpl->SetBackgroundColor(bgColor);
732 Canvas::GetBackgroundColor(void) const
734 CHECK_CONSTRUCTED_EX(Color::GetColor(COLOR_ID_BLACK));
736 return this->__pImpl->GetBackgroundColor();
740 Canvas::SetPosition(const Point& vcPoint)
744 result r = this->__pImpl->SetPosition(vcPoint);
746 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
752 Canvas::SetPosition(int vcX, int vcY)
756 result r = this->__pImpl->SetPosition(vcX, vcY);
758 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
763 }} // Tizen::Graphics