Announcement

Collapse
No announcement yet.

Graphics problems

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

  • Graphics problems

    I'm trying to write the display for a data logger. I'm using some code posted Pete Lameijn. I've kindda got it working but I'm stuck. My code to initialize
    [CODE]
    GetClientRect(PlotForm_GraphicArea,RectA)
    hDC = GetDC(%HWND_DESKTOP)
    hMemDC = CreateCompatibleDC (hDC)
    SetBkColor(hMemDC, GetSysColor(%COLOR_WINDOW))
    hMapBmp = CreateCompatibleBitmap (hDC, RectA.nright, RectA.nbottom)
    hMapBmpOld = SelectObject( hMemDC, hMapBmp )
    CALL ReleaseDC(%HWND_DESKTOP, hDC)

    PatBlt hMemDC, 0, 0, RectA.nright, RectA.nbottom, %WHITENESS

    VGridCount = 15 ' draw 15 vertical gridlines
    HGridCount = 10
    VertGridSpace = RectA.nRight \ VGridCount ' spacing of each verical gridline - integer divide
    HorizontalGridSpace = RectA.nBottom \ HGridCount ' spacing of each horizontal gridline
    NegGridSpace = -1 * HorizontalGridSpace '

    SelectObject hMemDC, hPenGl
    DECR RectA.nRight ' fix right grid line not displayed ?????
    FOR VGridCount = 0 TO RectA.nRight STEP VertGridSpace ' draw horizontal lines
    MoveToEx hMemDC, VGridCount, 0, BYVAL 0
    LineTo hMemDC, VGridCount, RectA.nBottom
    NEXT VGridCount

    DECR RectA.nBottom ' fix bottom grid line not displayed ?????
    FOR HGridCount = RectA.nBottom TO 0 STEP NegGridSpace ' draw vertical lines
    MoveToEx hMemDC, 0, HGridCount, BYVAL 0
    LineTo hMemDC, RectA.nright, HGridCount
    NEXT HGridCount

    SelectObject hMemDC, hPenC ' draw red box at limits - testing only - to show missing bottom row and right column
    MoveToEx hMemDC, 0, 0, BYVAL 0
    LineTo hMemDC, RectA.nRight, 0 ' top
    LineTo hMemDC, RectA.nright, RectA.nBottom ' right
    LineTo hMemDC, 0, RectA.nbottom ' bottom
    LineTo hMemDC, 0, 0 ' left

    InvalidateRect PlotForm_GraphicArea, BYVAL 0, 0
    /CODE]
    In my WM_Paint handler I have
    Code:
     
    GetClientRect(PlotForm_GraphicArea,RectA) MapDialogRect PlotForm_GraphicArea,RectD hDC = BeginPaint(PlotForm_GraphicArea, ps) lRet = BitBlt (hDC, RectD.nLeft, RectD.nTop, RectA.nright, RectA.nbottom, hMemDC, 0, 0, %SRCCOPY) ' copy from hMemDC to hDC EndPaint(PlotForm_GraphicArea, ps)
    I have two problems,
    a. if I omit the DECR RectA.nRight and DECR RectA.nBottom, the bottom row and right hand column of pixels arenot displayed. Why?
    b. How to set the background. Currently using PatBit with %whiteness?

  • #2
    See GRAPHIC SET OVERLAP in the Help file. I think that is the problem.
    Rod
    "To every unsung hero in the universe
    To those who roam the skies and those who roam the earth
    To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

    Comment


    • #3
      GetClientRect returns "canvas" borders, so any drawing at right/bottom must be -(line thickness) to show full line.

      One way to paint back ground:
      Code:
          LOCAL hBrush AS DWORD
          hBrush = CreateSolidBrush(RGB(255, 255, 255))
          Fillrect hMemDC, RectA, hBrush
          DeleteObject hBrush
      But there are other ways, repending on what kind of canvas you are using - dialog or label, etc - then see WM_CTLCOLORDLG or WM_CTLCOLORSTATIC.

      Comment


      • #4
        Thanks Borge, although I know it will do the job, Fillrect is going to fill the foreground.

        I'm using a label but it's not static (that way the IDE takes care of sizing) so I don't see which WM_CTL.... to use.

        Comment


        • #5
          What DDT calls "Label" is a Static control. A way to set colors to it:
          Code:
            CASE %WM_CTLCOLORSTATIC
                ' wParam is handle of control's display context (hDC)
                ' lParam is handle of control
                ' Example on how to set colors to a specific control:
                '-----------------------------------------------------
                IF lParam = PlotForm_GraphicArea THEN
                   SetBkColor wParam, GetSysColor(%COLOR_WINDOW)
                   SetTextColor wParam, GetSysColor(%COLOR_INFOTEXT) ' or some RGB color..
                   FUNCTION = GetSysColorBrush(%COLOR_WINDOW)        ' or use hBrush from CreateSolidBrush(..)
                END IF

          Comment


          • #6
            Another option. It is a (they are) DDT labels, try CONTROL SET COLOR. Demo that it works -
            Code:
            #compile exe
            #dim all
            %ID_testLbl    = 1000
            %ID_ChgClrBtn  = 1001
            %ID_ExitBtn    = 1002
            callback function DlgCB() as long
              static ForeClr as long
              local BackClr as long
              if cb.msg = %wm_command and cb.ctlmsg = %bn_clicked then
                select case const cb.ctl
                  case %ID_ChgClrBtn
                    select case long ForeClr
                      case %rgb_black
                        ForeClr = %rgb_red
                        BackClr = %rgb_lime
                      case %rgb_red
                        ForeClr = %rgb_green
                        BackClr = %rgb_yellow
                      case %rgb_green
                        ForeClr = %rgb_blue
                        BackClr = %rgb_aquamarine
                      case %rgb_blue
                        ForeClr = %rgb_black
                        BackClr = %rgb_white
                    end select
                    control set color cb.hndl, %ID_testLbl, ForeClr, BackClr
                    control redraw cb.hndl, %ID_testLbl
                  case %ID_ExitBtn
                    dialog end cb.hndl
                end select
              end if
            end function
            function pbmain () as long
              local hDlg as dword
              dialog default font "Arial Block", 12
              dialog new 0, "Color a label", , , 112, 42 to hDlg
              control add label, hDlg, %ID_testLbl, "Text", 10, 5, 92, 15
              control add button, hdlg, %ID_ChgClrBtn, "Label Color", 10, 22, 45, 15
              control add button, hDlg, %ID_ExitBtn, "Exit Demo", 57, 22, 45, 15
              dialog show modal hDlg call DlgCB
            end function
            Cheers,
            Dale

            Comment


            • #7
              There are several ways to display data logger data, the grid can move with the data (when plotted data "hits" the right hand side) or be fixed. Obviously if you move the grid with the plotted data, wether the appearent background really is bachground or just a fill in the foreground is unimportant but if you want the grid to stay still while the plotted data moves I imagine you would have to have the background as the grid. I can't decide which is best. But I'd like to be able to draw the grid on the background just in case. I really must read Graphic 101.

              From an app called SerialPlot (which I would happily use instead of writing but it has no API, I could use Com2Com but .....)

              Click image for larger version

Name:	test2.gif
Views:	84
Size:	768.1 KB
ID:	780279



              Comment


              • #8
                you could use a transparent dialog overlaid on the "main" dialog, and draw the plot on one and the grid on the other. I have used this in financial applications when plotting a price chart on the main dialog and a cursor with associated text on the overlay dialog. I think I posted something hear about a decade ago!

                In essence, something like:

                Code:
                            dialog new pixels, cb.hndl, "", 0,0,0,0, _
                                %ws_popup or %ws_visible, %ws_ex_layered to hCursorDlg
                            dialog show modeless hCursorDlg, call CCB
                In the modeless dialog initialisation, something like:

                Code:
                            hparent = getparent(cb.hndl)
                            setcapture hparent
                            SetLayeredWindowAttributes( cb.hndl, %white, 120, %LWA_ALPHA)
                Then use messages to size and draw on the modeless child dialog.

                Comment


                • #9
                  OK, it was 9 years ago but I forgot I had breathed on it last year. Old age does not come alone!

                  https://forum.powerbasic.com/forum/u...layered-dialog

                  Comment


                  • #10
                    OOOh, that looks neat, shall study but I'm not sure how to transpose the DDT Graphic control to SDK.

                    BTW "Old age does not come alone!" you certainly got that right in my case.

                    Comment

                    Working...
                    X