home *** CD-ROM | disk | FTP | other *** search
- 10 ! ******************************************************************
- 20 !
- 30 ! Example: Bitmap Viewer
- 40 !
- 50 ! This program demonstrates the use of the BITMAP widget. It
- 60 ! allows you to bring in and display bitmaps, as well as select
- 70 ! portions of them and save them in a file.
- 80 !
- 90 ! It also demonstrates the SCROLLABLE attribute for the PANEL ...
- 100 ! in particular the various operations needed to make SCROLL WIDTH
- 110 ! and SCROLL HEIGHT as correct as possible..
- 120 !
- 130 ! ******************************************************************
- 140 !
- 150 ! A few variables:
- 160 !
- 170 ! S$: General-purpose string.
- 180 ! N: General-purpose variable.
- 190 ! Btn: Returns button value from dialogs.
- 200 ! Sc: Scroll factor.
- 210 ! Bitfile$: Name of bitmap file to be read.
- 220 ! Dirname$: Directory name returned from FILE dialog.
- 230 ! B1$(*): Stores MENU BUTTONS.
- 240 ! A1$,A2$: Stores dialog attributes.
- 241 DLL UNLOAD ALL
- 250 DLL LOAD "HTBtree"
- 260 DLL GET "void HTBtree:Tctrl"
- 270 DIM S$[256]
- 280 INTEGER N,Btn,Sc
- 290 DIM Bitfile$[100],Dirname$[100],Btns$(1:3)[50],A1$[50],A2$[50]
- 300 !
- 310 DATA "BMP File","XWD File","Cancel","DIALOG BUTTONS","SELECTION",20
- 320 READ Btns$(*),A1$,A2$,Sc
- 330 !
- 340 ! Widget dimensions.
- 350 !
- 360 INTEGER Pw,Ph,Px,Py,Iw,Ih,Ww,Wh,Wx,Wy
- 370 !
- 380 ! Variables for display scaling.
- 390 !
- 400 INTEGER Cursor,D(1:4),Dw,Dh
- 410 !
- 420 ! Get display size.
- 430 !
- 440 GESCAPE CRT,3;D(*)
- 450 Dw=D(3)-D(1)
- 460 Dh=D(4)-D(2)
- 470 !
- 480 CLEAR SCREEN
- 490 KEY LABELS OFF
- 500 RUNLIGHT OFF
- 510 STATUS CRT,10;Cursor
- 520 CONTROL CRT,10;0
- 530 !
- 540 Pw=Dw*.7 ! PANEL width.
- 550 Ph=Dh*.7 ! PANEL height.
- 560 Px=(Dw-Pw)/2! Center PANEL.
- 570 Py=(Dh-Ph)/2
- 580 !
- 590 ! Create PANEL for BITMAP widget. Note how the SCROLL WIDTH
- 600 ! and HEIGHT are set to a small value so that scroll bars will not
- 610 ! appear initially. The actual heights are set later to fit the bitmap
- 620 ! that has been loaded.
- 630 !
- 640 ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)
- 650 CONTROL @Main;SET ("X":Px,"Y":Py,"WIDTH":Pw,"HEIGHT":Ph)
- 660 CONTROL @Main;SET ("TITLE":"Example: Bitmap Viewer")
- 670 CONTROL @Main;SET ("SIZE CONTROL":"SCROLLABLE","MINIMIZABLE":1)
- 680 CONTROL @Main;SET ("SCROLL WIDTH":1,"SCROLL WIDTH UNITS":Sc)
- 690 CONTROL @Main;SET ("SCROLL HEIGHT":1,"SCROLL HEIGHT UNITS":Sc)
- 700 !
- 710 ! Build menu.
- 720 !
- 730 ASSIGN @Menu TO WIDGET "PULLDOWN MENU";PARENT @Main
- 740 CONTROL @Menu;SET ("LABEL":"Menu")
- 750 ASSIGN @Getfile TO WIDGET "MENU BUTTON";PARENT @Menu
- 760 CONTROL @Getfile;SET ("LABEL":"Get Bitmap File")
- 770 ASSIGN @Savefile TO WIDGET "MENU BUTTON";PARENT @Menu
- 780 CONTROL @Savefile;SET ("LABEL":"Cut Bitmap To File")
- 790 ASSIGN @Cd TO WIDGET "MENU BUTTON";PARENT @Menu
- 800 CONTROL @Cd;SET ("LABEL":"Change Directory")
- 810 ASSIGN @S TO WIDGET "MENU SEPARATOR";PARENT @Menu
- 820 ASSIGN @Quit TO WIDGET "MENU BUTTON";PARENT @Menu
- 830 CONTROL @Quit;SET ("LABEL":"Quit")
- 840 !
- 850 ! Create and size BITMAP widget. (Setting RETAIN RASTER makes the
- 860 ! widget redraw quickly when overwritten by a dialog.)
- 870 !
- 880 ASSIGN @Bitmap TO WIDGET "BITMAP";PARENT @Main
- 890 CONTROL @Bitmap;SET ("RETAIN RASTER":1,"AUTO SIZE":1)
- 900 STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
- 910 Wx=Iw*.01
- 920 Wy=Ih*.01
- 930 Wh=Ih*.98
- 940 Ww=Iw*.98
- 950 CONTROL @Bitmap;SET ("X":Wx,"Y":Wy,"WIDTH":Ww,"HEIGHT":Wh)
- 960 !
- 970 ! Set events.
- 980 !
- 990 ON EVENT @Getfile,"ACTIVATED" GOSUB Getbitfile
- 1000 ON EVENT @Savefile,"ACTIVATED" GOSUB Savebits
- 1010 ON EVENT @Cd,"ACTIVATED" GOSUB Chdir
- 1020 ON EVENT @Quit,"ACTIVATED" GOTO Finis
- 1030 !
- 1040 CONTROL @Main;SET ("VISIBLE":1)
- 1050 !
- 1060 ! Loop and wait for input.
- 1070 !
- 1080 LOOP
- 1090 END LOOP
- 1100 STOP
- 1110 !
- 1120 ! *********************** End of Main Program **********************
- 1130 !
- 1140 ! This routine gets a bitmap file and displays it. Note how it gets
- 1150 ! the bitmap size and sets up PANEL scrolling accordingly. Note also
- 1160 ! how it turns the BITMAP widget invisible so the display will
- 1170 ! "thrash" as little as possible.
- 1180 !
- 1190 Getbitfile:!
- 1200 S$="Please enter the name of a bitmap (.XWD or .BMP) file:"
- 1210 DIALOG "FILE",S$,Btn;RETURN ("SELECTION":Bitfile$)
- 1220 !
- 1230 IF Btn=0 THEN
- 1240 CLEAR ERROR
- 1250 ON ERROR GOSUB Errtrap
- 1260 CONTROL @Bitmap;SET ("VISIBLE":0,"BITMAP FILE":Bitfile$)
- 1270 OFF ERROR
- 1280 IF ERRN<>0 THEN
- 1290 DIALOG "ERROR","Can't open file / invalid bitmap file."
- 1300 CONTROL @Bitmap;SET ("BITMAP FILE":"","VISIBLE":1)
- 1310 ELSE
- 1320 CONTROL @Bitmap;SET ("VISIBLE":0)
- 1330 STATUS @Bitmap;RETURN ("BITMAP HEIGHT":Wh,"BITMAP WIDTH":Ww)
- 1340 CONTROL @Main;SET ("SCROLL HEIGHT":2+INT(Wh/Sc))
- 1350 CONTROL @Main;SET ("SCROLL WIDTH":2+INT(Ww/Sc))
- 1360 CONTROL @Bitmap;SET ("VISIBLE":1)
- 1370 DIALOG "INFORMATION","File read completed!"
- 1380 END IF
- 1390 END IF
- 1400 RETURN
- 1410 !
- 1420 ! This routine allows you to cut a section of a bitmap and
- 1430 ! save it in a file. Note how string variables are used in
- 1440 ! the FILE dialog to specify the DIALOG BUTTONS attribute and
- 1450 ! the SELECTION attribute in order to keep the length of the
- 1460 ! statement compact.
- 1470 !
- 1480 Savebits:!
- 1490 S$="Enter file name, then click-and-drag image to save:"
- 1500 DIALOG "FILE",S$,Btn;SET (A1$:Btns$(*)),RETURN (A2$:Bitfile$)
- 1510 !
- 1520 SELECT Btn
- 1530 CASE 0
- 1540 S$="BMP"! Dump format is MS-Windows .BMP file.
- 1550 CASE 1
- 1560 S$="XWD"! Dump format is X11 XWD format.
- 1570 CASE 2
- 1580 RETURN
- 1590 END SELECT
- 1600 !
- 1610 CLEAR ERROR
- 1620 ON ERROR GOSUB Errtrap
- 1630 CONTROL @Bitmap;SET ("DUMP FORMAT":S$,"DUMP AREA":Bitfile$)
- 1640 OFF ERROR
- 1650 IF ERRN<>0 THEN
- 1660 DIALOG "ERROR","Can't open file."
- 1670 ELSE
- 1680 DIALOG "INFORMATION","Bitmap saved to "&S$&" file."
- 1690 END IF
- 1700 !
- 1710 RETURN
- 1720 !
- 1730 !
- 1740 ! This routine changes directories.
- 1750 !
- 1760 Chdir:!
- 1770 S$="Please enter the name of a directory:"
- 1780 ! DIALOG "FILE",S$,Btn;RETURN ("DIRECTORY":Dirname$)
- 1790 DIM Retstr$[260]
- 1800 Tctrl(S$,Dirname$)
- 1810 !
- 1820 Err=0
- 1830 CLEAR ERROR
- 1840 ON ERROR GOSUB Errtrap
- 1850 MASS STORAGE IS Dirname$
- 1860 OFF ERROR
- 1870 IF ERRN<>0 THEN
- 1880 DIALOG "ERROR","Can't change directory!"
- 1890 END IF
- 1900 RETURN
- 1910 !
- 1920 ! Dummy routine for trapping errors.
- 1930 !
- 1940 Errtrap: ERROR RETURN
- 1950 !
- 1960 ! ************** Go Here When Done ***********************
- 1970 !
- 1980 Finis:!
- 1990 ASSIGN @Main TO *
- 2000 CLEAR SCREEN
- 2010 KEY LABELS ON
- 2020 RUNLIGHT ON
- 2030 CONTROL CRT,10;Cursor
- 2040 END
-