我正在尝试了解 Tizen 中的多点触控示例。我在以下部分遇到问题(每次我将手指在画布上移动一个像素或更多时都会调用此方法):
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;
}
这是触摸方法的示例:
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");
}
我的 drawLine() 方法:
void
MainForm::DrawLine(const Tizen::Graphics::Point& prevPoint, const Tizen::Graphics::Point& point, const Tizen::Graphics::Color& color)
{
if (__pCanvas)
{
__pCanvas->DrawLine(prevPoint, point);
}
}
我不明白为什么在这里创建新画布(为什么旧画布被复制到新画布)。为什么调用 drawLine() 后旧画布没有更新?我们不能以某种方式刷新旧画布吗?
更新:
经过一些编辑,我设法创建了两个画布。我希望只能在 __pCanvas 范围内绘制,但现在它们是“蓝色”,我无法将它们设置为“红色”。
这是我的代码:
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;
}
和 onDraw 方法:
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;
}