Parece sencillo, pero no es fácil encontrar ejemplos. Suele ser siempre el mismo tipo de letra por defecto.
Aunque aquí os muestro como hacerlo en SDL1 no resultará nada complicado cambiarlo a SDL2. Son muy compatibles,
solo que en gambas hay propiedades y métodos que tenemos en SDL1 y en SDL2 no, ya que no están completas.
Const VENTANAANCHO As Integer = 640
Const VENTANAALTO As Integer = 480
Private $hWindow As Window
Public Sub Main()
$hWindow = New Window As "Window"
With $hWindow
.Width = VENTANAANCHO
.Height = VENTANAALTO
.Title = "Mostrar texto con un tipo de letra en ventana SDL"
.Resizable = False
.Show
.FrameRate = 30
End With
End
Public Sub Window_Draw()
Dim frase As String
Dim fuente As Font
Dim x As Integer
Dim y As Integer
frase = "Usando SDL1 con Gambas3"
$hWindow.Clear
$hWindow.Fill(Color.White)
fuente = Font.Load("/usr/share/fonts/truetype/freefont/FreeMono.ttf")
Draw.Font = fuente
Draw.Font.Size = 24
Draw.ForeColor = Color.Blue
x = (VENTANAANCHO - Draw.Font.Width(frase)) / 2
y = (VENTANAALTO - Draw.Font.Height("A")) / 2
Draw.Text(frase, x, y)
End
Public Sub Window_KeyPress()
Select Case Key.Code
Case Key.F1
$hWindow.FullScreen = Not $hWindow.FullScreen
Case Key.Esc
$hWindow.Close
End Select
End
Const VENTANAALTO As Integer = 480
Private $hWindow As Window
Public Sub Main()
$hWindow = New Window As "Window"
With $hWindow
.Width = VENTANAANCHO
.Height = VENTANAALTO
.Title = "Mostrar texto con un tipo de letra en ventana SDL"
.Resizable = False
.Show
.FrameRate = 30
End With
End
Public Sub Window_Draw()
Dim frase As String
Dim fuente As Font
Dim x As Integer
Dim y As Integer
frase = "Usando SDL1 con Gambas3"
$hWindow.Clear
$hWindow.Fill(Color.White)
fuente = Font.Load("/usr/share/fonts/truetype/freefont/FreeMono.ttf")
Draw.Font = fuente
Draw.Font.Size = 24
Draw.ForeColor = Color.Blue
x = (VENTANAANCHO - Draw.Font.Width(frase)) / 2
y = (VENTANAALTO - Draw.Font.Height("A")) / 2
Draw.Text(frase, x, y)
End
Public Sub Window_KeyPress()
Select Case Key.Code
Case Key.F1
$hWindow.FullScreen = Not $hWindow.FullScreen
Case Key.Esc
$hWindow.Close
End Select
End
Saludos
EjemploMuestraTexto.tar.gz | ||
Descripción: | Como mostrar un texto en una ventana SDL1 con un tipo de letra concreto | Descargar |
Nombre del archivo: | EjemploMuestraTexto.tar.gz | |
Tamaño: | 12.79 KB | |
Descargado: | 18 veces |
EjemploMuestraTexto.tar.gz | ||
Descripción: | Como mostrar un texto en una ventana SDL1 con un tipo de letra concreto | Descargar |
Nombre del archivo: | EjemploMuestraTexto.tar.gz | |
Tamaño: | 12.79 KB | |
Descargado: | 18 veces |
EjemploMuestraTexto.tar.gz | ||
Descripción: | Como mostrar un texto en una ventana SDL1 con un tipo de letra concreto | Descargar |
Nombre del archivo: | EjemploMuestraTexto.tar.gz | |
Tamaño: | 12.79 KB | |
Descargado: | 18 veces |