I'm making a digital whiteboard program with C++Builder.
It draws lines on a TImage
using MouseDown
and MouseMove
events, like this:
Image1->Picture->Bitmap->Canvas->LineTo(x, y);
There is no problem when using the mouse.
However, when I use a Wacom tablet to draw the line, it doesn't fully recognize the movement of the pen. The problem occurs more when writing than when drawing a figure on the whiteboard.
I have no idea how to solve this problem.
What is the cause of the problem? How can I solve it?
Attached is the captured one to help you understand the problem. Same is written with mouse on the left side, and tablet pen on right side.
Code is like this:
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
MouseClick = true;
Image1->Picture->Bitmap->Canvas->MoveTo(X,Y);
Image1->Picture->Bitmap->Canvas->LineTo(X,Y);
if (Pen==1){
if(type==0) //pen
{
Image1->Picture->Bitmap->Canvas->Pen->Color = ColorDialog1->Color;
PenColor = ColorDialog1->Color;
}
else if(type==1) //eraser
{
Image1->Picture->Bitmap->Canvas->Pen->Color = clWhite;
PenColor = clWhite;
}
Image1->Picture->Bitmap->Canvas->Pen->Width = ScrollBar1->Position;
PenWidth = ScrollBar1->Position;
}
}
//--------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if(MouseClick)
{
Image1->Picture->Bitmap->Canvas->LineTo(X,Y);
}
}
MouseUp
handler? You need to setMouseClick=false;
when the mouse is released, soMouseMove
won't keep drawing. Alternatively, get rid ofMouseClick
and instead check if theShift
parameter containsssLeft
orssPen
. Also, I suggest having theMouse
handlers look at theButton
parameter and only update state whenButton
ismbLeft
.