The class Whiteboard
works with the concept of several small traits. At each 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 strokes on the screen is in the method drawTo
within the 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 connected 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
), he ends up drawing a zero pixel segment, what 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]
While dragging touch (event of type PEN_DRAG
), for each drag catch the Whiteboard
will make a dash 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 from which the system picks up the click point (pe.x
and pe.y
) depends on your finger and also on the device. So far and the tests performed, the accuracy has been well satisfactory.
The class
Whiteboard
is open, goes together in the SDK. Feel free to derive it or create a new class based on it. Just a minute for a more complete answer– Jefferson Quesado