TilePreview 1.0 - GPL

Developed or developing a new product in PureBasic? Tell the world about it.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

TilePreview 1.0 - GPL

Post by dracflamloc »

This is a quick thingy I made to preview tile artwork to make sure it looks good. Also I use it to create an animation grid for characters in games like T3h Warg S3qual.

Its a quick hack but it works. Anyone can feel free to improve it. You can drag an image onto the executable to view it, or just launch the program. Press 'S' to save a tiled image.


Code: Select all

; TilePreview
; Copyright 2005 DracSoft
; This code is released under the GNU GPL.
; These comments must remain intact.
; (http://www.gnu.org/licenses/gpl.html)

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

tile.s = ProgramParameter()


OpenWindow(1,0,0,640,480,#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_TitleBar|#PB_Window_SystemMenu|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget,"DracSoft Tile Previewer")  
HideWindow(1,1)


If tile<>""
  LoadImage(1,tile)
Else
  tile=OpenFileRequester("Choose a tile...","","All Files|*.*",1)
  
  If tile<>""
    LoadImage(1,tile)
  Else
    End   
  EndIf   
EndIf 

If IsImage(1)
  SetWindowTitle(1,GetFilePart(tile)+" - "+GetWindowTitle(1))
  HideWindow(1,0)
  InitKeyboard()
  
  Repeat
    
    StartDrawing(WindowOutput())
    
    For i=0 To (WindowWidth()/ImageWidth())+1
      For j=0 To (WindowHeight()/ImageHeight())+1
        DrawImage(UseImage(1),i*ImageWidth(),j*ImageHeight())    
      Next 
    Next
    
    StopDrawing()
    
    ExamineKeyboard()
    If KeyboardReleased(#PB_Key_S)
      xt=Val(InputRequester("Save Tiled Image","Enter the number of times to tile on x axis:",""))
      If xt<=0 
        End
      EndIf 
      yt=Val(InputRequester("Save Tiled Image","Enter the number of times to tile on y axis:",""))
      If yt<=0 
        End
      EndIf 
      outfile.s=SaveFileRequester("Choose the output file...","","BMP Files|*.bmp",0)
      
      If outfile<>""      
        CreateImage(2,xt*ImageWidth(),yt*ImageHeight())
        If IsImage(2)
          UseImage(2)
          StartDrawing(ImageOutput())
          
          For i=0 To xt-1
            For j=0 To yt-1
              DrawImage(UseImage(1),i*ImageWidth(),j*ImageHeight())    
            Next 
          Next
          
          If MessageRequester("Save Tiled Image","Draw pink gridlines at the right and bottom of every tile?",#PB_MessageRequester_YesNo)=6 ;yes
                        
            For i=1 To xt
              Line(i*ImageWidth()-1,0,0,ImageHeight()*yt,RGB(255,0,255))
            Next
            For j=1 To yt
              Line(0,j*ImageHeight()-1,ImageWidth()*xt,0,RGB(255,0,255))
            Next 
          EndIf 
                    
          StopDrawing()
          If SaveImage(2,outfile,#PB_ImagePlugin_BMP)=0
            MessageRequester("Error","Couldn't create the image file.")
          EndIf 
          
        Else
          MessageRequester("Error","Couldn't create in-memory image.")
        EndIf 
      EndIf 
    EndIf 
    
    event=WaitWindowEvent()      
  Until event=#PB_Event_CloseWindow
  
  End
Else
  MessageRequester("Error","Couldn't load image.")
  End   
EndIf 
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Found a major bug. You use examinekeyboard without opening a screen.

Fixed it:

Code: Select all

; TilePreview
; Copyright 2005 DracSoft
; This code is released under the GNU GPL.
; These comments must remain intact.
; (http://www.gnu.org/licenses/gpl.html)

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

tile.s = ProgramParameter()


OpenWindow(1,0,0,640,480,#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_TitleBar|#PB_Window_SystemMenu|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget,"DracSoft Tile Previewer") 
OpenWindowedScreen(WindowID(1), 0, 0, 640, 480, 1, 0, 0)
HideWindow(1,1)


If tile<>""
  LoadImage(1,tile)
Else
  tile=OpenFileRequester("Choose a tile...","","All Files|*.*",1)
 
  If tile<>""
    LoadImage(1,tile)
  Else
    End   
  EndIf   
EndIf

If IsImage(1)
  SetWindowTitle(1,GetFilePart(tile)+" - "+GetWindowTitle(1))
  HideWindow(1,0)
  InitKeyboard()
 
  Repeat
   
    StartDrawing(WindowOutput())
   
    For i=0 To (WindowWidth()/ImageWidth())+1
      For j=0 To (WindowHeight()/ImageHeight())+1
        DrawImage(UseImage(1),i*ImageWidth(),j*ImageHeight())   
      Next
    Next
   
    StopDrawing()
   
    ExamineKeyboard()
    If KeyboardReleased(#PB_Key_S)
      xt=Val(InputRequester("Save Tiled Image","Enter the number of times to tile on x axis:",""))
      If xt<=0
        End
      EndIf
      yt=Val(InputRequester("Save Tiled Image","Enter the number of times to tile on y axis:",""))
      If yt<=0
        End
      EndIf
      outfile.s=SaveFileRequester("Choose the output file...","","BMP Files|*.bmp",0)
     
      If outfile<>""     
        CreateImage(2,xt*ImageWidth(),yt*ImageHeight())
        If IsImage(2)
          UseImage(2)
          StartDrawing(ImageOutput())
         
          For i=0 To xt-1
            For j=0 To yt-1
              DrawImage(UseImage(1),i*ImageWidth(),j*ImageHeight())   
            Next
          Next
         
          If MessageRequester("Save Tiled Image","Draw pink gridlines at the right and bottom of every tile?",#PB_MessageRequester_YesNo)=6 ;yes
                       
            For i=1 To xt
              Line(i*ImageWidth()-1,0,0,ImageHeight()*yt,RGB(255,0,255))
            Next
            For j=1 To yt
              Line(0,j*ImageHeight()-1,ImageWidth()*xt,0,RGB(255,0,255))
            Next
          EndIf
                   
          StopDrawing()
          If SaveImage(2,outfile,#PB_ImagePlugin_BMP)=0
            MessageRequester("Error","Couldn't create the image file.")
          EndIf
         
        Else
          MessageRequester("Error","Couldn't create in-memory image.")
        EndIf
      EndIf
    EndIf
   
    event=WaitWindowEvent()     
  Until event=#PB_Event_CloseWindow
 
  End
Else
  MessageRequester("Error","Couldn't load image.")
  End   
EndIf 
I could have also used shortcuts but I am lazy :P. By the way, nice program.
Thanks
Truth Seeker
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Why does the screen being open matter?

It works just fine without it here. :?
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

You code with debugger "ON", right? :wink:
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Heck no. I don't need the debugger. I've only used it once. It just tells me I can't do things that I obviously can :)
Post Reply