Page 1 of 1

Painting a triangle with GDI

Posted: Mon Nov 02, 2020 9:50 pm
by PHP
Hi,

i found this code on the board but it doesn't work anymore (no error, no result on the screen):

Code: Select all

Procedure Triangle(hdc,x1.l, y1.l, x2.l, y2.l, x3.l, y3.l)
  ProcedureReturn Polygon_(hdc, @x1, 3)
EndProcedure

OpenWindow(0, 0, 0, 320, 240, "Triangle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
Repeat
  hdc = StartDrawing( WindowOutput(0) )
  If hdc
    FrontColor(RGB(255, 0, 0))
    Triangle(hdc,10, 10, 10, 100, 100, 10)
    ;     Polygon_(hdc, @x1, 3)
   
    StopDrawing()
  EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
Has the GDI changed in the meantime or something?

Thanks!

Re: Painting a triangle with GDI

Posted: Mon Nov 02, 2020 10:04 pm
by infratec
Works here: win10 x64, PB 5.72 x86

Re: Painting a triangle with GDI

Posted: Mon Nov 02, 2020 10:08 pm
by infratec
Maybe this is 'safer'

Code: Select all

Procedure Triangle(hdc,x1.l, y1.l, x2.l, y2.l, x3.l, y3.l)
  
  Protected Dim Poly.l(5)
  
  Poly(0) = x1
  Poly(1) = y1
  Poly(2) = x2
  Poly(3) = y2
  Poly(4) = x3
  Poly(5) = y3
  
  ProcedureReturn Polygon_(hdc, @Poly(0), 3)
EndProcedure

Re: Painting a triangle with GDI

Posted: Tue Nov 03, 2020 11:43 am
by Fred
PHP wrote:Hi,

i found this code on the board but it doesn't work anymore (no error, no result on the screen):

Code: Select all

Procedure Triangle(hdc,x1.l, y1.l, x2.l, y2.l, x3.l, y3.l)
  ProcedureReturn Polygon_(hdc, @x1, 3)
EndProcedure

OpenWindow(0, 0, 0, 320, 240, "Triangle", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
Repeat
  hdc = StartDrawing( WindowOutput(0) )
  If hdc
    FrontColor(RGB(255, 0, 0))
    Triangle(hdc,10, 10, 10, 100, 100, 10)
    ;     Polygon_(hdc, @x1, 3)
   
    StopDrawing()
  EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow
Has the GDI changed in the meantime or something?

Thanks!
You shouldn't use WindowOutput(), it's an old command and still here for compatibility, but it can be erased by OS repainting etc. Better try with a CanvasOutput() instead.

Re: Painting a triangle with GDI

Posted: Wed Nov 04, 2020 5:09 am
by ozzie
Fred wrote:You shouldn't use WindowOutput(), it's an old command and still here for compatibility, but it can be erased by OS repainting etc. Better try with a CanvasOutput() instead.
Seems like I've got some extra work to do! I've just run a search on my program and have found 12 instances of StartDrawing(WindowOutput(...)).