The Whiteboard
class works with the concept of several small strokes. At every moment, it captures the point where the touch is and draws a line compared to the previous point.
The magic of this concept of small dashes on the screen is in the drawTo
method within Whiteboard
; given a new point, knowing the previous point, draw the line:
private void drawTo(Graphics g, int pex, int pey)
{
g.drawLine(oldX,oldY,pex,pey); // guich@580_34: draw directly on screen
if (thick)
{
g.drawLine(oldX+1,oldY+1,pex+1,pey+1);
g.drawLine(oldX-1,oldY-1,pex-1,pey-1);
g.drawLine(oldX+1,oldY+1,pex-1,pey-1);
g.drawLine(oldX-1,oldY-1,pex+1,pey+1);
}
}
Note: if you are turned on to make a thick drawing, it will make an additional set of parallel lines, as seen in if (thick)
.
In the case of the first touch (event of type PEN_DOWN
), it ends up drawing a segment of zero pixels , which turns a dot on the screen:
public onEvent(Event event)
{
PenEvent pe;
switch (event.type)
{
[...]
case PenEvent.PEN_DOWN:
pe = (PenEvent)event;
oldX = pe.x;
oldY = pe.y;
drawTo(gImg, pe.x,pe.y); // after
if (gScr != null) drawTo(gScr,pe.x,pe.y);
getParentWindow().setGrabPenEvents(this); // guich@tc100: redirect all pen events to here, bypassing other processings
if (Settings.isOpenGL) te = addTimer(100);
break;
[...]
} [fim do onEvent]
When dragging the touch (event of type PEN_DRAG
), each drag capture Whiteboard
will make a stroke from the previous touch to the current touch:
public onEvent(Event event)
{
PenEvent pe;
switch (event.type)
{
[...]
case PenEvent.PEN_DRAG:
pe = (PenEvent)event;
drawTo(gImg, pe.x,pe.y); // before
if (gScr != null) drawTo(gScr,pe.x,pe.y);
oldX = pe.x;
oldY = pe.y;
if (!Settings.isOpenGL) Window.safeUpdateScreen(); // important at desktop!
break;
[...]
} [fim do onEvent]
In this case, the sensitivity of where the system picks up the click point ( pe.x
and pe.y
) depends on your finger and also on the device. Until the current time and the tests performed, the accuracy has been quite satisfactory.