Scintilla : indicator

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
Zorro
Messages : 2185
Inscription : mar. 31/mai/2016 9:06

Scintilla : indicator

Message par Zorro »

je cherchais comment faire comme l'editeur officiel a propos des marquages
vous savez on selectionne un mot, et tout les memes mots sont Marqué dans tout le code

ben j'ai fini par trouver :)

voici un code qui est un melange de code Russe, et de la librairie Goscintilla
mais auquel j'ai apporté ma procedure qui va bien pour surligner ....

ici un petit editeur scintilla, avec des phrases comprenant des carateres aleatoire et un mot precis (qui sera surligné..et lui seul )

il suffit de cliquer plusieurs fois sur le bouton "surligne" pour voir les differents types de surlignage ...
(tout ça est deja implémenté dans mon futur EPB :) et ça marche bien )

il me reste cependant un petit soucis ! je n'arrive pas a faire changer quoique ce soit au niveau des parametres suivant :

ligne 190

Code : Tout sélectionner

ScintillaSendMessage(onglet,#SCI_INDICSETALPHA,1, 255) ; ALpha=0 transparent : 255=opaque
																ScintillaSendMessage(onglet,#SCI_INDICSETOUTLINEALPHA,1, 255)

c'est sensé changer l'apparence Apha de la selection numero 7 , mais chez moi ça ne change rien !!
doit y avoir encore un truc que j'ai pas saisie !!


Code : Tout sélectionner

Enumeration FormWindow
			#Win
EndEnumeration

Enumeration FormGadget
			#Button_0
			#Button_1
			#Scintilla
EndEnumeration
Enumeration 0
			#GOSCI_TEXT_RELOAD ; Replace the current text
			#GOSCI_TEXT_RELOAD_CLEARUNDOSTACK ; Replace the current text and clear undo stack
			#GOSCI_TEXT_APPEND					 ; Add text at the end of current text
			#GOSCI_TEXT_PREPEND					 ; Insert text before the beginning of current text
EndEnumeration
;{ les styles pour le surlignage 
#INDIC_PLAIN =0 ;Underlined With a single, straight line. 
#INDIC_SQUIGGLE =1 ;A squiggly underline. Requires 3 pixels of descender space. 
#INDIC_TT =2		 ;A line of small T shapes. 
#INDIC_DIAGONAL =3 ;Diagonal hatching. 
#INDIC_STRIKE =4	 ;Strike out. 
#INDIC_HIDDEN =5	 ;An indicator With no visual effect. 
#INDIC_BOX =6		 ;A rectangle around the text. 
#INDIC_ROUNDBOX =7 ;A rectangle With rounded corners around the text using translucent drawing With the interior usually more transparent than the border. You can use SCI_INDICSETALPHA And SCI_INDICSETOUTLINEALPHA To control the alpha transparency values. The Default alpha values are 30 For fill colour And 50 For outline colour. 
#INDIC_STRAIGHTBOX =8 ;A rectangle around the text using translucent drawing With the interior usually more transparent than the border. You can use SCI_INDICSETALPHA And SCI_INDICSETOUTLINEALPHA To control the alpha transparency values. The Default alpha values are 30 For fill colour And 50 For outline colour. This indicator does Not colour the top pixel of the line so that indicators on contiguous lines are visually distinct And disconnected. 
#INDIC_FULLBOX =16	 ;A rectangle around the text using translucent drawing similar To INDIC_STRAIGHTBOX but covering the entire character area. 
#INDIC_DASH =9			 ;A dashed underline. 
#INDIC_DOTS =10		 ;A dotted underline. 
#INDIC_SQUIGGLELOW =11;Similar To INDIC_SQUIGGLE but only using 2 vertical pixels so will fit under small fonts. 
#INDIC_DOTBOX =12		 ;A dotted rectangle around the text using translucent drawing. Translucency alternates between the alpha And outline alpha settings With the top-left pixel using the alpha setting. SCI_INDICSETALPHA And SCI_INDICSETOUTLINEALPHA control the alpha transparency values. The Default values are 30 For alpha And 50 For outline alpha. To avoid excessive memory allocation the maximum width of a dotted box is 4000 pixels. 
#INDIC_SQUIGGLEPIXMAP =13 ;A version of INDIC_SQUIGGLE that draws using a pixmap instead of As a series of line segments For performance. Measured To be between 3 And 6 times faster than INDIC_SQUIGGLE on GTK+. Appearance will Not be As good As INDIC_SQUIGGLE on OS X in HiDPI mode. 
#INDIC_COMPOSITIONTHICK =14 ;A 2-pixel thick underline located at the bottom of the line To try To avoid touching the character base. Each side is inset 1 pixel so that different indicators in this style covering a range appear isolated. This is similar To an appearance used For the target in Asian language input composition. 
#INDIC_COMPOSITIONTHIN =15	 ;A 1-pixel thick underline located just before the bottom of the line. Each side is inset 1 pixel so that different indicators in this style covering a range appear isolated. This is similar To an appearance used For non-target ranges in Asian language input composition. 
#INDIC_TEXTFORE =17			 ;Change the colour of the text To the indicator's fore colour. 
Declare Surligne_text2(onglet,Txt.s,coul_selec,Style,mode)

Declare OpenWindow_0(x = 0, y = 0, width = 352, height = 160)
Declare ResizeGadgetsWindow_0()
Declare GOSCI_SetText(id, text$, mode)
Declare.S GOSCI_GetLineText(id, lineIndex)
Global Style


If InitScintilla("Scintilla.dll")=0
			MessageRequester("", "pas trouvé scintilla.dll")
			End
EndIf

OpenWindow_0() : SmartWindowRefresh(#Win, #True)

For i = 1 To 14
			mots_aleat_deb$="" :mots_aleat_fin$=""
			For b=1 To 4
						mots_aleat_deb$=mots_aleat_deb$+Chr(Random(122,65))
						mots_aleat_fin$=mots_aleat_fin$+Chr(Random(122,65))
			Next b
			
			text$=mots_aleat_deb$+" mot surligné "+Str(i)+"  "+mots_aleat_fin$  +Chr(10)+Chr(13)
			GOSCI_SetText(#Scintilla, text$, 2)
Next i

Repeat
			Event = WaitWindowEvent()
			
			If Event = #PB_Event_Gadget
						Select EventGadget()
							Case #Button_0
										
									
										Style=style+1
										SetWindowTitle(#win, "Style :"+Str(Style)) 
										Surligne_text2(#Scintilla," mot surligné ",RGB(0,0,255),Style,#False) ; ici on indique le mot a ne plus surligner
										Surligne_text2(#Scintilla," mot surligné ",RGB(0,0,255),Style,#True) ; ici on indique le mot a surligner
									If Style =16 :Style=0:EndIf
										
							Case #Button_1
										
										
													Style=i
													Surligne_text2(#Scintilla," mot surligné ",RGB(0,0,255),Style,#False) ; ici on indique le mot a ne plus surligner
									
										
						EndSelect
						
			ElseIf  Event = #PB_Event_SizeWindow
						ResizeGadgetsWindow_0()
			EndIf
			
Until Event = #PB_Event_CloseWindow


Procedure OpenWindow_0(x = 0, y = 0, width = 352, height = 160)
			OpenWindow(#Win, x, y, width, height, "",#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
			ButtonGadget(#Button_0, 8, 12, 88, 28, "Surligne")
			ButtonGadget(#Button_1, 8, 48, 88, 28, "retire surlignage")
			ScintillaGadget(#Scintilla, 104, 12, 244, 144, 0)
EndProcedure

Procedure ResizeGadgetsWindow_0()
			Protected FormWindowWidth, FormWindowHeight
			FormWindowWidth = WindowWidth(#Win)
			FormWindowHeight = WindowHeight(#Win)
			ResizeGadget(#Scintilla, 104, 12, FormWindowWidth - 108, FormWindowHeight - 16)
EndProcedure

Procedure GOSCI_SetText(id, text$, mode)
			Protected utf8Buffer
			If IsGadget(id) And GadgetType(id)=#PB_GadgetType_Scintilla
						;Need to convert to utf-8 first.
						utf8Buffer=AllocateMemory(StringByteLength(text$, #PB_UTF8)+1)
						If utf8Buffer
									PokeS(utf8Buffer, text$, -1, #PB_UTF8)
									Select mode
										Case #GOSCI_TEXT_APPEND
													ScintillaSendMessage(id, #SCI_APPENDTEXT, MemorySize(utf8Buffer)-1, utf8Buffer)
										Case #GOSCI_TEXT_PREPEND
													ScintillaSendMessage(id, #SCI_INSERTTEXT, 0, utf8Buffer)
										Case #GOSCI_TEXT_RELOAD, #GOSCI_TEXT_RELOAD_CLEARUNDOSTACK
													ScintillaSendMessage(id, #SCI_SETTEXT, 0, utf8Buffer)
													If #GOSCI_TEXT_RELOAD_CLEARUNDOSTACK
																ScintillaSendMessage(id, #SCI_EMPTYUNDOBUFFER)
													EndIf
									EndSelect
									FreeMemory(utf8Buffer)
						EndIf
			EndIf
			; utilisation :
			; GOSCI_SetText(1, "ă prepended text", #GOSCI_TEXT_PREPEND)
			; GOSCI_SetText(1, "ă appended text", #GOSCI_TEXT_APPEND)
EndProcedure
ProcedureDLL.S GOSCI_GetLineText(id, lineIndex)
						Protected text$, numLines, lineLength, utf8Buffer, *ptrAscii.ASCII
						If IsGadget(id) And GadgetType(id) = #PB_GadgetType_Scintilla
									numLines = ScintillaSendMessage(id, #SCI_GETLINECOUNT)
									If lineIndex >=0 And lineIndex < numLines
												lineLength = ScintillaSendMessage(id, #SCI_LINELENGTH, lineIndex)
												If lineLength
															utf8Buffer = AllocateMemory(lineLength+1)
															If utf8Buffer
																		ScintillaSendMessage(id, #SCI_GETLINE, lineIndex, utf8Buffer)
																		;Remove any terminating EOL characters.
																		*ptrAscii = utf8Buffer + lineLength - 1
																		While (*ptrAscii\a = 10 Or *ptrAscii\a = 13) And lineLength
																					lineLength - 1
																					*ptrAscii - 1
																		Wend
																		text$ = PeekS(utf8Buffer, lineLength, #PB_UTF8)
																		FreeMemory(utf8Buffer)
															EndIf
												EndIf
									EndIf
						EndIf
						ProcedureReturn text$
			EndProcedure

Procedure Surligne_text2(onglet,Txt.s,coul_selec,Style,mode)
						;By Zorro
						; onglet =numero de l'editeur scintilla
						; Txt.s  =le text qui doit etre surligné
						;coul_select =la couleur de la selection
						; mode= si select ou unselect
						; 														#INDIC_PLAIN =0 ;Underlined With a single, straight line. 
						; 														#INDIC_SQUIGGLE =1 ;A squiggly underline. Requires 3 pixels of descender space. 
						; 														#INDIC_TT =2		 ;A line of small T shapes. 
						; 														#INDIC_DIAGONAL =3 ;Diagonal hatching. 
						; 														#INDIC_STRIKE =4	 ;Strike out. 
						; 														#INDIC_HIDDEN =5	 ;An indicator With no visual effect. 
						; 														#INDIC_BOX =6		 ;A rectangle around the text. 
						; 														#INDIC_ROUNDBOX =7 ;A rectangle With rounded corners around the text using translucent drawing With the interior usually more transparent than the border. You can use SCI_INDICSETALPHA And SCI_INDICSETOUTLINEALPHA To control the alpha transparency values. The Default alpha values are 30 For fill colour And 50 For outline colour. 
						; 														#INDIC_STRAIGHTBOX =8 ;A rectangle around the text using translucent drawing With the interior usually more transparent than the border. You can use SCI_INDICSETALPHA And SCI_INDICSETOUTLINEALPHA To control the alpha transparency values. The Default alpha values are 30 For fill colour And 50 For outline colour. This indicator does Not colour the top pixel of the line so that indicators on contiguous lines are visually distinct And disconnected. 
						; 														#INDIC_DASH =9			 ;A dashed underline. 
						; 														#INDIC_DOTS =10		 ;A dotted underline. 
						; 														#INDIC_SQUIGGLELOW =11;Similar To INDIC_SQUIGGLE but only using 2 vertical pixels so will fit under small fonts. 
						; 														#INDIC_DOTBOX =12		 ;A dotted rectangle around the text using translucent drawing. Translucency alternates between the alpha And outline alpha settings With the top-left pixel using the alpha setting. SCI_INDICSETALPHA And SCI_INDICSETOUTLINEALPHA control the alpha transparency values. The Default values are 30 For alpha And 50 For outline alpha. To avoid excessive memory allocation the maximum width of a dotted box is 4000 pixels. 
						; 														#INDIC_SQUIGGLEPIXMAP =13 ;A version of INDIC_SQUIGGLE that draws using a pixmap instead of As a series of line segments For performance. Measured To be between 3 And 6 times faster than INDIC_SQUIGGLE on GTK+. Appearance will Not be As good As INDIC_SQUIGGLE on OS X in HiDPI mode. 
						; 														#INDIC_COMPOSITIONTHICK =14 ;A 2-pixel thick underline located at the bottom of the line To try To avoid touching the character base. Each side is inset 1 pixel so that different indicators in this style covering a range appear isolated. This is similar To an appearance used For the target in Asian language input composition. 
						; 														#INDIC_COMPOSITIONTHIN =15	 ;A 1-pixel thick underline located just before the bottom of the line. Each side is inset 1 pixel so that different indicators in this style covering a range appear isolated. This is similar To an appearance used For non-target ranges in Asian language input composition. 
						; 														#INDIC_FULLBOX =16	 ;A rectangle around the text using translucent drawing similar To INDIC_STRAIGHTBOX but covering the entire character area. 
			#INDIC_TEXTFORE =17			 ;Change the colour of the text To the indicator's fore colour. 
						Protected indicator,pos,Chhh$
						Select Mode
							Case #True
										
										For i=0 To ScintillaSendMessage(#Scintilla, #SCI_GETLINECOUNT)
													chhh$= LCase(GOSCI_GetLineText(onglet, i))	
													If FindString(chhh$,LCase(Txt.s))>0
																pos=FindString(chhh$,Txt.s)														
																ScintillaSendMessage(onglet,#SCI_INDICSETSTYLE,1,Style)
																
																ScintillaSendMessage(onglet,#SCI_INDICSETALPHA,1, 255) ; ALpha=0 transparent : 255=opaque
																ScintillaSendMessage(onglet,#SCI_INDICSETOUTLINEALPHA,1, 255)
																ScintillaSendMessage(onglet,#SCI_INDICSETFORE,1,coul_selec)																	
																ScintillaSendMessage(onglet, #SCI_SETINDICATORCURRENT, 1)			
																ScintillaSendMessage(onglet, #SCI_INDICATORFILLRANGE,ScintillaSendMessage(onglet, #SCI_POSITIONFROMLINE,i)+(pos-1),Len(Txt.s))
													EndIf																	
										Next i
							Case #False
										For i=0 To ScintillaSendMessage(#Scintilla, #SCI_GETLINECOUNT)
													ScintillaSendMessage(onglet, #SCI_SETINDICATORCURRENT, 1)
													ScintillaSendMessage(onglet, #SCI_INDICATORCLEARRANGE,ScintillaSendMessage(onglet, #SCI_POSITIONFROMLINE, i),ScintillaSendMessage(onglet, #SCI_LINELENGTH, i))
										Next i
						EndSelect
			EndProcedure
Image
Image
Site: http://michel.dobro.free.fr/
Devise :"dis moi ce dont tu as besoin, je t'expliquerai comment t'en passer"
Bernie
Messages : 282
Inscription : mar. 22/mars/2016 10:12
Localisation : En France

Re: Scintilla : indicator

Message par Bernie »

Merci du partage une fois le mot surligné il reste plus à faire une option qui permet de changer le mot surligné
Avatar de l’utilisateur
Zorro
Messages : 2185
Inscription : mar. 31/mai/2016 9:06

Re: Scintilla : indicator

Message par Zorro »

là, c'est la methode pour faire afficher les indicators
(c'est a dire les mots surligné dans un editeur )

j'ai deja mis en oeuvre ceci dans EPB, bien sur a partir d'une selection
je sais pas si les selections ont été abordé a propos de scintilla
sur le forum ...

a l'occase je ferai un exemple de mise en oeuvre des indicator a partir d'une selection
ma procedure contient tout ce qu'il faut pour le surlignage
puisqu'elle est capable de surligner n'importe qu'elle terme qu'on lui passe

le systeme de selection , consiste a trouver le point de depart et de fin d'un mot dans une phrase
ce qu'on indique en cliquant au debut d'un mot , et qu'on selectionne jusqu'a la fin

bref , il n'y a pas grand choses a rajouter ...
Image
Image
Site: http://michel.dobro.free.fr/
Devise :"dis moi ce dont tu as besoin, je t'expliquerai comment t'en passer"
Répondre