Drawing Signature Onto Canvas (Windows Touchscreen)

  1. ‹ Older
  2. 12 months ago

    Dave S

    13 Dec 2018 San Diego, California USA
    Edited 12 months ago

    ok... perhaps just a few minutes.. .:)

    * add this property to the window

    Public Property points(-1) as pair

    * change mouseDOWN to this

    points.append x:y
    Self.Invalidate
    Return True

    change mouseDRAG to this

    points.append x:y
    Self.Invalidate

    change PAINT to this

    Dim i As Integer
    If points.Ubound<1 Then Return
    g.penwidth=5
    g.ForeColor=Color.blue
    For i=0 To points.Ubound-1
    g.drawline points(i).Left,points(i).Right,points(i+1).Left,points(i+1).Right
    Next i

    Super smooth, no voids

  3. Julian S

    13 Dec 2018 Pre-Release Testers, Xojo Pro UK
    Edited 12 months ago

    Cheers Dave. As Dave's pointing out, you need to interpolate a line between the samples as the sample/draw rate isn't fast enough to keep up with the motion of the pen so you need to fill the gaps in between. Straight lines as Dave's done here are nice and quick and are probably ample for your situation, if you want hyper smooth lines, break out your bezier curve formula ;)

  4. Aaron S

    13 Dec 2018 Pre-Release Testers, Xojo Pro San Diego, CA

    Dave - thank you so much! Just one minor issue...maybe has to do with being on the Windows platform. While I'm drawing, nothing appears until I let go of the mouse button. Very smooth lines, but I can't see what I'm drawing until I let go of the mouse.

    Julian - thank you for pointing me in the right direction. I'm more of a database guy with little expertise in the realm of graphic design, so bezier curve formulas would require some study :)

  5. Dave S

    13 Dec 2018 San Diego, California USA

    try replacing INVALIDATE with REFRESH and see it that works.... INVALIDATE is prefered (and works on macOS)... but WIndows may wait until other events are cleared first.

  6. Aaron S

    14 Dec 2018 Pre-Release Testers, Xojo Pro San Diego, CA

    Dave - you are amazing! How long did it take you to become this proficient in Xojo? I'm obviously in the learning phase and came from the world of FoxPro where I feel quite comfortable confident in my programming skills. Will you be at DevCon in Miami?

    There is just ONE more "quirk" with the code. When you release the mouse button and go somewhere else on the canvas to draw, a connecting line is made between the two drawings. Is there a way to circumvent this behaviour?

    I genuinely appreciate your guidance on this issue.

    -image-

  7. Dave S

    14 Dec 2018 San Diego, California USA

    @Aaron S Dave - you are amazing! How long did it take you to become this proficient in Xojo? I'm obviously in the learning phase and came from the world of FoxPro where I feel quite comfortable confident in my programming skills. Will you be at DevCon in Miami?

    There is just ONE more "quirk" with the code. When you release the mouse button and go somewhere else on the canvas to draw, a connecting line is made between the two drawings. Is there a way to circumvent this behaviour?

    I genuinely appreciate your guidance on this issue.

    -image-

    I will not be at DevCon or any other conference as I am on limited income and cannot afford such adventures :)

    The code would have to be modified to know when the mouse was "lifted", but at the same time it would have to know when you were starting and/or finishing a signature as well. This can all be done, I just quickly dashed out a solution that matched what the original program attempted to do

  8. Jeff T

    14 Dec 2018 Pre-Release Testers Midlands of England, Europe

    You need to notice that the mouse has been lifted in the MOUSEUP event.

    When another MOUSEDOWN occurs, you need a new set of POINTS()
    That suggests an array or a dictionary of Points() arrays.
    This may be a stretch for you at the moment

    OR (simpler)

    You notice the mouse has gone up in MOUSEUP, so you store a 'magic point' which is (for example) -1000,-1000

    Then your PAINT event becomes:

    Dim i As Integer
    If points.Ubound<1 Then Return
    g.penwidth=5
    g.ForeColor=Color.blue
    For i=0 To points.Ubound-1
         try
         if (points(i+1).left = -1000 and points(i+1).right = -1000 )    or  (points(i).left = -1000 and points(i).right = -1000 )      then
            //dont draw to or from the special point
         else
             g.drawline points(i).Left,points(i).Right,points(i+1).Left,points(i+1).Right
        end if
       catch
         //just in case out of range
        end try
    
    Next i
  9. Dave S

    14 Dec 2018 San Diego, California USA

    Not a NEW set of points, that would cause the first part of the signature to vanish.

    I would go with the "magic" point method. but you still need to know when you have started a totally NEW signature

  10. Dave S

    14 Dec 2018 San Diego, California USA

    Aaron..... this peaked my interest (yeah I'm bored).... I'll put together a whole demo based on what I posted originally... give me a bit

  11. Aaron S

    14 Dec 2018 Pre-Release Testers, Xojo Pro San Diego, CA

    Dave, Jeff, and Julian - thank you for your help! I'm grateful, as this will now help me create a signature area on a window with a content form. Ultimately, I'll need to assemble this consent form with the signature graphic and produce a PDF. This feature will also be very useful for a number of my other database projects.

    Dave, I'm very interested to see your demo!

  12. Dave S

    14 Dec 2018 Answer San Diego, California USA
    Edited 12 months ago

    That didn't take too long :)

    Here it is... should work just find on macOS or Windows

    www.rdsisemore.com/signature.xojo_xml_project.zip

    The CLEAR button erases the current signature so you can start over
    The ACCEPT button transfers the signature to a PICTURE image (imageSignature) so it can be used else where. The image is cropped to the minimum size for the signature to fit.

    When "writing" the signature is BLUE, when "accepted" it turns BLACK (so you know its been accepted and is stored in the image)

    It uses a modified version of what Jeff posted.

    FYI.... This routine could be coupled with my gPDF class to produce you final PDF document

  13. Aaron S

    14 Dec 2018 Pre-Release Testers, Xojo Pro San Diego, CA

    Dave - I love it! This works perfectly. I just purchased your gPDF class so I can pull all of this together. Thanks again. I'm sure many other developers will benefit from this solution. Maybe you should refine and sell this signature pad, make it work on iOS and web, etc.

  14. Ivan T

    14 Dec 2018 Pre-Release Testers
    Edited 12 months ago

    @Dave S That didn't take too long :)

    Here it is... should work just find on macOS or Windows

    www.rdsisemore.com/signature.xojo_xml_project.zip

    That is actually terrible code with terrible looking and terrible performance. It has a LOT of flicker and uses a LOT of procesing. As this is mostly used in portable devices, it will made a noticeable decrease in the battery life.

    Under any circumstances is a good idea to redraw ALL of the image just to ad a line of a few pixels. You shoud use caching and/or invalidating ONLY the modifyed part of the picture.

  15. Ivan T

    14 Dec 2018 Pre-Release Testers
    Edited 12 months ago

    @Dave S FYI.. macOS CPU maxxed at 12% for 2.5 seconds...

    Exactly, this approach is using 100% of the one core running the app. That is terrible performance for a simple task like this. Some people use 5 or 6 seconds, so, 100% core use for 4 seconds each it is a lot of wasted processing time and battery life.

    @Dave S In my testing, this works fantastically,

    The fact that in mac a bad aproeach looks ok, doesnt means that it is a good solution, nor taht it will work ok in other OS.

    @Dave S DO YOU HAVE A BETTER SOLUTION?

    shure:

    @Pedro I;Tellez&nbsp;Corella You shoud use caching and/or invalidating ONLY the modifyed part of the picture.

    @Dave S If you don't like it, need it or want it. then don't bother commenting...

    My coment whas for Aaron Schacht, to let him know the issues and propose some improvements. Dont take it personal.

  16. Bob K

    14 Dec 2018 Pre-Release Testers, Xojo Pro, Third Party Store Kansas City

    Let's keep the discussion civil, please.

  17. Aaron S

    16 Dec 2018 Pre-Release Testers, Xojo Pro San Diego, CA

    @Pedro I;Tellez&nbsp;Corella The solution Dave provided me with works very well, and in my particular case, it's only for a very specific purpose - quickly signing a legal waiver/release form on a Windows tablet. Pinning one CPU core for a few seconds will not really be an issue for my client. I do appreciate your suggestion. Still, I am too new to the Xojo platform to implement an image caching solution. Additionally, my strengths are more in the area of database development than anything else. Hopefully, in time, I'll develop my Xojo skills enough to offer my own suggestions and solutions to newbies on this forum!

or Sign Up to reply!