Some sources to play with the 3.70 update

Everything else that doesn't fall into one of the other PB categories.
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Some sources to play with the 3.70 update

Post by freak »

Here are som sources to play a bit with the new commands... 8)
I wrote them for testing, they show some of the new Gadgets and stuff.

First, a litlle more advanced Image viewer:

Code: Select all

UseJPEGImageDecoder()
UseTGAImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()

#Window = 0

#Tree = 1
#List = 2

#Text = 3
#Frame = 4

#ViewMode0 = 5
#ViewMode1 = 6
#ViewMode2 = 7
#ViewMode3 = 8

#ScrollArea = 9
#Image = 10

#Container1 = 11
#Container2 = 12
#Splitter1 = 13
#Splitter2 = 14

Procedure ResizeCallback(Window, Message, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  
  If Message = #WM_SIZE
  
    Select Window
    
      Case WindowID(#Window)
        ResizeGadget(#Splitter2, -1, -1, WindowWidth()-10, WindowHeight()-10)
        
      Case GadgetID(#Container1)
        ResizeGadget(#Frame, -1, -1, GadgetWidth(#Container1), -1)
        ResizeGadget(#Splitter1, -1, -1, GadgetWidth(#Container1), GadgetHeight(#Container1)-35)
        
      Case GadgetID(#Container2)
        ResizeGadget(#ScrollArea, -1, -1, GadgetWidth(#Container2), GadgetHeight(#Container2))
    
    EndSelect
  
  EndIf
  
  ProcedureReturn result
EndProcedure


If OpenWindow(#Window, 0, 0, 800, 600, #PB_Window_SystemMenu|#PB_Window_Screencentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget, "PB ImageViewer")
  If CreateGadgetList(WindowID())
  
    SetWindowCallback(@ResizeCallback())
  
    ExplorerTreeGadget(#Tree, 5, 5, 195, 590, "", #PB_Explorer_NoFiles|#PB_Explorer_AlwaysShowSelection)
    
    ContainerGadget(#Container1, 205, 5, 590, 590)
    
      Frame3DGadget(#Frame, 0, 0, 590, 30, "", #PB_Frame3D_Single)
      TextGadget(#Text, 15, 8, 60, 20, "View Mode:", #PB_Text_Right)
      OptionGadget(#ViewMode0, 100, 5, 80, 20, "Large Icons")
      OptionGadget(#ViewMode1, 190, 5, 80, 20, "Small Icons")
      OptionGadget(#ViewMode2, 280, 5, 50, 20, "List")
      OptionGadget(#ViewMode3, 330, 5, 50, 20, "Details")
      SetGadgetState(#ViewMode3, #True)
         
      ExplorerListGadget(#List, 0, 35, 590, 170, "*.jpg;*.bmp;*.tga;*.png;*.tiff", #PB_Explorer_NoFolders|#PB_Explorer_NoParentFolder|#PB_Explorer_AlwaysShowSelection)
      
      ContainerGadget(#Container2, 0, 210, 590, 380)
      
        ScrollAreaGadget(#ScrollArea, 0, 0, 590, 380, 0, 0, 1)
          ImageGadget(#Image, 0, 0, 0, 0, 0)
        CloseGadgetList()
      
      CloseGadgetList()
      
      SplitterGadget(#Splitter1, 0, 35, 590, 575, #List, #Container2,#PB_Splitter_Separator)
      SetGadgetState(#Splitter1, 170)
    
    CloseGadgetList()
    
    SplitterGadget(#Splitter2, 5, 5, 790, 590, #Tree, #Container1, #PB_Splitter_Vertical|#PB_Splitter_Separator)
    SetGadgetState(#Splitter2, 195)
  
    Repeat
      Event = WaitWindowEvent()
      
      If Event = #PB_EventGadget
        Select EventGadgetID()
        
          Case #ViewMode0: ChangeListIconGadgetDisplay(#List, 0)
          Case #ViewMode1: ChangeListIconGadgetDisplay(#List, 1)
          Case #ViewMode2: ChangeListIconGadgetDisplay(#List, 2)
          Case #ViewMode3: ChangeListIconGadgetDisplay(#List, 3)
          
          Case #Tree: SetGadgetText(#List, GetGadgetText(#Tree))
          
          Case #List
            If EventType() = #PB_EventType_Change
              
              If LoadImage(0, GetGadgetText(#List)+GetGadgetItemText(#List, GetGadgetState(#List), 0))
                
                FreeGadget(#Image)
                FreeGadget(#ScrollArea)
                
                OpenGadgetList(#Container2)
                
                ScrollAreaGadget(#ScrollArea, 0, 0, GadgetWidth(#Container2), GadgetHeight(#Container2), ImageWidth(), ImageHeight(), 10)
                  ImageGadget(#Image, 0, 0, ImageWidth(), ImageHeight(), ImageID())
                CloseGadgetList()
                
                CloseGadgetList()
                
              EndIf
              
            EndIf       
        
        EndSelect
      EndIf
    
    Until Event = #PB_EventCloseWindow
  
  EndIf
EndIf

End
And here's a example of the new Movie possibilitys, see for youself... :lol:

Code: Select all

#Width = 640
#Height = 480
#Box = 160

#Sprite = 0
#Sprite2 = 1
#Movie = 0

file.s = OpenFileRequester("Please choose a Movie...", "", "Movie Files|*.avi;*.mpg;*.mpeg;*.mov|All Files|*.*",1)
If file = "": End: EndIf

FieldX = #Width/#Box
FieldY = #Height/#Box

Dim Boxes.Point(FieldX, FieldY)
For x = 1 To FieldX
  For y = 1 To FieldY
    Boxes(x,y)\x = x
    Boxes(x,y)\y = y
  Next y
Next x
x = FieldX
y = FieldY
For i = 0 To 1000
  Select Random(3)
    Case 0
      If x > 1
        Boxes(x,y)\x = Boxes(x-1,y)\x        
        Boxes(x,y)\y = Boxes(x-1,y)\y
        x-1
      EndIf
    Case 1
      If x < FieldX
        Boxes(x,y)\x = Boxes(x+1,y)\x        
        Boxes(x,y)\y = Boxes(x+1,y)\y
        x+1
      EndIf
    Case 2
      If y > 1
        Boxes(x,y)\x = Boxes(x,y-1)\x        
        Boxes(x,y)\y = Boxes(x,y-1)\y
        y-1
      EndIf
    Case 3 
      If y < FieldY
        Boxes(x,y)\x = Boxes(x,y+1)\x        
        Boxes(x,y)\y = Boxes(x,y+1)\y
        y+1
      EndIf   
  EndSelect
Next i
x0 = x
y0 = y

MouseDown = #False

If InitSprite() And InitKeyboard() And InitMouse() And InitMovie()
 
  If OpenScreen(#Width, #Height, 32, "Game") 
  
    If LoadMovie(#Movie, file)

      Sprite = CreateSprite(#Sprite, #Width, #Height)
      CreateSprite(#Sprite2, 7, 7)
      StartDrawing(SpriteOutput(#Sprite2))
        Box(0, 0, 7, 7, $000000)
        Box(2, 2, 3, 3, $0000FF)
      StopDrawing()
    
      Repeat
        ExamineKeyboard()
        ExamineMouse()
        
        If MouseButton(1) And MouseDown = #False
          ox = Int(MouseX()/#Box)+1
          oy = Int(MouseY()/#Box)+1
          If (ox=x0 And (oy=y0+1 Or oy=y0-1)) Or (oy=y0 And (ox=x0+1 Or ox=x0-1))
            Boxes(x0,y0)\x = Boxes(ox,oy)\x
            Boxes(x0,y0)\y = Boxes(ox,oy)\y            
            x0 = ox
            y0 = oy
          EndIf
          MouseDown = #True
        EndIf
        
        If MouseDown = #True And MouseButton(1)=#False
          MouseDown = #False
        EndIf
    
        RenderMovieFrame(Sprite)
    
        ClearScreen(192,192,192)
        For x = 1 To FieldX
          For y = 1 To fieldY
            If x <> x0 Or y <> y0
              ClipSprite(#Sprite, (Boxes(x,y)\x-1)*#Box+2, (Boxes(x,y)\y-1)*#Box+2, #Box-4, #Box-4)
              DisplaySprite(#Sprite, (x-1)*#Box+2, (y-1)*#Box+2)
            EndIf
          Next y
        Next x
        StartDrawing(ScreenOutput())
          DrawingMode(4)
          For x = 1 To FieldX
            For y = 1 To fieldY
              If x <> x0 Or y <> y0
                Box((x-1)*#Box+1, (y-1)*#Box+1, #Box-2, #Box-2)
              EndIf
            Next y
          Next x        
        StopDrawing() 
        
        DisplaySprite(#Sprite2, MouseX(), MouseY())
        
        FlipBuffers()
    
      Until KeyboardPushed(#PB_Key_Escape)
  
    EndIf
  EndIf
EndIf
End
Have Fun...

Timo
quidquid Latine dictum sit altum videtur
JoRo
User
User
Posts: 70
Joined: Sat May 10, 2003 2:03 pm
Location: Essen, Germany
Contact:

Post by JoRo »

Really fun, nice examples.
Seems the renderengine 2D is very fast, take a 35 MB picture in the imagebrowser, it is faster then ifarnview, absolute smooth scrolling

Johannes
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

WOW!
A really very useful imageviewer and a superb memory-game!
I tried to puzzle the "Doors - Riders on the storm"-music-video
AMAZING !!
%1>>1+1*1/1-1!1|1&1<<$1=1
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post by Berikco »

And here an example of the ScrollBarGadget(), used wih a callback.
It does the same as scrollArea in this example :)

Code: Select all

; PureBasic Visual Designer v3.70


;- Window Constants
;
#Window_0 = 0

;- Gadget Constants
;
#Gadget_3   = 0
#Horizontal = 1
#Vertical   = 2

;- Image Plugins
UseJPEGImageDecoder()
UsePNGImageDecoder()

#ViewHeight = 350
#ViewWidth = 350

;- Image Globals
Global Image0, Image1, Height, Width
Image1 = 1
Image0 = 0

FileName$ = OpenFileRequester("", "", "Image (*.bmp,*.png,*.jpg)|*.bmp;*.png;*.jpg", 0)
If Filename$ = ""
  End
EndIf

LoadImage(Image0, FileName$)
Height = ImageHeight()
Width = ImageWidth()
GrabImage(Image0, Image1, 0, 0, #ViewWidth, #ViewHeight)


Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 450, 413,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "New window ( 0 )")
    If CreateGadgetList(WindowID())
      ImageGadget(#Gadget_3, 6, 5, #ViewWidth, #ViewHeight, UseImage(Image1), #PB_Image_Border)
      ScrollBarGadget(#Vertical  , #ViewWidth+12, 5, 18, #ViewHeight+3, 0, Height-1, #ViewHeight , 1)
      ScrollBarGadget(#Horizontal, 6, #ViewHeight+10, #ViewWidth+3, 18, 0, Width -1, #ViewWidth)
      
    EndIf
  EndIf
EndProcedure

Procedure WindowCallBack(WindowID, Message, wParam, lParam)
  
  Result = #PB_ProcessPureBasicEvents
  
  If Message = #WM_COMMAND
    If lparam = GadgetID(#Vertical)
      x = GetGadgetState(#Horizontal)
      y = GetGadgetState(#Vertical)
      GrabImage(Image0, Image1, x, y, #ViewWidth, #ViewHeight)
      SetGadgetState(#Gadget_3, UseImage(Image1))
      result = 0
    ElseIf lparam = GadgetID(#Horizontal)
      x = GetGadgetState(#Horizontal)
      y = GetGadgetState(#Vertical)
      GrabImage(Image0, Image1, x, y, #ViewWidth, #ViewHeight)
      SetGadgetState(#Gadget_3, UseImage(Image1))
      result = 0
    EndIf
    
  EndIf
  
  
  ProcedureReturn Result
EndProcedure

Open_Window_0()
SetWindowCallback(@WindowCallBack())

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_EventCloseWindow
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Redraw bug!

Post by fsw »

There is a redraw BUG as soon I use a ContainerGadget.

The same BUG can be found in the first example code above.
(didn't test the other examples)

How to find it:
1.) Increase the size of the ExplorerListGadget to the full.
2.) Move the mouse cursor over a bottom window corner, than resize the window.
3.) Keep resizing ( YES DON'T STOP )
4.) While you resize, you will see that the ExplorerListGadget is more flickering than the ExplorerTreeGadget (because of the container)
5.) Now move your mouse slower and try to find a Window size where the flickering time is getting longer .
6.) As you can see, if you catch the right size - the ExplorerListGadget IS GONE - you have to resize your window to see it again.

I found this bug per chance - just resized to the wrong size and the ExplorerListGadget disappeared.

Can anybody confirm this :?:

BTW: hope I explained myself enough to make you see the BUG.

I am to provide the public with beneficial shocks.
Alfred Hitshock
Post Reply