Totalcross - Whiteboard starts dash with difference from the point initially pressed

3

I'm using the Whiteboard component for signatures, but when I draw a line, it draws with a difference from the starting point where I pressed the screen, making a vertical scratch of approximately 30 points, to make the dash depressed on the screen, How do I resolve this?

    
asked by anonymous 05.04.2017 / 21:04

3 answers

0
     case PenEvent.PEN_DOWN:
        pe = (PenEvent)event;
        oldX = pe.x;
        oldY = pe.y;
        yIni = 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;
     case PenEvent.PEN_DRAG:
        pe = (PenEvent)event;
        if (yIni>0) {                
            yDif = yIni -pe.y;         
            yIni = 0;                 
        }
        drawTo(gImg, pe.x,pe.y + yDif); // before
        if (gScr != null) drawTo(gScr, pe.x, pe.y + yDif);  
        oldX = pe.x;
        oldY = pe.y + yDif;
        if (!Settings.isOpenGL) Window.safeUpdateScreen(); // important at desktop!
        break;

I set the routine this way, I calculated the difference of the pe.y of the PEN_DOWN event with the pe.y of the PEN_DRAG event and applied it to the pe.y to draw the line.

    
08.04.2017 / 00:44
2

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.

    
05.04.2017 / 21:34
2
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]

Include the class in the project and after debugging, I commented the line with the

getParentWindow().setGrabPenEvents(this);

and worked correctly as expected.

What should I have done so that it was not necessary to comment on this line ???

    
05.04.2017 / 23:27