Initial revision
[ssr] / StraySrc / Sculptrix / sculptrix / s / utils
1 ;
2 ; utils
3 ;
4 ; Various useful routines
5 ;
6 ; © 1995-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sculptrix.
12 ;
13 ; Sculptrix is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sculptrix is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sculptrix. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29 GET libs:header
30 GET libs:swis
31
32 GET libs:stream
33
34 ;----- Main code ------------------------------------------------------------
35
36 AREA |Module$$Code|,CODE,READONLY
37
38 ; --- utils_strWidth ---
39 ;
40 ; On entry: R0 == pointer to a string
41 ;
42 ; On exit: R0 == width of the string in OS units
43 ;
44 ; Use: Returns the width of a string, as it would be displayed in
45 ; an icon (i.e. taking into account things like the current
46 ; desktop font etc.) The width is exact, so if you want to
47 ; e.g. draw a box round it, you'll have to add on a little
48 ; clearance at each end. 8 OS units seems to be a good size
49 ; for the clearance (so the total width you'd use is given by
50 ; utils_strWidth(string)+16, because it has two ends).
51 ;
52 ; [Stolen and bodged from sapphire/wimp.s by mdw]
53
54 EXPORT utils_strWidth
55 utils_strWidth ROUT
56
57 ; --- We need to find the string length anyway ---
58 ;
59 ; This length calculation is done inline to avoid a
60 ; dependency on string. It's not very long, anyway, and
61 ; it *does* save a MOV R5,R0 :-)
62
63 STMFD R13!,{R1-R6,R14} ;Save a bunch of registers
64 MOV R5,#0 ;Length counter starts at 0
65 MOV R6,R0 ;Keep string pointer
66
67 00 LDRB R14,[R0,R5] ;Get a byte from the string
68 CMP R14,#' ' ;Is it a control char?
69 ADDCS R5,R5,#1 ;Bump on *anyway* (see above)
70 BCS %b00 ;If more to go, loop back
71
72 ; --- Now try to find the current font handle ---
73
74 MOV R0,#8 ;Read Wimp font handle
75 SWI XWimp_ReadSysInfo ;Find out from WindowMangler
76 MOVVS R0,#0 ;If nothing, assume no font
77 CMP R0,#0 ;Is there there a real font?
78 BEQ %10utils_strWidth ;No -- skip ahead too
79
80 ; --- Now suss out the width of the string ---
81
82 SWI Font_SetFont ;Set up the desktop font
83 MOV R1,#1000 ;A nice big round number
84 MOV R2,R1 ;And another nice big number
85 SWI Font_Converttopoints ;Font_StringWidth is weird
86 MOV R3,R2 ;Move coords to right regs
87 MOV R2,R1 ;That means both of them
88 MOV R1,R6 ;Retreive string pointer
89 MOV R4,#-1 ;Don't split the string
90 ADD R5,R5,#1 ;Move this counter on one
91 SWI Font_StringWidth ;Find the width of the string
92 MOV R1,R2 ;Move coordinates back again
93 MOV R2,R3 ;Again, that means both
94 SWI Font_ConverttoOS ;Convert to OS units now
95 MOV R0,R1 ;Put the width in R0
96 LDMFD R13!,{R1-R6,PC}^ ;Return to caller, then
97
98 ; --- Just normal system font ---
99
100 10 MOV R0,R5,LSL #4 ;Multiply by character width
101 LDMFD R13!,{R1-R6,PC}^ ;Return to caller
102
103 LTORG
104
105 ;----- That's all, folks ----------------------------------------------------
106
107 END