John.Wiley.and.Sons.Rapid.Mobile.Enterprise.Development.for.Symbian.OS.An.Introduction.to.OPL.Application.Design.and.Programming.May.2005.eBook-LinG (779881), страница 35
Текст из файла (страница 35)
Sets the current position to 0,0,its top left corner.gLOADBIT loads Symbian OS Picture files, whichare naturally in the same file format that is savedby gSAVEBIT. Symbian OS Picture files can also begenerated by exporting files created by the Sketch application. These are called multi-bitmap files (MBMs),though often containing just one bitmap as in the caseof gSAVEBIT or Sketch files, and are often given anextension .MBM.OPL COMMAND LIST199The bitmap is kept as a local copy in memory.gLOADBIT returns id%, which identifies this bitmapfor other keywords.A write% argument of KgLoadBitReadOnly% setsread-only access. Attempts to write to the bitmap inmemory will be ignored, but the bitmap can be usedby other programs without using more memory.
UsingKgLoadBitWriteable% for write% allows you to writeto and re-save the bitmap, which is the default.KgLoadBitReadOnly%KgLoadBitWriteable%01read-only accessread and write accessConstants are supplied in Const.oph.For bitmap files that contain more than one bitmap,index% specifies which one to load. For the first bitmap,use index%=0, which is also the default value.See also gCLOSE.gLOADFONTLoads a fontUsage: fileId%=gLOADFONT(file$)Loads the user-defined fonts specified in the file file$and returns the file ID of the font file, which can be usedonly with gUNLOADFONT. The maximum number offont files that may be loaded at any one time is 16.To use the fonts in a loaded font file you need to usetheir published UIDs, which will be defined in the fontfile itself, for example:fileId%=gLOADFONT("Music1")gFONT KMusic1Font1&...gUNLOADFONT fileId%gFONT itself is very efficient, so you should normallyload all required fonts at the start of a program.Note that the built-in fonts are automatically available, and do not need loading.See gUNLOADFONT.GLOBALDeclares global variablesUsage: GLOBAL variables200OPL COMMAND LISTDeclares variables to be used in the current procedure(as does the LOCAL command) and (unlike LOCAL)in any procedures called by the current procedure, orprocedures called by them.The variables may be of four types, depending onthe symbol they end with:Variable names not ending with $, %, &, or () arefloating point variables, for example price, xThose ending with a % are integer variables, forexample x%, sales92%Those ending with an & are long integer variables, forexample x&, sales92&Those ending with a $ are string variables.
String variable names must be followed by the maximum lengthof the string in brackets, for example names$(12), a$(3)Array variables have a number immediately followingthem in brackets that specifies the number of elementsin the array. Array variables may be of any type, forexample: x(6),y%(5),f$(5,12),z&(3).When declaring string arrays, you must give twonumbers in the brackets. The first declares the numberof elements, the second declares their maximum length.For example, surname$(5,8) declares five elements,each up to eight characters long.Variable names may be any combination of up to 32numbers and alphabetic characters and the underscorecharacter. They must start with an alphabetic characteror an underscore.The length of a variable name includes the %, &, or$ sign, but not the () in string and array variables.More than one GLOBAL or LOCAL statement may beused, but they must be on separate lines, immediatelyafter the procedure name.See also LOCAL.gMOVEMoves the current positionUsage: gMOVE dx%,dy%Moves the current position dx% to the right and dy%downwards, in the current drawable.A negative dx% causes movement to the left; anegative dy% causes upward movement.See also gAT.OPL COMMAND LISTgORDER201Moves the selected windowUsage: gORDER id%,position%Sets the window specified by id% to the selected foreground/background position, and redraws the screen.Position 1 is the foreground window, position 2 is next,and so on.
Any position greater than the number ofwindows is interpreted as the end of the list.On creation, a window is at position 1 in the list.Raises an error if id% is a bitmap.See also gRANK.gORIGINXWindow’s X positionUsage: x%=gORIGINXReturns the gap between the left side of the screen andthe left side of the current window.Raises an error if the current drawable is a bitmap.gORIGINYWindow’s Y positionUsage: y%=gORIGINYReturns the gap between the top of the screen and thetop of the current window.Raises an error if the current drawable is a bitmap.GOTOJumps to a labeled lineUsage:GOTO label or GOTO label::...label::Goes to the line following the label:: and continuesfrom there.
The label:Must be in the current procedureMust start with a letter and end with a double colon,although the double colon is not necessary in theGOTO statementMay be up to 32 characters long, excluding thecolonsGOTOMARKMakes a bookmarked record the current record202OPL COMMAND LISTUsage: GOTOMARK b%Makes the record with bookmark b%, as returned byBOOKMARK, the current record. b% must be a bookmark in the current view.gPATTDraws a pattern-filled rectangleUsage: gPATT id%,width%,height%,mode%Fills a rectangle of the specified size from the currentposition with repetitions of the drawable id%.As with gCOPY, this command can copy both setand clear pixels, so the same modes are available aswhen displaying text.
Set mode%=0 for set, 1 for clear,2 for invert, or 3 for replace. 0, 1, and 2 act only on setpixels in the pattern; 3 copies the entire rectangle, withset and clear pixels.If you set id%=–1 a predefined grey pattern is used.The current position is unaffected.gPEEKLINEReads a horizontal line from a drawableUsage: gPEEKLINE id%,x%,y%,d%(),ln%,mode%Reads a horizontal line from the black plane of thedrawable id%, length ln%, starting at x%,y%.
Theleftmost 16 pixels are read into d%(1), with the firstpixel read into the least significant bit.gPEEKLINE has an extra optional parameter mode%to specify the color mode:mode%−1012color modeblack and whiteblack and white4-color mode16-color modecolor of pixel thatsets bitsblackwhitewhitewhiteThe default mode% is −1. For 4- and 16-color modes,2 and 4 bits per pixel, respectively are used. This is toenable the color of the pixel to be ascertained from thebits that are set. White results in all 2 or 4 bits beingset, while black sets none of them. For example, in a4-color window, with the color set bygCOLOR 16,16,16OPL COMMAND LIST203a pixel of a line would peek as 0001 in binary.
Similarly,a pixel of a line with the color set togCOLOR 80,80,80would result in the value 0101 in binary when peeked.The array d%() must be long enough to hold thedata. You can work out the number of integers requiredwith ((ln%+15)/16) (using whole-number division).If the optional parameter mode% is used, the arraysize allowed must be adjusted accordingly: it must beat least twice as long as the array needed for black andwhite if the line you wish to peek is in 4-color mode,and four times as long in 16-color mode.gPOLYDraws a polygonUsage: gPOLY a%()Draws a sequence of lines, as if by gLINEBY andgMOVE commands.The array is set up as follows:a%(1)a%(2)a%(3)a%(4)a%(5)a%(6)a%(7)......starting x positionstarting y positionnumber of pairs of offsetsdx1%dy1%dx2%dy2%, etc.}} further pairs...The following constants can be used for the first fivearray indices:KgPolyAStartX%KgPolyAStartY%KgPolyANumPairs%KgPolyANumDx1%KgPolyANumDy1%12345Each pair of numbers dx1%,dy1%, for example, specifies a line or a movement.
To draw a line, dy% is the204OPL COMMAND LISTamount to move down, while dx% is the amount tomove to the right multiplied by two.To specify a movement (i.e. without drawing aline) work out the dx%,dy% as for a line, then add1 to dx%.(For drawing/movement up or left, use negativenumbers.)gPOLY is quicker than combinations of gAT,gLINEBY, and gMOVE.Example (to draw three horizontal lines 50 pixelslong at positions 20,10, 20,30, and 20,50):a%(1)=20 :a%(2)=10REM 20,10a%(3)=5REM 5 operationsa%(4)=50*2 :a%(5)=0REM draw right 50a%(6)=0*2+1 :a%(7)=20REM move down 20a%(8)=-50*2 :a%(9)=0REM draw left 50a%(10)=0*2+1 :a%(11)=20REM draw left 50a%(12)=50*2 :a%(13)=0REM draw right 50gPOLY a%()gPRINTPrints a list into a drawableUsage: gPRINT list of expressionsDisplays a list of expressions at the current position inthe current drawable.
All variable types are formattedas for PRINT.Unlike PRINT, gPRINT does not end by movingto a new line. A comma between expressions isstill displayed as a space, but a semicolon has noeffect. gPRINT without a list of expressions does nothing.See also gPRINTB, gPRINTCLIP, gTWIDTH, gXPRINT,gTMODE.gPRINTBPrints text into a cleared boxUsage: any ofgPRINTB t$,w%,al%,tp%,bt%,m%gPRINTB t$,w%,al%,tp%,bt%gPRINTB t$,w%,al%,tp%gPRINTB t$,w%,al%gPRINTB t$,w%OPL COMMAND LIST205Displays text t$ in a cleared box of width w% pixels.The current position is used for the left side of the boxand for the baseline of the text.al% controls the alignment of the text in the box:KgPrintBRightAligned%KgPrintBLeftAligned%KgPrintBDefAligned%KgPrintBCentredAligned%1223right alignmentleft alignmentdefault alignment (left)centeredtp% and bt% are the clearances between the text andthe top/bottom of the box. Together with the currentfont size, they control the height of the box.
An error israised if tp% plus the font ascent is greater than 255.m% controls the margins. For left alignment, m% isan offset from the left of the box to the start of the text.For right alignment, m% is an offset from the right ofthe box to the end of the text. For centering, m% is anoffset from the left or right of the box to the region inwhich to center, with positive m% meaning left andnegative meaning right:KgPrintBDefTop%0 default top clearanceKgPrintBDefBottom% 0 default bottom clearanceKgPrintBDefMargin% 0 default marginThese constants are supplied in Const.oph.See also gPRINT, gPRINTCLIP, gTWIDTH, gXPRINT.gPRINTCLIPPrints text that fits within defined areaUsage: w%=gPRINTCLIP(text$,width%)Displays text$ at the current position, displaying onlyas many characters as will fit inside width% pixels.Returns the number of characters displayed.See also gPRINT, gPRINTB, gTWIDTH, gXPRINT,gTMODE.gRANKGets foreground/background position of the currentwindowUsage: rank%=gRANKReturns the foreground/background position – from 1to 64 – of the current window.
Raises an error if thecurrent drawable is a bitmap.206OPL COMMAND LISTSee also gORDER.gSAVEBITSaves the current drawableUsage: gSAVEBIT name$,width%,height%orgSAVEBIT name$Saves the current drawable as the named bitmap file. Ifwidth% and height% are given, then only the rectangleof that size from the current position is copied.gSAVEBIT does not add a default filename extensionto the input argument name if none is provided onthe machine.gSCROLLScrolls pixelsUsage: gSCROLL dx%,dy%,x%,y%,wd%,ht%orgSCROLL dx%,dy%Scrolls pixels in the current drawable by offset dx%,dy%. Positive dx% means to the right, and positivedy% means down. The drawable itself does not changeits position.If you specify a rectangle in the current drawable,at x%,y% and of size wd%,ht%, only this rectangleis scrolled.The areas dx% wide and dy% deep ‘left behind’ bythe scroll are cleared.The current position is not affected.gSETPENWIDTH Sets the pen widthUsage: gSETPENWIDTH width%Sets the pen width in the current drawable to width%pixels.gSETWINChanges position/size of the current windowUsage: gSETWIN x%,y%,width%,height%orgSETWIN x%,y%Changes position and, optionally, the size of the current window.An error is raised if the current drawable is a bitmap.The current position is unaffected.If you use this command on the default window, youmust also use the SCREEN command to ensure that thearea for PRINT commands to use is wholly containedwithin the default window.OPL COMMAND LISTgSTYLE207Sets the style of text used in subsequent print commandsUsage: gSTYLE style%Sets the style of text displayed in subsequent gPRINT,gPRINTB, and gPRINTCLIP commands on the currentdrawable.