Edo Joined: 10 Aug 2005 Posts: 390 Location: Prismen - Vis
Posted: Wed Sep 28, 2005 5:08 pm Post subject: MBMView code snippet/applet
MBMView enables you to view (scroll) bitmaps in (multi)MBM files and to save them.
You can extract bitmaps from ROM-drive too, Jonas
It's the simplest viewer and at the same time enough powerful
It's only 1KB big and consists of only 2 procedures
Edo
Code:
REM MBMView code snippet ©Edo 28.09.05.
REM View MBM files (Scroll & Save bitmaps)
INCLUDE "Const.oph"
INCLUDE "System.oxh"
PROC Main:
GLOBAL MBM$(255)
LOCAL i%, Ev&(16), p%(6)
start::
AT 2, 1 : PRINT "MBM view - code applet ©Edo 2005" + REPT$(" ", 27)
AT 2, 2 : PRINT "Select MBM file" + REPT$(" ", 50)
dINIT "MBM view", KDlgButRight%
dFILE MBM$, "MBM file:", KDFileSelectorWithSystem% OR KDFileSelectorWithRom%
dBUTTONS "Cancel",KDButtonEsc%, "Ok",KDButtonEnter%
BUSY OFF
IF 0 = DIALOG
RETURN
ENDIF
AT 2, 1 : PRINT "--> RIGHT arrow <-- LEFT arrow / SAVE - “S” / ESC - Exit"
AT 2, 2 : PRINT "File:", MBM$
AT 2, 3 : PRINT "Bitmap "
ONERR End::
Draw:(0, 0)
WHILE KTrue%
DO
GETEVENT32 Ev&()
IF Ev&(KEvAType%) = kKeyRightArrow32%
i% = i% + 1
ONERR Lastbitmap
Draw:(i%, 0)
CONTINUE
Lastbitmap::
ONERR OFF
gIPRINT "Last bitmap", 2
i% = i% - 1
CONTINUE
ELSEIF Ev&(KEvAType%) = kKeyLeftArrow32%
i% = i% - 1
IF i% < 0
i%=0
gIPRINT "First bitmap", 2
CONTINUE
ENDIF
Draw:(i%, 0)
ELSEIF Ev&(KEvAType%) = ASC("s")
Draw:(i%, 1)
ELSEIF Ev&(KEvAType%) = kKeyEsc%
gIPRINT "Closing"+CHR$(133),2
PAUSE -20
STOP
ENDIF
UNTIL 0
ENDWH
End::
ONERR OFF
IF i%
ELSE
AT 2, 3 : PRINT "Error viewing file!"
BUSY "Getting dialog"+CHR$(133)
GOTO start::
ENDIF
ENDP
PROC Draw:(bit%, save%)
LOCAL ypos%, xpos%, width%, height%, bitmap%, p%(6), name$(255)
ypos%=45 : xpos%=10
bitmap% = gLOADBIT(MBM$, KgLoadBitReadOnly%, bit%)
width% = gWIDTH : height% = gHEIGHT
AT 9, 3 : PRINT RIGHT$("000"+GEN$(bit%,3),3), "("+NUM$(width%, 4)+"x"+NUM$(height%, 4)+" pixels)"+REPT$(" ",10)
gUSE 1
gAT xpos% - 1, ypos% - 1
gFILL gWIDTH, gHEIGHT, KGModeClear%
gGREY 1
gBOX width% + 2, height% + 2
gAT xpos%, ypos%
gCOPY bitmap%, 0, 0, width%, height%, 3
IF save%
name$ = PARSE$(".", MBM$, p%()) + RIGHT$("000"+GEN$(bit%,3),3) + ".mbm"
save::
name$ = SaveAsFileDialog$:(name$,#(0))
IF LEN(name$)
IF LEFT$(name$, 1) = "Z"
gIPRINT "Cannot save to ROM-drive", 2
GOTO save::
ENDIF
gUSE bitmap%
gSAVEBIT name$
gIPRINT name$+" saved", 2
ENDIF
ENDIF
gCLOSE bitmap%
ENDP