Results 1 to 7 of 7

Thread: draw paint Demo (canvas) :)

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    draw paint Demo (canvas) :)

    hello all.

    I have a simple question what would be the best way to draw a "line", "circle" or "box" by user like illustrator application or corel draw app. with thinbasic UI module? no joke. I have used canvas for my example, but I am not satisfied with this one. may be the MDI features are made better for this draw modus ? I have no experience with this case, perhaps anybody can make some suggestions. thanks in advance.

    best regards, Frank
    Attached Images Attached Images
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: draw line canvas ?

    Hi Frank,

    what does it mean "not satisfied". It doesn't work?

    Here is bare bones drawing example:
    [code=thinbasic]
    Uses "UI"

    ' -- ID numbers of controls
    Begin Const
    %bClose = 1000
    %cCanvas

    End Const

    ' -- Create dialog here
    Function TBMAIN()
    Local hDlg As DWord

    Dialog NEW 0, "Click to paint",-1,-1, 320, 220, _
    %WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg

    ' -- Place controls here
    Control ADD CANVAS, hDlg, %cCanvas, "", 5, 5, 310, 190
    Control ADD BUTTON, hDlg, %bClose, "Click to close", 255, 200, 60, 14, Call bCloseProc

    Dialog SHOW MODAL hDlg, Call dlgProc

    End Function

    ' -- Callback for dialog
    CallBack Function dlgProc()
    Dim mousePosition As POINTAPI
    Static lastMousePosition As POINTAPI
    Dim locX, locY As Long
    Dim lastPos As POINTAPI

    ' -- Test for messages
    Select Case CBMSG

    Case %WM_INITDIALOG
    ' -- Put code to be executed after dialog creation here
    CANVAS_Attach(CBHNDL, %cCanvas, %FALSE)
    CANVAS_Clear(%BLACK)
    CANVAS_Scale PIXELS


    Case %WM_MOUSEMOVE
    If CBWPARAM = %MK_LBUTTON Then
    ' -- Get mouse position, convert it to canvas local coordinates
    Control GET LOC CBHNDL, %cCanvas To locX, locY
    WIN_GetCursorPos(mousePosition)
    WIN_ScreenToClient(CBHNDL, mousePosition)
    mousePosition.x -= locX
    mousePosition.y -= locY

    ' -- Paint a line
    If lastMousePosition.x > -1 Then
    CANVAS_Line((lastMousePosition.x, lastMousePosition.y), (mousePosition.x, mousePosition.y), %WHITE)
    CANVAS_Redraw
    End If

    lastMousePosition.x = mousePosition.x
    lastMousePosition.y = mousePosition.y
    End If
    Case %WM_LBUTTONDOWN
    ' -- Get mouse position, convert it to canvas local coordinates
    Control GET LOC CBHNDL, %cCanvas To locX, locY
    WIN_GetCursorPos(lastMousePosition)
    WIN_ScreenToClient(CBHNDL, lastMousePosition)
    lastMousePosition.x -= locX
    lastMousePosition.y -= locY



    Case %WM_LBUTTONUP
    lastMousePosition.x = -1
    lastMousePosition.y = -1

    Case %WM_CLOSE
    ' -- Put code to be executed before dialog end here

    End Select

    End Function

    ' -- Callback for close button
    CallBack Function bCloseProc()

    If CBMSG = %WM_COMMAND Then
    If CBCTLMSG = %BN_CLICKED Then
    ' -- Closes the dialog
    Dialog End CBHNDL
    End If
    End If

    End Function
    [/code]
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: draw line canvas ?

    hello petr, all.

    thanks for your example! I have used another example with different ui, but I have done a very long and complicate way (tried to include some kind of "graphic*.inc") to success for painting

    better to make a clear, more simpler issue: I am showing one paint example you can see what you are able do with this application in nearly future. in a short time (some days) there will more to come (one step after another) with "tb_paintMe".

    I add only one Demo.exe you can draw some line for text or graphic shapes. try and risk it for fun! running exe file I add. this idea of "tb_paint_demo" is exactly one year old.

    best regards, frank
    Attached Images Attached Images
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  4. #4

    Re: draw paint Demo (canvas) :)

    hello frank. thank you for this ineresting draw example! I was looking for such nice things. I am curious how you continue. if I canhelp, say to me. good luck. tom

  5. #5
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: draw paint Demo (canvas) :)

    good evening.

    I have a serious question about how I can get the mouse position / handling for

    a) canvas_MouseGetRButton (I wish to have this command for ui/canvas module)
    b) canvas_MouseGetPosX (I wish to have this command for ui/canvas module)

    for tbgl this commands already exists.

    added: how I can handle this behaviour for canvas ui ???

    [code=thinbasic]
    Case %WM_MOUSEMOVE
    gMousePt.X = LO(WORD,lParam)
    gMousePt.Y = HI(WORD,lParam) ' Current Mouse X and Y Position
    IF glbdown THEN
    'msgbox 0, "StartDrag"
    startpt = gmousept
    WHILE dragdetect (hWnd, startpt)
    SLEEP 2
    getcursorpos ( dragpt) ' screen coordinates
    screentoclient(hWnd, dragpt) ' window coordinates
    'msgbox 0, "DrawDrag", dragpt.x, dragpt.y
    WEND
    'msgbox 0, "EndDrag"
    gmousept = dragpt
    END IF
    [/code]

    any help would be appreciated. thanks. frank

    you can't always get what you want, but if you try sometimes you might find, you get what you need

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: draw paint Demo (canvas) :)

    Hi Frank,

    everything you need is in the example I posted, really!
    All you need to do is to make simple wrapper.

    I will not torture you, here you have it, but please, when I give you code, try to analyze it, you will see everything is there.

    So here you have the functions (did not tested, I let the tweaking on you):
    [code=thinbasic]
    Function Frank_CanvasMouseGetPosX(hDlg As DWord, id As Long) As Long

    Local mousePosition As POINTAPI
    Local locX, locY As Long
    WIN_GetCursorPos(mousePosition)
    WIN_ScreenToClient(hDlg, mousePosition)
    Control GET LOC hDlg, id To locX, locY

    mousePosition.x -= locX
    mousePosition.y -= locY

    Return mousePosition.x

    End Function

    Function Frank_CanvasMouseGetPosY(hDlg As DWord, id As Long) As Long

    Local mousePosition As POINTAPI
    Local locX, locY As Long
    WIN_GetCursorPos(mousePosition)
    WIN_ScreenToClient(hDlg, mousePosition)
    Control GET LOC hDlg, id To locX, locY

    mousePosition.x -= locX
    mousePosition.y -= locY

    Return mousePosition.y

    End Function

    Function Frank_CanvasMouseGetLButton() As Long
    GetAsyncKeyState(%VK_LBUTTON)
    Return GetAsyncKeyState(%VK_LBUTTON)
    End Function

    Function Frank_CanvasMouseGetRButton() As Long
    GetAsyncKeyState(%VK_RBUTTON)
    Return GetAsyncKeyState(%VK_RBUTTON)
    End Function
    [/code]
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #7
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    Re: draw paint Demo (canvas) :)

    hello petr.

    thanks first of all for your example. I have mixed my two draw examples. one I have built three days before you have sent your bare-bone-example and then I have updated all things with my first not-very-perfect example I have written as you can see in my first post. better for me to ask more for details in such cases and check all with calm. I am truly and didn't want to have one kind of solution for it. I am learning more to jump over hurdles after doing experiments and find the best way for my task. I have checked your last code example and see it's not necessary to have new canvas_mousgetpos or canvas_MouseGetRButton features. I think you know what I am meaning thanks.

    nice evening. frank
    you can't always get what you want, but if you try sometimes you might find, you get what you need

Similar Threads

  1. Replies: 6
    Last Post: 16-06-2010, 06:40

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •