REBOL [ Author: "Shadwolf" Starting_Date: 21-05-2005 Purpose: {Research work on rebol draw capability to be used to write a Ritch text editor} ] comment {Reflexion: Bon voici la piste de reflexion que je poursuis. L'idée c'est de se servir de la détection de l'évènement clavier pour composer une liste dont chaque sousliste contiendrait l'offset de départ, le bloc avec la configuration de la font, la chaine à écrire. Une fonction de parsing interprêterait ces information et construirait un block draw et réaliserait le dessin dans le block contenant. Reste a trouver un moyen pour insérer un text formater dans un texte deja existant tout en gérant le déplacement du texte, ne pas avoir a tout redessinner constemment, gérer la sélection. inserer la gestion des changements de police et inserer la gestion de la meme même ligne si + grand que f/size/x / taille-police on passe automatiquement a la ligne et on decale toute les ligne qui suivent (mode paragraphe) [;mon document [;ligne 1 [text 1] ] [;ligne 2 [text 1] [text 2] [text 3] [text x] ] ] } stylize/master [ rte: box with [ color: gray tampon: "" buffer: [[]] line-index: 1 char-sz: 11 font-st: none current-text-offset: 0x0 cursor-text-offset: 0x0 max-text-offset: 0x0 text-color: black pane: [] set-font-style: func [ font-s [word!] sz-tt [integer!] ] [ if char-sz <> sz-tt [ char-sz: sz-tt] font-st: font-s insert tail buffer/:line-index compose/deep [[ [ space: 2x0 size: (char-sz) style: [(font-s)] color: (text-color)] (cursor-text-offset - 6x0) "" ]] ] feel: make feel [ engage: func [f a e] [ switch a [ key [ probe e/key switch/default e/key [ #"^M" [ probe "new line" probe "line-index avant" probe f/line-index probe "line-index aprs:" probe f/line-index f/cursor-text-offset: f/current-text-offset: as-pair 0 (f/current-text-offset/y + 20) insert tail f/buffer compose/deep [[[ [space: 2x0 size: (f/char-sz) style: [(f/font-st)] color: (f/text-color) ] (either cursor-text-offset/x <> 0 [cursor-text-offset][as-pair 0 (f/line-index * 20)]) "" ]]] f/line-index: f/line-index + 1 ] ][ f/tampon: copy rejoin [f/tampon to-string e/key] draw-text: [] print "f/buffer:" probe f/buffer ; on ajoute la nouvelle lettre saisieque dans le tampon correspondant à la ligne actuelle cur-line: f/line-index probe cur-line tmp-c-line: f/buffer/:cur-line tm-buff: third last tmp-c-line tm-buff: rejoin [ tm-buff e/key ] replace (last tmp-c-line) (third last tmp-c-line) tm-buff ; on redessinne dans la box ce qu'on a dans le tampon de saisie foreach line-to-draw f/buffer [ foreach text-block line-to-draw [ font-style: text-block/1 start-offset: text-block/2 text-to-show: text-block/3 font-obj: make face/font font-style ;insert tail draw-text compose [ font (font-obj) pen (f/text-color) text (start-offset) (text-to-show)] insert tail draw-text compose [ font (font-obj) pen (font-obj/color) text (start-offset) (text-to-show)] ] ] f/effect: make effect reduce [ 'draw draw-text ] draw-text: none f/cursor-text-offset: as-pair (f/cursor-text-offset/x + 5.5) f/current-text-offset/y ;show f ] f/pane/1/offset: f/cursor-text-offset probe "f/pane/1/offset" probe f/pane/1/offset show f ] down [ ;insert f/buffer compose [(as-pair 0 (line-index * 20)) ""] f/color: white show f focus f ] ] ] ] append init [ probe buffer set-font-style 'normal char-sz insert pane make face [ color: red size: 2x20 offset: cursor-text-offset ] show self ] ] ] view layout [ across btn "bold" [test-rte/set-font-style 'bold (to-integer dd1/text)] btn "underline" [test-rte/set-font-style 'underline (to-integer dd1/text)] btn "italic" [test-rte/set-font-style 'italic (to-integer dd1/text)] btn "normal" [test-rte/set-font-style 'normal (to-integer dd1/text)] dd1: drop-down "11" "12" "13" "14" "15" "16" "20" [test-rte/set-font-style test-rte/font-st (to-integer dd1/text) ] col-r: box 20x20 white edge [ siez: 2x2 color: black] [ test-rte/text-color: request-color col-r/color: test-rte/text-color show col-r test-rte/set-font-style test-rte/font-st test-rte/char-sz ] return test-rte: rte 300x300 ]