I am trying to understand example for multitouch in Tizen. I am having problem with following part (this method is called every time I move my finger over the canvas by one pixel or more):
result
MainForm::OnDraw(void)
{
__pCanvas->Show();
__pCanvas->
Canvas* pCanvas = GetCanvasN();
if (pCanvas)
{
pCanvas->Copy(Point(GetClientAreaBounds().x, GetClientAreaBounds().y),
*__pCanvas, GetClientAreaBounds());
delete pCanvas;
}
// Do not call Show(); it is called automatically after OnDraw() callback
return E_SUCCESS;
}
Here is example of touch method:
void
MainForm::OnTouchMoved(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
{
__pointCount++;
__strokes[__strokeCount].push_back(currentPosition);
DrawLine(__prevPosition, currentPosition, Color::GetColor(COLOR_ID_BLACK));
Tizen::Base::String string;
string.Append("...");
string.Append((int)__pointCount);
__pCanvas->DrawText(Point(50, 300), string);
__prevPosition = currentPosition;
Invalidate(false);
AppLog("OnTouchMoved");
}
And my drawLine() method:
void
MainForm::DrawLine(const Tizen::Graphics::Point& prevPoint, const Tizen::Graphics::Point& point, const Tizen::Graphics::Color& color)
{
if (__pCanvas)
{
__pCanvas->DrawLine(prevPoint, point);
}
}
I don't understand why new canvas is created here (why old one is copied to new one). Why old canvas doesn't update after calling drawLine()? Can't we just refresh somehow the old canvas?
UPDATE:
After some editing, I managed to create two canvas. I want to be able to draw only in __pCanvas bounds, but now they are "blue" and I have problems setting them to "red".
Here is my code:
result
MainForm::OnInitializing(void)
{
(...)
AddTouchEventListener(*this);
SetMultipointTouchEnabled(false);
//SetMultipointTouchEnabled(true);
__pCanvas = new (std::nothrow) Canvas();
Rectangle rect = Rectangle(GetBounds().x, GetBounds().y, GetBounds().width, GetBounds().height);
result r = __pCanvas->Construct(rect);
__pInformationCanvas = new (std::nothrow) Canvas();
r = __pInformationCanvas->Construct(Rectangle(0, 0, GetBounds().width, verticalDivider));
if (r == E_SUCCESS)
{
__pCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_WHITE));
__pCanvas->Clear();
__pInformationCanvas->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
__pInformationCanvas->Clear();
Font font;
font.Construct(FONT_STYLE_PLAIN, FONT_SIZE);
__pCanvas->SetFont(font);
Invalidate(false);
}
return E_SUCCESS;
}
And the onDraw method:
result
MainForm::OnDraw(void)
{
Canvas* pCanvas = GetCanvasN();
if (pCanvas != null)
{
pCanvas->Clear();
pCanvas->Copy(Point(GetClientAreaBounds().x, GetClientAreaBounds().y),
*__pCanvas,
GetClientAreaBounds());
// Copy the second Canvas to the center of the Form's Canvas
pCanvas->Copy(Point(GetClientAreaBounds().x, GetClientAreaBounds().y),
*__pInformationCanvas,
__pInformationCanvas->GetBounds());
delete pCanvas;
}
// Do not call Show(). It will be called automatically after OnDraw() callback.
return E_SUCCESS;
}