home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / s / swiftjpeg / !SwiftJPEG / Resources / Source (.txt)
Encoding:
RISC OS BBC BASIC V Source  |  1995-11-27  |  29.8 KB  |  1,185 lines

  1.  > !RunImage for !SwiftJPEG
  2.  A fast JPEG viewer using Acorn's
  3.  SpriteExtend module from RISC OS
  4.  v3.6 or later (module version
  5.  0.99 or later).
  6.  This source code may not run with
  7.  the WimpSlot allocated to the
  8.  crunched !RunImage; you may need
  9.  to increase the slot by the
  10.  difference in file size, rounded
  11.  up to a 4K block.
  12.  (C) Hipposoft 1995
  13. closechoices:
  14. restoremode:
  15.  "Hourglass_Smash":
  16. exit:
  17. $+" (at line "+
  18. )+")":
  19. choicefh%=0
  20. returnto%=-1
  21.  b% 256
  22.     !b%=3
  23. b%!4=5
  24. b%!8=&400C1
  25. b%!12=0
  26.  "Wimp_Initialise",350,&4B534154,"SwiftJPEG",b% 
  27.  wimp%,task%
  28.  wimp%<350 
  29.  490,"SwiftJPEG requires RISC OS 3.50 or later to run"
  30.  "Hourglass_Start",50
  31. version$="0.07 (27 Nov 95)"
  32. initialisemain
  33. iconbar
  34.  "Hourglass_Off"
  35. getp(a$)
  36.  a$<>"" 
  37. !b%=-1
  38. b%!40=
  39. filetype(a$)
  40. $(b%+44)=a$
  41. loadpicture
  42. quit%
  43.  -- General WIMP procedures
  44.  "XWimp_CloseDown",task%,&4B534154
  45. memusage
  46.  "Memory free           : ";
  47.  "Could decrease slot by: ";(((
  48.  4096)*4);"K"
  49.  "That would leave free : ";(
  50. )-(((
  51.  4096)*4096);" bytes"
  52.  "OS_ReadMonotonicTime" 
  53.  "Wimp_PollIdle",1,b%,a%+10000 
  54.  reason%
  55.  (returnto%<>-1) 
  56.  (reason%=1) 
  57. restoremode
  58. abortmul%=
  59.  closedis%=0 
  60. !fr%=displayh%
  61.  "Wimp_GetWindowInfo",,fr%
  62. fr%!4=0
  63. fr%!8=0
  64. fr%!12=&7FFFFFF
  65. fr%!16=&7FFFFFF
  66.  "Wimp_OpenWindow",,fr%
  67. opencentered(displayh%)
  68. reason%=3
  69. !b%=displayh%
  70.  reason% 
  71. redraw
  72.  "Wimp_OpenWindow",,b%
  73.  !b% 
  74.  displayh%
  75.  "OS_Byte",121 
  76.  (a%<>0) 
  77.  "Wimp_CloseWindow",,b%
  78. setslotsize(basislot%,a%)
  79. greyoutmenu(mainmenuaddr%,2)
  80. greyoutmenu(mainmenuaddr%,3)
  81.  a%,c%,d%
  82.  (d% 
  83. a$=jpegname$
  84. (a$) 
  85. a$,a%,1)="." 
  86. a$,a%-1):a%=0:c%=
  87.  c%<>
  88.  a$<>"" 
  89.  "XOS_CLI","Filer_OpenDir "+a$
  90.  choicesh%
  91. iconh%=12
  92. adju%=0
  93. setopt(choicesh%,iconh%,
  94. choicesclick
  95. setopt(choicesh%,iconh%,
  96.  "Wimp_CloseWindow",,b%
  97. click
  98. keyboard
  99. menuselect
  100.  17,18,19:
  101. message
  102. click
  103. windh%=b%!12
  104. iconh%=b%!16
  105. adju%=(b%!8) 
  106. menu%=(b%!8) 
  107. sele%=(b%!8) 
  108.  windh% 
  109. open(displayh%) 
  110.  adju%<>0 
  111. fullscreen
  112. openmainmenu(
  113.  displayh%:
  114. openmainmenu(
  115.  zoomh%:
  116. zoomclick
  117.  choicesh%:
  118. choicesclick
  119. keyboard
  120. windh%=!b%
  121. iconh%=b%!4
  122.  windh% 
  123.  zoomh%
  124.  b%!24 
  125.  &00D
  126. textuntil(!(zow%+108+32*iconh%),33))>20 
  127.  $(!(zow%+108+32*iconh%))="20":
  128. forceredraw(zoomh%,iconh%)
  129. textuntil(!(zow%+108+32*iconh%),33))<1 
  130.  $(!(zow%+108+32*iconh%))="1":
  131. forceredraw(zoomh%,iconh%)
  132.  iconh%=2 
  133. iconh%=4
  134.  "Wimp_SetCaretPosition",zoomh%,4,b%!8,b%!12,b%!16,
  135. textuntil(!(zow%+236),33))
  136. iconh%=2
  137.  "Wimp_CreateMenu",-1
  138. keyzoom
  139.  iconh%=4 
  140.  "Wimp_GetCaretPosition",,fr%
  141. showmenu(topmenu%,topx%,topy%)
  142.  "Wimp_SetCaretPosition",!fr%,fr%!4,fr%!8,fr%!12,fr%!16,fr%!20
  143.  "Wimp_ProcessKey",b%!24
  144. message
  145.  b%!16 
  146.  0:quit%=
  147.  3,5:
  148. loadpicture
  149.  &400C1:
  150. open(displayh%) 
  151. resizemainwindow
  152. setslotsize(a%,
  153.  Pass the absolute slot size you want to set, and a variable
  154.  into which the slot size on exit from the procedure
  155.  is passed.
  156.  c%,d%
  157.  Read the size of the Current slot and Free pool. The total
  158.  free space is then in d% since the Free pool is the global
  159.  free space rather than the Wimp definition which is the
  160.  global free space minus the space in the Next slot.
  161.  "Wimp_SlotSize",-1,-1 
  162.  c%,,d%
  163.  If the current slot isn't the size requested already, and if the
  164.  size of the free memory plus the basic slot is greater than or
  165.  equal to the amount we want to claim (i.e., if there is enough free!)
  166.  then the memory is claimed.
  167.  "Wimp_SlotSize",a%,-1
  168.  Now read the Current slot again. This will return either an amount
  169.  greater than basislot% in which case the allocation was successful, or
  170.  it will return basislot% directly, in which case there was not enough
  171.  memory. The error for this is handled by the caller of the procedure.
  172.  "Wimp_SlotSize",-1,-1 
  173. redraw
  174.  "Wimp_RedrawWindow",,b% 
  175.  SYS "JPEG_PlotScaled",basememo%,b%!4-b%!20,b%!16-windheig%-b%!24,0,jpegleng%,df%
  176.  "JPEG_PlotScaled",basememo%,b%!4-b%!20,b%!16-windheig%-b%!24,sc%,jpegleng%,df%
  177.  "Wimp_GetRectangle",,b% 
  178. forceredraw(a%,c%)
  179.  Pass a window and icon handle. Performs a 'true' redraw
  180.  of the icon (so it might flicker a bit).
  181. !fr%=a%
  182. fr%!4=c%
  183.  "Wimp_GetIconState",,fr%
  184.  "Wimp_ForceRedraw",!fr%,fr%!8,fr%!12,fr%!16,fr%!20
  185. redrawtitlebar(a%)
  186. open(a%) 
  187. !s%=a%
  188.  "Wimp_GetWindowState",,s%
  189. c%=s%!16
  190. !s%=a%
  191.  "Wimp_GetWindowOutline",,s%
  192.  s%!8<c% 
  193.  s%!8=c%
  194.  "Wimp_ForceRedraw",-1,s%!4,s%!8,s%!12,s%!16
  195.  -- Initialisation procedures
  196. initialisemain
  197.  Initialise fundamental variables and dimension arrays.
  198. quit%=
  199. returnto%=-1
  200. abortmul%=
  201. isp%=1280
  202.  ib% 32
  203.  s% 1024,fr% 1024
  204.  i% isp%,m% 512,mi% 1024
  205.  inw% 768,diw% 256,zow% 768,jiw% 512,chw% 1280
  206.  mos% 128,sc% 16
  207.  Load choices and sprites relevant to current display
  208.  resolution.
  209. loadchoices
  210. loadsprites
  211.  xbig%, ybig% and bbpp% are eventually set globally to the
  212.  x and y size of the largest available screenmode; xclr%,
  213.  yclr% AND cbpp% to the most colourful. This can be done
  214.  here, or when the actual function is requested (the check
  215.  is made to see if xbig% or xclr% are zero, and if so, work
  216.  out the biggest or most colourful).
  217. xbig%=0
  218. ybig%=0
  219. bbpp%=0
  220. xclr%=0
  221. yclr%=0
  222. cbpp%=0
  223.  modesons%<>0 
  224. findbiggest(xbig%,ybig%,bbpp%)
  225. findcolours(xclr%,yclr%,cbpp%)
  226.  Find out Current slot size and record it in
  227.  basislot% for use by the wimp slot sizing procedure.
  228.  "Wimp_SlotSize",-1,-1 
  229.  basislot%
  230.  Now the usual initialisation, loading
  231.  templates, making menus, adding submenus
  232.  and so on.
  233. templates
  234. zoomm%=1
  235. zoomd%=1
  236. $(!(zow%+172))="1"
  237. $(!(zow%+236))="1"
  238. createmainmenu
  239. attach(mainmenuaddr%,0,infoh%)
  240. attach(mainmenuaddr%,1,zoomh%)
  241. attach(mainmenuaddr%,2,jpeginfoh%)
  242. greyoutmenu(mainmenuaddr%,2)
  243. greyoutmenu(mainmenuaddr%,3)
  244. setopt(choicesh%,2+ditherit%,
  245.  fullscrn%>0 
  246. setopt(choicesh%,6+fullscrn%,
  247.  autofull%<>0 
  248. setopt(choicesh%,16,
  249.  modesons%<>0 
  250. setopt(choicesh%,17,
  251.  closedis%<>0 
  252. setopt(choicesh%,18,
  253. loadchoices
  254.  a%,c%,a$
  255.  "XOS_ReadVarVal","SwiftJPEG$Dir",fr%,256 
  256.  ,,a%
  257.  a%=0 
  258.  490,"System variable 'SwiftJPEG$Dir' not defined; ensure you double-click on !SwiftJPEG to run it, and not one of its component files"
  259. W1choipath$=
  260. textuntil(fr%,32),a%)+".!Choices"
  261. choicefh%=
  262. (choipath$)
  263.  choicefh%=0 
  264.  490,"Can't find the !Choices file"
  265. getchoice("Dithering","012",ditherit%)
  266. df%=ditherit%-(ditherit%=2)
  267. getchoice("Full Screen","0123",fullscrn%)
  268. getchoice("Auto Full Screen","01",autofull%)
  269. getchoice("Modes On Startup","01",modesons%)
  270. getchoice("Close Display","01",closedis%)
  271. #choicefh%
  272. choicefh%=0
  273. closechoices
  274.  choicefh%<>0 
  275. #choicefh%
  276. restoremode
  277.  returnto%<>-1 
  278.  "Wimp_SetMode",returnto%
  279. returnto%=-1
  280. getchoice(b$,a$,
  281.  c%,c$
  282. upper(
  283. #choicefh%)=
  284. upper(b$) 
  285.  (c%=
  286. #choicefh%)
  287.  490,"Can't find '"+b$+"' entry in !Choices file"
  288. #choicefh%
  289. a$,c$)=0) 
  290. (c$)<>1) 
  291.  490,b$+" option not understood in !Choices file"
  292. putchoice(a$,a%)
  293.  c%,b$
  294. upper(
  295. #choicefh%)
  296. upper(a$) 
  297.  (c%=
  298. #choicefh%)
  299.  490,"Can't find 'Dithering' entry in !Choices file"
  300. #choicefh%,a%+48
  301. loadsprites
  302.  a%,a$
  303.  "OS_ReadModeVariable",-1,4 
  304.  ,,xeig%
  305.  "OS_ReadModeVariable",-1,5 
  306.  ,,yeig%
  307. a$="<SwiftJPEG$Dir>."
  308.  xeig%>1 
  309.  yeig%>1 
  310.  a$+="Sprites" 
  311.  a$+="Sprites22"
  312. filetype(a$)
  313.  a%<0 
  314.  (1<<30)+2,"Can't find Sprites file"
  315.  a%<>&FF9 
  316.  (1<<30)+2,"Sprites file doesn't have Sprite filetype &FF9"
  317. filelength(a$)
  318.  a%=-1 
  319.  (1<<30)+2,"Can't find the Sprites file"
  320.  sprites% a%+1024
  321. !sprites%=0
  322. sprites%!4=16
  323.  "OS_SpriteOp",265,sprites%
  324.  "OS_SpriteOp",266,sprites%,a$
  325. iconbar
  326. $(ib%)="iconbar"
  327. !b%=-1
  328. b%!4=0
  329. b%!8=0
  330. b%!12=68
  331. b%!16=68
  332. b%!20=&3102
  333. b%!24=ib%
  334. b%!28=sprites%
  335. b%!32=11
  336.  "Wimp_CreateIcon",,b% 
  337.  iconbarh%
  338. getp(
  339.  "OS_GetEnv" 
  340. textuntil(a%,32)
  341. a$,"""")
  342.  a%<>0 
  343. a$,a%+1)
  344. a$,""" ")
  345.  a%<>0 
  346. a$,a%+2) 
  347.  a$=""
  348.  -- Template and window handling procedures
  349. open(a%)
  350.  a%=-1 
  351. !fr%=a%
  352.  "Wimp_GetWindowState",,fr%
  353.  ((fr%!32) 
  354.  &10000)<>0 
  355. loadtemp(a%,a$,
  356.  "Wimp_LoadTemplate",,a%,i%,io%+isp%,-1,a$,0 
  357.  ,,i%
  358. a%!64=sprites%
  359.  "Wimp_CreateWindow",,a% 
  360. templates
  361.  "Wimp_OpenTemplate",,"<SwiftJPEG$Dir>.Templates"
  362. io%=i%
  363. loadtemp(inw%,"Info",infoh%)
  364. $(!(inw%+332))=version$
  365. loadtemp(diw%,"Display",displayh%)
  366. loadtemp(zow%,"Zoom",zoomh%)
  367. loadtemp(jiw%,"JPEG info",jpeginfoh%)
  368. loadtemp(chw%,"Choices",choicesh%)
  369.  "Wimp_CloseTemplate"
  370. opencentered(f%)
  371.  a%,c%,d%,e%
  372. readscreensize(a%,c%)
  373. !fr%=f%
  374.  "Wimp_GetWindowState",,fr%
  375. d%=fr%!12-fr%!4
  376. e%=fr%!16-fr%!8
  377. xpo%=(a%-d%)/2
  378. ypo%=(c%-e%)/2+68
  379.  (fr%!32) 
  380.  &4000000 
  381.  ypo%-=20
  382.  (fr%!32) 
  383.  &40000000 
  384.  ypo%+=20
  385.  (fr%!32) 
  386.  &10000000 
  387.  xpo%-=20
  388. fr%!4=xpo%
  389. fr%!8=ypo%
  390. fr%!12=xpo%+d%
  391. fr%!16=ypo%+e%
  392. fr%!28=-1
  393.  "Wimp_OpenWindow",,fr%
  394. titlebarchange(a%,a$)
  395.  Pass a window handle, and a string to put in the
  396.  title bar.
  397. !fr%=a%
  398.  "Wimp_GetWindowInfo",,fr%
  399. (a$)>48 
  400.  c$="..."+
  401. a$,45) 
  402.  c$=a$
  403.  Line below - If the pathname is >48 characters, then the '...' is put
  404.  in front of the last 45. But what happens if those 45, by chance,
  405.  start with a '.' of a directory separator? The line below should remove
  406.  one dot should the string start with four of them, which indicates
  407.  that the used 45 characters did indeed start with a dot.
  408. c$,4)="...." 
  409. c$,2)
  410. $(fr%!76)=c$+
  411. redrawtitlebar(a%)
  412. zoomclick
  413.  a%,c%
  414. a%=zoomm%
  415. c%=zoomd%
  416.  adju% 
  417.  iconh% 
  418.  0:iconh%=1
  419.  1:iconh%=0
  420.  5:iconh%=6
  421.  6:iconh%=5
  422.  iconh% 
  423. *zoomm%=
  424. textuntil(!(zow%+172),33))+1
  425.  zoomm%>20 
  426.  zoomm%=20
  427. textuntil(!(zow%+172),33)<>
  428. (zoomm%) 
  429.  $(!(zow%+172))=
  430. (zoomm%):
  431. forceredraw(zoomh%,2)
  432. *zoomm%=
  433. textuntil(!(zow%+172),33))-1
  434.  zoomm%<1 
  435.  zoomm%=1
  436. textuntil(!(zow%+172),33)<>
  437. (zoomm%) 
  438.  $(!(zow%+172))=
  439. (zoomm%):
  440. forceredraw(zoomh%,2)
  441. *zoomd%=
  442. textuntil(!(zow%+236),33))+1
  443.  zoomd%>20 
  444.  zoomd%=20
  445. textuntil(!(zow%+236),33)<>
  446. (zoomd%) 
  447.  $(!(zow%+236))=
  448. (zoomd%):
  449. forceredraw(zoomh%,4)
  450. "*zoomd%=
  451. textuntil(!(zow%+236),33))-1
  452.  zoomd%<1 
  453.  zoomd%=1
  454. textuntil(!(zow%+236),33)<>
  455. (zoomd%) 
  456.  $(!(zow%+236))=
  457. (zoomd%):
  458. forceredraw(zoomh%,4)
  459.  a%<>zoomm% 
  460.  c%<>zoomd% 
  461. open(displayh%) 
  462. resizemainwindow
  463. !fr%=displayh%
  464.  "Wimp_CloseWindow",,fr%
  465.  "Wimp_GetWindowState",,fr%
  466.  "Wimp_OpenWindow",,fr%
  467. showmenu(topmenu%,topx%,topy%)
  468. keyzoom
  469.  a%,c%
  470. a%=zoomm%
  471. c%=zoomd%
  472. 8(zoomm%=
  473. textuntil(!(zow%+172),33))
  474. 9(zoomd%=
  475. textuntil(!(zow%+236),33))
  476.  zoomm%<1 
  477.  zoomm%=1
  478.  zoomm%>20 
  479.  zoomm%=20
  480.  zoomd%<1 
  481.  zoomd%=1
  482.  zoomd%>20 
  483.  zoomd%=20
  484.  zoomm%<>a% 
  485.  $(!(zow%+172))=
  486. (zoomm%):
  487. forceredraw(zoomh%,2)
  488.  zoomd%<>c% 
  489.  $(!(zow%+236))=
  490. (zoomd%):
  491. forceredraw(zoomh%,4)
  492.  a%<>zoomm% 
  493.  c%<>zoomd% 
  494. open(displayh%) 
  495. resizemainwindow
  496. !fr%=displayh%
  497.  "Wimp_CloseWindow",,fr%
  498.  "Wimp_GetWindowState",,fr%
  499.  "Wimp_OpenWindow",,fr%
  500. choicesclick
  501.  a%,c%,a$
  502.  iconh% 
  503.  2,3,4
  504. getopt(choicesh%,iconh%)=
  505. getopt(choicesh%,2) 
  506. setopt(choicesh%,2,
  507. getopt(choicesh%,3) 
  508. setopt(choicesh%,3,
  509. getopt(choicesh%,4) 
  510. setopt(choicesh%,4,
  511. setopt(choicesh%,iconh%,
  512.  7,8,9
  513. getopt(choicesh%,iconh%)=
  514. getopt(choicesh%,7) 
  515. setopt(choicesh%,7,
  516. getopt(choicesh%,8) 
  517. setopt(choicesh%,8,
  518. getopt(choicesh%,9) 
  519. setopt(choicesh%,9,
  520. setopt(choicesh%,iconh%,
  521. setopt(choicesh%,iconh%,
  522.  'Save'; store the choices *as displayed in the window* -
  523.  an 'OK' is needed to make those the current internal
  524.  choices.
  525. choicefh%=
  526. (choipath$)
  527.  choicefh%=0 
  528.  490,"Can't find the !Choices file"
  529. getopt(choicesh%,2) 
  530.  a%=0
  531. getopt(choicesh%,3) 
  532.  a%=1
  533. getopt(choicesh%,4) 
  534.  a%=2
  535. putchoice("Dithering",a%)
  536. getopt(choicesh%,7) 
  537.  a%=1
  538. getopt(choicesh%,8) 
  539.  a%=2
  540. getopt(choicesh%,9) 
  541.  a%=3
  542. putchoice("Full Screen",a%)
  543. getopt(choicesh%,16) 
  544.  a%=1 
  545.  a%=0
  546. putchoice("Auto Full Screen",a%)
  547. getopt(choicesh%,17) 
  548.  a%=1 
  549.  a%=0
  550. putchoice("Modes On Startup",a%)
  551. getopt(choicesh%,18) 
  552.  a%=1 
  553.  a%=0
  554. putchoice("Close Display",a%)
  555. #choicefh%
  556. choicefh%=0
  557.  'Default' (Accurate dithering and Best Fit for
  558.  Full Screen option).
  559. getopt(choicesh%,4)=
  560. getopt(choicesh%,2) 
  561. setopt(choicesh%,2,
  562. getopt(choicesh%,3) 
  563. setopt(choicesh%,3,
  564. getopt(choicesh%,4) 
  565. setopt(choicesh%,4,
  566. setopt(choicesh%,4,
  567. getopt(choicesh%,7)=
  568. getopt(choicesh%,7) 
  569. setopt(choicesh%,7,
  570. getopt(choicesh%,8) 
  571. setopt(choicesh%,8,
  572. getopt(choicesh%,9) 
  573. setopt(choicesh%,9,
  574. setopt(choicesh%,7,
  575. getopt(choicesh%,16) 
  576. setopt(choicesh%,16,
  577. getopt(choicesh%,17) 
  578. setopt(choicesh%,17,
  579. getopt(choicesh%,18) 
  580. setopt(choicesh%,18,
  581.  'Cancel'; reset choices to as they were when
  582.  the window opened.
  583. getopt(choicesh%,ditherit%+2)=
  584. getopt(choicesh%,2) 
  585. setopt(choicesh%,2,
  586. getopt(choicesh%,3) 
  587. setopt(choicesh%,3,
  588. getopt(choicesh%,4) 
  589. setopt(choicesh%,4,
  590. setopt(choicesh%,ditherit%+2,
  591.  fullscrn%>0 
  592. getopt(choicesh%,fullscrn%+6)=
  593. getopt(choicesh%,7) 
  594. setopt(choicesh%,7,
  595. getopt(choicesh%,8) 
  596. setopt(choicesh%,8,
  597. getopt(choicesh%,9) 
  598. setopt(choicesh%,9,
  599. setopt(choicesh%,fullscrn%+6,
  600. getopt(choicesh%,7) 
  601. setopt(choicesh%,7,
  602. getopt(choicesh%,8) 
  603. setopt(choicesh%,8,
  604. getopt(choicesh%,9) 
  605. setopt(choicesh%,9,
  606.  autofull%=0 
  607. getopt(choicesh%,16) 
  608. setopt(choicesh%,16,
  609.  autofull%=1 
  610. getopt(choicesh%,16)=
  611. setopt(choicesh%,16,
  612.  modesons%=0 
  613. getopt(choicesh%,17) 
  614. setopt(choicesh%,17,
  615.  modesons%=1 
  616. getopt(choicesh%,17)=
  617. setopt(choicesh%,17,
  618.  closedis%=0 
  619. getopt(choicesh%,18) 
  620. setopt(choicesh%,18,
  621.  closedis%=1 
  622. getopt(choicesh%,18)=
  623. setopt(choicesh%,18,
  624.  adju%=0 
  625. waitforrelease
  626. !fr%=choicesh%
  627.  "Wimp_CloseWindow",,fr%
  628.  'OK'; store choices internally and force the display window
  629.  to redraw if it is open, if the dithering method has changed.
  630. a%=ditherit%
  631. getopt(choicesh%,2) 
  632.  ditherit%=0
  633. getopt(choicesh%,3) 
  634.  ditherit%=1
  635. getopt(choicesh%,4) 
  636.  ditherit%=2
  637. df%=ditherit%-(ditherit%=2)
  638. fullscrn%=0
  639. getopt(choicesh%,7) 
  640.  fullscrn%=1
  641. getopt(choicesh%,8) 
  642.  fullscrn%=2
  643. getopt(choicesh%,9) 
  644.  fullscrn%=3
  645. getopt(choicesh%,16) 
  646.  autofull%=1 
  647.  autofull%=0
  648. getopt(choicesh%,17) 
  649.  modesons%=1 
  650.  modesons%=0
  651. getopt(choicesh%,18) 
  652.  closedis%=1 
  653.  closedis%=0
  654. waitforrelease
  655. !fr%=choicesh%
  656.  "Wimp_CloseWindow",,fr%
  657. open(displayh%) 
  658.  (a%<>ditherit%) 
  659. !fr%=displayh%
  660.  "Wimp_GetWindowState",,fr%
  661.  "Wimp_CloseWindow",,fr%
  662.  "Wimp_OpenWindow",,fr%
  663.  -- Icon handling procedures
  664. setopt(a%,c%,d%)
  665. getopt(a%,c%)<>d%
  666. !s%=a%
  667. s%!4=c%
  668.  "Wimp_GetIconState",,s%
  669.  s%!8=0 
  670.  s%!8=&200000
  671. !s%=a%
  672. s%!4=c%
  673. s%!12=&200000
  674.  "Wimp_SetIconState",,s%
  675.  -- Menu handling procedures
  676. createmainmenu
  677. datapntr%=s%
  678. $s%="SwiftJPEG"
  679. $(s%+10)="Info"
  680. $(s%+15)="Zoom"
  681. $(s%+20)="Picture"
  682. $(s%+28)="Full screen..."
  683. $(s%+43)="Choices...
  684. $(s%+56)="Quit"
  685. $(s%+61)="*"+
  686. (0)+"*"
  687. #mainmenuaddr%=
  688. makemenu(m%,mi%)
  689. openmainmenu(a%)
  690. showmenu(mainmenuaddr%,!b%-116,140+5*44+24) 
  691. showmenu(mainmenuaddr%,!b%-116,b%!4+22)
  692. attach(a%,c%,d%)
  693. !(a%+28+c%*24+4)=d%
  694. showmenu(a%,x%,y%)
  695. !topmenu%=a%:topx%=x%:topy%=y%
  696.  "Wimp_CreateMenu",,a%,x%,y%
  697. settick(a%,c%,d%)
  698.  a%!(28+c%*24)=a%!(28+c%*24)
  699.  a%!(28+c%*24)=a%!(28+c%*24)
  700. &FFFFFFFE
  701. greyoutmenu(a%,c%)
  702. /a%!(28+c%*24+8)=(a%!(28+c%*24+8)) 
  703.  (1<<22)
  704. ungreymenu(a%,c%)
  705. 3a%!(28+c%*24+8)=(a%!(28+c%*24+8)) 
  706.  (1<<22))
  707. menuselect
  708.  a%,c%,d%,a$
  709.  "Wimp_GetPointerInfo",,s%
  710. adju%=(s%!8 
  711.  "Wimp_DecodeMenu",,topmenu%,b%,s%
  712.  $s% 
  713.  "Info"
  714.  "Wimp_GetPointerInfo",,fr%
  715.  "Wimp_CreateMenu",,infoh%,!fr%-22,fr%!4-22
  716.  "Zoom"
  717.  "Wimp_GetPointerInfo",,fr%
  718. showmenu(zoomh%,!fr%-30,fr%!4+36)
  719.  "Picture"
  720.  "Wimp_GetPointerInfo",,fr%
  721.  "Wimp_CreateMenu",,jpeginfoh%,!fr%-20,fr%!4-20
  722.  "Choices..."
  723. opencentered(choicesh%)
  724.  "Full screen..."
  725. fullscreen
  726.  "Quit"
  727. quit%=
  728.  adju% 
  729. showmenu(topmenu%,topx%,topy%)
  730.  -- Full Screen handling procedures
  731. fullscreen
  732.  a%,c%,x%,y%,x1%,y1%
  733. x1%=xpic%*zoomm%/zoomd%
  734. y1%=ypic%*zoomm%/zoomd%
  735.  returnto%=-1 
  736.  returnto%=-1 
  737. returnto%=
  738.  returnto%>127 
  739.  a%=0 
  740.  127 
  741. mos%!a%=returnto%!a%
  742. returnto%=mos%
  743.  "Hourglass_Start",5
  744.  fullscrn% 
  745.  "OS_ReadModeVariable",-1,11 
  746.  ,,x%
  747.  "OS_ReadModeVariable",-1,12 
  748.  ,,y%
  749. X    x%+=1
  750. Y    y%+=1
  751. findbestfit(x1%,y1%,x%,y%,a%)
  752.  xbig%=0 
  753. findbiggest(xbig%,ybig%,bbpp%)
  754. x%=xbig%
  755. y%=ybig%
  756. a%=bbpp%
  757.  xclr%=0 
  758. findcolours(xclr%,yclr%,cbpp%)
  759. x%=xclr%
  760. y%=yclr%
  761. a%=cbpp%
  762.  "Wimp_SetColour",7
  763. 0,0,32767
  764.  "Hourglass_Off"
  765.  fullscrn%<>0 
  766. !fr%=1
  767. fr%!4=x%
  768. fr%!8=y%
  769. fr%!12=a%
  770. fr%!16=-1
  771. fr%!20=-1
  772. >127 
  773.  fr%!4<>!(
  774.  fr%!8<>!(
  775.  fr%!12<>!(
  776. +12) 
  777.  "Wimp_SetPalette"
  778.  "Wimp_SetPalette"
  779.  "Wimp_SetColour",7
  780. 0,0,32767
  781. x%=x%-x1%
  782. y%=y%-y1%
  783. !fr%=zoomm%
  784. fr%!4=zoomm%
  785. fr%!8=zoomd%
  786. fr%!12=zoomd%
  787.  "XJPEG_PlotScaled",basememo%,x%,y%,fr%,jpegleng%,df%
  788.  "OS_Byte",121 
  789.  a%=255
  790.  "OS_Byte",121 
  791.  a%<>255
  792.  (a%=112) 
  793.  (autofull%<>0) 
  794.  abortmul%=
  795. 0,0,32767
  796.  "Hourglass_Start",15
  797.  d%,d%,a%
  798.  a%=0
  799.  "XOS_CLI","FX 15"
  800.  "Hourglass_Off"
  801.  Force a redraw of the display window. Even if it's subsequently
  802.  closed before we get back to polling, this will force just one
  803.  return from the Wimp with reason code 1. If you don't do this,
  804.  then since Wimp_PollIdle is used, the polling code doesn't get
  805.  called for ages, and the Desktop screen mode isn't returned to.
  806.  Yes, I know, it's a horrible kludge. Well, sort of; it isn't
  807.  that bad really, and the benefits of Wimp_PollIdle outweigh
  808.  this little stumbling block...
  809. !fr%=displayh%
  810.  "Wimp_GetWindowState",,fr%
  811.  "Wimp_CloseWindow",,fr%
  812.  "Wimp_OpenWindow",,fr%
  813. findbiggest(
  814.  Pass three variables into which will be
  815.  passed the x and y sizes of a screen mode,
  816.  and it's colour depth (as in a mode selector
  817.  block; 0=1 bpp, 1=2bpp, 2=4bpp, 3=8bpp etc).
  818.  The routine passes the largest mode, with
  819.  the best colour depth available for the
  820.  size.
  821.  Modes where the y size is bigger than the
  822.  x size, or where the y size when doubled is
  823.  larger than the x size are not chosen as
  824.  these are assumed to be in the first case,
  825.  of undesirable aspect ratio and in the
  826.  second case, of medium resolution (like
  827.  mode 12, 640x256x16 colours).
  828.  To avoid stupid resolutions like 320x250,
  829.  which for many people will have no advantages
  830.  over, say, 320x256 though at least the
  831.  latter may have a 100Hz equivalent for those
  832.  with monitors that would otherwise letterbox
  833.  things, the x and y coordinates must both
  834.  be divisible by 4.
  835.  a%,d%,e%
  836.  "OS_ScreenMode",2 
  837.  ,,d%
  838.  e%=0 
  839.  (-d%)-1
  840.  "OS_ScreenMode",2,,e%,,,,b%,64
  841.  (b%!8>b%!12) 
  842.  ((b%!12)*2>b%!8) 
  843.  (b%!8 
  844.  4=0) 
  845.  (b%!12 
  846.  4=0) 
  847.  (b%!8>=x%) 
  848.  (b%!12>=y%) 
  849.  x%=b%!8:y%=b%!12:c%=b%!16
  850. findcolours(
  851.  As PROCbiggest, but returns the largest mode
  852.  available from the list of those with the
  853.  highest colour depth available (e.g. 640x480
  854.  by 16.7M with 1Mb VRAM, 800x600 by 16.7M with
  855.  2Mb).
  856.  a%,d%
  857.  "OS_ScreenMode",2 
  858.  ,,d%
  859.  e%=0 
  860.  (-d%)-1
  861.  "OS_ScreenMode",2,,e%,,,,b%,64
  862.  (b%!8>b%!12) 
  863.  ((b%!12)*2>b%!8) 
  864.  (b%!8 
  865.  4=0) 
  866.  (b%!12 
  867.  4=0) 
  868.  (b%!16>=c%) 
  869.  (b%!8>=x%) 
  870.  (b%!12>=y%) 
  871.  x%=b%!8:y%=b%!12:c%=b%!16
  872. findbestfit(x1%,y1%,
  873.  Pass an x and y size and three variables as for
  874.  PROCbiggest and PROCcolours. This routine returns
  875.  the mode which is of greater or equal size to the
  876.  x and y coordinates you pass.
  877.  If no mode will is big enough, PROCbiggest is called
  878.  and those values returned. If it's important, then,
  879.  check that the returned x and y sizes really are both
  880.  bigger than the passed x and y sizes.
  881.  a%,d%,e%,x2%,y2%
  882.  "OS_ScreenMode",2 
  883.  ,,d%
  884.     x2%=0
  885.     y2%=0
  886. x%=1E9
  887. y%=1E9
  888.  e%=0 
  889.  (-d%)-1
  890.  "OS_ScreenMode",2,,e%,,,,b%,64
  891.  (b%!8>b%!12) 
  892.  ((b%!12)*2>b%!8) 
  893.  (b%!8 
  894.  4=0) 
  895.  (b%!12 
  896.  4=0) 
  897.  (b%!8>=x1%) 
  898.  (b%!12>=y1%) 
  899.  ((b%!8-x1%)<=x%) 
  900.  ((b%!12-y1%)<=y%) 
  901.  x2%=b%!8:y2%=b%!12:x%=x2%-x1%:y%=y2%-y1%:c%=b%!16
  902.  x2%=0 
  903. findbiggest(x2%,y2%,c%)
  904. x%=x2%
  905. y%=y2%
  906.  -- Miscellaneous procedures
  907. readscreensize(
  908.  a%,c%
  909.  "OS_ReadModeVariable",-1,11 
  910.  ,,d%
  911.  "OS_ReadModeVariable",-1,12 
  912.  ,,e%
  913. #    d%+=1
  914. $    e%+=1
  915.  "OS_ReadModeVariable",-1,4 
  916.  ,,a%
  917.  "OS_ReadModeVariable",-1,5 
  918.  ,,c%
  919. d%=d%<<a%
  920. e%=e%<<c%
  921. read(
  922.  a%,b$
  923. -    b$=""
  924. a%=?datapntr%
  925.  a%>31 
  926.  b$+=
  927. datapntr%+=1
  928.  a%<32
  929. 3    a$=b$
  930. waitforrelease
  931.  a%,c%,d%
  932.  "Hourglass_On"
  933.  a%,c%,d%
  934.  d%=0
  935.  "Hourglass_Off"
  936. wait(a%)
  937.  a%>0
  938. B    a%-=1
  939.  Miscellaneous functions
  940. text(c%,d%,f%)
  941.  Pass an address, a text string length, and
  942.  a threshold. A string is returned of the specified
  943.  length minus characters omitted which had an ASCII
  944.  code LESS THAN the threshold. That is, pass 32 to
  945.  include spaces and anything with higher codes, say.
  946.  a%,b$
  947. T    b$=""
  948.  a%=c% 
  949.  c%+d%-1
  950.  ?a%>=f% 
  951.  b$=b$+
  952. (?a%)
  953. textuntil(c%,d%)
  954.  Pass an address, and a threshold. A string
  955.  is returned of consecutive bytes from the
  956.  address. The function exits when a byte LESS
  957.  THAN the threshold you specified.
  958.  a%,b$
  959. b    b$=""
  960. c    a%=c%
  961.  ?a%>=d% 
  962.  b$=b$+
  963. (?a%):a%+=1
  964.  ?a%<d% 
  965.  b$=255
  966. upper(a$)
  967.  Pass a string; returns the same string, all
  968.  in upper case characters.
  969.  a%,b$
  970. o    b$=""
  971.  a%=1 
  972. a$,a%,1)>="a" 
  973. a$,a%,1)<="z" 
  974.  b$+=
  975. a$,a%,1))-32) 
  976.  b$+=
  977. a$,a%,1)
  978.  -- Icon handling functions
  979. getopt(a%,c%)
  980. !fr%=a%:fr%!4=c%
  981.  "Wimp_GetIconState",,fr%
  982. =((fr%!24) 
  983.  (1<<21))<>0
  984.  -- Menu handling functions
  985. makemenu(p1%,p2%)
  986.  a%,c%,d%,e%,a$,b$,c$
  987.  p1%=m% 
  988.  p2%=mi% 
  989. a%=p1%
  990. read(a$)
  991. $(a%)=a$
  992. a%?12=7
  993. a%?13=2
  994. a%?14=7
  995. a%?15=0
  996. a%!20=44
  997. a%!24=0
  998. (a$)-3
  999. p1%+=28
  1000. read(c$)
  1001.  c$<>"*" 
  1002. p1%!8=&07000021
  1003. !p1%=0
  1004.  ul% 
  1005. (c$)-ul%)
  1006. b$,"T") 
  1007.  !p1%=!p1% 
  1008. b$,"D") 
  1009.  !p1%=!p1% 
  1010. b$,"W") 
  1011. !p1%=!p1% 
  1012. read(a$)
  1013. buffer%=
  1014. read(a$)
  1015. buflen%=
  1016. b$,"M") 
  1017.  !p1%=!p1% 
  1018. c$,ul%-1)
  1019. c$>d% 
  1020. p1%!4=-1
  1021. p1%!8=&0700F121
  1022. p1%!12=buffer%
  1023. p1%!16=-1
  1024. p1%!20=buflen%
  1025. $buffer%=c$
  1026.  c$<12 
  1027. p1%!8=&07000021
  1028. $(p1%+12)=c$
  1029. p1%!8=&07000121
  1030. p1%!12=p2%
  1031. p1%!16=-1
  1032. p1%!20=
  1033. $p2%=c$
  1034. p2%+=
  1035. p1%+=24
  1036.  c$="*"
  1037. a%!16=d%*16+32
  1038. !(p1%-24)=!(p1%-24) 
  1039.  m%=p1%:mi%=p2%
  1040. readtick(a%,c%)
  1041.  a%!(28+c%*24)=a%!(28+c%*24) 
  1042.  &FFFFFFFE 
  1043.  -- File I/O functions
  1044. filetype(a$)
  1045.  a%,c%,d%
  1046.  "OS_File",17,a$ 
  1047.  c%,,a%
  1048.  c%<>1 
  1049.  d%=-2
  1050.  (a%>>>20)=&FFF 
  1051.  d%=(a%>>>8)
  1052. &FFF 
  1053.  d%=-1
  1054. filelength(a$)
  1055. filetype(a$)<>-2 
  1056.  "OS_File",5,a$ 
  1057.  ,,,,a% 
  1058.  a%=-1
  1059.  -- JPEG handling procedures
  1060. loadpicture
  1061.  a%,c%
  1062.  abortmul%=
  1063.  Only start a load if the file is settyped as a JPEG.
  1064.  b%!40=&C85 
  1065. "jpegname$=
  1066. textuntil(b%+44,33)
  1067. $jpegleng%=
  1068. filelength(jpegname$)
  1069.  Send DataLoadAck message, if !b%<>-1 (in which case
  1070.  this routine was called because the entire application
  1071.  was launched from a double-click on a JPEG file, and
  1072.  there is no DataLoad message to reply to.
  1073.  !b%<>-1 
  1074. a%=b%!4
  1075. b%!4=task%
  1076. b%!12=b%!8
  1077. b%!16=4
  1078.  "Wimp_SendMessage",17,b%,a%
  1079. workspce%=256
  1080. setslotsize(basislot%+jpegleng%+workspce%,a%)
  1081.  a%>=basislot%+jpegleng%+workspce% 
  1082.  "Hourglass_On"
  1083. basememo%=
  1084.  sc%=basememo%+jpegleng%+16
  1085.  "Load "+jpegname$+" "+
  1086. ~basememo%
  1087. titlebarchange(displayh%,jpegname$)
  1088.  "Hourglass_Off"
  1089.  Kill scrapfile if it was used.
  1090. textuntil(b%+44,33)="<Wimp$Scrap>" 
  1091.  "XOS_File",6,"<Wimp$Scrap>"
  1092. open(displayh%) 
  1093. !fr%=displayh%
  1094.  "Wimp_CloseWindow",,fr%
  1095. resizemainwindow
  1096. !fr%=displayh%
  1097.  "Wimp_GetWindowInfo",,fr%
  1098. fr%!4=0
  1099. fr%!8=0
  1100. fr%!12=&7FFFFFF
  1101. fr%!16=&7FFFFFF
  1102.  "Wimp_OpenWindow",,fr%
  1103. opencentered(displayh%)
  1104. fillininfo
  1105.  autofull%<>0 
  1106. fullscreen
  1107.  ENDIF from check to see if there was enough memory
  1108.  to load the file.
  1109.  ENDIF from check to see if the file had the JPEG
  1110.  filetype (&C85).
  1111.  ELSE from check to see if abortmul% was FALSE; if the below
  1112.  code is executed it was.
  1113.  Send DataLoadAck if the file was a JPEG, but don't
  1114.  actually do anything with it.
  1115.  b%!40=&C85 
  1116. a%=b%!4
  1117. b%!4=task%
  1118. b%!12=b%!8
  1119. b%!16=4
  1120.  "Wimp_SendMessage",17,b%,a%
  1121.  ENDIF from check to see if abortmul% was TRUE or not.
  1122. resizemainwindow
  1123.  "OS_ReadModeVariable",-1,4 
  1124.  ,,xeig%
  1125.  "OS_ReadModeVariable",-1,5 
  1126.  ,,yeig%
  1127.  xeig%>0 
  1128. !sc%=1
  1129. sc%!8=xeig%
  1130. !sc%=2
  1131. sc%!8=1
  1132.  yeig%>0 
  1133. sc%!4=1
  1134. sc%!12=yeig%
  1135. sc%!4=2
  1136. sc%!12=1
  1137. !sc%=(!sc%)*zoomm%
  1138. sc%!4=(sc%!4)*zoomm%
  1139. sc%!8=(sc%!8)*zoomd%
  1140. sc%!12=(sc%!12)*zoomd%
  1141.  "XJPEG_Info",,basememo%,jpegleng% 
  1142.  ,,xpic%,ypic%,xdpi%,ydpi%,mem%
  1143.  IF mem%<>0 THEN ERROR 490,"JPEG requires extra workspace to plot - can't allocate it"
  1144. !fr%=0
  1145. Y$fr%!4=((-ypic%*2)*zoomm%)/zoomd%
  1146. Z#fr%!8=((xpic%*2)*zoomm%)/zoomd%
  1147. fr%!12=0
  1148.  ((fr%!4) 
  1149.  2)<>0 
  1150.  fr%!4=(((fr%!4) 
  1151.  2)-1)*2
  1152.  ((fr%!8) 
  1153.  2)<>0 
  1154.  fr%!8=(((fr%!8) 
  1155.  2)+1)*2
  1156.  "Wimp_SetExtent",displayh%,fr%
  1157. windheig%=-fr%!4
  1158. fillininfo
  1159. (jpegname$)>27 
  1160.  a$="..."+
  1161. jpegname$,24) 
  1162.  a$=jpegname$
  1163.  Line below - If the pathname is >27 characters, then the '...' is put
  1164.  in front of the last 24. But what happens if those 24, by chance,
  1165.  start with a '.' of a directory separator? The line below should remove
  1166.  one dot should the string start with four of them, which indicates
  1167.  that the used 24 characters did indeed start with a dot.
  1168. a$,4)="...." 
  1169. a$,2)
  1170. $(!(jiw%+108))=a$
  1171. (jpegleng%)
  1172. (a$)>7 
  1173.  a$=">9.5Mb!"
  1174. $(!(jiw%+236))=a$
  1175. (xpic%)
  1176. (a$)>6 
  1177.  a$="V.Wide"
  1178. $(!(jiw%+268))=a$
  1179. (ypic%)
  1180. (a$)>6 
  1181.  a$="V.Tall"
  1182. $(!(jiw%+300))=a$
  1183. ungreymenu(mainmenuaddr%,2)
  1184. ungreymenu(mainmenuaddr%,3)
  1185.