Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #211 > unrolled thread

How to put a caret in a window

Started byPaul Sprangers <Paul@sprie.nl>
First post2011-04-25 17:34 +0200
Last post2011-04-30 00:05 +0200
Articles 20 on this page of 28 — 10 participants

Back to article view | Back to comp.sys.acorn.programmer


Contents

  How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-04-25 17:34 +0200
    Re: How to put a caret in a window Matthew Phillips <mnews@sinenomine.freeserve.co.uk> - 2011-04-25 19:29 +0100
      Re: How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-04-25 23:28 +0200
        Re: How to put a caret in a window Matthew Phillips <mnews@sinenomine.freeserve.co.uk> - 2011-04-26 23:17 +0100
          Re: How to put a caret in a window Matthew Phillips <mnews@sinenomine.freeserve.co.uk> - 2011-04-27 07:38 +0100
            Re: How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-04-27 13:31 +0200
              Re: How to put a caret in a window Jeremy Nicoll - news posts <jn.nntp.scrap007@wingsandbeaks.org.uk> - 2011-04-27 13:14 +0100
                Re: How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-04-27 17:15 +0200
              Re: How to put a caret in a window pdm <pd.miller2@tiscali.co.uk> - 2011-04-27 08:59 -0700
                Re: How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-04-27 21:50 +0200
                Re: How to put a caret in a window pdm <pd.miller2@tiscali.co.uk> - 2011-04-27 23:19 -0700
              Re: How to put a caret in a window Matthew Phillips <mnews@sinenomine.freeserve.co.uk> - 2011-04-27 19:58 +0100
                Re: How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-04-27 22:15 +0200
                  Re: How to put a caret in a window Martin Wuerthner <spamtrap@mw-software.com> - 2011-04-30 17:12 +0200
                    Re: How to put a caret in a window Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-04-30 19:12 +0200
                    Re: How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-05-02 09:37 +0200
                      Re: How to put a caret in a window Alan Wrigley <spamhater@keepyourfilthyspamtoyourself.co.uk> - 2011-05-02 08:49 +0100
                        Re: How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-05-02 09:59 +0200
                          Re: How to put a caret in a window Alan Adams <alan@adamshome.org.uk> - 2011-05-02 21:27 +0100
                      Re: How to put a caret in a window Steve Fryatt <news@stevefryatt.org.uk> - 2011-05-02 09:08 +0100
                  Re: How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-04-30 12:54 +0200
                    Re: How to put a caret in a window Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-04-30 13:52 +0200
                  Re: How to put a caret in a window cferris@freeRemoveuk.com.invalid - 2011-04-30 13:34 +0100
                    Re: How to put a caret in a window Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-04-30 15:39 +0200
                  Re: How to put a caret in a window Matthew Phillips <mnews@sinenomine.freeserve.co.uk> - 2011-04-28 08:20 +0100
                    Re: How to put a caret in a window pdm <pd.miller2@tiscali.co.uk> - 2011-04-28 02:16 -0700
                    Re: How to put a caret in a window Paul Sprangers <Paul@sprie.nl> - 2011-04-29 17:49 +0200
                      Re: How to put a caret in a window Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-04-30 00:05 +0200

Page 1 of 2  [1] 2  Next page →


#211 — How to put a caret in a window

FromPaul Sprangers <Paul@sprie.nl>
Date2011-04-25 17:34 +0200
SubjectHow to put a caret in a window
Message-ID<51c98770d3Paul@sprie.nl>
Dear all,

As usual, I.m stuck.
How on earth (or in BASIC) do I put a caret in a window?
More precisely, when I Font_Paint a string on a window, how can I get a red
caret after the last character?

I've tried Font_Caret, Font_ScanString and several combinations of both,
with all the parameters that I could think of, but alas... no caret.

Very curious about your knowledge.

Kind regards,
Paul Sprangers

[toc] | [next] | [standalone]


#212

FromMatthew Phillips <mnews@sinenomine.freeserve.co.uk>
Date2011-04-25 19:29 +0100
Message-ID<3f7697c951.Matthew@sinenomine.freeserve.co.uk>
In reply to#211
In message <51c98770d3Paul@sprie.nl>
 on 25 Apr 2011 Paul Sprangers  wrote:

> As usual, I.m stuck.
> How on earth (or in BASIC) do I put a caret in a window?
> More precisely, when I Font_Paint a string on a window, how can I get a red
> caret after the last character?
> 
> I've tried Font_Caret, Font_ScanString and several combinations of both,
> with all the parameters that I could think of, but alas... no caret.

Try Wimp_SetCaretPosition.  You can work out the required position using
Font_ScanString, but making it appear needs Wimp_SetCaretPosition.

-- 
Matthew Phillips
Durham

[toc] | [prev] | [next] | [standalone]


#213

FromPaul Sprangers <Paul@sprie.nl>
Date2011-04-25 23:28 +0200
Message-ID<51c9a7e1b5Paul@sprie.nl>
In reply to#212
Dear Matthew,

> Try Wimp_SetCaretPosition.  You can work out the required position using
> Font_ScanString, but making it appear needs Wimp_SetCaretPosition.

Thank you for your prompt advise.
However, it doesn't stop me muddling.
The StrongHelp files say (amongst other enigmas) that R5 should contain the
Index into string on entry. What on earth is an Index into string?

Could you perhaps provide some sample code? Or add corrections to mine?
Here's what I have so far:

DEF PROCredraw(wh%)
!block%=wh%
SYS "Wimp_GetWindowInfo",,block%
SYS "Wimp_RedrawWindow",,block% TO more%
ox%=block%!4-block%!20
oy%=block%!16-block%!24
WHILE more%
   SYS "Wimp_SetFontColours",,0,7
   SYS "Font_SetFont",plain%
   SYS "Font_Paint",,string$,16,ox%+10,oy%-30
   SYS "Font_ScanString",0,string$,&20100,0,0 TO ,,,cx%,cy%
   SYS "Wimp_SetCaretPosition",wh%,-1,cx%,cy%,?????
   SYS "Wimp_GetRectangle",,block% TO more%
ENDWHILE
ENDPROC

No doubt, the way I use the Font_ScanString call, is mud as well.
This routine, however, does paint the desired string to the desired
position (after having REMmed out the SetCaretPosition line, of course),
but how do I get the equally desired caret after that string?

Kind regards,
Paul Sprangers

[toc] | [prev] | [next] | [standalone]


#216

FromMatthew Phillips <mnews@sinenomine.freeserve.co.uk>
Date2011-04-26 23:17 +0100
Message-ID<702330ca51.Matthew@sinenomine.freeserve.co.uk>
In reply to#213
In message <51c9a7e1b5Paul@sprie.nl>
 on 25 Apr 2011 Paul Sprangers  wrote:

> > Try Wimp_SetCaretPosition.  You can work out the required position using
> > Font_ScanString, but making it appear needs Wimp_SetCaretPosition.
> 
> Thank you for your prompt advise.
> However, it doesn't stop me muddling.
> The StrongHelp files say (amongst other enigmas) that R5 should contain the
> Index into string on entry. What on earth is an Index into string?
> 
> Could you perhaps provide some sample code? Or add corrections to mine?
> Here's what I have so far:
> 
> DEF PROCredraw(wh%)
> !block%=wh%
> SYS "Wimp_GetWindowInfo",,block%
> SYS "Wimp_RedrawWindow",,block% TO more%
> ox%=block%!4-block%!20
> oy%=block%!16-block%!24
> WHILE more%
>    SYS "Wimp_SetFontColours",,0,7
>    SYS "Font_SetFont",plain%
>    SYS "Font_Paint",,string$,16,ox%+10,oy%-30
>    SYS "Font_ScanString",0,string$,&20100,0,0 TO ,,,cx%,cy%

Not sure about setting bit 8 in the flags when your R0 value is 0.  I'd put
R0 equal to plain% but it may not matter.

You have set bit 17 to return the nearest caret position in R3,4 but the
"mouse click" x,y you are passing in is zero.  If you use these values you'll
be getting the caret appearing at the *start* of the string.  You'll need to
pass a large integer as the initial value of R3 and R4 (i.e. to pretend your
"mouse click" for placing the caret is way off the right-hand end).  I've
found that passing 7FFFFFFF sometimes causes problems so go for something not
quite so big like &3FFFFFFF.  You should also set R7 to the length of the
string (if you choose a value "n" for R7 then the caret position "n"
characters into the string will be returned). 

>    SYS "Wimp_SetCaretPosition",wh%,-1,cx%,cy%,?????

The values in cx% and cy% will be relative to plotting the string at 0,0 so
you will need to adjust the caret placement according to where you are
actually painting the string.  Font_Paint takes the x and y relative to the
screen origin, but Wimp_SetCaretPosition will be relative to the window work
area origin.  Nasty sums!

The Wimp_SetCaretPosition should not really be in the redraw loop.  You
should be doing this when the caret is placed.  The Wimp redraws the caret
for you.

R5 should be -1 -- the index into string value only applies if you are
placing the caret in a writable icon, and you are placing it at a specific
location on the window background.  By "index into the string" it means how
many characters from the start of the string in the writable icon should the
caret be placed at.  Actually it's not characters, strictly speaking, it's
bytes in the case of multi-byte character sets like UTF-8.  You want "-1"
anyway, so don't worry.

R4 is more tricky.  I don't think you have to worry about the height of the
caret when just placing it in a writable icon.  On the window background you
may need to be specific.  It's just in OS units.  Put something reasonably
sensible in to get started, and tweak later if there's any chance the font
size is going to vary.

>    SYS "Wimp_GetRectangle",,block% TO more%
> ENDWHILE
> ENDPROC
> 
> No doubt, the way I use the Font_ScanString call, is mud as well.
> This routine, however, does paint the desired string to the desired
> position (after having REMmed out the SetCaretPosition line, of course),
> but how do I get the equally desired caret after that string?

Hope that helps,

-- 
Matthew Phillips
Durham

[toc] | [prev] | [next] | [standalone]


#217

FromMatthew Phillips <mnews@sinenomine.freeserve.co.uk>
Date2011-04-27 07:38 +0100
Message-ID<8a105eca51.Matthew@sinenomine.freeserve.co.uk>
In reply to#216
In message <702330ca51.Matthew@sinenomine.freeserve.co.uk>
 on 26 Apr 2011 Matthew Phillips  wrote:

> In message <51c9a7e1b5Paul@sprie.nl>
>  on 25 Apr 2011 Paul Sprangers  wrote:
>
> >    SYS "Font_Paint",,string$,16,ox%+10,oy%-30
> >    SYS "Font_ScanString",0,string$,&20100,0,0 TO ,,,cx%,cy%
> >    SYS "Wimp_SetCaretPosition",wh%,-1,cx%,cy%,?????
> 
> The values in cx% and cy% will be relative to plotting the string at 0,0 so
> you will need to adjust the caret placement according to where you are
> actually painting the string.  Font_Paint takes the x and y relative to the
> screen origin, but Wimp_SetCaretPosition will be relative to the window
> work area origin.  Nasty sums!

Sorry, perhaps I wasn't very clear.  I mean that the values returned into cx%
and cy% by Font_ScanString will be as though the string was painted at 0,0
(or maybe at the location specified in the transformation matrix if you were
using one, which you're not).

So before passing to Wimp_SetCaretPosition they'll need adjusting to take
account of the window work area co-ordinates at which you are painting the
string.

-- 
Matthew Phillips
Durham

[toc] | [prev] | [next] | [standalone]


#218

FromPaul Sprangers <Paul@sprie.nl>
Date2011-04-27 13:31 +0200
Message-ID<51ca78d47ePaul@sprie.nl>
In reply to#217
Dear Matthew,

Thank you very much for your comprehensive explanation.
It brought me a little bit further indeed, but there's still an issue about
the correct placement of the caret.

What I want, is actually quite simple. I want to font_paint a short string
to a small window (size of a little icon). Actually, the window should
mimic an ordinary writable icon, the red caret included. The only
difference is that my window should accept UTF8 input (which it does).

Let me show what I have now:

DEF PROCkeypress(wh%,k%)
 [...]  Here, valid keypresses are added to the string 'string$'
SYS
"Font_ScanString",plain%,string$,(1<<7)+(1<<17),&3FFFFFFF,&3FFFFFFF,,,LEN(string$)
TO ,,,cx%,,,,len%
SYS "Wimp_SetCaretPosition",window%,-1,cx%+10,-44,40,-1
PROCredraw(window%)
ENDPROC

As you can see, I've set bit 7 and bit 17 in R2 of the ScanString call.
I've also followed your advice to use large integers in R3 and R4.
Moreover, I've also taken the length of the string in account, although I
don't know what to do with it.
Anyway, whatever integer or value I try, the resulting cx% is always 0.

As the window can only display a single string, I don't care about the cy%
value. When I set that one to -44, the caret will be displayed properly,
albeit always at x=10, no matter how long the string is.

Obviously, I'm still overlooking something (or many things). Can you help
me further?

Kind regards,
Paul Sprangers

[toc] | [prev] | [next] | [standalone]


#219

FromJeremy Nicoll - news posts <jn.nntp.scrap007@wingsandbeaks.org.uk>
Date2011-04-27 13:14 +0100
Message-ID<mpro.lkb8nu0077sqc0294@wingsandbeaks.org.uk.invalid>
In reply to#218
Paul Sprangers <Paul@sprie.nl> wrote:

> As you can see...

Code yes, but not effect.  Maybe a screenshot** of what this does would help
you explain what it doesn't do?

** not posted to the newsgroup though.  Put it elsewhere & post the URL.

-- 
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsreplyaaa@wingsandbeaks.org.uk replacing "aaa" by "284".  

[toc] | [prev] | [next] | [standalone]


#221

FromPaul Sprangers <Paul@sprie.nl>
Date2011-04-27 17:15 +0200
Message-ID<51ca8d5bf0Paul@sprie.nl>
In reply to#219
Dear Jeremy,

> Code yes, but not effect.  Maybe a screenshot** of what this does would
> help you explain what it doesn't do?

Indeed, I should have remembered the phrase 'A picture says more than a
thousand words'. Here's a little sprite (that shows two words, though):

www.riscos.sprie.nl/Downloads/Temp/Example.zip

As you can probably see now, I'm able to type unicode text (ArialUni\EUFT8,
in fact) into the window, but the caret doesn't move along.

The Font_ScanString call, as exposed in the previous mails, should somehow
give a clue about the new position of the caret after every key stroke. Its
value is supposed to be represented by cx%. But no matter which strings or
values or numbers (or fonts!) I choose, cx% always remains 0.

Hopefully, I've now made my point clear. And hopefully, you can now point
at all the nonsense in my code.

Kind regards,
Paul Sprangers

[toc] | [prev] | [next] | [standalone]


#222

Frompdm <pd.miller2@tiscali.co.uk>
Date2011-04-27 08:59 -0700
Message-ID<1888c5b2-8f0a-4c3a-8103-e646835453ce@w36g2000vbi.googlegroups.com>
In reply to#218
On Apr 27, 12:31 pm, Paul Sprangers <P...@sprie.nl> wrote:

<snip>

> Let me show what I have now:
>
> DEF PROCkeypress(wh%,k%)
>  [...]  Here, valid keypresses are added to the string 'string$'
> SYS
> "Font_ScanString",plain%,string$,(1<<7)+(1<<17),&3FFFFFFF,&3FFFFFFF,,,LEN(string$)
> TO ,,,cx%,,,,len%
> SYS "Wimp_SetCaretPosition",window%,-1,cx%+10,-44,40,-1
> PROCredraw(window%)
> ENDPROC
>
> As you can see, I've set bit 7 and bit 17 in R2 of the ScanString call.
> I've also followed your advice to use large integers in R3 and R4.
> Moreover, I've also taken the length of the string in account, although I
> don't know what to do with it.
> Anyway, whatever integer or value I try, the resulting cx% is always 0.
>
> As the window can only display a single string, I don't care about the cy%
> value. When I set that one to -44, the caret will be displayed properly,
> albeit always at x=10, no matter how long the string is.
>
> Obviously, I'm still overlooking something (or many things). Can you help
> me further?
>
I haven't looked at your screen shot yet, and I'm not using unicode
text, but have a couple of suggestions.

Have you tried &7FFFFFFF for the large  y integer value. I tried the
Font_ScanString call using &3FFFFFFF for both the x and y values and
got cx%=0, but it worked using &3FFFFFFF for the x value and &7FFFFFFF
for the y value.

Also, I thought that Font_ScanString operates with millipoint values.
Does the cx% value from Font_ScanString need converting to OS units
using Font_ConverttoOS -

SYS "Font_ConverttoOS",cx% TO ,cx%.

Now you are using plain% as the initial font do you want to set bit 8
again in the Font_ScanString call?


Regards,

Pete Miller.

[toc] | [prev] | [next] | [standalone]


#225

FromPaul Sprangers <Paul@sprie.nl>
Date2011-04-27 21:50 +0200
Message-ID<51caa67f20Paul@sprie.nl>
In reply to#222
Dear Pete,

> Have you tried &7FFFFFFF for the large  y integer value. I tried the
> Font_ScanString call using &3FFFFFFF for both the x and y values and
> got cx%=0, but it worked using &3FFFFFFF for the x value and &7FFFFFFF
> for the y value.

Ah, now we're getting somewhere!
When I increase both values for x and y to &7FFFFFFF on entry, then I do
get a response in cx% other than 0.

> SYS "Font_ConverttoOS",cx% TO ,cx%.

When I put an extra comma before the first cx%, then this call does a
proper conversion indeed. Now, when I type some text, either in Russian or
in English, the caret follows the string obediently and accurately. Great!

The new challenge is finding out how to place the caret there, where I
click the mouse within a given string. Mmm... any clue?

Kind regards,
Paul Sprangers

[toc] | [prev] | [next] | [standalone]


#237

Frompdm <pd.miller2@tiscali.co.uk>
Date2011-04-27 23:19 -0700
Message-ID<db1800fd-a5c0-43cd-9101-df3216db0a47@28g2000yqu.googlegroups.com>
In reply to#222
On Apr 27, 4:59 pm, pdm <pd.mill...@tiscali.co.uk> wrote:
> On Apr 27, 12:31 pm, Paul Sprangers <P...@sprie.nl> wrote:
>
>
<snip>
>
> Does the cx% value from Font_ScanString need converting to OS units
> using Font_ConverttoOS -
>
> SYS "Font_ConverttoOS",cx% TO ,cx%.
>

The correct call is

SYS "Font_ConverttoOS",,cx% TO ,cx%.

- the x and y parameters are passed to Font_ConverttoOS in registers
r1 and r2.

Regards,

Pete Miller.

[toc] | [prev] | [next] | [standalone]


#223

FromMatthew Phillips <mnews@sinenomine.freeserve.co.uk>
Date2011-04-27 19:58 +0100
Message-ID<31d0a1ca51.Matthew@sinenomine.freeserve.co.uk>
In reply to#218
In message <51ca78d47ePaul@sprie.nl>
 on 27 Apr 2011 Paul Sprangers  wrote:

> Let me show what I have now:
> 
> DEF PROCkeypress(wh%,k%)
>  [...]  Here, valid keypresses are added to the string 'string$'
> SYS
> "Font_ScanString",plain%,string$,(1<<7)+(1<<17),&3FFFFFFF,&3FFFFFFF,,,LEN(string$)
> TO ,,,cx%,,,,len%
> SYS "Wimp_SetCaretPosition",window%,-1,cx%+10,-44,40,-1
> PROCredraw(window%)
> ENDPROC
> 
> As you can see, I've set bit 7 and bit 17 in R2 of the ScanString call.
> I've also followed your advice to use large integers in R3 and R4.
> Moreover, I've also taken the length of the string in account, although I
> don't know what to do with it. Anyway, whatever integer or value I try, the
> resulting cx% is always 0.

Don't set bit 17.  That should fix it.  You'll need to set bit 8 in order to
make sure the right font is measured, but don't set bit 17.

I think that bit 17 should only be set if you have a real x,y of a mouse
click in your R3,4 and want to know the caret position and index into the
string that is appropriate for placing the caret given the click at that x,y
position.

That should do it!

Font_ScanString, in my experience, is one of the nastiest SWIs going because
it has so many different functions and it's so easy to get your parameters
wrong.  It pays to write a set of functions to do the real operations you
want to do (place a caret at a set position into the string, return the width
of the string, find a split point, etc.) and then stick to them!

-- 
Matthew Phillips
Durham

[toc] | [prev] | [next] | [standalone]


#226

FromPaul Sprangers <Paul@sprie.nl>
Date2011-04-27 22:15 +0200
Message-ID<51caa8d5c0Paul@sprie.nl>
In reply to#223
Dear Matthew,

> You'll need to set bit 8 in order to make sure the right font is measured

As far as I understand, bit 8 doesn't need to be set if R1 contains the
pointer to the intended font. Anyhow, as you can read in my reply to Pete,
the caret is now basically working.

> I think that bit 17 should only be set if you have a real x,y of a mouse
> click in your R3,4 and want to know the caret position and index into
> the string that is appropriate for placing the caret given the click at
> that x,y position.

That is exactly what is next on my ToDo list,
My window has to mimic a writable icon, so it must be possible to click
somewhere in a given string and put the caret there. The only question at
the moment is: How?

> Font_ScanString, in my experience, is one of the nastiest SWIs going
> because it has so many different functions and it's so easy to get your
> parameters wrong.

I fully agree. For example, since I don't need the y value (it's all about
just one single line), I thought I could forget about the appropriate
register (R4). But no, as soon as I removed the y value on entry, it
immediately affected the x value on exit (which was 0 again).
For a simple soul like me, such logic doesn't immediately spring to mind.

Anyhow, the next challenge is putting the caret somewhere in the middle of
a given string, by clicking the mouse.

Kind regards,
Paul Sprangers

[toc] | [prev] | [next] | [standalone]


#228

FromMartin Wuerthner <spamtrap@mw-software.com>
Date2011-04-30 17:12 +0200
Message-ID<ad9618cc51.martin@bach.planiverse.com>
In reply to#226
In message <51cc00fe22Paul@sprie.nl>
          Paul Sprangers <Paul@sprie.nl> wrote:

> The first problem that I encounter, when I read the OS stronghelp file (or
> your extract), is that I can't decide whether I need to find the 'Address
> of a mouse click?' or the 'Graphical position of a caret?'

The two are exactly opposite operations. Say you have a string "Hi 
there" and your application wants to place the caret at the beginning 
of the word "there". That word is at index 3 into the string, so you 
would find the "graphical position of a caret" at index 3. If, on the 
other hand, the user clicks at x position [start of word on screen] + 
39 OS units, you need the "address of a mouse click" with r3 = 39 
converted to millipoints. "Address of a mouse click" is not official 
terminology, it is a misnomer invented by whoever wrote the StrongHelp 
page. Anyway, you pass in the position and you get back the index into 
the string at which the caret should be placed.

> When I go for the Address of a mouse click, then I have to 'Use correct
> width in R3...' First of all, I have no idea what is meant by 'correct
> width'. Is it the width of the entire string, or the width of the string
> until the position of the caret? Or is it something completely different?
> And what is 'correct'? What are the dimensions? Pixels, points,
> millipoints, number of characters?

When you think about it, it can only mean one thing - the horizontal 
offset of the click position from the start position of the string on 
screen. Units are always millipoints.

> Anyhow, when I enter a value in [R3] other than &7FFFFFFF, the call will
> always return 0 in [R3] on exit.

Then something else is going wrong. The basic approach is correct. See 
the code below that demonstrates it complete with output.

Maybe it helps if you understand how the SWI works: For the sake of 
simplicity, let us assume a standard Western font rendered 
horizontally without any vertical movement operators in the string, so 
we only care about x positions. The SWI starts at x=0 and scans the 
string character by character adding the advance of each character to 
the x position. It stops when
a) it finds the end of the string
OR
b) if a length is specified (flags bit 7 set), when the number of
   characters given in r7 has been consumed.
OR
c) when x exceeds R3 on entry

So, that explains why you get the width of the entire string if you 
pass a very large value in R3 on entry because the SWI only terminates 
on condition a). In order to find your mouse click position in the 
string, you pass the x position at which your mouse click occurred 
(relative to the start of the string on screen, of course, and 
converted to millipoints, i.e., multiplied by 400). Then, the SWI 
scans until a character is beyond that position. It returns a pointer 
to that character, or, if bit 17 is set, it looks whether you clicked 
into the left or right half of the character and in the latter case, 
returns the next character. You then place the caret before the 
returned character (which is the usual meaning of the caret index).

Interactive Font_ScanString tutorial in BBC BASIC
-------------------------------------------------

>SYS "Font_FindFont",,"Trinity.Medium",12*16,12*16,0,0 TO handle%
>DIM S% 100
>$S%="ABCDEFGHIJK"+CHR$0

*** Find width of entire string:

>SYS "Font_ScanString",handle%,S%,(1<<8),&7fffffff,&7fffffff TO ,r1,,r3
>PRINT r1-S%
        11

*** returned index 11, i.e., total length of string

>PRINT r3/400
    204.99

*** string is 204.99 OS units wide

*** so, how much of the string fits into 90 OS units space?

>SYS "Font_ScanString",handle%,S%,(1<<8),400*90,&7fffffff TO ,r1,,r3
>PRINT r1-S%
         4

*** 4 characters, i.e., "ABCD" fits, "E" no longer fits

*** so, how wide is "ABCD" (first 4 characters) actually?

>SYS "Font_ScanString",handle%,S%,(1<<8)+(1<<7),&7fffffff,&7fffffff,,,4
 TO ,r1,,r3
>PRINT r3/400
     83.34

*** "ABCD" has width 83.34 OS units

*** how wide is "ABCDE" (first 5 characters)?

>SYS "Font_ScanString",handle%,S%,(1<<8)+(1<<7),&7fffffff,&7fffffff,,,5
 TO ,r1,,r3
>PRINT r3/400
     101.67

*** "ABCDE" has width 101.67 OS units

*** where do we put the caret after a click at offset 90 OS units?

>SYS "Font_ScanString",handle%,S%,(1<<8)+(1<<17),400*90,&7fffffff TO ,r1,,r3
>PRINT r1-S%
         4

*** index 4 into the string, i.e., between "D" and "E"
*** at which horizontal position on screen is that?

> PRINT r3/400
>     83.34

*** 83.34 OS units, what a surprise, just what we got above for the
*** width of "ABCD"

*** where do we put the caret after a click at offset 100 OS units?

>SYS "Font_ScanString",handle%,S%,(1<<8)+(1<<17),400*100,&7fffffff TO ,r1,,r3
>PRINT r1-S%
         5

*** index 5 into the string, i.e., between "E" and "F"
*** and at which horizontal position is that?

> PRINT r3/400
>     101.67

*** again, what a surprise, that is width of "ABCDE"

> SYS "Font_LoseFont",handle%

As you can see, both clicks were over the character "E", but depending 
on where the click was (left or right half of character), we got caret 
position 4 (before "E") or 5 (before "F", i.e., after "E").

-- 
Martin
---------------------------------------------------------------------
Martin Wuerthner         MW Software      http://www.mw-software.com/
        RISC OS Software for Design, Printing and Publishing
---------------------------------------------------------------------

[toc] | [prev] | [next] | [standalone]


#261

FromRick Murray <heyrickmail-usenet@yahoo.co.uk>
Date2011-04-30 19:12 +0200
Message-ID<4dbc42f2$0$30794$ba4acef3@reader.news.orange.fr>
In reply to#228
On 30/04/2011 17:12, Martin Wuerthner wrote:

> Interactive Font_ScanString tutorial in BBC BASIC
> -------------------------------------------------

;-) Now why didn't the PRM include this, instead of lots and lots of 
complicated guff.


Best wishes,

Rick.

[toc] | [prev] | [next] | [standalone]


#268

FromPaul Sprangers <Paul@sprie.nl>
Date2011-05-02 09:37 +0200
Message-ID<51ccf698a7Paul@sprie.nl>
In reply to#228
Dear Martin,

Rather than your extensive knowledge of SYS calls, it's especially your
notion of my misunderstanding that doubles my admiration.

I sigh with Rick Murray: If only the PRM's were as clear as that...

That doesn't mean, though, that I understand everything now.
For example:

>DIM S% 100
>$S%="ABCDEFGHIJK"+CHR$0
>SYS "Font_ScanString",handle%,S%,(1<<8),&7fffffff,&7fffffff TO ,r1,,r3
>PRINT r1-S%

If you didn't tell me, how would I ever have discovered that when I want to
retrieve a sensible value from [R1], I first have to subtract the address
of the memory block that contains the string? In other words, where in the
manuals is written that, when using the call with these parameters, [R1]
will contain the length of the string, PLUS the memory address of the
string!?

Things like this make so little logic to me, that I really have to collect
the last bits of courage in order to continue writing my piteous code.

However, if people like you didn't help, I had to stop coding long ago in
the first place. So, thank you all very much once more.

Kind regards,
Paul Sprangers

[toc] | [prev] | [next] | [standalone]


#269

FromAlan Wrigley <spamhater@keepyourfilthyspamtoyourself.co.uk>
Date2011-05-02 08:49 +0100
Message-ID<gemini.lkk5q9000bnn002hc.spamhater@keepyourfilthyspamtoyourself.co.uk>
In reply to#268
Paul Sprangers <Paul@sprie.nl> wrote:

> >SYS "Font_ScanString",handle%,S%,(1<<8),&7fffffff,&7fffffff TO ,r1,,r3
> >PRINT r1-S%
> 
> In other words, where in the
> manuals is written that, when using the call with these parameters, [R1]
> will contain the length of the string, PLUS the memory address of the
> string!?

Maybe where it says "R1 = pointer to end of string"?

Alan

-- 
RISC OS - you know it makes cents

[toc] | [prev] | [next] | [standalone]


#270

FromPaul Sprangers <Paul@sprie.nl>
Date2011-05-02 09:59 +0200
Message-ID<51ccf8a8d9Paul@sprie.nl>
In reply to#269
   Alan Wrigley wrote:

> > In other words, where in the manuals is written that, when using the
> > call with these parameters, [R1] will contain the length of the
> > string, PLUS the memory address of the string!?

> Maybe where it says "R1 = pointer to end of string"?

Only after minutes of deep and willingly thinking, some sense of logic
creeps into mind.

I'm afraid that only one thing is bright and clear: I don't have the right
type of brains for programming.

Kind regards,
Paul Sprangers

[toc] | [prev] | [next] | [standalone]


#272

FromAlan Adams <alan@adamshome.org.uk>
Date2011-05-02 21:27 +0100
Message-ID<dd1c3dcd51.Alan.Adams@laptop.adamshome.org.uk>
In reply to#270
In message <51ccf8a8d9Paul@sprie.nl>
          Paul Sprangers <Paul@sprie.nl> wrote:


>    Alan Wrigley wrote:

>>> In other words, where in the manuals is written that, when using the
>>> call with these parameters, [R1] will contain the length of the
>>> string, PLUS the memory address of the string!?

>> Maybe where it says "R1 = pointer to end of string"?

> Only after minutes of deep and willingly thinking, some sense of logic
> creeps into mind.

When reading theb PRMs you need to keep in mind that they were 
originally written for C programmers. In C pointer means address.

I just checked, and I agree it isn't clear - the word pointer occurs 
in the description of the first type of return value, and is only 
lightly implied for the second and third. However as you pass in the 
address of the string, it is fairly logical that information returned 
would also be addresses.

> I'm afraid that only one thing is bright and clear: I don't have the right
> type of brains for programming.

> Kind regards,
> Paul Sprangers



-- 
Alan Adams, from Northamptonshire
alan@adamshome.org.uk
http://www.nckc.org.uk/

[toc] | [prev] | [next] | [standalone]


#271

FromSteve Fryatt <news@stevefryatt.org.uk>
Date2011-05-02 09:08 +0100
Message-ID<mpro.lkk6lv00w8meo01ll.news@stevefryatt.org.uk>
In reply to#268
On 2 May, Paul Sprangers wrote in message
    <51ccf698a7Paul@sprie.nl>:

> > DIM S% 100 $S%="ABCDEFGHIJK"+CHR$0 SYS
> > "Font_ScanString",handle%,S%,(1<<8),&7fffffff,&7fffffff TO ,r1,,r3 PRINT
> > r1-S%
> 
> If you didn't tell me, how would I ever have discovered that when I want
> to retrieve a sensible value from [R1], I first have to subtract the
> address of the memory block that contains the string? In other words,
> where in the manuals is written that, when using the call with these
> parameters, [R1] will contain the length of the string, PLUS the memory
> address of the string!?
> 
> Things like this make so little logic to me, that I really have to collect
> the last bits of courage in order to continue writing my piteous code.

The PRM states that it's a "pointer to point in string" or "[pointer to] end
of string".  It's also a fairly common convention in the RISC OS API, so
even if you don't spot it at first you should certainly consider the
possibility before looking elsewhere.

Also, this is definitely a case where the StrongHelp manuals are more
cryptic than the official PRM.

-- 
Steve Fryatt - Leeds, England

http://www.stevefryatt.org.uk/

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.sys.acorn.programmer


csiph-web