Announcement

Collapse
No announcement yet.

help in drawing and 'undrawing' lines (more efficiently)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • help in drawing and 'undrawing' lines (more efficiently)

    'I want to move a line across a screen, so I need to 'undraw' 'the line that was there when I move to a new location.
    'Is there a way to draw-undraw an entire line (or shape)?
    'Surely there's a better way than pixel by pixel!!!

    'For now, this works, but it's slow!
    'this section sets each pixel in the line back to what it was
    'if the (0) part of the array shows we drew a line
    If ishapes&(0) Then
    ishapes&(0)=0
    For j=1 To wline
    Graphic Set Pixel (ixloc,wline-j) , ishapes&(j)
    Next
    End If
    '-------------------------
    'this section prepares to draw a line
    'whether or not the previous one exisited
    'it saves what was in each pixel to the array
    'then it draws a line in the new location

    ixloc=ixleft+(ixprint-ix1)*ixs 'find x axis
    ishapes&(0)=1'set pre condition to undraw it
    For j=1 To wline
    Graphic Get Pixel (ixloc,wline-j) To ishapes&(j)
    Next
    Graphic Style 2
    Graphic Line(ixloc, wline-1)-(ixloc,wy0),%Red

  • #2
    To un-draw why not
    GRAPHIC LINE (oldstartx,y) - (oldendx,y), backgroundcolor

    It will leave gaps in any intersecting lines, but your bit-by-bit appears to do that too, so maybe it's not an issue.

    Cheers,
    Dale

    Comment


    • #3
      Hi Doug,
      maybe GRAPHIC SET MIX can be useful

      Code:
      #COMPILE EXE
      #DIM ALL
      
      FUNCTION PBMAIN () AS LONG
      
        LOCAL hGWin AS DWORD
        LOCAL t AS STRING
      
        GRAPHIC WINDOW "Undraw test...",0,0,800,600 TO hGWin
        GRAPHIC ATTACH hGWin, 0, REDRAW
      
        GRAPHIC SET MIX %MIX_NOTXORSRC
      
        GRAPHIC LINE (200,200)-(600,500)
        GRAPHIC REDRAW
      
        SLEEP 2000
        GRAPHIC LINE (200,200)-(600,500)
        GRAPHIC SET POS (10,10)
        GRAPHIC PRINT "Press a key to exit..."
        GRAPHIC REDRAW
        
        ' restore the default mode...
        GRAPHIC SET MIX %MIX_COPYSRC
      
        
        GRAPHIC SET FOCUS
        DO
          GRAPHIC INKEY$ TO t
        LOOP UNTIL t <> ""
      
        GRAPHIC WINDOW END
      
      END FUNCTION
      bye

      Sergio

      Comment


      • #4
        Doug:

        I had the same problem aiming to restore the background screen after I draw something on it. My first trial was as you did, but actually it's quite slow. Then I tried using the Bitmap commands, since they are very fast, even restoring a big portion of the screen. You have to save the whole screen as a bitmap in the hard disk, and to restore you have to copy back just the necessary portion.

        Regards,
        Last edited by Manuel Valdes; 28 May 2009, 04:05 PM.

        Comment


        • #5
          Doug,
          depending on circumstances, a better plan may be as demonstrated here:
          http://www.powerbasic.com/support/pb...68&postcount=3

          One bitmap contains the background and you repeatedly redraw the background from that bitmap and draw over it the lines (or text in this case). That way you never need to undraw anything, you just redraw the original background over the top.

          Paul.

          Comment


          • #6
            Dale,
            Thanks, but I do need a quality image.
            I'm moving a cursor over market data.

            Sergio,
            I'm going to try that.

            Paul,
            That also looks pretty cool. It appears I could just "GRAPHIC COPY" where I am going to place a line or shape instead of the whole screen.

            Thanks all. I'll give these a try.

            Comment


            • #7
              Code:
               
              #COMPILE EXE
              #CONSOLE OFF
              DEFLNG a-z
              FUNCTION PBMAIN () AS LONG
               DESKTOP GET CLIENT TO PixW,PixH
               x1=0
               y1=0
               x2=PixW
               y2=PixH
               DESKTOP GET SIZE TO WinX,WinY
               Caption$=""
               GRAPHIC WINDOW caption$,x1,y1,x2,y2 TO hwin
               GRAPHIC ATTACH hwin,0,REDRAW
               GRAPHIC CLEAR &HDCF5F5
               GRAPHIC SET LOC -1,0
               GRAPHIC WIDTH 1
               FONT NEW "Courier New",20,1,0,0,0 TO fnt1
               GRAPHIC SET FONT fnt1
               GRAPHIC CHR SIZE TO CarW,CarH
               GRAPHIC COLOR %GRAY,&HDCF5F5
               FOR J=1 TO 20
                GRAPHIC SET POS(100,100+J*CarH)
                GRAPHIC PRINT "BACKGROUND BACKGROUND BACKGROUND BACKGROUND BACKGROUND BACKGROUND"
               NEXT
               GRAPHIC SET POS(100,100+CarH*22)
               GRAPHIC PRINT "Use cursor keys to move around or mouse clicks"
               GRAPHIC SET POS(100,100+CarH*23)
               GRAPHIC PRINT "to set the 'cursor' position.....<Esc> to exit"
               GRAPHIC REDRAW
               GRAPHIC SAVE "PANT.BMP"
               GRAPHIC BITMAP LOAD "PANT.BMP",0,0 TO hven
               J=1
               I=0
               DO
                GRAPHIC SET POS(100+11*CarW*I,100+CarH*J)
                GRAPHIC COLOR %BLACK,&H87B8DE
                GRAPHIC PRINT "BACKGROUND"
                GRAPHIC BOX(100+11*CarW*I,100+CarH*J)-(100-CarW+11*CarW*(I+1),100+CarH*(J+1)),,%RED
                GRAPHIC REDRAW
                DO
                 GRAPHIC INKEY$ TO CH$
                 GRAPHIC WINDOW CLICK TO clk&,mx!,my!
                 IF CH$<>"" OR clk&>0 THEN EXIT LOOP
                LOOP
                GRAPHIC COPY hven,0,(100+11*CarW*I,100+CarH*J)-(100+11*CarW*(I+1),100+CarH*(J+1)) TO (100+11*CarW*I,100+CarH*J)
                GRAPHIC REDRAW
                SELECT CASE CH$
                 CASE CHR$(0,80)
                  INCR J
                  IF J>20 THEN J=1
                 CASE CHR$(0,72)
                  DECR J
                  IF J<1 THEN J=20
                 CASE CHR$(0,77)
                  INCR I
                  IF I>5 THEN
                   I=0
                   INCR J
                   IF J>20 THEN J=1
                  END IF
                 CASE CHR$(0,75)
                  DECR I
                  IF I<0 THEN
                   I=5
                   DECR J
                   IF J<1 THEN J=20
                  END IF
                 CASE CHR$(27)
                  EXIT LOOP
                END SELECT
                IF (mx!>100 AND mx!<(100+66*CarW)) AND (my!>(100+CarH) AND my!<(100+21*CarH)) THEN
                 I=(mx!-100)\11*CarW
                 J=(my!-100)\CarH
                END IF
               LOOP
               GRAPHIC BITMAP END
               GRAPHIC WINDOW END
              END FUNCTION
              Last edited by Manuel Valdes; 30 May 2009, 07:25 PM.

              Comment


              • #8
                What about using XOR mode.

                ...
                Patrice Terrier
                www.zapsolution.com
                www.objreader.com
                Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                Comment


                • #9
                  The XOR effect may be what I am looking for, but I can't figure it out from the CC50 references.

                  Comment


                  • #10
                    Doug, I might be wrong, but.

                    Isn't that what Serigo is showing you with Graphic Set Mix, you might check it out.

                    Comment


                    • #11
                      Here is how to do it, using plain SDK:

                      Code:
                      DrawLine:
                          LOCAL lpen AS LOGPEN
                      
                          CALL GetClientRect(hView, rc)
                          hRgn& = CreateRectRgn(rc.nLeft, rc.nTop, rc.nRight, rc.nBottom)
                          CALL SelectClipRgn(hDC&, hRgn&)
                      
                          CALL SetROP2(hDC&, %R2_NOTXORPEN)
                      
                          lp.X = 1: lp.Y = 1
                          lpen.lopnStyle = %PS_SOLID
                          lpen.lopnWidth = lp
                          hPen& = SelectObject(hDC&, CreatePenIndirect(lpen))
                      
                          IF (LOWRD(InDrawingMode&) = %OBJECT_ELLIPSE) OR (LOWRD(InDrawingMode&) = %OBJECT_RECT) THEN
                             IF LOWRD(InDrawingMode&) = %OBJECT_RECT THEN
                                CALL Rectangle(hDC&, Drw.p(1).x - xCurrentScroll, Drw.p(1).y - yCurrentScroll, Drw.MouseX, Drw.MouseY)
                             ELSE
                                dX& = (Drw.MouseX + xCurrentScroll) - Drw.p(1).x: dY& = (Drw.MouseY + yCurrentScroll) - Drw.p(1).y
                                CALL Ellipse(hDC&, Drw.p(1).x - dX& - xCurrentScroll, Drw.p(1).y - dY& - yCurrentScroll, Drw.MouseX, Drw.MouseY)
                             END IF
                          ELSE
                             CALL MoveToEx(hDC&, Drw.p(1).x - xCurrentScroll, Drw.p(1).y - yCurrentScroll, BYVAL %NULL)
                             IF (LOWRD(InDrawingMode&) = %OBJECT_CURVE) OR (LOWRD(InDrawingMode&) = %OBJECT_POLYLINE) THEN
                                FOR D& = 2 TO Drw.count
                                    CALL LineTo(hDC&, Drw.p(D&).x - xCurrentScroll, Drw.p(D&).y - yCurrentScroll)
                                NEXT
                             END IF
                             CALL LineTo(hDC&, Drw.MouseX, Drw.MouseY)
                          END IF
                      
                          CALL zcDeleteObject(SelectObject(hDC&, hPen&))
                      
                          CALL SetROP2(hDC&, %R2_COPYPEN)
                          CALL zcDeleteObject(hRgn&)
                      
                          RETURN
                      See the MoveToEx, LineTo API, try also Googling the NET using R2_NOTXORPEN and SetROP2.

                      ...
                      Patrice Terrier
                      www.zapsolution.com
                      www.objreader.com
                      Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                      Comment


                      • #12
                        Hi Doug,

                        After the release of PBWIN 8, in 2005, I wrote several small programs to test the new facilities related with graphics. This is one that was made to test the write and unwrite lines using the %R2_NOTXORPEN mode for GRAPHIC SET MIX with excelent results. All in DDT mode.

                        The program is for PBWIN, I don't have an actual PBCC, but can be used with minor changes to PBCC. Perhaps can be useful.

                        Jordi
                        Attached Files

                        Comment


                        • #13
                          Doug,

                          try this:

                          Code:
                          ' PBCC5.XX
                          #COMPILE EXE
                          #DIM ALL
                          #INCLUDE "win32api.inc"
                          
                          FUNCTION PBMAIN () AS LONG
                          
                           PRINT STR$(%R2_NOTXORPEN);"/";STR$(%MIX_NOTXORSRC)  
                          
                            WAITKEY$
                            
                          END FUNCTION
                          %MIX_NOTXORSRC (used in my example) has the same value of %R2_NOTXORPEN

                          bye

                          Sergio

                          Comment


                          • #14
                            Rather than draw the lines a simple trick is to just use controls for the lines and then move the controls as needed. No worry about the background image.

                            Here is an example (PBWin 9.0):

                            Code:
                            ' ***************************************************************
                            '   This code can be used Royalty Free and Freely Distributed !
                            ' ***************************************************************
                            #COMPILE EXE
                            #REGISTER NONE
                            #DIM ALL          '  This is helpful to prevent errors in coding
                            
                            #INCLUDE "win32api.inc"   ' Must come first before other include files !
                            ' *************************************************************
                            '                  Constants and Declares (#1)
                            ' *************************************************************
                            %FORM1_Label1             = 90
                            %FORM1_LINEH              = 100
                            %FORM1_LINEV              = 105
                            %FORM1_BUTTON1            = 110
                            ' --------------------------------------------------
                            DECLARE SUB ShowDialog_Form1(BYVAL hParent&)
                            DECLARE CALLBACK FUNCTION Form1_DLGPROC
                            DECLARE CALLBACK FUNCTION CBF_FORM1_BUTTON1()
                            ' *************************************************************
                            '               Application Globals Variables (#2)
                            ' *************************************************************
                            GLOBAL hForm1&    ' Dialog handle
                            '
                            ' *************************************************************
                            '                    Application Entrance
                            ' *************************************************************
                            '
                            FUNCTION PBMAIN
                                LOCAL Count&
                                ShowDialog_Form1 0
                                DO
                                    DIALOG DOEVENTS TO Count&
                                LOOP UNTIL Count&=0
                            END FUNCTION
                            '
                            SUB MoveLines(BYVAL HPos&, BYVAL VPos&)
                                 LOCAL R AS RECT, hCtrl&, R1 AS RECT, R2 AS RECT
                                 GetClientRect hForm1&, R
                                 SendMessage hForm1&, %WM_SETREDRAW,0,0
                                 CONTROL HANDLE hForm1&,%FORM1_LINEH TO hCtrl&
                                 MoveWindow hCtrl&,0, HPos&, R.nRight-1,1,0
                                 CONTROL HANDLE hForm1&,%FORM1_LINEV TO hCtrl&
                                 MoveWindow hCtrl&,VPos&, 0, 1, R.nBottom-1,0
                                 SendMessage hForm1&, %WM_SETREDRAW,1,0
                                 DIALOG REDRAW hForm1&
                            END SUB
                            SUB ShowDialog_Form1(BYVAL hParent&)
                                LOCAL Style&, ExStyle&
                                LOCAL N&, CT&        '  Variables used for Reading Data in Arrays for Listbox and Combobox
                                '   hParent& = 0 if no parent Dialog
                                Style& = %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER OR %WS_CLIPCHILDREN
                                ExStyle& = 0
                                DIALOG NEW hParent&, "Moving Lines across dialog which are actually controls", 0, 0,  411,  243, Style&, ExStyle& TO hForm1&
                                DIALOG SET COLOR hForm1&, 0, RGB(255,255,255)
                            
                                CONTROL ADD LABEL, hForm1&,  %FORM1_LINEH,  "", 51, 103, 80, 12, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %WS_CLIPSIBLINGS
                                CONTROL SET COLOR hForm1&,  %FORM1_LINEH, 0, RGB(0,0,255)
                                CONTROL ADD LABEL, hForm1&,  %FORM1_LINEV,  "", 155, 25, 8, 170, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %WS_CLIPSIBLINGS
                                CONTROL SET COLOR hForm1&,  %FORM1_LINEV,0,RGB(0,0,255)
                                CONTROL ADD LABEL, hForm1&, %FORM1_Label1, "This is something in the background", 103,61, 206,122, %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER OR %WS_CLIPSIBLINGS OR %SS_CENTER OR %WS_BORDER OR %SS_CENTERIMAGE
                                CONTROL SET COLOR hForm1&,  %FORM1_Label1, 0, RGB(128,255,128)
                                CONTROL ADD "Button", hForm1&,  %FORM1_BUTTON1,  "Move Lines across", 315, 219, 91, 15, _
                                    %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_FORM1_BUTTON1
                                DIALOG SHOW MODELESS hForm1& , CALL Form1_DLGPROC
                            END SUB
                            ' *************************************************************
                            '                             Dialog Callback Procedure
                            '                             for Form Form1
                            '                             uses Global Handle - hForm1&
                            ' *************************************************************
                            CALLBACK FUNCTION Form1_DLGPROC
                                SELECT CASE CBMSG
                                    CASE %WM_INITDIALOG
                                         MoveLines 0,0
                                    CASE ELSE
                                END SELECT
                            END FUNCTION
                            '
                            ' *************************************************************
                            '   Application Callback Functions (or Subs) for Controls (#4)
                            ' *************************************************************
                            '
                            CALLBACK FUNCTION CBF_FORM1_BUTTON1
                                IF CBCTLMSG=%BN_CLICKED THEN
                                     LOCAL R AS RECT, X&, Y&, H&, V&
                                     DIALOG DISABLE hForm1&
                                     GetClientRect hForm1&, R
                                     FOR V&=0 TO (R.nRight-1)
                                         H&=V& MOD (R.nBottom)
                                         MoveLines H&, V&
                                         DIALOG DOEVENTS 1
                                         SLEEP 20
                                     NEXT I&
                                     DIALOG ENABLE hForm1&
                                END IF
                            END FUNCTION
                            Attached Files
                            Chris Boss
                            Computer Workshop
                            Developer of "EZGUI"
                            http://cwsof.com
                            http://twitter.com/EZGUIProGuy

                            Comment


                            • #15
                              Oblique ...
                              Patrice Terrier
                              www.zapsolution.com
                              www.objreader.com
                              Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                              Comment


                              • #16
                                In my opinion the easiest way is to use double buffer technic.

                                Double buffer allows you to work like with the old basic PCOPY.

                                ...
                                Patrice Terrier
                                www.zapsolution.com
                                www.objreader.com
                                Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                                Comment


                                • #17
                                  Doug, this is how easy it is to use Sergio's example to draw a line through text and remove it out without disturbing the text.

                                  Code:
                                  #COMPILE EXE
                                  #DIM ALL
                                  
                                  FUNCTION PBMAIN () AS LONG
                                  
                                    LOCAL hGWin AS DWORD
                                    LOCAL t AS STRING
                                  
                                    GRAPHIC WINDOW "Undraw test...",0,0,800,600 TO hgwin
                                    GRAPHIC ATTACH hGWin, 0, REDRAW
                                    
                                    GRAPHIC SET POS (200,300)
                                    GRAPHIC PRINT "Now is the time for all good men to come to the aid of their country"
                                    GRAPHIC SET POS (200,340)
                                    GRAPHIC PRINT "The quick red fox jumped over the lazy dogs back many times."
                                    GRAPHIC SET POS (200,380)
                                    GRAPHIC PRINT "Now is the time for all good men to come to the aid of their country"
                                    GRAPHIC REDRAW
                                    SLEEP 2000
                                    GRAPHIC SET MIX %MIX_NOTXORSRC
                                  
                                    GRAPHIC LINE (200,200)-(600,500)
                                    GRAPHIC REDRAW
                                  
                                    SLEEP 4000
                                    GRAPHIC LINE (200,200)-(600,500)
                                  
                                  
                                    GRAPHIC REDRAW
                                  
                                    ' restore the default mode...
                                    GRAPHIC SET MIX %MIX_COPYSRC
                                  
                                  
                                    GRAPHIC SET FOCUS
                                    SLEEP 4000
                                  
                                    GRAPHIC WINDOW END
                                  
                                  END FUNCTION
                                  Last edited by Jerry Fielden; 7 Jun 2009, 06:47 AM.

                                  Comment


                                  • #18
                                    What a great community!!!

                                    Jerry,
                                    I even tried your simple technique with various colors and large graphic width (1 to 8)

                                    Very nice. I got great ideas from the other folks, but this is easy for me to understand and doesn't require external stuff.

                                    Thanks all - this was a great exercise and very helpful!

                                    Doug

                                    Comment

                                    Working...
                                    X