Re: [Pharo-project] Customizing the Caret of a PluggableTextMorph
Hi Sean, you can take a look at Athens-PangoCairo (in squeaksource). Using NativeBoost, i'm using the Pango layout library [1], and the Pango-Cairo binding [2], to avoid laying out text using the outdated (and messy) stuff in the image. Check out the classes: ParagraphDescription & AthensPangoCairoParagraph. I'm using them as the basis for the TextShape,LabelShape, and EditableTextShape in Shapes / Gaucho ( using TextEditor, SingleLineEditor ). Maybe somebody can do the same for Morphic? use Pango to layout the text, and code a new TextMorph on top of it? Fernando [1] http://developer.gnome.org/pango/stable/pango-Layout-Objects.html [2] http://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html On Wed, Jul 18, 2012 at 7:28 AM, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
On Jul 16, 2012, at 9:38 PM, Sean P. DeNigris wrote:
For VimPharo, I want to have a different cursor depending on whether a tool is in insert or normal mode.
I tried a handful of ways, but they all failed or worked partially/inconsistently. Here's some of them: * add the state to the paragraph, but the entire paragraph gets replaced during the life of the tool, so the state gets lost * add the state to the editor, but the situation is the same * add the state to PluggableTextMorph, override and access it from TextMorphForEditView>>updateFromParagraph. This was an extreme PITA and got me very acquainted with the emergency evaluator. It "worked", but only after using the arrows a bit.
Does anyone have any idea where I might hook in?
<rant>I find the whole text system very confusing. What the heck does a paragraph know about insertion points?? A view has one paragraph object, even if there are several paragraphs (as understood by the rest of humanity as a block of text with breaks between the adjoining ones. Editors and Paragraphs are thrown out and replaced on a whim. I'm finding it very hard to understand and modify</rant>
I got burned by that when I worked on my botanics envâ¦. it was terrible.
Thanks, Sean
-- View this message in context: http://forum.world.st/Customizing-the-Caret-of-a-PluggableTextMorph-tp464024... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
I wouldn't do that for basic morphs as it would make Cairo necessary and then make completely ununderstandable what happens for laying out text for someone who wants to understand it (which is an important aspect of an open smalltalk image). TextMorph>>onBlinkCursor leads you to Paragraph (of course since it deals with the display) onBlinkCursor "Blink the cursor" | para | para := self paragraph ifNil:[^nil]. Time millisecondClockValue < self blinkStart ifTrue:[ "don't blink yet" ^para showCaret: para focused. ]. para showCaret: para showCaret not. para caretRect ifNotNil:[:r| self invalidRect: r]. so, para>>focused if where to look (but it is only a variable change so, you'll need to track the usage) Phil 2012/7/20 Fernando Olivero <fernando.olivero@usi.ch>
Hi Sean, you can take a look at Athens-PangoCairo (in squeaksource).
Using NativeBoost, i'm using the Pango layout library [1], and the Pango-Cairo binding [2], to avoid laying out text using the outdated (and messy) stuff in the image.
Check out the classes: ParagraphDescription & AthensPangoCairoParagraph.
I'm using them as the basis for the TextShape,LabelShape, and EditableTextShape in Shapes / Gaucho ( using TextEditor, SingleLineEditor ).
Maybe somebody can do the same for Morphic? use Pango to layout the text, and code a new TextMorph on top of it?
Fernando
[1] http://developer.gnome.org/pango/stable/pango-Layout-Objects.html [2] http://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html On Wed, Jul 18, 2012 at 7:28 AM, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
On Jul 16, 2012, at 9:38 PM, Sean P. DeNigris wrote:
For VimPharo, I want to have a different cursor depending on whether a
tool
is in insert or normal mode.
I tried a handful of ways, but they all failed or worked partially/inconsistently. Here's some of them: * add the state to the paragraph, but the entire paragraph gets replaced during the life of the tool, so the state gets lost * add the state to the editor, but the situation is the same * add the state to PluggableTextMorph, override and access it from TextMorphForEditView>>updateFromParagraph. This was an extreme PITA and got me very acquainted with the emergency evaluator. It "worked", but only after using the arrows a bit.
Does anyone have any idea where I might hook in?
<rant>I find the whole text system very confusing. What the heck does a paragraph know about insertion points?? A view has one paragraph object, even if there are several paragraphs (as understood by the rest of humanity as a block of text with breaks between the adjoining ones. Editors and Paragraphs are thrown out and replaced on a whim. I'm finding it very hard to understand and modify</rant>
I got burned by that when I worked on my botanics envâ¦. it was terrible.
Thanks, Sean
-- View this message in context:
http://forum.world.st/Customizing-the-Caret-of-a-PluggableTextMorph-tp464024...
Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
Hello 2012/7/20 Fernando Olivero <fernando.olivero@usi.ch>
Hi Sean, you can take a look at Athens-PangoCairo (in squeaksource).
Using NativeBoost, i'm using the Pango layout library [1], and the Pango-Cairo binding [2], to avoid laying out text using the outdated (and messy) stuff in the image.
Check out the classes: ParagraphDescription & AthensPangoCairoParagraph.
I'm using them as the basis for the TextShape,LabelShape, and EditableTextShape in Shapes / Gaucho ( using TextEditor, SingleLineEditor ).
Maybe somebody can do the same for Morphic? use Pango to layout the text, and code a new TextMorph on top of it?
How I can try your code? Do you have ready image to play with it? I am very interested with clean and simple alternative to morphic. I want it for Presenty framework. (But I really like morphic as live user interface environment) Best regards, Denis
So, there is the damn caret drawing code: Paragraph>>displaySelectionInLine: line on: aCanvas | leftX rightX w caretColor | selectionStart ifNil: [^self]. "No selection" aCanvas isShadowDrawing ifTrue: [ ^self ]. "don't draw selection with shadow" selectionStart = selectionStop ifTrue: ["Only show caret on line where clicked" selectionStart textLine ~= line ifTrue: [^self]] ifFalse: ["Test entire selection before or after here" (selectionStop stringIndex < line first or: [selectionStart stringIndex > (line last + 1)]) ifTrue: [^self]. "No selection on this line" (selectionStop stringIndex = line first and: [selectionStop textLine ~= line]) ifTrue: [^self]. "Selection ends on line above" (selectionStart stringIndex = (line last + 1) and: [selectionStop textLine ~= line]) ifTrue: [^self]]. "Selection begins on line below" leftX := (selectionStart stringIndex < line first ifTrue: [line ] ifFalse: [selectionStart ])left. rightX := (selectionStop stringIndex > (line last + 1) or: [selectionStop stringIndex = (line last + 1) and: [selectionStop textLine ~= line]]) ifTrue: [line right] ifFalse: [selectionStop left]. selectionStart = selectionStop ifTrue: [rightX := rightX + 1. w := self caretWidth. caretRect := (leftX-w) @ line top corner: (rightX+w)@ line bottom. self showCaret ifFalse:[^self]. caretColor := self insertionPointColor. 1 to: w do: [:i | "Draw caret triangles at top and bottom" aCanvas fillRectangle: ((leftX - w + i - 1) @ (line top + i - 1) extent: ((w - i) * 2 + 3) @ 1) color: caretColor. aCanvas fillRectangle: ((leftX - w + i - 1) @ (line bottom - i) extent: ((w - i) * 2 + 3) @ 1) color: caretColor]. aCanvas fillRectangle: (leftX @ line top corner: rightX @ line bottom) color: caretColor] ifFalse: [caretRect := nil. aCanvas fillRectangle: (leftX @ line top corner: rightX @ line bottom) color: self selectionColor] Paragraph class>>insertionPointColor has the color. I was fed up of blue, turned it red :-) This one is hardcoded and could take a hint from the selection color twiceDarker for example. Phil 2012/7/20 Denis Kudriashov <dionisiydk@gmail.com>
Hello
2012/7/20 Fernando Olivero <fernando.olivero@usi.ch>
Hi Sean, you can take a look at Athens-PangoCairo (in squeaksource).
Using NativeBoost, i'm using the Pango layout library [1], and the Pango-Cairo binding [2], to avoid laying out text using the outdated (and messy) stuff in the image.
Check out the classes: ParagraphDescription & AthensPangoCairoParagraph.
I'm using them as the basis for the TextShape,LabelShape, and EditableTextShape in Shapes / Gaucho ( using TextEditor, SingleLineEditor ).
Maybe somebody can do the same for Morphic? use Pango to layout the text, and code a new TextMorph on top of it?
How I can try your code? Do you have ready image to play with it?
I am very interested with clean and simple alternative to morphic. I want it for Presenty framework.
(But I really like morphic as live user interface environment)
Best regards, Denis
-- Philippe Back Dramatic Performance Improvements Mob: +32(0) 478 650 140 | Fax: +32 (0) 70 408 027 Mail: phil@highoctane.be| Web: http://philippeback.eu | Blog: http://philippeback.be High Octane SPRL rue cour Boisacq 101 1301 Bierges Belgium
participants (3)
-
Denis Kudriashov -
Fernando Olivero -
phil@highoctane.be