Bug hunt anyone?

Everything else that doesn't fall into one of the other PB categories.
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Bug hunt anyone?

Post by dmoc »

Aim is to allow user to switch dynamically between windowed/ fullscreen. So far I'm getting dizzy with going in circles, fix one problem another pops up, fixed that then get another one, fix that and the first pops up again... you get the picture. For starters: ClearScreen() no longer works.

PS: Win98se

Code: Select all

Declare WinTest()
WinTest()

Structure WinInfoT
  ; Windowed
  pi.l  ; PB Window Identifier
  ph.l  ; PB Window Handle
  wx.l  ; Window X offset
  wy.l  ; Window Y offset
  ww.l  ; Window 
  wh.l  ; Window 
  wt.s  ; Window 
  wf.l  ; Window 

  ; Screen
  sm.l  ; Screen Mode (0: Windowed, 1: Fullscreen)
  sx.l  ; Screen X offset (windowed mode) 
  sy.l  ; Screen Y offset (windowed mode)
  sw.l  ; Screen Width (fullscreen)
  sh.l  ; Screen Height (fullscreen)
  sc.l  ; Screen Colour Bits (fullscreen)

  ws.l  ; Window State (0:  Opening, 1: Active, 2: Closing)
EndStructure


Procedure.l testWindow(x.l, y.l, w.l, h.l, wf.l, t.s) 
  Shared wi.WinInfoT
  
  ExamineScreenModes()

  wi\wx = x
  wi\wy = y
  wi\ww = w
  wi\wh = h
  wi\wf = wf
  wi\wt = t

  wi\sm = 0
  wi\sx = 0
  wi\sy = 0
  wi\sw = w
  wi\sh = h
  wi\sc = ScreenModeDepth()

  wi\ph = OpenWindow(wi\pi, wi\wx, wi\wy, wi\ww, wi\wh, wi\wf, wi\wt)
  If wi\ws: CloseScreen(): EndIf
  OpenWindowedScreen(wi\ph, wi\sx, wi\sy, wi\ww, wi\wh, 0, 0, 0)
  
  wi\ws = 1
EndProcedure


Procedure.l testScreen(w.l, h.l, c.l, d.l, t.s) 
  Shared wi.WinInfoT
  
  ExamineScreenModes()

  wi\sm = 1
  wi\sw = w
  wi\sh = h
  wi\sc = c
  wi\wt = t

  If wi\ws: CloseScreen(): EndIf
  OpenScreen(wi\sw, wi\sh, wi\sc, wi\wt)

  SetFrameRate(75)
  wi\ws = 1
EndProcedure


Procedure.l testWinClose() 
  Shared wi.WinInfoT
  
  wi\ws = 2
  
  If wi\sm
    CloseScreen()
  Else
    CloseWindow(wi\pi)
  EndIf
  
EndProcedure


Procedure.l WinResize(w.l, h.l) 
  Shared wi.WinInfoT
  
  If wi\sm: ProcedureReturn: EndIf

  wi\ww = w
  wi\wh = h

  wi\sm = 0
  wi\sw = w
  wi\sh = h

  If wi\ph = 0
    wi\ph = OpenWindow(wi\pi, wi\wx, wi\wy, wi\ww, wi\wh, wi\wf, wi\wt)
  EndIf

  CloseScreen()
  OpenWindowedScreen(wi\ph, wi\sx, wi\sy, wi\sw, wi\sh, 0, 0, 0)
EndProcedure


Procedure testDraw()
  Shared wi.WinInfoT

  If IsScreenActive()
    ; Simple PB test code
    ;
    If wi\sm
      StartDrawing(ScreenOutput())
    Else
      StartDrawing(WindowOutput())
    EndIf
    
      ClearScreen(192, 192, 255) 
      DrawingMode(4)

      Box(0, 0, wi\sw, wi\sh , cRed)
      LineXY(0, 0, wi\sw, wi\sh , cRed)
      LineXY(0, wi\sh, wi\sw, 0 , cRed)
      Circle((wi\sw-1)/2, (wi\sh-1)/2, (wi\sh-1)/2, cRed) 

      Locate(10,10)
      DrawText(Str(wi\ww)+","+Str(wi\wh))
      Locate(10,25)
      DrawText(Str(wi\sw)+","+Str(wi\sh))

    StopDrawing()
  EndIf
EndProcedure



Procedure.l WinTest() 
  Shared wi.WinInfoT
  
  wf = #PB_Window_SizeGadget    ;: Adds the sizeable feature To a window. 

  InitSprite()

  w=800: h=600: c=32: d=32: f=0
  
  testWindow(0,0, w, h, wf, "Test")
;  testScreen(w, h, c, d, "Test")

  cBlack  = RGB(0,0,0)
  cWhite  = RGB(255,255,255)
  cRed    = RGB(255,0,0)
  cSky    = RGB(192, 192, 255) 
  
  InitKeyboard()
  Repeat

    testDraw()
    
    FlipBuffers()

    If wi\sm=0
      e = WindowEvent()
      If e = #WM_SIZE: WinResize(WindowWidth(), WindowHeight()): EndIf
    EndIf

    Delay(1)
    ExamineKeyboard()
    
    If KeyboardReleased(#PB_KEY_F12)
      If wi\sm
        testWindow(wi\wx, wi\wy, wi\ww, wi\wh, wi\wf, wi\wt)
      Else
        testScreen(800, 600, 32, 16, wi\wt)
      EndIf
    EndIf

  Until KeyboardPushed(#PB_KEY_ESCAPE)
    
  testWinClose()
EndProcedure
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

You must call StartDrawing() and StopDrawing() every loop
and not once at start and end.

Try this, F12 for switching screen:

Code: Select all

Structure WinInfoT 
  ; Windowed
  pi.l  ; PB Window Identifier 
  ph.l  ; PB Window Handle 
  wx.l  ; Window X offset 
  wy.l  ; Window Y offset 
  ww.l  ; Window 
  wh.l  ; Window 
  wt.s  ; Window 
  wf.l  ; Window 

  ; Screen 
  sm.l  ; Screen Mode (0: Windowed, 1: Fullscreen) 
  sx.l  ; Screen X offset (windowed mode) 
  sy.l  ; Screen Y offset (windowed mode) 
  sw.l  ; Screen Width (fullscreen) 
  sh.l  ; Screen Height (fullscreen) 
  sc.l  ; Screen Colour Bits (fullscreen) 
  sd.l  ; Screen Depth Bits (fullscreen) 

  ws.l  ; Window State (0:  Opening, 1: Active, 2: Closing) 
  
EndStructure 

Global wi.WinInfoT 
Global cBlack,cWhite,cRed,cSky 

cBlack  = RGB(0,0,0) 
cWhite  = RGB(255,255,255) 
cRed    = RGB(255,0,0) 
cSky    = RGB(192, 192, 255) 
  
;============================================================================ 

Procedure.l WinResize(w.l, h.l) 
  wi\ww = w: wi\wh = h 
  CloseScreen() 
  OpenWindowedScreen(wi\ph, wi\sx, wi\sy, wi\sw, wi\sh, 1, 0, 0) 
EndProcedure 

Procedure SwitchScreen()
  wi\sm = wi\sm ! 1

  If wi\ws
    CloseScreen()
  Else
    wi\ws=1
  EndIf
  
  If wi\sm = 0 ; Windowed
    wi\ph = OpenWindow(wi\pi, wi\wx, wi\wy, wi\ww, wi\wh, wi\wf, wi\wt) 
    OpenWindowedScreen(wi\ph, wi\sx, wi\sy, wi\ww, wi\wh, 0, 0, 0)
    SetFocus_(wi\ph)
  Else
    If wi\ph : CloseWindow(wi\pi) : wi\ph=0 : EndIf
    OpenScreen(wi\sw,wi\sh,wi\sc,wi\wt)
  EndIf

EndProcedure

;============================================================================ 

If InitSprite()=0 Or InitKeyboard()=0
  MessageRequester("ERROR","Cant init DirectX !",#MB_ICONERROR):End
EndIf

  w=800: h=600: c=32: d=32: 
  wi\wx = 0: wi\wy = 0
  wi\ww = 800
  wi\wh = 600
  wi\sc = 32
  wi\wf = #PB_Window_SizeGadget
  wi\wt = "Flip Test"

  wi\sm = 1
  wi\sx = 0
  wi\sy = 0 
  wi\sw = 800
  wi\sh = 600 

SwitchScreen()

SetFrameRate(50)

Repeat
    FlipBuffers()
    ExamineKeyboard()

    If IsScreenActive()
      ClearScreen(192, 192, 255)

      StartDrawing(ScreenOutput()) 
        DrawingMode(4) 
        Box(0, 0, wi\sw, wi\sh , cRed) 
        LineXY(0, 0, wi\sw, wi\sh , cRed) 
        LineXY(0, wi\sh, wi\sw, 0 , cRed) 
        Circle((wi\sw-1)/2, (wi\sh-1)/2, (wi\sh-1)/2, cRed) 

        DrawingMode(1) 
        FrontColor(255,255,255) 
        Locate(10,10) 
        DrawText(Str(wi\ww)+","+Str(wi\wh)) 
        Locate(10,25) 
        DrawText(Str(wi\sw)+","+Str(wi\sh)) 
      StopDrawing()

    EndIf

    If wi\sm = 0
      Select WindowEvent()
        Case #WM_SIZE
          WinResize(WindowWidth(),WindowHeight())
      EndSelect
    EndIf

    If KeyboardReleased(#PB_KEY_F12)
      SwitchScreen()
    EndIf

    Delay(1)

Until KeyboardReleased(#PB_KEY_ESCAPE) 

CloseWindow(wi\pi) 
Works here... hopyfully for you too... :D
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Yes, thanks Danilo, this works. By the time I saw your thread I had arrived at the code below. I have noticed a strange difference though: with your solution text is scaled, where as in mine it isn't (only diff appears to be SetFocus_()). I'm finding PB a little unpredictable (not to mention frustrating when things like #PB_Event_MoveWindow have been reported long ago but not fixed).

Info: the aim of the code is to allow a user to switch between windowed and fullscreen. Ultimate aim is PB-only code that works on both Linux and Windows unchanged. Not there yet.

Code: Select all

Declare WinTest()

Global cBlack,cWhite,cRed,cSky

cBlack  = RGB(0,0,0)
cWhite  = RGB(255,255,255)
cRed    = RGB(255,0,0)
cSky    = RGB(192, 192, 255) 
  
WinTest()

Structure WinInfoT
  ; Windowed
  pi.l  ; PB Window Identifier
  pw.l  ; PB Window Handle
  wx.l  ; Window X offset
  wy.l  ; Window Y offset
  ww.l  ; Window 
  wh.l  ; Window 
  wt.s  ; Window 
  wf.l  ; Window 

  ; Screen
  ps.l  ; PB Screen Handle
  sm.l  ; Screen Mode (0: Windowed, 1: Fullscreen)
  sx.l  ; Screen X offset (windowed mode) 
  sy.l  ; Screen Y offset (windowed mode)
  sw.l  ; Screen Width (fullscreen)
  sh.l  ; Screen Height (fullscreen)
  sc.l  ; Screen Colour Bits (fullscreen)
  sd.l  ; Screen Depth Bits (fullscreen)

  ws.l  ; Window State (0:  Opening, 1: Active, 2: Closing)
EndStructure

;============================================================================

Procedure.l testWinClose() 
  Shared wi.WinInfoT
  
  wi\ws = 2
  
  If wi\sm
    CloseScreen()
  Else
    While WindowEvent(): Wend
    CloseScreen()
    CloseWindow(wi\pi)
  EndIf
  
  wi\pw = 0
  wi\ps = 0
  wi\ws = 0
EndProcedure


Procedure WinCB(wid, m, w, l)
  Shared wi.WinInfoT

  r = #PB_ProcessPureBasicEvents

  Select m
    Case #WM_MOVE
      wi\wx = WindowX()
      wi\wy = WindowY()
  EndSelect
  
  ProcedureReturn r
EndProcedure


Procedure.l testWindow(x.l, y.l, w.l, h.l, wf.l, t.s) 
  Shared wi.WinInfoT
  
  wi\wx = x: wi\wy = y
  wi\ww = w: wi\wh = h
  wi\wf = wf
  wi\wt = t

  wi\sm = 0
  wi\sx = 0: wi\sy = 0
  wi\sw = w: wi\sh = h
  wi\sc = ScreenModeDepth()

  wi\pw = OpenWindow(wi\pi, wi\wx, wi\wy, wi\ww, wi\wh, wi\wf, wi\wt)
  wi\ps = OpenWindowedScreen(wi\pw, wi\sx, wi\sy, wi\ww, wi\wh, 0, 0, 0)
  
  SetWindowCallback(@WinCB())

  wi\ws = 1
EndProcedure


Procedure.l testScreen(w.l, h.l, c.l, d.l, t.s) 
  Shared wi.WinInfoT
  
  wi\sm = 1
  wi\sw = w: wi\sh = h
  wi\sc = c: wi\sd = d
  wi\wt = t

  wi\ps = OpenScreen(wi\sw, wi\sh, wi\sc, wi\wt)

  wi\ws = 1
EndProcedure


Procedure.l WinResize(w.l, h.l) 
  Shared wi.WinInfoT
  
  If wi\sm: ProcedureReturn: EndIf

  wi\sm = 0
  wi\ww = w: wi\wh = h
  wi\sw = w: wi\sh = h

  If wi\pw = 0: wi\pw = OpenWindow(wi\pi, wi\wx, wi\wy, wi\ww, wi\wh, wi\wf, wi\wt): EndIf

  CloseScreen()
  wi\ps = OpenWindowedScreen(wi\pw, wi\sx, wi\sy, wi\sw, wi\sh, 0, 0, 0)
EndProcedure


Procedure testDraw()
  Shared wi.WinInfoT
  Shared ed
  
  ClearScreen(192, 192, 255) 

  StartDrawing(ScreenOutput())
    DrawingMode(4)
    Box(0, 0, wi\sw, wi\sh , cRed)

    LineXY(0, 0, wi\sw, wi\sh , cRed)
    LineXY(0, wi\sh, wi\sw, 0 , cRed)

    cx = (wi\sw-1)/2
    cy = (wi\sh-1)/2

    If wi\sh > wi\sw: r.l = (wi\sw-1)/2: Else: r.l = (wi\sh-1)/2: EndIf
    Circle(cx, cy, r, cRed) 

    DrawingMode(1)
    FrontColor(255,255,255)

    Locate(10,10)
    DrawText("w: "+Str(wi\wx)+","+Str(wi\wy)+","+Str(wi\ww)+","+Str(wi\wh))

    Locate(10,25)
    DrawText("s: "+Str(wi\sw)+","+Str(wi\sh))
    
    Locate(10,40)
    DrawText("e: "+Str(ed))

    Locate(10,55)
    DrawText("t: "+FormatDate("%hh:%ii:%ss", Date()))

    s = Second(Date())
    rx = cx+r*Sin((360*s/60)/57.295779)
    ry = cy-r*Cos((360*s/60)/57.295779)
    LineXY((wi\sw-1)/2, (wi\sh-1)/2, rx, ry, cRed)
  StopDrawing()
EndProcedure


Procedure.l WinTest() 
  Shared wi.WinInfoT
  Shared ed
  
  w=400: h=400: c=32: d=32: wf=#PB_Window_SizeGadget

  InitSprite()
  ExamineScreenModes()

  testWindow(100,150, w, h, wf, "Test")
;  testScreen(w, h, c, d, "Test")

  InitKeyboard()
  Repeat
    ExamineKeyboard()

    If wi\ps
      f+1: If f>20
      : f=0: EndIf

      testDraw()
      FlipBuffers()

      If wi\sm=0
        e = WindowEvent()
        If e: ed=e: EndIf
        Select e
          Case #WM_SIZE
            WinResize(WindowWidth(), WindowHeight())
;          Case #PB_Event_MoveWindow
;            wi\wx = WindowX()
;            wi\wy = WindowY()
        EndSelect
      EndIf

      If KeyboardReleased(#PB_KEY_F12)
        If wi\ws: testWinClose(): EndIf
        If wi\sm
          testWindow(wi\wx, wi\wy, wi\ww, wi\wh, wi\wf, wi\wt)
        Else
          testScreen(800, 600, 32, 16, wi\wt)
        EndIf
      EndIf

      sleep_(1)
    Else
      sleep_(200)
    EndIf
  Until KeyboardReleased(#PB_KEY_ESCAPE)

  testWinClose()
EndProcedure
Post Reply