Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.acorn.programmer > #228
| From | Martin Wuerthner <spamtrap@mw-software.com> |
|---|---|
| Newsgroups | comp.sys.acorn.programmer |
| Subject | Re: How to put a caret in a window |
| Date | 2011-04-30 17:12 +0200 |
| Organization | MW Software |
| Message-ID | <ad9618cc51.martin@bach.planiverse.com> (permalink) |
| References | (7 earlier) <51caa8d5c0Paul@sprie.nl> <7fbce5ca51.Matthew@sinenomine.freeserve.co.uk> <51cb982b94Paul@sprie.nl> <4dbb363e$0$30746$ba4acef3@reader.news.orange.fr> <51cc00fe22Paul@sprie.nl> |
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
---------------------------------------------------------------------
Back to comp.sys.acorn.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web