Skip to content

Commit 8aa6746

Browse files
committed
preparada ayuda contextual freetype cairo
1 parent bc26d6a commit 8aa6746

File tree

6 files changed

+152
-9
lines changed

6 files changed

+152
-9
lines changed

BebasKai.otf

31.8 KB
Binary file not shown.

ROLLDEC.BI

+35-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Declare Sub moveresto (ByVal StartInsert As integer,ByRef indaux as Integer, Byr
88
Declare Sub movedato (ByVal StartInsert As Integer, ByRef indaux As Integer, Byref insert As Integer,Byref nota As integer)
99
' 128 track,16 canales o sea cada canal con 8 voces
1010
Declare Sub cursor(c AS cairo_t Ptr, n As Integer,nro As Integer)
11-
11+
'Declare Function print_text(ByVal x As Integer, ByVal y As Integer, ByRef text As String, _
12+
' ByVal font As FT_Face, ByVal size As Integer, ByVal col As UInteger ) As Integer
1213
Dim Shared nro As Integer '''borrar despues jmg ja quedo
1314
Dim Shared As Integer vroll, vdur ' borrar
1415
Dim shared as ubyte notasInsertadas (1 to 1500)
@@ -39,6 +40,7 @@ Dim Shared sil As Integer = 0 'silencio entrada con s = 1 con silencio
3940
' ej tecleo 1+.+A=O* en linea A dela octava que sea
4041
' ej tecleo s+1+.+A =sO* en A..
4142
' tambien en vez de estos simbolos usare los de un pentagrama comun,,,,futuro
43+
Dim Shared As BOOLEAN ayuda
4244

4345
espacio=0:cursorVert=0:borrar=0:cambiadur=0:InicioDeLectura=0
4446
menuAccion=0:insert=0:agregarNota=0
@@ -59,3 +61,35 @@ Dim Shared As Integer menuNro, menuNew
5961
''Declare Function MessageBox Alias "MessageBoxW"(n1 As Integer,s1 As Wstring,s2 As Wstring,MB As Integer) As Integer:Sleep 1
6062
Dim Shared As Integer x, y, buttons, res,xscreen
6163
Dim Shared as Integer StartInsert,indaux,NroCol, carga, curpos, resultado
64+
' free type
65+
#Include once "freetype2/freetype.bi"
66+
'' The FB headers don't contain this prototype
67+
extern "C"
68+
declare function _
69+
cairo_ft_font_face_create_for_ft_face ( as FT_Face, as long ) as cairo_font_face_t ptr
70+
end extern
71+
72+
'' Convenience
73+
type FreeType
74+
public:
75+
declare constructor()
76+
declare destructor()
77+
78+
declare operator Cast() as FT_Library
79+
80+
private:
81+
as FT_Library _library
82+
end type
83+
84+
constructor FreeType()
85+
FT_Init_FreeType( @_library )
86+
end constructor
87+
88+
destructor FreeType()
89+
FT_Done_FreeType( _library )
90+
end destructor
91+
92+
operator FreeType.cast() as FT_Library
93+
return( _library )
94+
end Operator
95+

ROLLSUB.BI

+26-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ If *octava < 0 Then
128128
*octava = 99
129129
Exit Sub
130130
EndIf
131+
If ayuda=TRUE Then
132+
Var cface => cairo_ft_font_face_create_for_ft_face( ftface, 0 )
133+
cairo_set_font_face( c, cface )
134+
cairo_set_font_size( c, 36 )
135+
dim as string text => "HOLA SOY tU AYUDA!"
136+
dim As cairo_text_extents_t extents
137+
cairo_text_extents( c, text, @extents )
138+
cairo_move_to( c, mousex, mousey )
139+
cairo_set_source_rgba( c, 0, 0, 1, 1.0 )
140+
cairo_show_text( c, text )
141+
142+
'' Draw String (MOUSEX, MOUSEY), "HOLA SOY tU AYUDA!",8
143+
144+
145+
EndIf
131146

132147
End Sub
133148
''========================= C U R S O R ============
@@ -844,9 +859,17 @@ cairo_stroke(cm)
844859
End Sub
845860
'------------------------------------
846861
' https://www.freebasic.net/forum/viewtopic.php?t=10398
862+
' Many times in my games I want to act on a single key press.
863+
' Multikey returns -1 constantly if a key is down and that isn't always what I want
864+
' so I created this function which uses multikey but will only return -1 once
865+
' for a particular key. The user must release and press the key again for it to fire.
866+
' Call it just like Multikey....
867+
'
868+
' If KeyPress(SC_ESC)=-1 then .....!!! USARLO O USAR E.EVENT CREO ES SIMILAR O NO???
869+
847870
Function KeyPress(Key As Integer) As Integer
848871
Static LastKey(255) As Integer
849-
872+
' DETECTA UNA APRETDA DEL USUARIO Y SOLO UNA CREO PROBAR
850873
If MultiKey(Key) = -1 Then
851874
If Key = LastKey(Key) Then
852875
Return (0)
@@ -859,4 +882,5 @@ Static LastKey(255) As Integer
859882
Return (0)
860883
End If
861884

862-
End Function
885+
End Function
886+
' -------------------------------------------------------------

RollMusic.bas

+91-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ AnchoInicial=ANCHO
7171
AltoInicial=ALTO
7272
NroCol = (ANCHO / 20 ) - 4 ' 20 Tamaño figuras, nota guia 6 columnas "B_8_[ "
7373
'cambie a directX !!! versi anda winpopup
74+
7475
ScreenControl SET_DRIVER_NAME,"GDI" ' le da foco a la aplicacion
76+
7577
' con Directx nunca tomaelfoco se lodebe dar elusuario
7678
'nofuncionaningun comndo de winuser.bipara tomar el foco...
7779
'''''ScreenControl POLL_EVENTS '200
@@ -81,7 +83,9 @@ ScreenControl SET_DRIVER_NAME,"GDI" ' le da foco a la aplicacion
8183
Dim As String driver
8284

8385
ScreenRes ANCHO, ALTO, 32,2, GFX_NO_FRAME Or GFX_HIGH_PRIORITY
86+
8487
ScreenControl GET_WINDOW_POS, x0, y0
88+
8589
''ScreenControl SET_WINDOW_POS, 10,10
8690
'ScreenControl 103,"Directx" ' cambio ja
8791
' CAIRO NO SOPORTA LA �!!! ESO ERA TODO!!!!
@@ -152,7 +156,16 @@ Dim As hWnd hwnd = Cast(hwnd,IhWnd)
152156
'AppendMenu(exelist, MF_STRING,1,"Uno")
153157
'AppendMenu(exelist, MF_STRING,2,"Dos")
154158
Dim comienzo As Integer = 0
159+
'--FFT FREE FONT- ...HCEDESAPRECER LA APLICCION PORQUERIA
160+
var Shared ft => FreeType()
161+
162+
'' Load a font with FreeType
163+
Dim Shared as FT_Face ftface
155164

165+
FT_New_Face( ft, "Bebaskai.otf", 0, @ftface )
166+
167+
168+
'----- -FIN
156169

157170
'' --------------- LOOP 1 ---------------
158171
Do
@@ -165,19 +178,22 @@ ScreenLock()
165178

166179
'' Create a cairo drawing context, using the FB screen as surface.
167180
'' l originalestba mal sizeof(integer ) es mu chico debe ser 4
168-
stride =cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, ANCHO)
181+
stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, ANCHO)
169182

170183

171184
Var surface = cairo_image_surface_create_for_data(ScreenPtr(), CAIRO_FORMAT_ARGB32, ANCHO, ALTO, stride)
172185
Var c = cairo_create(surface)
173186

187+
188+
189+
'' Measure the text, used with SDL_RenderCopy() to draw it without scaling
174190

175191
' https://www.cairographics.org/tutorial/
176192

177193

178194

179195
If comEdit = TRUE Then
180-
' cairo_set_source_rgba(c, 0.6, 0.5, 0.6, 1)
196+
' cairo_set_source_rgba(c, 0.6, 0.5, 0.6, 1)
181197
cairo_set_source_rgba(c, 0.6, 0.6, 0.7, 1)
182198
Else
183199
cairo_set_source_rgba c, 0.6, 0.7, 0.8, 1
@@ -694,6 +710,10 @@ If MultiKey(SC_ESCAPE) Then
694710

695711
if MessageBox(hWnd,"¿SEGURO FINALIZA?","RollMusic End ",4 or 64) =6 then
696712
cairo_destroy(c)
713+
' cairo_surface_destroy( surface )
714+
' cairo_font_face_destroy( cface )
715+
FT_Done_Face( ftface )
716+
697717
Close 1
698718
End
699719
EndIf
@@ -900,6 +920,61 @@ If comEdit = TRUE Then
900920
EndIf
901921
' ojo ver q no habia exit do antes !!!!!
902922
EndIf
923+
' ----HELP PRUEBA DE TEXT
924+
If MultiKey(SC_F1) Then
925+
' estopodemos hacer ayuda contextual
926+
'' Define character range
927+
Const FIRSTCHAR = 32, LASTCHAR = 127
928+
929+
Const NUMCHARS = (LASTCHAR - FIRSTCHAR) + 1
930+
Dim As UByte Ptr p, myFont
931+
Dim As Integer i
932+
933+
934+
'' Create custom font into PUT buffer
935+
936+
myFont = ImageCreate(NUMCHARS * 32, 9)
937+
938+
'' Put font header at start of pixel data
939+
940+
#ifndef ImageInfo '' older versions of FB don't have the ImageInfo feature
941+
p = myFont + IIf(myFont[0] = 7, 32, 4)
942+
#else
943+
ImageInfo( myFont, , , , , p )
944+
#endif
945+
946+
p[0] = 0
947+
p[1] = FIRSTCHAR
948+
p[2] = LASTCHAR
949+
950+
'' PUT each character into the font and update width information
951+
For i = FIRSTCHAR To LASTCHAR
952+
953+
'' Here we could define a custom width for each letter, but for simplicity we use
954+
'' a fixed width of 8 since we are reusing the default font glyphs
955+
p[3 + i - FIRSTCHAR] = 12
956+
957+
'' Create character onto custom font buffer by drawing using default font
958+
Draw String myFont, ((i - FIRSTCHAR) * 12, 1), Chr(i), 32 + (i Mod 24) + 24
959+
960+
Next i
961+
962+
'' Now the font buffer is ready; we could save it using BSAVE for later use
963+
Rem BSave "myfont.bmp", myFont
964+
965+
'' Here we draw a string using the custom font
966+
'Draw String (10, 10), "ABCDEFGHIJKLMNOPQRSTUVWXYZ", , myFont
967+
'Draw String (10, 26), "abcdefghijklmnopqrstuvwxyz", , myFont
968+
'Draw String (66, 58), "Hello world!", , myFont
969+
970+
'' Free the font from memory, now we are done with it
971+
ImageDestroy myFont
972+
973+
974+
Draw String (MOUSEX, MOUSEY), "HOLA SOY tU AYUDA!", ,myFont
975+
Draw String (MOUSEX, MOUSEY+20), "QUE QUERES SABER", ,myFont
976+
EndIf
977+
'
903978
If comEdit = FALSE Then '''???????????????? veremos para que usarlo
904979
' para ubicrno enun octava dada
905980

@@ -1382,6 +1457,10 @@ If (mousex>=(ANCHO-40)) And (mousey <= 16) Then
13821457
If MouseButtons And 1 Then
13831458
if MessageBox(hWnd,"¿SEGURO FINALIZA? (puede usar Escape tambien)","RollMusic End ",4 or 64) =6 then
13841459
cairo_destroy(c)
1460+
' cairo_surface_destroy( surface )
1461+
' cairo_font_face_destroy( cface )
1462+
FT_Done_Face( ftface )
1463+
13851464
Close
13861465

13871466
End
@@ -1425,8 +1504,14 @@ If (mousex>=(ANCHO-40)) And (mousey > 33) And (mousey < 50) Then
14251504

14261505
'' EndIf
14271506
EndIf
1507+
If MouseButtons And 2 Then
1508+
'' Width 40,43
1509+
ayuda=TRUE
1510+
EndIf
1511+
If mouseButtons And 1 And ayuda=TRUE Then
1512+
ayuda=FALSE
14281513

1429-
1514+
EndIf
14301515
If resize = TRUE Then ' <===== MOVER Y REDIMENSIONAR LA PANTALLA NO TAN FACIL
14311516
'CLICKEAR CERCA DEL CENTRO Y DRAGAR DERECHA IZQUIERDA ARRIBA ABAJO
14321517
m.res = GetMouse( m.x, m.y, m.wheel, m.buttons, m.clip )
@@ -1479,7 +1564,6 @@ EndIf
14791564
'' DEBE SEGUIR EJECUTNDO HACIA ABAJO Y CALCULARINDICE VAMOS A MOVER
14801565
''ESTEIF AL FINAL
14811566
EndIf
1482-
14831567
Exit Do
14841568

14851569
EndIf ' end (ScreenEvent(@e))
@@ -1505,8 +1589,9 @@ Loop
15051589
errorhandler:
15061590
Dim er As Integer
15071591
er = Err
1508-
Print "Error detected ", er
1509-
Print Erl, Erfn,Ermn,Err
1592+
Print #1,"Error detected ", er
1593+
Print #1,Erl, Erfn,Ermn,Err
1594+
Close 1
15101595

15111596

15121597

RollMusic.exe

5 KB
Binary file not shown.

libpcre-1.dll

277 KB
Binary file not shown.

0 commit comments

Comments
 (0)