functions.html
来自「palm的pocketc」· HTML 代码 · 共 1,088 行 · 第 1/5 页
HTML
1,088 行
<html>
<head>
<title>Library Routines</title>
</head>
<body bgcolor="ffffff">
<h1>Built-in Functions</h1>
<h3>Basic I/O</h3>
<ul>
<li><i>puts(string text)</i> - append a string to the output form. Does not add a
newline. (To add a newline, add a "\n" to the end of your string). </li>
<li><i>gets(string prompt)</i> - presents an input dialog with the given string as a
prompt. Returns a string if the user pressed OK, or an empty string if the user presses
Cancel. The dialog can contain 2 lines of text, use the '\r' character to wrap to the
second line.</li>
<li><i>getsd(string prompt, string defaultValue)</i> - presents an input dialog with
the given string as a prompt and a default value in the input field. Returns a string if
the user pressed OK, or an empty string if the user presses Cancel. The dialog can contain
2 lines of text, use the '\r' character to wrap to the second line.</li>
<li><i>getsi(int x, int y, int w, string defaultValue)</i> - presents an input dialog
at the x, y coordinates specified, with
the given string as a default value. The input dialog will have an edit
field of width <i>w</i> (though the dialog will be larger). A string is
returned when the user presses OK (there is no cancel option).</li>
<li><i>getsm(int x, int y, int w, int lines, string defaultValue)</i> - exactly
like <i>getsi()</i>, but the edit field created is <i>lines</i> lines tall.</li>
<li><i>alert(string msg)</i> - displays an alert dialog with the given text.</li>
<li><i>alertc(string title, string message, string buttons, int type)</i> -
displays an alert dialog with the specified title, message, and buttons. <i>
buttons</i> is the name of a button, or a string containing several buttons
names separated by a colon (e.g. "OK:Cancel"). Returns the 0-based index of
the button pressed. <i>type</i> is one of the following: [0] info, [1]
question, [2] warning, [3] error.</li>
<li><i>promptc(string title, string message, string buttons, int type, pointer
pentry)</i> - displays a prompt dialog with the specified title, message, and
buttons. <i>buttons</i> is the name of a button, or a string containing
several buttons names separated by a colon (e.g. "OK:Cancel"). The entered
string is placed in the string pointed to by pentry. Returns the 0-based index
of the button pressed. <i>type</i> is one of the following: [0] info, [1]
question, [2] warning, [3] error.</li>
<li><i>confirm(string msg)</i> - pops up an alert dialog with the given text and Yes/No
buttons. Returns 1 for Yes, 0 for No. </li>
<li><i>clear()</i> - clears the output form. </li>
</ul>
<h3>Event System</h3>
<ul>
<li><i>event(int time)</i> - check for events in the event queue. If time is zero,
event returns immediately. If time is one, the function waits indefinitely
for an event to occur. If time is >1, time represents the timeout period
in 1/100s of a second, e.g. event(50) waits for up to one half second. Events are as follows: [0]
none, [1] key (character), [2] pen down, [3] pen up, [4] pen move, [5] page
up key (or 5-way up), [6] page down key (or 5-way down), [7-10] hard key1-4, [11] menu button, [12]
launch/home button, [13] find button, [14] calc button, [15] HotSync button,
[16] 5-way left, [17] 5-way right, [18] 5-way select.
In order to receive messages from the hard
keys or silkscreen buttons (7-15), you must call the corresponding hook function (see below).</li>
<li><i>key()</i> - retrieve the character written during the last event() </li>
<li><i>penx()</i> - retrieve the x value of the pen event processed by the last call to
wait, waitp, or event. </li>
<li><i>peny()</i> - retrieve the y value of the previous pen event. </li>
<li><i>npenx()</i> - retrieve the x value of the previous pen event in native
coordinates. </li>
<li><i>npeny()</i> - retrieve the y value of the previous pen event in native
coordinates. </li>
<li><i>pstate()</i> - returns 1 if the pen in down, 0 otherwise. </li>
<li><i>bstate()</i> - returns the state of the hard buttons. Returns [0] neither, [1] page
up, [-1] page down. </li>
<li><i>wait()</i> - wait for a pen or character event. Returns the character written to
the graffiti area or -1 for pen event. Use <em>penx()</em> and <em>peny() </em>to retrieve
the location of a pen event, or <em>key() </em>to retrieve the character.</li>
<li><i>waitp()</i> - wait for a pen event. Use <em>penx()</em> and <em>peny() </em>to
retrieve the location of a pen event.</li>
<li><i>getc()</i> - wait for and return a character written to the graffiti area.</li>
<li><em>hookhard(int bHook)</em> - if <em>bHook</em> is nonzero, hard keys (address button,
etc.) are not processed by the OS. Instead, they are intercepted by the <em>event()</em>
function. If <em>bHook</em> is zero, hard key presses are no longer intercepted.</li>
<li><em>hookmenu(int bHook)</em> - if <em>bHook</em> is nonzero, the menu silkscreen button is
not processed by the OS. Instead, it is intercepted by the <em>event()</em> function. If <em>bHook</em>
is zero, menu button presses are no longer intercepted.</li>
<li><em>hooksilk(int bHook)</em> - if <em>bHook</em> is nonzero, all silkscreen buttons
are not processed by the OS. Instead, it is intercepted by the <em>event()</em> function. If <em>bHook</em>
is zero, silkscreen button presses are no longer intercepted.</li>
<li><em>hooksync(int bHook)</em> - if <em>bHook</em> is nonzero, the HotSync
cradle button is
not processed by the OS. Instead, it is intercepted by the <em>event()</em> function. If <em>bHook</em>
is zero, the button events are no longer intercepted.</li>
</ul>
<h3>String</h3>
<ul>
<li><i>strlen(string)</i> - returns the length of a string. </li>
<li><i>substr(string, int first, int len)</i> - returns a string which consists of len
characters from the original string starting at first character. (e.g. <code>substr(“Hello”,
1, 3)</code> returns “ell”) </li>
<li><i>strleft(string, int len)</i> - returns the len leftmost characters from the
string. </li>
<li><i>strright(string, int len)</i> - returns the len rightmost characters from the
string. </li>
<li><i>strupr(string)</i> - returns the original string in all uppercase. </li>
<li><i>strlwr(string)</i> - returns the original string in all lowercase. </li>
<li><i>strstr(string str, string sub, int first)</i> - searches str for a substring sub
starting at the character first. Returns the starting position of sub within str or -1 on
failure. </li>
<li><i>hex(int n)</i> - returns the hexadecimal representation of <i>n</i> </li>
<li><i>format(float f, int prec)</i> - returns the string representation of <i>f</i> with <i>prec</i>
decimal places.</li>
<li><em>strtoc(string str, pointer ptr)</em> - fill the array of chars pointed to by <em>ptr</em>
with the characters from the string <em>str</em>. <em>ptr</em> must either point to an
array of characters long enough to hold the string plus the terminating 0, or it must be a
pointer alloced with <em>malloc()</em>. If the pointer was allocated by <em>malloc()</em>,
you must be sure that all the memory is of type char by calling <em>settype()</em>.</li>
<li><em>ctostr(pointer ptr)</em> - takes the char array pointed to by <em>ptr</em>, and
returns a string composed of its characters. The memory pointed to by <em>ptr</em> must be
of type char and must end with a 0.</li>
<li><i>strtok(string source, pointer result, string delims, int first)</i>
- breaks a string into tokens which are delimited by a character from the <i>delims</i>
string. The resulting string is stored in the location referenced by the
pointer <i>res</i>. Returns the location to use for <i>first</i> for the
next call, or -1 if the end was already reached. If <i>result</i> is 0 or
null, returns the number of tokens in the string. Example: string result;
int first; first = strtok("1:2#3", &result, "#:",
0); while (first != -1) { puts(result); first = strtok("1:2#3",
&result, "#:", first); } This would print "1"
"2" and "3"</li>
</ul>
<h3>Math</h3>
<ul>
<li><i>cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh (float)</i>
- returns the expected trigonometric value, using radians. These functions require <b>MathLib</b>
to be present. </li>
<li><i>pow(float x, float y)</i> - returns x^y. This function requires <b>MathLib</b>
to be present. </li>
<li><i>atan2(float y, float x)</i> - returns the arctangent of y/x. This function
requires <b>MathLib</b> to be present. </li>
<li><i>sqrt(float x)</i> - returns square root of x. This function requires <b>MathLib</b>
to be present. </li>
<li><i>log(float x)</i> - returns natural log of x. This function requires <b>MathLib</b> to
be present. </li>
<li><i>log10(float x)</i> - returns log base 10 of x. This function requires <b>MathLib</b>
to be present. </li>
<li><i>exp(float x)</i> - returns e^x. This function requires <b>MathLib</b> to be present. </li>
<li><i>rand()</i> - returns a random float between 0 and 1. </li>
<li><i>random(int n)</i> - returns a random int between 0 and n-1. </li>
<li><i>mathlib()</i> - returns 1 if MathLib is present, 0 otherwise. </li>
</ul>
<b>
<p>Note:</b> Functions that require <b>MathLib</b> will return integer 0 if the library is
not present. </p>
<h3>Graphics</h3>
<ul>
<li><b>General APIs</b>
<ul>
<li><i>graph_on()</i> - switches to the graphics form.</li>
<li><i>graph_off()</i> - switches from the graphics form to the output form. The
appearance of the graphics form is not preserved.</li>
<li><i>title(string title)</i> - set the graphic form title to <i>title</i>.</li>
<li><i>clearg()</i> - clear the graphics form.</li>
<li><em>saveg()</em> - save the graphics form internally. Returns 0 on failure, 1 otherwise.</li>
<li><em>restoreg()</em> - restore the graphics form previously saved by a call to saveg().
This can only be called once for each time saveg() is called.</li>
<li><i>pushdraw()</i> - push the current drawing state (pen colors,
native/standard drawing mode, etc.). This function should be called before
calling any other drawing function. This does nothing on OS < 3.5.</li>
<li><i>popdraw()</i> - pop the previous drawing state. This function should be
called after completing a set of drawing operations (matching the previous
call to pushdraw()). This does nothing on OS < 3.5</li>
<li><i>drawnative(int bNative)</i> - sets the current drawing mode to native
coordinates if <i>bNative</i> is true, standard (160x160) otherwise, which
determines how coordinates are interpreted. You must
return to standard drawing mode before allowing any UI to be drawn (e.g.
calling alert() or confirm()). When drawing natively, first call pushdraw(),
then this function, complete your drawing, then popdraw() to reset the drawing
state. Because this mode affect OS UI (such as the find dialog box), you
should only enable native drawing mode when drawing, and disable as soon as
possible.</li>
<li><i>getscreenattrib(int attrib)</i> - get a screen attribute. Available
attributes are width[0], height[1], density[5].</li>
</ul>
</li>
<li><b>Text Operations</b>
<ul>
<li><i>text(int x, int y, string str)</i> - display a string str at locations (x,y).</li>
<li><i>textattr(int font, int color, int underline)</i> - set the current text drawing
attributes. font is a number 0-6. Available fonts are normal[0], bold[1], large[2],
symbol[3], symbol11[4], symbol7[5], LED[6], Large Bold[7] (OS 3.0 only). color is a number
0-2. Available colors are background[0], foreground[1], inverted[2]. underline is a number 0-2.
Underline modes are none[0], solid[1], dotted[2].</li>
<li><em>textalign(char alignmentYX)</em> - sets the alignment that <em>text()</em>
uses. The parameter is a number between 0 and 22, where the first decimal digit describes
the vertical alignment, and the second describes the horizontal. left[0], center[1],
right[2].</li>
<li><i>textwidth(string str)</i> - returns the width in pixels of <i>str</i>
with the current font settings.</li>
</ul>
</li>
<li><b>Drawing Primitives</b>
<ul>
<li><i>pixel(int col, int x, int y)</i> - draws a pixel at (x, y) in color col.
background[0], foreground[1], XOR[3].</li>
<li><i>line(int col, int x1, int y1, int x2, int y2)</i> - draws a line from (x1, y1)
to (x2, y2) in color col. background[0], foreground[1], dotted[2], XOR[3].</li>
<li><i>rect(int col, int x1, int y1, int x2, int y2, int radius)</i> - draws a
rectangle from (x1, y1) to (x2, y2) in color col with corners of radius<i> radius</i>. A
radius of 0 has square edges. background[0], foreground[1], XOR[3]. (This function doesn't support
dotted)</li>
<li><i>frame(int col, int x1, int y1, int x2, int y2, int radius)</i> - same as rect() but
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?