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