Announcement

Collapse
No announcement yet.

Graphic clear

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

  • Graphic clear

    GRAPHIC CLEAR and GRAPHIC CLEAR -1 seems to be failing.

    According to the docs:
    rgbColor&
    Optional RGB value representing the fill color. If rgbColor& is omitted (or -1), the graphic target is cleared to the default background color for the selected graphic target
    However, that does not seem to be the case:
    Code:
    #COMPILE EXE
    DEFLNG A - Z
    
    #IF NOT %DEF(%WINAPI)
      #INCLUDE "WIN32API.INC"
    #ENDIF
    
    #IF NOT %DEF(%COMMCTRL_INC)
      #INCLUDE "COMMCTRL.INC"
    #ENDIF
    
    #INCLUDE "PBForms.INC"
    
    %IDD_DIALOG1   =  101
    %LBX_Relations = 1001
    %LBL_Relations = 1002
    %GFX_Relations = 1003
    
    %DLG_MESS      = %WM_USER + 500
    
    $NULSPC = CHR$(0 TO 32)
    
    DECLARE FUNCTION Set_Box(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, Ag$(), Sz) AS LONG
    
    
    DECLARE FUNCTION Relations_DLG(BYVAL hParent AS DWORD) AS LONG
    
    DECLARE CALLBACK FUNCTION Relations_CB()
    
    FUNCTION PBMAIN()
      Relations_DLG %HWND_DESKTOP
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    
    CALLBACK FUNCTION Relations_CB()
    
    STATIC NumHeads   AS DWORD
    STATIC NumDatas   AS DWORD
    STATIC Nd         AS DWORD
    STATIC TxtWide    AS DWORD
    STATIC ChrWide    AS DWORD
    STATIC ChrHigh    AS DWORD
    STATIC NumAg      AS DWORD
    
    STATIC Dstart()   AS DWORD
    STATIC Dfield()   AS DWORD
    
    STATIC Dheads()   AS STRING
    STATIC Ddat()     AS STRING
    STATIC Abbr()     AS STRING
    STATIC Ag()       AS STRING
    STATIC Tribes()   AS STRING
    
    STATIC Dcat       AS STRING
    
    LOCAL DlgHnd  AS DWORD
    LOCAL CtlHnd  AS DWORD
    
    LOCAL Wparam  AS LONG
    LOCAL Lparam  AS LONG
    LOCAL CtlMess AS LONG
    
    LOCAL A   AS STRING
    LOCAL B   AS STRING
    
    DlgHnd = CBHNDL
    CtlHnd = CBCTL
    
    Lparam = CBLPARAM
    Wparam = CBWPARAM
    
    SELECT CASE AS LONG CBMSG
      CASE %WM_INITDIALOG
        ' Initialization handler
    
        LOCAL TxtHigh AS LONG
    
        DIM Ag$(1 TO 1)
        DIM Dstart(1 TO 1)
        DIM Dfield(1 TO 1)
        DIM Dheads$(1 TO 1)
        DIM Ddat$(1 TO 1)
    
        CALL Agreements(Ag$(), NumAg)
    '    CALL Read_Db(CURDIR$ + "\gamedb\$Leaders.FDB", Numheads, NumDatas, Dstart(), _
    '                 Dfield(), Dheads$(), Dcat$, Ddat$())
        NumDatas = 9
        DIM Tribes$(1 TO NumDatas)
    
    '    FOR I = 1 TO NumDatas
    '      Tribes$(I) = RTRIM$(MID$(Ddat$(I), Dstart(2), Dfield(2)), ANY $NULSPC)
    '    NEXT I
    
    '    CALL Read_Db(CURDIR$ + "\gamedb\$Relations.FDB", Numheads, Nd, Dstart(), _
    '                 Dfield(), Dheads$(), Dcat$, Ddat$())
    
        FOR I = 1 TO NumDatas
    '      IF VAL(MID$(Ddat$(I), Dstart(5), Dfield(5))) = 0 THEN Tribes$(I) = "?"
          Tribes$(I) = "?"
        NEXT I
    
    
        'if Val(Mid$(Ddat$(1), Dstart(5), Dfield(5)) = 0 then
        '  DestroyWindow(DlgHnd)
        'end if
    
        Set_Box(DlgHnd, %LBX_Relations, Ag$(), NumAg)
    
        GRAPHIC ATTACH DlgHnd, %GFX_Relations
    '    GRAPHIC CLEAR -1
    '    GRAPHIC Attach DlgHnd, %GFX_Relations, redraw
    
        GRAPHIC COLOR RGB(128, 0, 0), -2
        FONT NEW "courier new", 10, 3, 0, 1, 0 TO Fhndl
        GRAPHIC SET FONT Fhndl
    
        A$ = "0"
        GRAPHIC CHR SIZE TO ChrWide, ChrHigh
    
        ChrWide = ChrWide * 2
        ChrHigh = ChrHigh * 2
    
    '    A$ = SPACE$(Dfield(2))
        A$ = SPACE$(4)
        GRAPHIC TEXT SIZE A$ TO TxtWide, TxtHigh
    
        PostMessage(DlgHnd, %DLG_MESS, %LB_SETSEL, 1)
        PostMessage(DlgHnd, %DLG_MESS, %LB_GETSEL, 0)
    
      CASE %WM_NCACTIVATE
        STATIC hWndSaveFocus AS DWORD
        IF ISFALSE Wparam THEN
          ' Save control focus
          hWndSaveFocus = GetFocus()
        ELSEIF hWndSaveFocus THEN
          ' Restore control focus
          SetFocus(hWndSaveFocus)
          hWndSaveFocus = 0
        END IF
    
      CASE %WM_COMMAND
        ' Process control notifications
        CtlMess = CBCTLMSG
        SELECT CASE AS LONG CtlHnd
          CASE %LBX_Relations
            IF CtlMess = %LBN_SELCHANGE OR CtlMess = %LBN_DBLCLK THEN
              CONTROL HANDLE DlgHnd, %LBX_Relations TO CtlHnd
              Choice = SendMessage(CtlHnd, %LB_GETCURSEL, 0, 0) + 1
    
              CONTROL SET TEXT DlgHnd, %LBL_Relations, Ag$(Choice)
    
              GRAPHIC ATTACH DlgHnd, %GFX_Relations
    '          GRAPHIC CLEAR -1
    '          CALL Relations(DlgHnd, TxtWide, ChrWide, ChrHigh, Nd, NumDatas, _
    '                         Dstart(), Dfield(), Ddat$(), Tribes$(), I)
    
    '====================================================================
    
    '      AT THIS POINT GRAPHIC CLEAR should change the background color to white 
    '      then back to gray.  It doesn't.
    
    '====================================================================
    
              GRAPHIC CLEAR %WHITE
    
              SLEEP 1000
    
              GRAPHIC CLEAR -1
    
    '====================================================================
    
              X! = TxtWide + ChrWide
              Y! = 0
    
              GRAPHIC GET CLIENT TO Gfxx, Gfxy
    
              FOR I = 1 TO NumDatas
                GRAPHIC SET POS(X!, Y!)
                GRAPHIC PRINT Tribes$(I)
                Lx! = X! + TxtWide \ 2
                Ly! = Y! + ChrHigh \ 2
                IF Choice < 2 THEN
                  GRAPHIC LINE (Lx!, Ly!) - (Lx!, Gfxy), %BLUE
                ELSE
                  'GRAPHIC LINE (Lx!, Ly!) - (Lx!, Gfxy), %RED
                END IF
                X! = X! + TxtWide + ChrWide
              NEXT I
    
              X! = 0!
              Y! = ChrHigh
    
              FOR I = 1 TO NumDatas
                GRAPHIC SET POS(X!, Y!)
                GRAPHIC PRINT Tribes$(I)
                Lx! = X! + TxtWide + ChrWide
                Ly! = Y! + ChrHigh \ 4
                IF Choice < 2 THEN
                  GRAPHIC LINE (Lx!, Ly!) - (Gfxx, Ly!), %BLUE
                END IF
                Y! = Y! + ChrHigh
              NEXT I
    
    '          GRAPHIC REDRAW
              FUNCTION = 1
              EXIT FUNCTION
            END IF
    
        END SELECT
      CASE %DlG_MESS
        IF Wparam = %LB_SETSEL THEN LISTBOX SELECT DlgHnd, %LBX_Relations, Lparam
        IF Wparam = %LB_GETSEL THEN
          Wparam = MAK(DWORD, %LBX_Relations, %LBN_DBLCLK)
          CONTROL HANDLE DlgHnd, %LBX_Relations TO CtlHnd
          Lparam = MAK(DWORD, CtlHnd, 0)
          PostMessage(DlgHnd, %WM_COMMAND, Wparam, Lparam)
        END IF
    END SELECT
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '   ** Sample Code **
    '------------------------------------------------------------------------------
    
    FUNCTION Set_Box(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, Ag$(), Sz) AS LONG
    
    LOCAL I AS LONG
    
    FOR I = 1 TO Sz
      LISTBOX ADD hDlg, lID, Ag$(I)
    NEXT I
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    
    FUNCTION Relations_DLG(BYVAL hParent AS DWORD) AS LONG
    
    LOCAL lRslt AS LONG
    LOCAL hDlg  AS DWORD
    
    DIALOG NEW hParent, "Foreign Relations", 86, 55, 429, 223, %WS_OVERLAPPED _
      OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
      %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
      %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
      %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
    
    CONTROL ADD LISTBOX, hDlg, %LBX_Relations, , 5, 10, 95, 195, %WS_CHILD OR _
      %WS_VISIBLE OR %WS_TABSTOP OR %WS_VSCROLL OR %WS_HSCROLL OR %LBS_NOTIFY OR _
      %LBS_HASSTRINGS, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING _
      OR %WS_EX_RIGHTSCROLLBAR
    
    CONTROL ADD LABEL,   hDlg, %LBL_Relations, "War", 100, 10, 325, 10, _
      %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
    
    CONTROL ADD GRAPHIC, hDlg, %GFX_Relations, "", 110, 25, 315, 195
    
    CONTROL SET COLOR    hDlg, %LBL_Relations, RGB(0, 0, 128), -1 'RGB(128, 0, 0), -1
    
    hFont1 = PBFormsMakeFont("Courier New", 12, 700, %FALSE, %FALSE, %FALSE, _
      %ANSI_CHARSET)
    
    CONTROL SEND hDlg, %LBL_Relations, %WM_SETFONT, hFont1, 0
    
    DIALOG SHOW MODAL hDlg, CALL Relations_CB TO lRslt
    
    FUNCTION = lRslt
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    
    SUB Agreements(Ag$(), Sz)
    
    DATA "War"
    DATA "Preferred Trading Partner"
    DATA "Trade Embargos"
    DATA "Mutual Protection Pact"
    DATA "War Passage"
    DATA "Safe Passage"
    DATA "Trade Passage"
    DATA "Worker Passage"
    DATA "Military Alliances"
    
    Sz = DATACOUNT
    
    REDIM Ag$(1 TO Sz)
    
    FOR I = 1 TO Sz
      Ag$(I) = READ$(I)
    NEXT I
    
    END SUB
    Walt Decker

  • #2
    Walt,
    Since we seem to be working on the same sort of concepts at the same time, maybe this will demo where you may be going wrong

    Your problem is the default color not being set (until I check docs maybe just luck it was white and you set it white???)

    Anyways....check the 3 lines that have my comments '<---

    It should point it out.

    Code:
    #COMPILE EXE
    DEFLNG A - Z
    
    #IF NOT %DEF(%WINAPI)
      #INCLUDE "WIN32API.INC"
    #ENDIF
    
    #IF NOT %DEF(%COMMCTRL_INC)
      #INCLUDE "COMMCTRL.INC"
    #ENDIF
    
    #INCLUDE "PBForms.INC"
    
    %IDD_DIALOG1   =  101
    %LBX_Relations = 1001
    %LBL_Relations = 1002
    %GFX_Relations = 1003
    
    %DLG_MESS      = %WM_USER + 500
    
    $NULSPC = CHR$(0 TO 32)
    
    DECLARE FUNCTION Set_Box(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, Ag$(), Sz) AS LONG
    
    
    DECLARE FUNCTION Relations_DLG(BYVAL hParent AS DWORD) AS LONG
    
    DECLARE CALLBACK FUNCTION Relations_CB()
    
    FUNCTION PBMAIN()
      Relations_DLG %HWND_DESKTOP
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    
    CALLBACK FUNCTION Relations_CB()
    
    STATIC NumHeads   AS DWORD
    STATIC NumDatas   AS DWORD
    STATIC Nd         AS DWORD
    STATIC TxtWide    AS DWORD
    STATIC ChrWide    AS DWORD
    STATIC ChrHigh    AS DWORD
    STATIC NumAg      AS DWORD
    
    STATIC Dstart()   AS DWORD
    STATIC Dfield()   AS DWORD
    
    STATIC Dheads()   AS STRING
    STATIC Ddat()     AS STRING
    STATIC Abbr()     AS STRING
    STATIC Ag()       AS STRING
    STATIC Tribes()   AS STRING
    
    STATIC Dcat       AS STRING
    
    LOCAL DlgHnd  AS DWORD
    LOCAL CtlHnd  AS DWORD
    
    LOCAL Wparam  AS LONG
    LOCAL Lparam  AS LONG
    LOCAL CtlMess AS LONG
    
    LOCAL A   AS STRING
    LOCAL B   AS STRING
    
    DlgHnd = CBHNDL
    CtlHnd = CBCTL
    
    Lparam = CBLPARAM
    Wparam = CBWPARAM
    
    SELECT CASE AS LONG CBMSG
      CASE %WM_INITDIALOG
        ' Initialization handler
    
        LOCAL TxtHigh AS LONG
    
        DIM Ag$(1 TO 1)
        DIM Dstart(1 TO 1)
        DIM Dfield(1 TO 1)
        DIM Dheads$(1 TO 1)
        DIM Ddat$(1 TO 1)
    
        CALL Agreements(Ag$(), NumAg)
    '    CALL Read_Db(CURDIR$ + "\gamedb\$Leaders.FDB", Numheads, NumDatas, Dstart(), _
    '                 Dfield(), Dheads$(), Dcat$, Ddat$())
        NumDatas = 9
        DIM Tribes$(1 TO NumDatas)
    
    '    FOR I = 1 TO NumDatas
    '      Tribes$(I) = RTRIM$(MID$(Ddat$(I), Dstart(2), Dfield(2)), ANY $NULSPC)
    '    NEXT I
    
    '    CALL Read_Db(CURDIR$ + "\gamedb\$Relations.FDB", Numheads, Nd, Dstart(), _
    '                 Dfield(), Dheads$(), Dcat$, Ddat$())
    
        FOR I = 1 TO NumDatas
    '      IF VAL(MID$(Ddat$(I), Dstart(5), Dfield(5))) = 0 THEN Tribes$(I) = "?"
          Tribes$(I) = "?"
        NEXT I
    
    
        'if Val(Mid$(Ddat$(1), Dstart(5), Dfield(5)) = 0 then
        '  DestroyWindow(DlgHnd)
        'end if
    
        Set_Box(DlgHnd, %LBX_Relations, Ag$(), NumAg)
    
        GRAPHIC ATTACH DlgHnd, %GFX_Relations
    '    GRAPHIC CLEAR -1
    '    GRAPHIC Attach DlgHnd, %GFX_Relations, redraw
    
        GRAPHIC COLOR RGB(128, 0, 0), -2
        FONT NEW "courier new", 10, 3, 0, 1, 0 TO Fhndl
        GRAPHIC SET FONT Fhndl
    
        A$ = "0"
        GRAPHIC CHR SIZE TO ChrWide, ChrHigh
    
        ChrWide = ChrWide * 2
        ChrHigh = ChrHigh * 2
    
    '    A$ = SPACE$(Dfield(2))
        A$ = SPACE$(4)
        GRAPHIC TEXT SIZE A$ TO TxtWide, TxtHigh
    
        PostMessage(DlgHnd, %DLG_MESS, %LB_SETSEL, 1)
        PostMessage(DlgHnd, %DLG_MESS, %LB_GETSEL, 0)
    
      CASE %WM_NCACTIVATE
        STATIC hWndSaveFocus AS DWORD
        IF ISFALSE Wparam THEN
          ' Save control focus
          hWndSaveFocus = GetFocus()
        ELSEIF hWndSaveFocus THEN
          ' Restore control focus
          SetFocus(hWndSaveFocus)
          hWndSaveFocus = 0
        END IF
    
      CASE %WM_COMMAND
        ' Process control notifications
        CtlMess = CBCTLMSG
        SELECT CASE AS LONG CtlHnd
          CASE %LBX_Relations
            IF CtlMess = %LBN_SELCHANGE OR CtlMess = %LBN_DBLCLK THEN
              CONTROL HANDLE DlgHnd, %LBX_Relations TO CtlHnd
              Choice = SendMessage(CtlHnd, %LB_GETCURSEL, 0, 0) + 1
    
              CONTROL SET TEXT DlgHnd, %LBL_Relations, Ag$(Choice)
    
    GRAPHIC COLOR %BLUE, %RED                                             '<--- Set Default colors and watch what happens when you graphic clear
              GRAPHIC ATTACH DlgHnd, %GFX_Relations
    '          GRAPHIC CLEAR -1
    '          CALL Relations(DlgHnd, TxtWide, ChrWide, ChrHigh, Nd, NumDatas, _
    '                         Dstart(), Dfield(), Ddat$(), Tribes$(), I)
    
    '====================================================================
    
    '      AT THIS POINT GRAPHIC CLEAR should change the background color to white
    '      then back to gray.  It doesn't.
    
    '====================================================================
    
    '          GRAPHIC CLEAR %WHITE
              GRAPHIC CLEAR %BLACK                                             '<--- Clear and set background to black for demo
    
              SLEEP 1000
    
              GRAPHIC CLEAR -1                                                 '<--- Clear and set DEFAULT background
    
    '====================================================================
    
              X! = TxtWide + ChrWide
              Y! = 0
    
              GRAPHIC GET CLIENT TO Gfxx, Gfxy
    
              FOR I = 1 TO NumDatas
                GRAPHIC SET POS(X!, Y!)
                GRAPHIC PRINT Tribes$(I)
                Lx! = X! + TxtWide \ 2
                Ly! = Y! + ChrHigh \ 2
                IF Choice < 2 THEN
                  GRAPHIC LINE (Lx!, Ly!) - (Lx!, Gfxy), %BLUE
                ELSE
                  'GRAPHIC LINE (Lx!, Ly!) - (Lx!, Gfxy), %RED
                END IF
                X! = X! + TxtWide + ChrWide
              NEXT I
    
              X! = 0!
              Y! = ChrHigh
    
              FOR I = 1 TO NumDatas
                GRAPHIC SET POS(X!, Y!)
                GRAPHIC PRINT Tribes$(I)
                Lx! = X! + TxtWide + ChrWide
                Ly! = Y! + ChrHigh \ 4
                IF Choice < 2 THEN
                  GRAPHIC LINE (Lx!, Ly!) - (Gfxx, Ly!), %BLUE
                END IF
                Y! = Y! + ChrHigh
              NEXT I
    
    '          GRAPHIC REDRAW
              FUNCTION = 1
              EXIT FUNCTION
            END IF
    
        END SELECT
      CASE %DlG_MESS
        IF Wparam = %LB_SETSEL THEN LISTBOX SELECT DlgHnd, %LBX_Relations, Lparam
        IF Wparam = %LB_GETSEL THEN
          Wparam = MAK(DWORD, %LBX_Relations, %LBN_DBLCLK)
          CONTROL HANDLE DlgHnd, %LBX_Relations TO CtlHnd
          Lparam = MAK(DWORD, CtlHnd, 0)
          PostMessage(DlgHnd, %WM_COMMAND, Wparam, Lparam)
        END IF
    END SELECT
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '   ** Sample Code **
    '------------------------------------------------------------------------------
    
    FUNCTION Set_Box(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, Ag$(), Sz) AS LONG
    
    LOCAL I AS LONG
    
    FOR I = 1 TO Sz
      LISTBOX ADD hDlg, lID, Ag$(I)
    NEXT I
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    
    FUNCTION Relations_DLG(BYVAL hParent AS DWORD) AS LONG
    
    LOCAL lRslt AS LONG
    LOCAL hDlg  AS DWORD
    
    DIALOG NEW hParent, "Foreign Relations", 86, 55, 429, 223, %WS_OVERLAPPED _
      OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
      %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
      %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
      %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
    
    CONTROL ADD LISTBOX, hDlg, %LBX_Relations, , 5, 10, 95, 195, %WS_CHILD OR _
      %WS_VISIBLE OR %WS_TABSTOP OR %WS_VSCROLL OR %WS_HSCROLL OR %LBS_NOTIFY OR _
      %LBS_HASSTRINGS, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING _
      OR %WS_EX_RIGHTSCROLLBAR
    
    CONTROL ADD LABEL,   hDlg, %LBL_Relations, "War", 100, 10, 325, 10, _
      %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
    
    CONTROL ADD GRAPHIC, hDlg, %GFX_Relations, "", 110, 25, 315, 195
    
    CONTROL SET COLOR    hDlg, %LBL_Relations, RGB(0, 0, 128), -1 'RGB(128, 0, 0), -1
    
    hFont1 = PBFormsMakeFont("Courier New", 12, 700, %FALSE, %FALSE, %FALSE, _
      %ANSI_CHARSET)
    
    CONTROL SEND hDlg, %LBL_Relations, %WM_SETFONT, hFont1, 0
    
    DIALOG SHOW MODAL hDlg, CALL Relations_CB TO lRslt
    
    FUNCTION = lRslt
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    
    SUB Agreements(Ag$(), Sz)
    
    DATA "War"
    DATA "Preferred Trading Partner"
    DATA "Trade Embargos"
    DATA "Mutual Protection Pact"
    DATA "War Passage"
    DATA "Safe Passage"
    DATA "Trade Passage"
    DATA "Worker Passage"
    DATA "Military Alliances"
    
    Sz = DATACOUNT
    
    REDIM Ag$(1 TO Sz)
    
    FOR I = 1 TO Sz
      Ag$(I) = READ$(I)
    NEXT I
    
    END SUB
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

    Comment


    • #3
      No, Cliff that isn't the problem. I've been trying to figure this out for three days now and finally found the problem.

      Recreating the dialog line by line in a separate app I found that there is a conflict between GRAPHIC COLOR and GRAPHIC CLEAR.

      If, in the WM_INITDIALOG portion, GRAPHIC COLOR is rem'ed out it works. However, any text displayed will then be black instead of the color specified in GRAPHIC COLOR.

      At this point the only workaround I can think of is to either create a bitmap of the control prior to any drawing and copy that back to the control or repaint it the color of the dialog.

      Perhaps at this point specifying GRAPHIC COLOR -1, -2 prior to GRAPHIC CLEAR -1 then GRAPHIC COLOR Clr, -2 will work. However, if there is a subsequent module that performs GRAPHIC CLEAR -1 it will fail.

      Guess I'll have to send this to support, along with another app that crashes the compiler.
      Last edited by Walt Decker; 3 Apr 2009, 08:26 PM.
      Walt Decker

      Comment


      • #4
        >If, in the WM_INITDIALOG portion...

        I have no substantive documentation nor specific empirical results to offer, but over the years I have found that some GDI stuff does not seem to work correctly if you try to do it either on WM_INITDIALOG or WM_CREATE, which occur before the window is shown.

        So what I do is wait until the window IS shown to do it via posting myself a message...

        Code:
        %PWM_AFTER_CREATE   =  %WM_USER + 1 
        
        [CALLBACK]  FUNCTION WindowProcedure [ (params)] 
        
             ....
               CASE %WM_INITDIALOG  |  %WM_CREATE 
                    ... other stuff
                   ' LAST statement here 
                    PostMessage hWNd, %PWM_AFTER_CREATE, wParam, lparam 
              CASE %PWM_AFTER_CREATE 
                  ' this will be the first notificaton processed after 
                 ' the window is shown
        If nothing else it's really really easy to give this a try to see if it solves your problem.

        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Walt,

          I think this is what is going on..

          1). In INITDIALOG you are using GRAPHIC COLOR RGB(128, 0, 0), -2
          That's having the effect of setting the Forground Color -> REDish, BackGround -> NOT painted
          (allow pixels currently in that location to remain visible aka 'transparent'). This is not the same
          setting the background color to a particular value.

          2). In WM_COMMAND you are using GRAPHIC CLEAR %WHITE
          ie Clear all target pixels using White fill.

          After a delay you issue GRAPHIC CLEAR -1
          i.e. The Graphic Target is cleared to the 'default' background color for the Graphic Target.
          Because of the GRAPHIC COLOR statement in 1) that's 'Transparent' so the white shows through!

          Here's a work-around to get the effect you're expecting..
          Code:
            CASE %WM_INITDIALOG
              ' Initialization handler
          ...
              STATIC GFX_Bgnd As Long                             ' *
              GRAPHIC GET PIXEL (2, 2) TO GFX_Bgnd                ' *
              GRAPHIC COLOR RGB(128, 0, 0), -2
          ...
            CASE %WM_COMMAND
              ' Process control notifications
          ...
          '====================================================================
           
                    GRAPHIC CLEAR %WHITE
           
                    SLEEP 1000
           
                    GRAPHIC CLEAR GFX_Bgnd                        ' *
           
          '====================================================================
          ...
          Rgds, Dave

          Comment


          • #6
            Michael:

            I thought that "postmessage" worked that way, but that is not necessarily the case. In the example I post messages to %DLG_MESS to set the listbox selection and retrieve that selection. This is done on the assumption that those messages will be processed after the window is completely drawn. However, those messages are processed before the window is completed, at least in DDT they are.

            After doing a great deal of experimenting I found that no matter where GRAPHIC COLOR is used, GRAPHIC CLEAR -1 will fail if GRAPHIC COLOR Positive_Color is used first.

            Dave:

            GRAPHIC CLEAR has to do with clearing the window to either the default background color or the specified color, i. e., it erases everything on the window and replaces it with some color. GRAPHIC COLOR has to do with drawing text and sets the text color and text background color. There should not be a conflict between the two statements.

            A better workaround is:

            GRAPHIC COLOR -1, -2 (assuming that GRAPHIC COLOR was set previously with a positive value)

            GRAPHIC CLEAR -1 assuming you want the default background color which I do

            GRAPHIC COLOR ForeColor, BackColor
            GRAPHIC PRINT String$

            If one does not want the default control color, the above is not necessary because GRAPHIC CLEAR with a positive value will work.
            Last edited by Walt Decker; 4 Apr 2009, 11:27 AM.
            Walt Decker

            Comment


            • #7
              A GRAPHIC REDRAW after each of the GRAPHIC CLEAR statements might help.

              Comment


              • #8
                Walt,

                Your assumptions are leading you astray
                Try this...
                Code:
                '====================================================================
                          GRAPHIC CLEAR %WHITE
                 
                          SLEEP 1000
                 
                          Graphic Set Pos (55, 55)
                          Graphic Print "Why isn't this erased?"
                          Sleep 1000
                 
                          GRAPHIC CLEAR -1
                '====================================================================
                Last edited by Dave Biggs; 4 Apr 2009, 01:10 PM. Reason: Format
                Rgds, Dave

                Comment


                • #9
                  I have always had this problem, still on 8.04. GRAPHIC ATTACH without the REDRAW option instantly draws lines text etc but the background colour wont change without a specific GRAPHIC REDRAW

                  Comment


                  • #10
                    I don't think REDRAW is the problem here, it's more to do with what 'default background' means. Almost whether it's a color or a property.

                    Graphic Color -1, -2
                    If the background parameter is -2, the background is not painted, allowing the content behind to be visible.
                    This is not the same as setting the default background color to equal the current background (indeed the background may not be all one color).

                    In Walt's sample, when the graphic target is redraw by the GRAPHIC CLEAR -1 statement, it is drawn with the current background property - which has no colour assigned - allowing what is currently on the screen in that position to show through - ie White. (I think Walt is expecting to see the underlying dialog's background colour).
                    Rgds, Dave

                    Comment


                    • #11
                      Dave:

                      Your assumptions are leading you astray
                      It is not an assumption. In your snippet the text will be erased but the white background will not. This is due to a conflict between GRAPHIC COLOR maroon and GRAPHIC CLEAR no parameter or GRAPHIC CLEAR -1. If GRAPHIC COLOR is not specified before GRAPHIC CLEAR or if GRAPHIC COLOR -1 is specified before GRAPHIC CLEAR the background color of the graphic control will be shown. In any case, the text will be erased.

                      John:

                      Any time GRAPHIC ATTACH ... REDRAW is specified, a GRAPHIC REDRAW must follow otherwise the graphic control will not be updated.

                      The following code will illustrate the conflict. In the grid sub if Clr is -1 the background color of the graphic control, which is gray, should be shown. It is not because GRAPHIC COLOR maroon is stated before GRAPHIC CLEAR is stated.

                      Code:
                      #PBFORMS CREATED V1.51
                      '------------------------------------------------------------------------------
                      ' The first line in this file is a PB/Forms metastatement.
                      ' It should ALWAYS be the first line of the file. Other
                      ' PB/Forms metastatements are placed at the beginning and
                      ' end of "Named Blocks" of code that should be edited
                      ' with PBForms only. Do not manually edit or delete these
                      ' metastatements or PB/Forms will not be able to reread
                      ' the file correctly.  See the PB/Forms documentation for
                      ' more information.
                      ' Named blocks begin like this:    #PBFORMS BEGIN ...
                      ' Named blocks end like this:      #PBFORMS END ...
                      ' Other PB/Forms metastatements such as:
                      '     #PBFORMS DECLARATIONS
                      ' are used by PB/Forms to insert additional code.
                      ' Feel free to make changes anywhere else in the file.
                      '------------------------------------------------------------------------------
                      
                      #COMPILE EXE
                      DEFLNG A - Z
                      
                      '------------------------------------------------------------------------------
                      '   ** Includes **
                      '------------------------------------------------------------------------------
                      #PBFORMS BEGIN INCLUDES
                      #IF NOT %DEF(%WINAPI)
                        #INCLUDE "WIN32API.INC"
                      #ENDIF
                      #IF NOT %DEF(%COMMCTRL_INC)
                        #INCLUDE "COMMCTRL.INC"
                      #ENDIF
                      #INCLUDE "PBForms.INC"
                      #PBFORMS END INCLUDES
                      '------------------------------------------------------------------------------
                      
                      '------------------------------------------------------------------------------
                      '   ** Constants **
                      '------------------------------------------------------------------------------
                      #PBFORMS BEGIN CONSTANTS
                      %IDD_DIALOG1   =  101
                      %LBX_Relations = 1001
                      %GFX_Relations = 1002
                      %BTN_Redraw    = 1003
                      %LBL_Relations = 1004
                      #PBFORMS END CONSTANTS
                      
                      %DLG_MESS = %WM_USER + 500
                      '------------------------------------------------------------------------------
                      
                      '------------------------------------------------------------------------------
                      '   ** Declarations **
                      '------------------------------------------------------------------------------
                      DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                      DECLARE FUNCTION SampleListBox(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL _
                        lCount AS LONG) AS LONG
                      DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                      #PBFORMS DECLARATIONS
                      '------------------------------------------------------------------------------
                      
                      '------------------------------------------------------------------------------
                      '   ** Main Application Entry Point **
                      '------------------------------------------------------------------------------
                      FUNCTION PBMAIN()
                        PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
                          %ICC_INTERNET_CLASSES)
                      
                        ShowDIALOG1 %HWND_DESKTOP
                      END FUNCTION
                      '------------------------------------------------------------------------------
                      
                      '------------------------------------------------------------------------------
                      '   ** CallBacks **
                      '------------------------------------------------------------------------------
                      CALLBACK FUNCTION ShowDIALOG1Proc()
                      
                      LOCAL DlgHnd  AS DWORD
                      LOCAL CtlHnd  AS DWORD
                      LOCAL DlgMess AS DWORD
                      
                      LOCAL Wparam  AS LONG
                      LOCAL Lparam  AS LONG
                      
                      DlgHnd = CBHNDL
                      CtlHnd = CBCTL
                      
                      Wparam = CBWPARAM
                      Lparam = CBLPARAM
                      
                        SELECT CASE AS LONG CBMSG
                          CASE %WM_INITDIALOG
                            ' Initialization handler
                            GRAPHIC ATTACH DlgHnd, %GFX_Relations
                            GRAPHIC COLOR RGB(128, 0, 0), 0
                            PostMessage(DlgHnd, %DLG_MESS, %LB_SETSEL, 1)
                            PostMessage(DlgHnd, %DLG_MESS, %LB_GETSEL, 0)
                      
                          CASE %WM_NCACTIVATE
                            STATIC hWndSaveFocus AS DWORD
                            IF ISFALSE CBWPARAM THEN
                              ' Save control focus
                              hWndSaveFocus = GetFocus()
                            ELSEIF hWndSaveFocus THEN
                              ' Restore control focus
                              SetFocus(hWndSaveFocus)
                              hWndSaveFocus = 0
                            END IF
                      
                          CASE %WM_COMMAND
                            CtlMess = CBCTLMSG
                            ' Process control notifications
                            SELECT CASE AS LONG CtlHnd
                              CASE %LBX_Relations
                                IF CtlMess = %LBN_SELCHANGE OR CtlMess = %LBN_DBLCLK THEN
                                  CONTROL HANDLE DlgHnd, CtlHnd TO CtlHnd
                                  I = SendMessage(CtlHnd, %LB_GETCURSEL, 0, 0) + 1
                                  SELECT CASE I
                                    CASE 1
                                      Clr = %BLACK
                                      ClerClr = -1
                                    CASE 2
                                      Clr = %WHITE
                                      ClerClr = RGB(128, 0, 0)
                                    CASE 3
                                      Clr = %BLUE
                                      ClerClr = RGB(0, 128, 0)
                                    CASE 4
                                      Clr = %GREEN
                                      ClerClr = RGB(0, 0, 128)
                                    CASE 5
                                      Clr = %MAGENTA
                                      ClerClr = RGB(128, 128, 128)
                                  END SELECT
                                  GRAPHIC CLEAR RGB(RND(0, 255), RND(0, 255), RND(0, 255))
                                  GRAPHIC SET POS(0, 0)
                                  GRAPHIC PRINT "This is some text"
                                  SLEEP 1000
                                  CALL Grid(ClerClr, Clr)
                                  SLEEP 1000
                                  CALL Circle(Clr)
                                END IF
                              CASE %BTN_Redraw
                                IF CtlMess = %BN_CLICKED THEN
                                  GRAPHIC REDRAW
                                END IF
                      
                            END SELECT
                          CASE %DlG_MESS
                            IF Wparam = %LB_SETSEL THEN LISTBOX SELECT DlgHnd, %LBX_Relations, Lparam
                            IF Wparam = %LB_GETSEL THEN
                              Wparam = MAK(DWORD, %LBX_Relations, %LBN_DBLCLK)
                              CONTROL HANDLE DlgHnd, %LBX_Relations TO CtlHnd
                              Lparam = MAK(DWORD, CtlHnd, 0)
                              PostMessage(DlgHnd, %WM_COMMAND, Wparam, Lparam)
                            END IF
                      
                        END SELECT
                      END FUNCTION
                      '------------------------------------------------------------------------------
                      
                      '------------------------------------------------------------------------------
                      '   ** Sample Code **
                      '------------------------------------------------------------------------------
                      FUNCTION SampleListBox(BYVAL hDlg AS DWORD, BYVAL lID AS LONG, BYVAL lCount _
                        AS LONG) AS LONG
                        LOCAL i AS LONG
                      
                        FOR i = 1 TO lCount
                          LISTBOX ADD hDlg, lID, USING$("Test Item #", i)
                        NEXT i
                      END FUNCTION
                      '------------------------------------------------------------------------------
                      
                      '------------------------------------------------------------------------------
                      '   ** Dialogs **
                      '------------------------------------------------------------------------------
                      FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                        LOCAL lRslt AS LONG
                      
                      #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
                        LOCAL hDlg   AS DWORD
                        LOCAL hFont1 AS DWORD
                      
                        DIALOG NEW hParent, "Dialog1", 59, 70, 388, 249, %WS_POPUP OR %WS_BORDER OR _
                          %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR _
                          %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
                          %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                          %WS_EX_RIGHTSCROLLBAR, TO hDlg
                        CONTROL ADD LISTBOX, hDlg, %LBX_Relations, , 10, 20, 90, 185, %WS_CHILD OR _
                          %WS_VISIBLE OR %WS_TABSTOP OR %WS_VSCROLL OR %LBS_NOTIFY, _
                          %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                          %WS_EX_RIGHTSCROLLBAR
                        CONTROL ADD GRAPHIC, hDlg, %GFX_Relations, "", 105, 35, 280, 170
                        CONTROL ADD BUTTON,  hDlg, %BTN_Redraw, "Redraw", 140, 230, 65, 10
                        CONTROL ADD LABEL,   hDlg, %LBL_Relations, "War", 100, 10, 270, 20, _
                          %WS_CHILD OR %WS_VISIBLE OR %SS_CENTER, %WS_EX_LEFT OR %WS_EX_LTRREADING
                        CONTROL SET COLOR    hDlg, %LBL_Relations, RGB(128, 0, 0), -1
                      
                        hFont1 = PBFormsMakeFont("Courier New", 10, 700, %FALSE, %FALSE, %FALSE, _
                          %ANSI_CHARSET)
                      
                        CONTROL SEND hDlg, %LBL_Relations, %WM_SETFONT, hFont1, 0
                      #PBFORMS END DIALOG
                      
                        SampleListBox  hDlg, %LBX_Relations, 5
                      
                        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                      
                      #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
                        DeleteObject hFont1
                      #PBFORMS END CLEANUP
                      
                        FUNCTION = lRslt
                      END FUNCTION
                      
                      '---------------------------------------------
                      '---------------------------------------------
                      
                      SUB Circle(Clr)
                      
                      GRAPHIC GET CLIENT TO X, Y
                      Rad! = 4 * ATN(1)
                      Rad! = Rad! / 180
                      Radius = 25
                      Cx! = X \ 2
                      Cy! = Y \ 2
                      Lx! = Cx!
                      Ly! = Cy! - Radius
                      
                      GRAPHIC SET POS(Lx!, Ly!)
                      
                      FOR K = 0 TO 360 STEP 15
                        XX! = Cx! + Radius * SIN(K * Rad!)
                        YY! = Cy! - Radius * COS(K * Rad!)
                        GRAPHIC LINE (Lx!, Ly!) - (XX!, YY!), Clr
                        Lx! = XX!
                        Ly! = YY!
                      NEXT K
                      GRAPHIC PAINT (Cx!, Cy!), Clr, Clr
                      
                      END SUB
                      
                      '-------------------------------------------------
                      '-------------------------------------------------
                      
                      SUB Grid(BYVAL Clr AS LONG, BYVAL Choice AS DWORD)
                      
                      GRAPHIC CLEAR Clr
                      
                      GRAPHIC GET CLIENT TO Gfxx, Gfxy
                      
                      Offsx = Gfxx \ 10
                      Offsy = Gfxy \ 10
                      
                      FOR I = 0 TO Gfxx STEP Offsx
                        GRAPHIC LINE(I, 0) - (I, Gfxy), %BLUE
                      NEXT I
                      
                      FOR I = 0 TO Gfxy STEP Offsy
                        GRAPHIC LINE(0, I) - (Gfxx, I), %BLUE
                      NEXT I
                      
                      END SUB
                      Walt Decker

                      Comment


                      • #12
                        Sorry if I'm making assumptions about what you are assuming

                        In your snippet the text will be erased but the white background will not.
                        Actually the text is NOT erased - that was the point really.

                        Please try the snippet in the code that you originally posted. If it doesn't give the
                        same result as on my machine, there would have to be a hardware component to this issue.

                        On my machine the text is still there after the grid has been redrawn as it is at this point part of the
                        background which is allowed to show through with the combined effects of these statements..

                        GRAPHIC COLOR RGB(128, 0, 0), -2 (Set (default) Background to UnPainted)
                        GRAPHIC CLEAR -1 (Clear with default Background (UnPainted)).


                        In your latest sample the background color of %GFX_Relations is being set to %Black (0) in INITDIALOG
                        (That statement occurs after the CONTROL SET COLOR statement in ShowDIALOG1).
                        In the previous example you used -2 in the GRAPHIC COLOR statement.

                        You are processing a bunch of stuff in INITDIALOG too which is possibly muddying the waters.
                        (see http://www.powerbasic.com/support/pb...ad.php?t=40271 posts 8 & 9 )
                        Last edited by Dave Biggs; 5 Apr 2009, 05:37 AM. Reason: Fix link to Graphic attach, ....Redraw thread
                        Rgds, Dave

                        Comment


                        • #13
                          Here's another test to explore the relationship between GRAPHIC COLOR and GRAPHIC CLEAR.
                          Code:
                          #COMPILE EXE
                          #DIM ALL
                          #INCLUDE "win32API.inc"
                          FUNCTION PBMAIN() AS LONG
                           LOCAL hDlg AS DWORD
                            DIALOG NEW PIXELS, 0, "Color Test", 300, 300, 200, 200, %WS_OVERLAPPEDWINDOW TO hDlg
                              CONTROL ADD BUTTON, hDlg, 100, "Add GFX Control", 50, 10, 100, 20
                              DIALOG SET COLOR hDlg, -1&, %RGB_HONEYDEW
                           
                            DIALOG SHOW MODAL hDlg CALL DlgProc
                          END FUNCTION
                          '------------------/
                           
                          CALLBACK FUNCTION DlgProc() AS LONG
                             IF CB.MSG = %WM_COMMAND AND CB.CTL = 100 AND CB.CTLMSG = %BN_CLICKED THEN
                                CONTROL ADD GRAPHIC, CB.HNDL, 101, "", 10, 40, 180, 150, _
                                                     %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %SS_NOTIFY
                                ' Graphic Control is initially drawn with frgnd = %COLOUR_WINDOWTEXT, bkgnd = %COLOR_3DFACE
                                ' (NB. CONTROL SET COLOR statement has no effect on a Graphic Control)
                           
                                GRAPHIC ATTACH CB.HNDL, 101                         ' <- Target has initial frgnd and bkgnd.
                                GRAPHIC PRINT "(1) Text on background"
                                SLEEP 1000
                                GRAPHIC CLEAR -1&                                   ' (1) Erased by Graphic Clear -1    
                                WinBeep 1000,50 : SLEEP 1000                        ' as 'Default' Bgnd = %COLOR_3DFACE 
                           
                                GRAPHIC COLOR -1, -2                                ' <- sets background to "Unpainted".
                                GRAPHIC PRINT "(2) Text on background"
                                SLEEP 1000
                                GRAPHIC CLEAR -1&                                   ' (2) Not erased by Graphic Clear -1 
                                WinBeep 400,50 : SLEEP 1000                         ' as 'Default' Bgnd now = "Unpainted"
                           
                                GRAPHIC COLOR %RED, -2
                                GRAPHIC SET POS (25, 10)
                                GRAPHIC PRINT "Red, transp"
                                GRAPHIC ELLIPSE (25,25)-(150,55)
                           
                                GRAPHIC SET POS (25, 60)
                                GRAPHIC COLOR %GREEN, %RGB_BLUE
                                GRAPHIC PRINT "Green, Blue"
                                GRAPHIC ELLIPSE (25,75)-(150,110)
                           
                                GRAPHIC ELLIPSE (25,120)-(100,140), , %YELLOW
                                '
                                'GRAPHIC ELLIPSE (x1!, y1!) - (x2!, y2!) [, [rgbColor&] [,[fillcolor&] [, [fillstyle&]]]]
                                'rgbColor& - Optional RGB color of the ellipse edge.
                                '            If omitted (or -1), the edge color defaults to the current foreground color for
                                '            the selected graphic window.
                                'fillcolor& - Optional RGB color of the ellipse interior.
                                '            If fillcolor& is omitted (or -2), the interior of the ellipse is not filled,
                                '            allowing the background to show through.
                             END IF
                          END FUNCTION
                          '------------------/
                          Rgds, Dave

                          Comment


                          • #14
                            Originally posted by Walt Decker View Post
                            John:

                            Any time GRAPHIC ATTACH ... REDRAW is specified, a GRAPHIC REDRAW must follow otherwise the graphic control will not be updated.
                            Walt
                            You misread my post, I said without using the REDRAW option.
                            In your first code example you gave a simple 3 lines of code which just set the background colour twice using GRAPHIC CLEAR. Why not humour me and just add a GRAPHIC REDRAW after each of the two GRAPHIC CLEAR statements. If it doen't work I will apologise for wasting a small amount of your time.
                            John

                            Comment


                            • #15
                              John:

                              I'm sorry. I did misread your post. In this case graphic redraw does not help because of the conflict between graphic color and graphic clear.

                              Dave:

                              You're almost there, but not quite. The point is, GRAPHIC CLEAR and GRAPHIC CLEAR -1 should erase everything on the window and expose the default window color (gray). It doesn't when GRAPHIC COLOR ForeColor, -2 is specified. In fact, it doesn't erase anything.

                              Also, GRAPHIC COLOR ForeColor, BackColor over-rides GRAPHIC CLEAR / (-1) with BackColor. It shouldn't.

                              In the following PBCC5 example:

                              GRAPHIC COLOR is set to maroon (&H80), -2 (transparent).
                              GRAPHIC CLEAR is set to -1 (clear to default window color).

                              When you enter a number the window is supposed to clear the
                              rectangle and draw another at a different location, but,
                              as you can see, nothing is cleared.

                              If you enter a number 3 times, GRAPHIC COLOR is set to
                              &H80, %WHITE. No change is made to GRAPHIC CLEAR.

                              One more entry and the color of the window is painted white
                              This causes subsequent rectangles to be overwritten by the
                              background color of the text.

                              On the 5th entry, GRAPHIC COLOR is set to &H80, -2, and
                              once again nothing is erased.

                              If this doesn't point out the conflict I don't know what else I can do to explain it.

                              Code:
                              #COMPILE EXE
                              #BREAK ON
                              DEFLNG A - Z
                              
                              FUNCTION PBMAIN () AS LONG
                              
                              CONSOLE SET SCREEN 4, 40
                              PRINT "press 0 to quit"
                              PRINT "press any other number to continue"
                              
                              RANDOMIZE TIMER
                              
                              Ux = 50
                              Uy = 50
                              Lx = Ux + 50
                              Ly = Uy + 50
                              
                              GRAPHIC WINDOW "", 200, 200, 300, 300 TO WinHndl
                              GRAPHIC ATTACH WinHndl, 0
                              CONSOLE SET FOCUS
                              GRAPHIC COLOR &H80, -2
                              Times = 0
                              Continue: '
                              
                              GRAPHIC BOX (Ux, Uy) - (Lx, Ly), 0, %RED, RGB(RND(0, 255), RND(0, 255), RND(0, 255))
                              GRAPHIC SET POS (0, 0)
                              GRAPHIC PRINT "GRAPHIC COLOR is set to maroon (&H80), -2 (transparent)"
                              GRAPHIC SET POS(0, 15)
                              GRAPHIC PRINT "GRAPHIC CLEAR is set to -1 (clear to default window color)"
                              GRAPHIC SET POS(0, 45)
                              GRAPHIC PRINT "When you enter a number the window is supposed to clear the"
                              GRAPHIC SET POS(0, 60)
                              GRAPHIC PRINT "rectangle and draw another at a different location, but, "
                              GRAPHIC SET POS(0, 75)
                              GRAPHIC PRINT "as you can see, nothing is cleared"
                              GRAPHIC SET POS(0, 105)
                              GRAPHIC PRINT "If you enter a number 3 times, GRAPHIC COLOR is set to"
                              GRAPHIC SET POS(0, 120)
                              GRAPHIC PRINT "&H80, %WHITE. No change is made to GRAPHIC CLEAR"
                              GRAPHIC SET POS(0, 155)
                              GRAPHIC PRINT "One more entry and the color of the window is painted white"
                              GRAPHIC SET POS(0, 170)
                              GRAPHIC PRINT "This causes subsequent rectangles to be overwritten by the"
                              GRAPHIC SET POS(0, 185)
                              GRAPHIC PRINT "background color of the text"
                              GRAPHIC SET POS(0, 215)
                              GRAPHIC PRINT "On the 5th press, GRAPHIC COLOR is set to &H80, -2, and"
                              GRAPHIC SET POS(0, 230)
                              GRAPHIC PRINT "once again nothing is erased"
                              INPUT A
                              
                              IF A = 0 THEN EXIT FUNCTION
                              
                              Ux = RND(0, 250)
                              Uy = RND(0, 250)
                              Lx = Ux + 50
                              Ly = Uy + 50
                              
                              GRAPHIC CLEAR -1
                              
                              INCR Times
                              
                              IF Times = 3 THEN
                                GRAPHIC COLOR &H80, %WHITE
                              END IF
                              
                              IF Times = 5 THEN
                                GRAPHIC COLOR &H80, -2
                              END IF
                              
                              GOTO Continue
                              
                              END FUNCTION
                              Last edited by Walt Decker; 5 Apr 2009, 02:57 PM. Reason: change statements
                              Walt Decker

                              Comment


                              • #16
                                Originally posted by Walt Decker View Post
                                John:

                                I'm sorry. I did misread your post. In this case graphic redraw does not help because of the conflict between graphic color and graphic clear.
                                Thats OK Walt we all speed read, so what actually happened when you changed these three lines
                                Code:
                                          GRAPHIC CLEAR %WHITE
                                
                                          SLEEP 1000
                                
                                          GRAPHIC CLEAR -1
                                to
                                Code:
                                          GRAPHIC CLEAR %WHITE
                                          GRAPHIC REDRAW
                                
                                          SLEEP 1000
                                
                                          GRAPHIC CLEAR -1
                                          GRAPHIC REDRAW
                                I am not trying to be difficult, just learn. I am not good at GUI but do have programmes that redraw graphs approx every 30 seconds for many hours. Probaby a good idea to add a zero or two to the sleep so you can see what happens.
                                John

                                Comment


                                • #17
                                  Nothing, John. Because GRAPHIC COLOR is set to background transparent, nothing is cleared. It doesn't matter whether GRAPHIC ATTACH ... REDRAW is specified or not. This is demonstrated in (without GRAPHIC ATTACH ... REDRAW) in the above PBCC code.

                                  CONTROL REDRAW might work, but if it does it won't work on a graphic window.
                                  DIALOG REDRAW might work, but, again, it won't work on a graphic window.

                                  There are only three workarounds I can see at this point:
                                  Code:
                                  1) Get a pixel from the default control/window background and set 
                                      graphic clear to that as Dave suggested,
                                  
                                  2) 
                                       A - set graphic clear to -1, 
                                       B - set graphic color to forecolor, -2, 
                                       C - print text/graphic
                                       D - set graphic color to forecolor, -1
                                  
                                  3) Subclass the control/window and do all the text/drawing myself.
                                  Walt Decker

                                  Comment


                                  • #18
                                    Walt,

                                    Your PBCC program does show up the dilema. I've reproduced it below, with a few changes, in PBWin format. (I don't have a newer PBCC compiler).

                                    The point is, GRAPHIC CLEAR and GRAPHIC CLEAR -1 should erase everything on the window and expose the default
                                    window color (gray).
                                    What the help doc says is a bit ambiguous.
                                    If rgbColor& is omitted (or -1), the graphic target is cleared to the default background color for the
                                    selected graphic target.
                                    I think if might help resolve the conflict if PB were to change the wording to something like:
                                    ..the graphic target is cleared to the current background color for the selected graphic target
                                    unless the current background parameter has been set to '-2' (by the Graphic Color statement), in which
                                    case the graphic target is unchanged.
                                    BTW It would appear that the default background color that the Graphic Control and the Graphic Window are
                                    initially drawn with is %COLOR_3D_FACE so "GRAPHIC CLEAR GetSysColor(%COLOR_3DFACE)" should give the effect of clearing
                                    the target to the 'default window color' for the system that your program is running on (may not be gray).

                                    Code:
                                    #COMPILE EXE
                                    #Include "win32API.inc"
                                    DEFLNG A - Z
                                    FUNCTION PBMAIN () AS LONG
                                    RANDOMIZE TIMER
                                    Ux = 50
                                    Uy = 50
                                    Lx = Ux + 50
                                    Ly = Uy + 50
                                    GRAPHIC WINDOW "Press any key to start / loop", 200, 200, 300, 300 TO WinHndl
                                    GRAPHIC ATTACH WinHndl, 0
                                    'CONSOLE SET FOCUS
                                    GRAPHIC COLOR &H80, -2
                                    BGColor$="-2"
                                    Times = 0
                                    Graphic WaitKey$
                                    Continue: '
                                    Dialog Set Text WinHndl, "Draw Box"
                                    Sleep 500
                                    GRAPHIC BOX (Ux, Uy) - (Lx, Ly), 0, %RED, RGB(RND(0, 255), RND(0, 255), RND(0, 255))
                                    Sleep 2000
                                    Dialog Set Text WinHndl, "Draw Text, w/"+"Bgnd: "+BGColor$
                                    Sleep 500
                                    GRAPHIC SET POS (0, 0)
                                    GRAPHIC PRINT "GRAPHIC COLOR is set to maroon (&H80), -2 (transparent)"
                                    GRAPHIC SET POS(0, 15)
                                    GRAPHIC PRINT "GRAPHIC CLEAR is set to -1 (clear to default window color)"
                                    GRAPHIC SET POS(0, 45)
                                    GRAPHIC PRINT "When you enter a number the window is supposed to clear the"
                                    GRAPHIC SET POS(0, 60)
                                    GRAPHIC PRINT "rectangle and draw another at a different location, but, "
                                    GRAPHIC SET POS(0, 75)
                                    GRAPHIC PRINT "as you can see, nothing is cleared"
                                    GRAPHIC SET POS(0, 105)
                                    GRAPHIC PRINT "If you hit any key 3 times, GRAPHIC COLOR is set to"
                                    GRAPHIC SET POS(0, 120)
                                    GRAPHIC PRINT "&H80, %WHITE. No change is made to GRAPHIC CLEAR"
                                    GRAPHIC SET POS(0, 155)
                                    GRAPHIC PRINT "One more entry and the color of the window is painted white"
                                    GRAPHIC SET POS(0, 170)
                                    GRAPHIC PRINT "This causes subsequent rectangles to be overwritten by the"
                                    GRAPHIC SET POS(0, 185)
                                    GRAPHIC PRINT "background color of the text"
                                    GRAPHIC SET POS(0, 215)
                                    GRAPHIC PRINT "On the 5th press, GRAPHIC COLOR is set to &H80, -2, and"
                                    GRAPHIC SET POS(0, 230)
                                    GRAPHIC PRINT "once again nothing is erased"
                                    GRAPHIC SET Pos(180, 280)
                                    GRAPHIC Print "press any key on beep"
                                    WinBeep 800, 25
                                    Graphic Waitkey$
                                    Ux = RND(0, 250)
                                    Uy = RND(0, 230)
                                    Lx = Ux + 50
                                    Ly = Uy + 50
                                    GRAPHIC CLEAR -1
                                      Dialog Set Text WinHndl, "GRAPHIC CLEAR -1 (bg " + BGColor$ + ")"
                                      Sleep 2000
                                    INCR Times
                                      GRAPHIC SET POS(0, 280)
                                      GRAPHIC PRINT "Key press:"space$(Times *3)+str$(Times)
                                    IF Times = 3 THEN
                                      GRAPHIC COLOR &H80, %WHITE
                                        Dialog Set Text WinHndl, "GRAPHIC COLOR &H80, %WHITE"
                                        BGColor$ = "%WHITE"
                                        Sleep 2000
                                    END IF
                                    IF Times = 5 THEN
                                      GRAPHIC COLOR &H80, -2
                                        Dialog Set Text WinHndl, "GRAPHIC COLOR &H80, -2"
                                        BGColor$ = "-2"
                                        Sleep 2000
                                    END IF
                                    If IsWin(WinHndl) = 0 Then Exit Function
                                    GOTO Continue
                                    END FUNCTION
                                    Rgds, Dave

                                    Comment


                                    • #19
                                      Graphic Clear clears the window using the current background color. If you set the background color to -2 and then execute a Graphic Clear statement the background is not changed because you set the background color to transparent. If you want to clear the graphic with a specific color, then you must set this rgb background color in the Graphic Color statement or in the Graphic Clear statement.
                                      Sincerely,

                                      Steve Rossell
                                      PowerBASIC Staff

                                      Comment

                                      Working...
                                      X