[B2D] TXT Extended

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

Crono

Betreff: [B2D] TXT Extended

BeitragSo, Jul 23, 2006 21:34
Antworten mit Zitat
Benutzer-Profile anzeigen
Hierbei handelt es sich um zwei Funktionen.

Mit der ersten kann man einfach nur ein transparentes Rechteck zeichnen (Angabe der X und Y Koordinaten, Breite, Höhe, Farbe).
Mit der zweiten kann man einen einen Text, der mit einem Transparenten Kasten umgeben ist (X und Y Koordinaten, Farbe des transparenten hintergrundes, Farbe des Textes, Text, Rahmen) erstellen.

Code: [AUSKLAPPEN]

; -----------------------------
; TXT Extended
; -----------------------------
; By Crono
; crono@planetgenerally.de
; -----------------------------

Graphics 640,480,32,1
SetBuffer BackBuffer()
ClsColor 255,255,255
HidePointer

font = LoadFont ("Verdana",16,1)
SetFont font

; BEISPIEL SPIELSCHLEIFE ##############################################################

Repeat

   Cls
   
   ; Rechtecke zu Testzwecke
   Color 150,200,000
   Rect 100,100,100,100,1
   Color 020,150,230
   Rect 350,250,100,100
   
   ; FPS anzeigen
   Frames = Frames + 1
   If ZaehlStart + 1001 < MilliSecs() Then
     FramesJeSekunde = Frames
     Frames = 0
     ZaehlStart = MilliSecs()
    EndIf
   Color 160, 180, 200
   Text 450, 10, FramesJeSekunde + " FPS"
   
   ; Transparentes Rechteck/Text zeichnen
   alphatext(10,10,100,150,250,000,000,000,CurrentTime(),1)
   alpharect(90,90,100,30,100,100,100,0)
   alphatext(MouseX()+5,MouseY()+5,100,100,100,000,000,000,"Test für den Text",0)
   
   ; Mauszeiger anzeigen (kleines schwarzes Rechteck)
   Color 000,000,000
   Rect MouseX(), MouseY(), 5, 5, 1
   
   Flip

Until KeyHit(1)

End

; FUNKTIONEN ###########################################################################

; alpharect(xposition, yposition, breite, höhe, r, g, b, rahmen(1/0))
Function alpharect(ar_x%, ar_y%, ar_w%, ar_h%, ar_r%, ar_g%, ar_b%, ar_frame%)

   LockBuffer BackBuffer()

   For x = (ar_x) To (ar_x + ar_w)
   For y = (ar_y) To (ar_y + ar_h)
      rgb_alt = ReadPixelFast (x,y,BackBuffer())
      WritePixelFast x,y, (255*$1000000 + (((((rgb_alt And $FF0000)/$10000) + ar_r)/2)*$10000) + (((((rgb_alt And $FF00)/$100) + ar_g)/2)*$100) + ((((rgb_alt And $FF) + ar_b)/2))),BackBuffer()
   Next
   Next
   
   UnlockBuffer BackBuffer()
   
   If ar_frame% = 1 Then
      Color 000,000,000
      Rect ar_x,ar_y,ar_w+1,ar_h+1,0
   End If

End Function

; alphatext(xposition, yposition, r, g, b, r, g, b, text, rahmen(1/0))
Function alphatext(at_x%, at_y%, at_r%, at_g%, at_b%, at_tr%, at_tg%, at_tb%, msg$, at_frame%)

   msgw=StringWidth(msg$)+2
   msgh=StringHeight(msg$)+2

   LockBuffer BackBuffer()

   For x = (at_x) To (at_x + msgw)+3
   For y = (at_y) To (at_y + msgh)+2
      rgb_alt = ReadPixel (x,y)
      WritePixel x,y, (255*$1000000 + (((((rgb_alt And $FF0000)/$10000) + at_r)/2)*$10000) + (((((rgb_alt And $FF00)/$100) + at_g)/2)*$100) + ((((rgb_alt And $FF) + at_b)/2)))
   Next
   Next
   
   UnlockBuffer BackBuffer()
   
   If at_frame% = 1 Then
      Color 000,000,000
      Rect at_x,at_y,msgw+4,msgh+3,0
   End If
   
   Color at_tr%,at_tg%,at_tb%
   Text at_x+3,at_y+2, msg$

End Function
User posted image

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group