Die Werte müssen von Word auf Byte umgestellt werden und die Werte anders gesetzt werden. Das mache ich in der Prozedur unter "Attribute der Scriptengine für Scintilla umsetzen". Kann ich den Code zum Umsetzen performanter gestalten?
Code: Alles auswählen
EnableExplicit
Procedure.i GetScriptTextAttributes (Code.s)
;Gibt einen Zeiger auf die Textattribute zurück, die direkt in Scintilla verwendet
;werden können. Der übergebene Speicher ist vom Aufrufer freizugeben..
Define *CodeAttsB
Define *CodeAttsW
Define lenCode.i
Define valW .i
Define i .i
;Simulation des Ergebnisses das normal von der Scriptmachine kommt
DataSection
CodeAttsW:
Data.w $0001, $0001, $0001, $0000, $0100, $0100, $0100, $0100, $0000, $0000
Data.w $0000, $0000, $0000, $0000, $0100, $0100, $0100, $0100, $0100, $0100
Data.w $0000, $0020, $0020, $0020, $0020, $0020, $0020, $0020, $0020, $0020
Data.w $0020, $0020, $0020, $0000, $0000, $0001, $0001, $0001, $0001, $0001
Data.w $0001, $0001, $0000, $0000
EndDataSection
*CodeAttsW = ?CodeAttsW
;Attribute der Scriptengine für Scintilla umsetzen
LenCode = Len (Code)
*CodeAttsB = AllocateMemory (LenCode)
For i = 0 To LenCode - 1
valW = PeekW (*CodeAttsW + i * 2)
Select valW
Case 0 : valW = 1
Case 1 : valW = 2
Case 2 : valW = 3
Case 4 : valW = 4
Case 8 : valW = 5
Case 16 : valW = 6
Case 32 : valW = 7
Case 256 : valW = 8
Case 512 : valW = 9
Case 1024 : valW =10
EndSelect
PokeB (*CodeAttsB + i, valW)
Next i
ProcedureReturn *CodeAttsB
EndProcedure
Define *CodeAtts
Define Code .s
Define CodeUtf8 .s
Define i .i
;Prüfen ob Programm in Unicode compiliert
If #PB_Compiler_Unicode = #False
MessageRequester ("", "Unicode erforderlich")
End
EndIf
;Window und Gadget erstellen
InitScintilla()
OpenWindow (0, 0, 0, 500, 500, "Scintilla", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScintillaGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0)
ScintillaSendMessage (0, #SCI_SETCODEPAGE, #SC_CP_UTF8)
;Farbcodes für Scintilla setzen
ScintillaSendMessage (0, #SCI_STYLESETFORE , 0, $000000) ;Standardstyle
ScintillaSendMessage (0, #SCI_STYLESETFORE , 1, $000000) ;Allgemeine Zeichen
ScintillaSendMessage (0, #SCI_STYLESETFORE , 2, $C00000) ;Schlüsselwörter
ScintillaSendMessage (0, #SCI_STYLESETFORE , 3, $008000) ;Kommentare
ScintillaSendMessage (0, #SCI_STYLESETFORE , 5, $000000) ;Operatoren
ScintillaSendMessage (0, #SCI_STYLESETFORE , 6, $800080) ;Nummern
ScintillaSendMessage (0, #SCI_STYLESETFORE , 7, $909090) ;Texte
ScintillaSendMessage (0, #SCI_STYLESETFORE , 8, $000000) ;Sonstiges
ScintillaSendMessage (0, #SCI_STYLESETFORE , 9, $000000) ;Punkt bei Objekten
ScintillaSendMessage (0, #SCI_STYLESETFORE ,10, $000000) ;ME Objekt
;Sci Code hinzufügen
Code = "Sub Main()" + #CRLF$
Code + " MsgBox " + #DQUOTE$ + "Hallo Welt" + #DQUOTE$ + #CRLF$
Code + "End Sub" + #CRLF$
CodeUtf8 = Space (StringByteLength (Code, #PB_UTF8))
PokeS (@CodeUtf8, Code, -1, #PB_UTF8)
ScintillaSendMessage(0, #SCI_SETTEXT, 0, @CodeUtf8)
;Codeattribute erstellen
*CodeAtts = GetScriptTextAttributes (Code)
;Sci Code stylen
ScintillaSendMessage (0, #SCI_STARTSTYLING, 0, 31)
ScintillaSendMessage (0, #SCI_SETSTYLINGEX, Len(Code), *CodeAtts)
;Freigaben
FreeMemory (*CodeAtts) : *CodeAtts = 0
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow