Nutzung der G15 Userlib von HeX0r

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
Bisonte
Beiträge: 2470
Registriert: 01.04.2007 20:18

Nutzung der G15 Userlib von HeX0r

Beitrag von Bisonte »

Ich kam am Anfang nicht wirklich mit HeX0r's Beispielen klar und
da ich laufend gefragt werde, wie ich das mit dem G15 Applet gemacht habe,
hab ich mal eben schnell ein Gerüst gebastelt, damit jeder was davon hat.

Es handelt sich um eine kleine Demo, die HeX0r's G15 Userlib,Windows (XP),und natürlich eine G15 (Treiber Version 2.0+) benötigt.

In der "Demo" habe ich die Knöpfe 1,2 und 4 mit Funktionen belegt...
Ich hoffe das Schnipselchen ist selbsterklärend...

Der Thread zur Userlib befindet sich hier : http://www.purebasic.fr/german/viewtopi ... 883#176883

Code: Alles auswählen

;####################################################################################
;####################################################################################
;##### 
;##### G15 - Display
;##### 
;##### Needed G15 Userlib by HeX0r - http://www.purebasic.fr/german/
;##### Needed G15 Keyboard ;)
;##### Needed G15 Keyboard Device Driver V2.0+
;##### Needed Windows OS 
;##### 
;####################################################################################
;####################################################################################

;##### 
;##### Global Variables
;##### 
;####################################################################################

Global Programname.s="G15 AppletDemo by Bisonte"
Global Font=LoadFont(1,"Small Fonts",6)
Global G15_QuitButton.l=0
Global Work.b = 0

;# G15 Userlib by Hex0r

#HAVE_G15_KEYBOARD = #True

Structure _G15_STATIC_VARS_
	Device.l
	Connection.l
	ImageID.l
EndStructure

;##### 
;##### other working code ... Procedures
;##### 
;####################################################################################



;##### 
;##### Procedures to G15
;##### 
;####################################################################################

Procedure G15_TitleScreen(ImageID.l)

;##### 160 x 43 Pixel

StartDrawing(ImageOutput(ImageID))

  DrawingFont(FontID(Font))
  DrawingMode(#PB_2DDrawing_Transparent)

  FillArea(0,0,-1,$FFFFFF)
  
  DrawText(1,1,"G15 Applet Demo")
  DrawText(1,10,"by Bisonte")
  DrawText(1,30,"of HeX0r's G15 - Userlib")

StopDrawing()

EndProcedure

Procedure G15_WorkScreen(ImageID.l)

;##### 160 x 43 Pixel 

StartDrawing(ImageOutput(ImageID))
  
  DrawingFont(FontID(Font))
  DrawingMode(#PB_2DDrawing_Transparent)

  FillArea(0,0,-1,$FFFFFF)

  Box(0,0,#LGLCD_BMP_WIDTH,#LGLCD_BMP_HEIGHT,0)
  Box(1,1,#LGLCD_BMP_WIDTH-2,#LGLCD_BMP_HEIGHT-2,$FFFFFF)
  
  DrawText(1,0,"Only a watch :")
  DrawText(#LGLCD_BMP_WIDTH-36,0,FormatDate("%hh:%ii:%ss",Date()))

StopDrawing()

EndProcedure

Procedure G15_Display(Progress.l)

Protected ctx.lgLcdConnectContext, ctxo.lgLcdOpenContext
Protected InitMode.l, Result.l

Static G15._G15_STATIC_VARS_

If G15\Device = 0

  If #HAVE_G15_KEYBOARD
	    InitMode = #LGLCD_INIT_NORMAL ;| #LGLCD_INIT_ADD_DISPLAY;| #LGLCD_INIT_NEED_EXTRA_KEYS ;| #LGLCD_INIT_ADD_DISPLAY
		Else
  		InitMode = #LGLCD_INIT_ONLY_DISPLAY
  EndIf
  
		If lgLcdInit(InitMode) = #ERROR_SUCCESS
			ctx\appFriendlyName = @ProgramName
			ctx\isPersistent    = #False
			ctx\isAutostartable = #True

			If lgLcdConnect(@ctx) <> #ERROR_SUCCESS
				lgLcdDeInit()
			Else
				ctxo\connection = ctx\connection
				ctxo\index      = 0
				G15\Connection  = ctx\connection
				If lgLcdOpen(@ctxo) <> #ERROR_SUCCESS
					lgLcdDisconnect(G15\Connection)
					lgLcdDeInit()
				Else
					G15\Device  = ctxo\Device
					G15\ImageID = CreateImage(#PB_Any, #LGLCD_BMP_WIDTH, #LGLCD_BMP_HEIGHT, 8)
					
					;##### 
					;##### Display Selection
					;##### 
					
					Select Progress
					
					  Case 1
					    G15_WorkScreen(G15\ImageID)
					    
		        Case 2
		          ; more Displays if you made some
					
					  Default
					    G15_TitleScreen(G15\ImageID)
					    
          EndSelect

					If lgLcdUpdateBitmap(G15\Device,G15\ImageID, LGLCD_ASYNC_UPDATE(#LGLCD_PRIORITY_ALERT)) = #ERROR_SUCCESS
						lgLcdSetAsLCDForegroundApp(G15\Device, #LGLCD_LCD_FOREGROUND_APP_YES)
					EndIf
					Result = #True
				EndIf
			EndIf
		EndIf		

	ElseIf Progress = -1
	  
		lgLcdClose(G15\Device)
		lgLcdDisconnect(G15\Connection)
		lgLcdDeInit()
		G15\Device = 0
		FreeImage(G15\ImageID)
		Result = #True
		
	ElseIf IsImage(G15\ImageID)
		FreeImage(G15\ImageID)
		G15\ImageID = CreateImage(#PB_Any, #LGLCD_BMP_WIDTH, #LGLCD_BMP_HEIGHT, 8)

		;##### 
		;##### Display Selection
	  ;##### 
					
		Select Progress
					
		  Case 1
		    G15_WorkScreen(G15\ImageID)
					    
		  Case 2
		    ; more Displays if you made some
				
		  Default
		    G15_TitleScreen(G15\ImageID)
					    
    EndSelect

 		lgLcdUpdateBitmap(G15\Device, G15\ImageID, LGLCD_ASYNC_UPDATE(#LGLCD_PRIORITY_ALERT))
		Result = #True
	EndIf  

;##### 
;##### G15 Buttons
;##### 
;####################################################################################
  
  lgLcdReadSoftButtons(G15\Device, @Buttons.l)

  If Buttons=#LGLCDBUTTON_BUTTON0
    ; Button 1
    Work=0

    ElseIf Buttons=#LGLCDBUTTON_BUTTON1
    ;Button 2
    Work=1

    ElseIf Buttons=#LGLCDBUTTON_BUTTON2
    ;Button 3
      
    ElseIf Buttons=#LGLCDBUTTON_BUTTON3
    G15_QuitButton=1 ; Button 4
    
  EndIf	
  
ProcedureReturn Result
	
EndProcedure

;##### 
;##### Prepare the Main-Loop
;##### 

;##### 
;##### Window for the EventHandling
;##### 
;####################################################################################

;{
WindowNr.l = OpenWindow(#PB_Any,10,10,10,10,"",#PB_Window_Invisible)

If WindowNr
 ;go on
 Else
 MessageRequester("Achtung","Konnte kein Window öffnen")
 End
EndIf

;}

;##### 
;##### Main Loop
;##### 
;####################################################################################

;Work = 1 ; Something to Display
;Work = 0 ; Titlescreen of G15

Repeat

  WindowEvent()

  G15_Display(Work)
  
  Delay(200) ; Picture Refreshrate... 200 Milliseconds are quite often enough and Windows also needs CPU-Time to work ...

Until G15_QuitButton = 1


;##### End - Free Ressources

;{

If WindowNr
  CloseWindow(WindowNr)
EndIf

;}

End
PureBasic 6.21 (Windows x86/x64) | Windows11 Pro x64 | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | GeForce RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​