' Gambas class file
Private acontArchivo1 As String[]
Private contenedorprincipal As Panel
Private esdescripcion As Boolean
Public Sub Form_Open()
Dim contenido As String
Dim linea As String
Dim frase1 As String
Dim frase2 As String
Dim posicion As Integer
'Solicitamos información sobre el paquete oregano.
Shell "apt show oregano" To contenido
acontArchivo1 = Split(contenido, gb.NewLine, "", True)
esdescripcion = False
With Me
.Arrangement = Arrange.Horizontal
.Spacing = True
.H = 0
End With
contenedorprincipal = New Panel(Me)
With contenedorprincipal
.Arrangement = Arrange.Vertical
.Expand = True
.Margin = True
End With
For Each linea In acontArchivo1
posicion = InStr(linea, ":")
If posicion > 0 And Not esdescripcion Then
frase1 = String.Mid(linea, 1, posicion - 1)
frase2 = String.Mid(linea, posicion + 1)
If frase1 <> "Description" Then
ConstruirBloque(frase1, frase2)
Else
esdescripcion = True
frase2 = ""
Endif
Else
If esdescripcion Then frase2 &= linea & gb.NewLine
Endif
Next
If esdescripcion Then ConstruirBloque(frase1, frase2)
esdescripcion = False
End
Public Sub ConstruirBloque(encabezado As String, contenido As String)
'TODO: En caso de ser dependencias puede que se deba crear un TextArea para que se muestre mejor la información para estas
Dim contenedor As Panel
Dim etiqueta As Label
Dim cajadetexto As TextBox
Dim cajatextarea As TextArea
contenedor = New Panel(contenedorprincipal)
With contenedor
.Arrangement = Arrange.Horizontal
.Spacing = True
.H = 25
Me.H += .H
End With
If Not esdescripcion Then
etiqueta = New Label(contenedor)
With etiqueta
.W = 180
.H = 20
.Alignment = Align.Right
.Font = Font["MonoSpace,Bold"]
.Text = encabezado
End With
cajadetexto = New TextBox(contenedor)
With cajadetexto
.H = 20
.Text = contenido
.Expand = True
End With
Else
etiqueta = New Label(contenedor)
With etiqueta
.W = 140
.H = 20
.Alignment = Align.Left
.Font = Font["MonoSpace,Bold"]
.Text = encabezado
End With
cajatextarea = New TextArea(contenedorprincipal)
With cajatextarea
.H = 100
.Text = contenido
.ScrollBar = Scroll.Vertical
.Expand = True
.Pos = 0
Me.H += .H
End With
Endif
End
Const NUMDECUADRADOS As Integer = 3
Const ANCHOVENTANA As Integer = 600
Const ALTOVENTANA As Integer = 600
Private figuras As Rectangulo[]
Private unrect As Rectangulo
Private unformulario As FormTestContenedores
Private obs As Observer
For i As Integer = 0 To NUMDECUADRADOS - 1
unrect = New Rectangulo([Pizarra.W / 2, Pizarra.h / 2], [Rand(-5, 5), Rand(-5, 5)], pizarra, i)
figuras.Add(unrect)
obs = New Observer(figuras) As "Vigilo"
Next
Event Izquierdo(mensaje As String, indice As Integer)
Event Derecho(mensaje As String, indice As Integer)
Event Superior(mensaje As String, indice As Integer)
Event Inferior(mensaje As String, indice As Integer)
Public Sub Actualizar()
If Me.xy[0] < 0 Then
Raise Izquierdo("Rectángulo choca con borde izquierdo", Me.indice)
Me.acel[0] *= -1
Else If Me.xy[0] > Me.area.W - ANCHORECT Then
Raise Derecho("Renctángulo choca borde derecho", Me.indice)
Me.acel[0] *= -1
Endif
If Me.xy[1] > Me.area.H - ALTORECT Then
Raise Inferior("Rectángulo choca con borde inferior", Me.indice)
Me.acel[1] *= -1
Else If Me.xy[1] < 0 Then
Raise Superior("Rectángulo choca con borde superior", Me.indice)
Me.acel[1] *= -1
Endif
Me.xy[0] += Me.acel[0]
Me.xy[1] += Me.acel[1]
End
Public Sub MostrarMensaje(mensaje As String, indice As Integer)
Dim ob As Object
For Each ob In paneles[indice].Children
If ob.tag = 1 Then
ob.text = mensaje
Break
Endif
Next
End
' Gambas class file
Const VENTANA_ANCHO As Integer = 800
Const VENTANA_ALTO As Integer = 600
Private canvas As DrawingArea
Private timer1 As Timer
Private terminar As Boolean
Private pulsado As Boolean
Private cuenta As Integer
Private vigilante As Observer
Public Sub Form_Open()
vigilante = New Observer(Me) As "Vigilante"
With Me
.Background = Color.Black
.Title = "Evento MouseDown y MouseUP"
.Arrangement = Arrange.Horizontal
.Resizable = False
.AutoResize = True
End With
canvas = New DrawingArea(Me) As "Canvas"
With canvas
.W = VENTANA_ANCHO
.H = VENTANA_ALTO
.Background = Color.Black
End With
timer1 = New Timer As "Timer1"
Timer1.Delay = 1000
End
Public Sub Canvas_MouseDown()
If Not terminar Then
If Mouse.Left Then
pulsado = True
Timer1.Start
Endif
Endif
End
Public Sub Canvas_MouseUp()
If Not terminar Then
pulsado = False
cuenta = 0
Timer1.Stop
Endif
canvas.Refresh
End
Public Sub Canvas_Draw()
Dibujar
End
Public Sub Dibujar()
Dim RC As RectF
Dim mensaje As String
Paint.Font = Font["MonoSpace, 14"]
If pulsado And Not terminar Then
mensaje = "Se ha pulsado el boton izquierdo del ratón durante: " & Str(cuenta) & " segundos"
RC = Paint.TextSize(mensaje)
Else If Not pulsado And Not terminar Then
mensaje = "Se ha levantado el dedo del botón izquierdo del ratón"
RC = Paint.TextSize(mensaje)
Else If Not pulsado And terminar Then
mensaje = "Este programa se cerrará en " & Str(cuenta) & " segundos"
RC = Paint.TextSize(mensaje)
Endif
Paint.Text(mensaje, (canvas.w - RC.Width) / 2, (canvas.Height - RC.Height) / 2, RC.Width, RC.Height)
Paint.Brush = Paint.Color(Color.Green)
Paint.Fill
End
Public Sub Timer1_Timer()
If Not terminar Then
cuenta += 1
canvas.Refresh
Else If terminar And cuenta > 0 Then
cuenta -= 1
canvas.Refresh
Else If terminar And cuenta = 0 Then
Timer1.Stop
Me.Close
Endif
End
Public Sub Vigilante_Close()
If Not terminar Then
pulsado = False
terminar = True
cuenta = 4
Timer1.Start
Endif
End
Public Sub Form_Close()
If cuenta = 0 And terminar Then
Quit
Else
'Evitar el cierre del programa si no se cumplen las condiciones
Stop Event
Endif
End