2
0
Эх сурвалжийг харах

Added pixmap, polledinput, event and timer examples.

woollybah 6 жил өмнө
parent
commit
f385af89c8

+ 15 - 0
event.mod/doc/createevent.bmx

@@ -0,0 +1,15 @@
+SuperStrict
+
+Graphics 640,480
+
+Const MY_EVENT:Int = 99
+Local myEvent:TEvent=CreateEvent(MY_EVENT)
+Local myTimer:TTImer = CreateTimer(10,myEvent)
+Repeat
+	WaitEvent
+	Cls
+	If EventID() = MY_EVENT
+		DrawText "Timer has ticked " + TimerTicks(myTimer) + " times",10,15
+	EndIf
+	Flip
+Until AppTerminate()

+ 19 - 0
pixmap.mod/doc/clearpixels.bmx

@@ -0,0 +1,19 @@
+SuperStrict
+
+Graphics 800 , 600
+
+Local mypix:TPixmap = LoadPixmap(BlitzMaxPath()+"/samples/hitoro/gfx/boing.png")
+If mypix = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+DrawPixmap mypix, 0, 0
+
+ClearPixels(mypix, $FFFFFF)
+ 
+
+DrawPixmap mypix, 300, 0
+
+Flip
+
+WaitKey

+ 18 - 0
pixmap.mod/doc/copypixmap.bmx

@@ -0,0 +1,18 @@
+SuperStrict
+
+Graphics 640 , 480
+
+Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+If pix = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+
+Local newPix:TPixmap=CopyPixmap(pix)
+
+Repeat
+	Cls
+	DrawPixmap pix, 50, 50
+	DrawPixmap newPix, MouseX(), MouseY()
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 14 - 0
pixmap.mod/doc/loadpixmap.bmx

@@ -0,0 +1,14 @@
+SuperStrict
+
+Graphics 640,480
+Local player:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+
+If player = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+Repeat
+	Cls
+	DrawPixmap Player,10,10
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 15 - 0
pixmap.mod/doc/loadpixmap_1.bmx

@@ -0,0 +1,15 @@
+SuperStrict
+
+Graphics 640 , 480
+
+Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+'converts Pixmap to Image
+'note alpha transparency
+Local image:TImage=LoadImage(pix)
+
+Repeat
+	Cls
+	DrawPixmap pix, 50, 50
+	DrawImage image, MouseX(), MouseY()
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 19 - 0
pixmap.mod/doc/pixmapheight.bmx

@@ -0,0 +1,19 @@
+SuperStrict
+
+Graphics 640,480
+
+Local pix:TPixmap = LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+
+If pix = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+Repeat
+	Cls
+	
+	' Display Information
+	DrawText "Image Width:"+PixmapWidth(pix)+"  Image Height:"+PixmapHeight(pix),0,0 
+
+	DrawPixmap pix,100,100
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 17 - 0
pixmap.mod/doc/pixmapwidth.bmx

@@ -0,0 +1,17 @@
+SuperStrict
+
+Graphics 640,480
+Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+
+If pix = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+Repeat
+	Cls
+	' Display Information
+	DrawText "Image Width:"+PixmapWidth(pix)+"  Image Height:"+PixmapHeight(pix),0,0 
+
+	DrawPixmap pix,100,100
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 19 - 0
pixmap.mod/doc/resizepixmap.bmx

@@ -0,0 +1,19 @@
+SuperStrict
+
+Graphics 640 , 480
+
+Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+
+If pix = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+'Reduce Image by 50%
+Local newPix:TPixmap=ResizePixmap(pix, Int(PixmapWidth(pix)*.5), Int(PixmapHeight(pix)*.5))
+
+Repeat
+	Cls
+	DrawPixmap pix, 50, 50
+	DrawPixmap newPix, MouseX() , MouseY()
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 31 - 0
pixmap.mod/doc/savepixmapjpg.bmx

@@ -0,0 +1,31 @@
+SuperStrict
+
+Graphics 640,480
+
+Local pix:TPixmap = LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+
+If pix = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+Repeat
+	Cls
+	DrawText "Press S to save Image to Disk",10,10
+	
+	' Save pixmap
+	If KeyHit(KEY_S)
+		'Prompt the user for a path to save to
+		Local path:String = RequestFile("Save As","PNG:png;JPG:jpg",True)
+		
+		' Save the TPixmap into a file according to its format
+		Select ExtractExt(path)
+			Case "png"
+				SavePixmapPNG(pix, path)
+			Case "jpg"
+				SavePixmapJPeg(pix, path)
+		End Select					
+   End If
+
+	DrawPixmap pix,100,100
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 31 - 0
pixmap.mod/doc/savepixmappng.bmx

@@ -0,0 +1,31 @@
+SuperStrict
+
+Graphics 640,480
+
+Local pix:TPixmap = LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+
+If pix = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+Repeat
+	Cls
+	DrawText "Press S to save Image to Disk",10,10
+	
+	' Save pixmap
+	If KeyHit(KEY_S)
+		'Prompt the user for a path to save to
+		Local path:String = RequestFile("Save As","PNG:png;JPG:jpg",True)
+		
+		' Save the TPixmap into a file according to its format
+		Select ExtractExt(path)
+			Case "png"
+				SavePixmapPNG(pix, path)
+			Case "jpg"
+				SavePixmapJPeg(pix, path)
+		End Select					
+   End If
+
+	DrawPixmap pix,100,100
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 30 - 0
pixmap.mod/doc/tpixmap.bmx

@@ -0,0 +1,30 @@
+SuperStrict
+
+'Prompt the user for an image file
+Local path:String = RequestFile("Select an Image File","Image Files:png,jpg,bmp")
+
+Local pix:TPixmap
+
+'Load the file into a TPixmap according to its format
+Select ExtractExt(path)
+	Case "png"
+		pix = LoadPixmapPNG(path)
+	Case "jpg"
+		pix = LoadPixmapJPeg(path)
+	Default
+		pix = LoadPixmap(path)
+EndSelect
+
+'Ensure the file loaded
+If Not pix Then
+	Notify "The File Could Not Load. The Program Will Now End."
+	End
+End If
+
+'Setup the window
+Graphics 600,600,0,60,2
+Repeat
+	Cls
+	DrawPixmap Image , 20 , 20
+	Flip
+Until KeyDown(KEY_ESCAPE) Or AppTerminate()

+ 26 - 0
pixmap.mod/doc/xflippixmap.bmx

@@ -0,0 +1,26 @@
+SuperStrict
+
+Graphics 640,480
+
+Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+
+If pix = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+Repeat
+	Cls
+	DrawText "Press Key X or Y to change Orientation" , 10 , 10
+	
+	' Change pixmap orientation
+	If KeyHit(KEY_X) Then
+		pix = XFlipPixmap(pix)
+	End If
+	
+	If KeyHit(KEY_Y) Then
+		pix = YFlipPixmap(pix)
+	End If
+	
+	DrawPixmap pix,50,50
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 26 - 0
pixmap.mod/doc/yflippixmap.bmx

@@ -0,0 +1,26 @@
+SuperStrict
+
+Graphics 640,480
+
+Local pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
+
+If pix = Null Then
+	RuntimeError ("Error Loading Image")
+End If
+
+Repeat
+	Cls
+	DrawText "Press Key X or Y to change Orientation" , 10 , 10
+	
+	' Change pixmap orientation
+	If KeyHit(KEY_X) Then
+		pix = XFlipPixmap(pix)
+	End If
+	
+	If KeyHit(KEY_Y) Then
+		pix = YFlipPixmap(pix)
+	End If
+	
+	DrawPixmap pix,50,50
+	Flip
+Until KeyHit(key_escape) Or AppTerminate()

+ 14 - 0
polledinput.mod/doc/appsuspended.bmx

@@ -0,0 +1,14 @@
+SuperStrict
+
+SetGraphicsDriver GLMax2DDriver()
+Graphics 800,600
+
+While Not KeyHit(KEY_ESCAPE)
+	Cls
+	If AppSuspended() = True
+		DrawText "Application Suspended!",10,10
+	Else
+		DrawText "Application Running...",10,10
+	EndIf
+	Flip
+Wend

+ 7 - 0
polledinput.mod/doc/waitkey.bmx

@@ -0,0 +1,7 @@
+SuperStrict
+
+Graphics 640,480
+
+DrawText "Press any key to end this program.", 10 , 10
+Flip
+WaitKey()

+ 10 - 0
polledinput.mod/doc/waitmouse.bmx

@@ -0,0 +1,10 @@
+'detects which mouse button was pressed 
+
+SuperStrict
+
+Graphics 640,480
+
+Repeat
+	DrawText "Click Mouse to exit" , 200 , 200
+	Flip 
+Until WaitMouse()

+ 13 - 0
timer.mod/doc/createtimer.bmx

@@ -0,0 +1,13 @@
+SuperStrict
+
+'Maximum allowable Timer is 16
+Global timers:TTimer[500]
+
+For Local n:Int = 0 Until 18
+	timers[n] = CreateTimer(1)
+	If timers[n] = Null
+		Print "Cannot create timer "+n
+	Else
+		Print "Successfully created timer "+n
+	EndIf
+Next

+ 26 - 0
timer.mod/doc/createtimer_1.bmx

@@ -0,0 +1,26 @@
+'Animation on MaxGUI canvas
+SuperStrict
+
+Import MaxGUI.Drivers
+
+Local MyWindow:TGadget=CreateWindow("Canvas Example", 200,200,320,240)
+Local MyCanvas:TGadget=CreateCanvas(10,10,290,140,MyWindow)
+Local timer:TTimer=CreateTimer(60)
+Local x:Int=0
+
+Repeat
+  WaitEvent()
+  Select EventID()
+  Case EVENT_WINDOWCLOSE
+     End
+  Case EVENT_TIMERTICK
+     x=x+1
+     If x>240 x=0
+     RedrawGadget(MyCanvas)
+  Case EVENT_GADGETPAINT
+    SetGraphics CanvasGraphics (MyCanvas)
+    Cls
+    DrawRect  x,20,50,80
+    Flip
+   End Select
+Forever