home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
programs
/
fonts
/
a_q
/
fontwindow
/
!Demo
/
EditorSrc
(
.txt
)
< prev
next >
Wrap
RISC OS BBC BASIC V Source
|
1993-03-02
|
14KB
|
500 lines
>EditorSrc
Demonstration of use of FontWindow module
Multi-document application, windows with anti-aliased title bars
Windows are demand-created
Look for REM### to see where I've put the FontModule code
Look for REM#++ to see menu code
documents are kept in a simple linked list
v1.20 now has some menu items *not* indirected
MACHINE: Archimedes
LANGUAGE: BBC BASIC V (v1.05)
AUTHOR: Cy Booker,
86 Church View, Main Road, Crockenhill, Swanley, Kent.
BR8 8JW
apologies for the crappy coding, but it is done in a hurry
main(
, "12")
main(0, 0, "x")
main(FontWindow, FontMenu, Title$)
= &8000+64*1024
Debug% =
q% 256
$q%="TASK"
"Wimp_Initialise",200,!q%, Title$
, TaskHandle%
need local error handlers before poll loop...
FontMenu
$Q flags = 1 << 16 :
menus as fonts in all resolutions
menufont 48
&> menufont!0 = 15*16 :
X size of font
'> menufont!4 = 14*16 :
Y size of font
(\ $(menufont+8) = "Trinity.Medium" :
Font name (40 chars including CR terminator)
)I version = 120 :
latest version know about
*_ flags += 1 << 18 :
calculate menu width automatically if fontified
+^ flags += 1 << 19 :
automatically indirect menu items if fontified
,
version = 100
flags = 0
/6 menufont = 0 :
unused
0
1K malloc_routine = 0 :
default allocate RMA memory
2G free_routine = 0 :
default free RMA memory
3d gethandle_routine = 1 :
default one for abstract == pointer to window handle
4d recreate_routine = 1 :
default one for abstract == pointer to window handle
56 routine_r12 = 0 :
unused
6C fonttable = 0 :
please allocate one
"FontWindow_Initialise", TaskHandle%, malloc_routine,free_routine, gethandle_routine,recreate_routine, routine_r12, fonttable, version
flags, menufont
FontTable%
9=
FontTable% 256:
i%= 0
255:FontTable%?i% = 0:
Documents 4 :
pointer to pointer to linked list of'em
=$ !Documents = 0
>L DocNumber = 1 :
so can tell documents apart visually
Each document is stored in the following structure:
BE Doc_Next = 0 << 2 :
pointer to next in linked list
C9 Doc_Window = 1 << 2 :
wimp window handle
DR Doc_Title = 2 << 2 :
pointer to indirected title bar icon buffer
sizeof_Doc = 3 << 2
loadtemplates
makemenus
makeiconbaricon
reporterror
O"
"Wimp_Poll",&31,q%
Q%
"Wimp_OpenWindow",, q%
closewindow
mouseclick
menuselect
17,18:
message
V
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
closewindow
docwindow_p(doc, !q%)
quitdocument(doc)
a"
"Wimp_CloseWindow",, q%
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
createdocument
doc, dx, dy, len
doc sizeof_Doc :
claim memory [kludge]
we now redirect the indirected data
this is a kludge (a bad one) because only redirect the title bar
should be re-directing all the indirected icons as well...
len = Document_WDef%!80
doc!Doc_Title len
o' Document_WDef%!72 = doc!Doc_Title
putz(doc!Doc_Title,
"Document number "+
(DocNumber), len-1))
DocNumber += 1
### -- note the TO parameter in the next line
FontWindow
tb
"FontWindow_CreateWindow", TaskHandle%, Document_WDef%, doc+Doc_Window
doc!Doc_Window
v@
"Wimp_CreateWindow",, Document_WDef%
doc!Doc_Window
!q% = doc!Doc_Window
"Wimp_GetWindowState",, q%
zD dx = (
(64) - &1F) * 16 :
so not on top of eachother!
dy = (
(64) - &1F) * 16
q%!4 += dx
q%!8 += dy
q%!12 += dx
q%!16 += dy
q%!28 = -1
"Wimp_OpenWindow",, q% :
no need to fontwindow_openwindow, although could
doc!Doc_Next = !Documents
G !Documents = doc :
new head of linked list
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
quitdocument(doc)
parent
parent = Documents
!parent <> doc
% parent = (!parent) + Doc_Next
FontWindow
A
"FontWindow_DeleteWindow", TaskHandle%, doc+Doc_Window
/
"Wimp_DeleteWindow",, doc+Doc_Window
!parent = doc!Doc_Next
<release memory used by document>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
returns TRUE if window belongs to a document, setting doc
if true
docwindow_p(
doc, w%)
rc% =
doc = !Documents
doc
# rc% = (doc!Doc_Window = w%)
$
rc%
doc = doc!Doc_Next
= rc%
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
closedown
!Documents
!
quitdocument(!Documents)
FontWindow
4
"FontWindow_CloseDown", TaskHandle%,
i%=0
FontTable%?i%
#
"XFont_LoseFont", i%
FontTable%?i% -= 1
"Wimp_CloseDown"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
doesn't actually load window, but saves definition in memory
if make multiple clones of a windows then need to redirect
all of the indirected data...
loadtemplate(name$,
wh%)
siz, i, pos
$q% = name$+
"Wimp_LoadTemplate",, buf%, indrove%, ind%+bufsiz%, FontTable%, q%, 0
,, indrove%,,,, pos
pos=0
1, "Can't find template "+ name$
siz = 88+((buf%!84)*32)
wh% siz
i = 0
siz-1
wh%!i = buf%!i
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
message_modechange
FontWindow
/
"FontWindow_ModeChange", TaskHandle%
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
message_menuwarning
x% = q%!24
y% = q%!28
item% = q%!32
item%
ProgInfo_WDef%
ProgInfo_WPtr% 4
FontWindow
g
"FontWindow_CreateWindow", TaskHandle%, ProgInfo_WDef%, ProgInfo_WPtr%
!ProgInfo_WPtr%
E
"Wimp_CreateWindow",, ProgInfo_WDef%
!ProgInfo_WPtr%
5 ProgInfo_WDef% = 0 :
release memory
FontWindow
E
"FontWindow_UpdateWindow", TaskHandle%, ProgInfo_WPtr%
9
"Wimp_CreateSubMenu",, !ProgInfo_WPtr%, x%, y%
SaveAs_WDef%
SaveAs_WPtr% 4
FontWindow
a
"FontWindow_CreateWindow", TaskHandle%, SaveAs_WDef%, SaveAs_WPtr%
!SaveAs_WPtr%
A
"Wimp_CreateWindow",, SaveAs_WDef%
!SaveAs_WPtr%
3 SaveAs_WDef% = 0 :
release memory
FontWindow
C
"FontWindow_UpdateWindow", TaskHandle%, SaveAs_WPtr%
7
"Wimp_CreateSubMenu",, !SaveAs_WPtr%, x%, y%
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mouseclick
(q%!12 = -2)
(q%!16 = IconBarIcon%)
(q%!8
(
menutick(Menu%, 2, FontMenus)
L
"Wimp_CreateMenu",, Menu%, q%!0 - ((Menu%!16)>>1), 96+44*5+24*0
createdocument
menuselect
!q%
FontMenus
?
"FontWindow_DeRegisterMenu", TaskHandle%, Menu%,
F
"FontWindow_DeRegisterMenu", TaskHandle%, MenuColours%,
:
"FontWindow_RegisterMenu", TaskHandle%, Menu%
A
"FontWindow_RegisterMenu", TaskHandle%, MenuColours%
FontMenus =
FontMenus
&
menutick(Menu%, 2, FontMenus)
q%!4 >= 0
$
q%!4 <> CurrentColour%
6
menutick(MenuColours%, CurrentColour%,
!! CurrentColour% = q%!4
#4
menutick(MenuColours%, CurrentColour%,
$
closedown
"Wimp_GetPointerInfo",, q%
q%!8
)$
"Wimp_CreateMenu",, Menu%
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
reporterror
!q% =
Debug%
2'
putz(q%+4,
$+ " code "+
putz(q%+4,
"Wimp_ReportError", q%, 3, Title$
, choice%
choice% = 2
closedown
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
loadtemplates
bufsiz% = 10*1024
buf% bufsiz% :
kludge
ind% bufsiz% :
kludge
indrove% = ind%
"Wimp_OpenTemplate",, "<DemoFontWindow$Dir>.Templates"
local error handler...
loadtemplate("ProgInfo", ProgInfo_WDef%)
loadtemplate("SaveAs", SaveAs_WDef%)
loadtemplate("Document", Document_WDef%)
ID :
the following window will not be cached, as it contains no
anti-aliased fonts.
loadtemplate("Query", Query_WDef%)
"Wimp_CreateWindow",, Query_WDef%
Query_W%
"Wimp_CloseTemplate"
free buf% memory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
makemenus
col$, i
FontMenus = FontMenu
CurrentColour% = 0
col$ = "0123456789ABCDEF"
menusiz% = 10*1024
Menu% menusiz%
_% MenuColours% =
maddr(Menu%, 5)
menu% = Menu%
menu% += 28
menuitem("Info", 1 << 3, &8004)
menuitem("Save as", 1 << 3, &8004)
menuitem("Use FONTS", 0, 0)
FontWindow =
menu%!-16 += 1 << 22
menuitem("Colours", 0, MenuColours%)
menuitem("Quit", 1 << 7, -1)
menutitle(Menu%, Title$)
menu% += 28
i= 0
menu%!0 = 0
menu%!4 = 0
fore
o1 menu%!8 = (i << 28)
(fore << 24)
&129
p menu%!12 =
strdup(
s1
give menu item an "F" validation string
t8
which will be used IF the item is anti-aliased
u?
this validation string will be used by the FontWindow
v)
when we DeRegister the sub/menu
w :
xB menu%!16 =
strdup("F"+
col$, i+1, 1)+
col$, fore+1, 1))
menu%!20 =
(i))+1
menu%+=24
menu%!-24 += 1 << 7
menutitle(MenuColours%, "Colours")
7,7,7,0, 0,0,0,0, 0,7,7,0, 7,0,7,7
FontWindow
FontMenu
:
"FontWindow_RegisterMenu", TaskHandle%, Menu%
A
"FontWindow_RegisterMenu", TaskHandle%, MenuColours%
strdup(s$)
(s$) + 1
$s = s$
maddr(base, item)
item >= 0
base += 28 + (item * 24)
= base
menutick(base, item, boolean)
boolean
boolean = 1 << 0
base =
maddr(base, item)
' base!0 = (base!0
boolean
menutitle(menu%, title$)
maxw%, w%, item$, item%
(title$)>12
menu%!0
(title$)+1
$(menu%!0) = title$
menu%!4 = -1
menu%!8 =
(title$)+1
menu%!28 += 1 << 8
< $menu% = title$ :
do this now
menu%?12 = 7
menu%?13 = 2
menu%?14 = 7
menu%?15 = 0
menu%!20 = 44
menu%!24 = 0
maxw% =
(title$) * 16
item% = menu% + 28 - 24
item% += 24
item%!8
(1 << 8)
item$ = $(item%!12)
w% = 13
item%?24, w%
item$ = $(item%+12)
item%?24, w%
w% =
(item$) * 16 + 8
!
maxw% < w%
maxw% = w%
(item%!0)
(1 << 7)
menu%!16 = maxw%
menuitem(item$, flags%, data%)
menu%!0 = flags%
menu%!4 = data%
menu%!8 = &07000021
(item$)<=12
. $(menu%+12) =
item$+
(13)), 12)
menu%!8 += 1 << 8
menu%!12
(item$)+1
$(menu%!12) = item$
menu%!16 = -1
menu%!20 =
(item$)+1
menu%+=24
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
makeiconbaricon
name% 13
$name% = "!demo"
q%!0 = -1
q%!4 = 0
q%!8 = 0
q%!12 = 68
q%!16 = 68
q%!20 = &07006102
q%!24 = name%
q%!28 = +1
q%!32 =
($name%) + 1
"Wimp_CreateIcon",, q%
IconBarIcon%
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
message
q%!16
closedown
&400C0:
message_menuwarning
&400C1:
message_modechange
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Debug%
!
$+ ", ["+
)+ "]"
getz(q%)
?q%:V$+=
(?q%):q%+=1:
putz(z%, z$)
$z% = z$
z%?
z$ = 0