屏幕#
介绍#
screen 类派生自 brain 基类。它控制 IQ(第一代)大脑如何在其内置屏幕上显示文本和数值。
IQ(第一代)大脑屏幕最多支持 5 行 21 列文本。

使用权#
可以通过以下方式访问 screen 类:
Brain.Screen
笔记#
The
screenobject is provided by the Brain. It is not constructed directly.项目使用单个全局
Brain对象,因此屏幕函数使用Brain.Screen调用。
例子#
/* This constructor is required when using VS Code.
A Brain is generated automatically at the start of
VEXcode projects. */
// Create the Brain
brain Brain = brain();
// Print text to the Brain screen
Brain.Screen.print("Hello!");
成员功能#
screen 类包含以下成员函数:
print— 将格式化的文本、数字或布尔值打印到 Brain 屏幕。setCursor— 将文本光标移动到指定的行和列。newLine— 清除当前行的剩余内容并将光标移至下一行。clearLine— 清除当前行的剩余部分或清除指定的行。row— 返回要打印文本的行。column— 返回要打印文本的列。getStringHeight— 使用当前字体返回字符串的像素高度。getStringWidth— 使用当前字体返回字符串的像素宽度。printAt— 在 x, y 像素位置打印格式化文本(可选不透明)。clearScreen— 清除整个屏幕(可选择清除为指定颜色)。setFont— 设置用于屏幕打印的字体。setPenWidth— 设置绘制的线条和形状轮廓的粗细。setPenColor— 设置文本、像素、线条和形状轮廓的颜色。setFillColor— 设置绘制形状和打印文本背景的填充颜色。setOrigin— 设置屏幕坐标的原点。setClipRegion— 将屏幕输出限制在矩形区域内。drawPixel— 在坐标处绘制一个像素。drawLine— 在两点之间画一条线。drawRectangle— 在 x, y 位置绘制一个指定大小的矩形。drawCircle— 在 x, y 位置绘制一个具有指定半径的圆。render— 启用双缓冲或将后缓冲区渲染到屏幕。
在调用任何 screen 成员函数之前,必须创建一个 brain 实例,如下所示:
// Create the Brain
brain Brain = brain();
print#
在 IQ(第一代)大脑屏幕上显示文本、数字或布尔值。
Available Functions1 — 使用字符串字面量或只读 C 风格字符串打印格式化文本。
void print( const char* format, ... );
Parameters2 — 使用可修改的字符数组打印格式化文本。
void print( char* format, ... );
范围 |
类型 |
描述 |
|---|---|---|
|
|
以字符串字面量或只读 C 风格字符串形式提供的格式字符串(例如, |
|
|
以可修改字符数组形式提供的格式字符串。 |
|
插入到格式字符串中的一个或多个附加值,以逗号分隔。 |
此函数不返回值。
NotesOutput begins at the current cursor position on the screen.
打印文本使用 屏幕字体。
打印文本使用 笔颜色。
使用
print打印的文本始终带有背景,背景颜色由 当前填充颜色决定。使用格式字符串时,传递的值的数量和类型必须与字符串中的 格式说明符 匹配。
// Display a message at the starting cursor
Brain.Screen.print("Hello, Robot!");
setCursor#
将光标移动到 IQ(第一代)Brain 屏幕上的特定行和列。下一次 print 调用将从该位置开始打印。
void setCursor(
int32_t row,
int32_t col );
范围 |
类型 |
描述 |
|---|---|---|
|
|
要将光标移动到的行。 |
|
|
要将光标移动到的列。 |
此函数不返回值。
Notes Examples// Print at row 3 column 7
Brain.Screen.setCursor(3, 7);
Brain.Screen.print("VEXcode!");

newLine#
将光标移动到大脑屏幕上下一行的开头。
Available Functionsvoid newLine();
此函数不接受任何参数。
Return Values此函数不返回值。
Notes如果光标位于句子的中间,则
newLine将清除光标之后的行的其余部分,然后再移动到下一行。调用
newLine后,光标位于下一行的第一列。使用
setCursor设置光标位置和行号。
// Display two lines of text
Brain.Screen.print("First message");
Brain.Screen.newLine();
Brain.Screen.print("Second message");

clearLine#
清除 IQ(第一代)大脑屏幕上某一行的文本。
Available Functions1 — 清除光标位置的当前行剩余内容。
void clearLine();
2 — 使用当前配置的 填充颜色 清除指定的行。
void clearLine( int number );
3 — 使用预定义或 自定义颜色 对象清除指定的行。
void clearLine( int number, const color& color );
4 — 使用十六进制颜色值清除指定的行。
void clearLine( int number, const char* color );
Parameters5 — 使用色调值清除指定的行。
void clearLine( int number, int hue );
范围 |
类型 |
描述 |
|---|---|---|
|
|
要清除的行号。行号从 |
|
|
使用
|
|
|
使用十六进制颜色值清除行(例如, |
|
|
使用 |
此函数不返回值。
Notes清除一行不会改变当前光标位置。
使用
setCursor设置光标位置和行号。IQ(第一代)Brain屏幕是单色显示屏,因此指定的颜色不会显示在屏幕上。
// Display text on two rows
Brain.Screen.print("This text stays");
Brain.Screen.newLine();
Brain.Screen.print("This disappears");
// Wait 3 seconds before clearing row 2
wait(3, seconds);
Brain.Screen.clearLine(2);
row#
返回 IQ(第一代)Brain 屏幕上当前光标所在的行位置。
Available Functionsint32_t row();
此函数不接受任何参数。
Return Values返回 int32_t ,表示要打印文本的行。
行号从1开始。
Notes Examples// Display the cursor's current row
Brain.Screen.setCursor(3, 12);
Brain.Screen.print("row: ", Brain.Screen.row());
column#
返回 IQ(第一代)大脑屏幕上将打印文本的列。
Available Functionsint32_t column();
此函数不接受任何参数。
Return Values返回 int32_t ,表示要打印文本的列。
列编号从 1 开始。
Notes Examples// Display the cursor's current column
Brain.Screen.print("column: ", Brain.Screen.column());
getStringHeight#
返回字符串在 IQ(第一代)Brain 屏幕上渲染时的高度(以像素为单位)。
Available Functionsint32_t getStringHeight(
const char* cstr );
范围 |
类型 |
描述 |
|---|---|---|
|
|
要测量的文本,以 C 风格字符串 的形式提供(例如, |
返回 int32_t ,表示字符串在 Brain 屏幕上渲染时的像素高度。
getStringWidth#
返回字符串在 IQ(第一代)Brain 屏幕上渲染时的宽度(以像素为单位)。
Available Functionsint32_t getStringWidth(
const char* cstr );
范围 |
类型 |
描述 |
|---|---|---|
|
|
要测量的文本,以 C 风格字符串 的形式提供(例如, |
返回 int32_t ,表示字符串在 Brain 屏幕上渲染时的像素宽度。
返回的 取决于当前选定的屏幕字体。
该函数测量字符串的长度,但不将其绘制到屏幕上。
返回的宽度反映了字符串打印时的显示方式。
printAt#
在 IQ(第一代)大脑屏幕上的特定坐标处打印文本、数字或布尔值。
Available Functions1 — 在指定的像素位置打印格式化的输出。
void printAt( int32_t x, int32_t y, const char* format, ... );
Parameters2 — 在指定的像素位置打印格式化的输出,并设置文本背景是不透明还是透明。
void printAt( int32_t x, int32_t y, bool bOpaque, const char* format, ... );
范围 |
类型 |
描述 |
|---|---|---|
|
|
打印位置的 x 坐标,以屏幕原点为参考。 |
|
|
打印位置的 y 坐标,以屏幕原点为参考。 |
|
|
Controls whether the printed text is drawn opaquely or transparently:
|
|
|
控制屏幕上打印内容的格式字符串(例如, |
|
插入到格式字符串中的一个或多个附加值,以逗号分隔。 |
此函数不返回值。
Notesx和y坐标是相对于当前屏幕原点的,可以使用setOrigin进行更改。打印文本使用 屏幕字体。
打印文本使用 笔颜色。
使用格式字符串时,传递的值的数量和类型必须与字符串中的 格式说明符 匹配。
// Print the number 1 at pixel (100, 40)
Brain.Screen.printAt(100, 40, 1);
clearScreen#
清除大脑屏幕上的所有图画和文字。
Available Functions1 — 将屏幕清空至黑色。
void clearScreen();
2 — 使用预定义或 自定义颜色 对象清除屏幕。
void clearScreen( const color& color );
3 — 使用十六进制颜色值清除屏幕。
void clearScreen( const char* color );
Parameters4 — 使用色调值清除屏幕。
void clearScreen( int hue );
范围 |
类型 |
描述 |
|---|---|---|
|
|
使用
|
|
|
使用以字符串形式表示的十六进制颜色值清除屏幕(例如, |
|
|
使用 |
此函数不返回值。
NotesIQ(第一代)Brain屏幕是单色显示屏,因此指定的颜色不会显示在屏幕上。
// Clear screen after 2 seconds
Brain.Screen.print("VEXcode");
wait(2, seconds);
Brain.Screen.clearScreen();
// Clear screen to blue after 2 seconds
Brain.Screen.print("VEXcode");
wait(2, seconds);
Brain.Screen.clearScreen(red);
setFont#
设置 IQ(第一代)大脑屏幕上显示的文本所用的字体。
这控制在使用屏幕文本功能(例如 print)时应用于后续文本输出的字体。
void setFont(
fontType font );
范围 |
类型 |
描述 |
|---|---|---|
|
|
将字体设置为以下选项之一:
|
此函数不返回值。
Examples// Display two different fonts on
// two separate lines
Brain.Screen.setFont(mono20);
Brain.Screen.print("Mono Medium");
Brain.Screen.newLine();
Brain.Screen.setFont(prop20);
Brain.Screen.print("Prop Medium");
setPenWidth#
设置绘制线条和形状轮廓的粗细。
Available Functionsvoid setPenWidth(
uint32_t width );
范围 |
类型 |
描述 |
|---|---|---|
|
|
笔的宽度,以像素为单位,范围从 0 到 32。 |
此函数不返回值。
Notes笔宽适用于诸如
drawLine、drawRectangle和drawCircle之类的绘图函数。
// Draw a circle with a pen width of 5
Brain.Screen.drawCircle(40, 70, 20);
Brain.Screen.setPenWidth(5);
Brain.Screen.drawCircle(100, 70, 20);
setPenColor#
设置文本、像素、线条和形状轮廓的颜色。
Available Functions1 — 使用预定义或 自定义颜色 对象设置画笔颜色。
void setPenColor( const color& color );
2 — 使用十六进制颜色值设置画笔颜色。
void setPenColor( const char* color );
Parameters3 — 使用色调值设置画笔颜色。
void setPenColor( int hue );
范围 |
类型 |
描述 |
|---|---|---|
|
|
使用
|
|
|
使用以字符串形式表示的十六进制颜色值设置画笔颜色(例如, |
|
|
使用 |
此函数不返回值。
NotesIQ(第一代)Brain屏幕是单色显示屏,因此指定的颜色不会显示在屏幕上。
Brain.Screen.drawRectangle(100, 50, 10, 20);
Brain.Screen.setPenColor(blue);
Brain.Screen.drawRectangle(50, 50, 10, 20);
setFillColor#
设置绘制形状时使用的填充颜色。
Available Functions1 — 使用预定义或 自定义颜色 对象设置填充颜色。
void setFillColor( const color& color );
2 — 使用十六进制颜色值设置填充颜色。
void setFillColor( const char* color );
Parameters3 — 使用色调值设置填充颜色。
void setFillColor( int hue );
范围 |
类型 |
描述 |
|---|---|---|
|
|
使用
|
|
|
使用以字符串形式表示的十六进制颜色值设置填充颜色(例如, |
|
|
使用 |
此函数不返回值。
NotesIQ(第一代)Brain屏幕是单色显示屏,因此指定的颜色不会显示在屏幕上。
// Draw a circle filled with yellow
Brain.Screen.setFillColor(yellow);
Brain.Screen.drawCircle(50, 50, 20);
setOrigin#
设置大脑屏幕上绘制图形的原点。
Available Functionsvoid setOrigin(
int32_t x,
int32_t y );
范围 |
类型 |
描述 |
|---|---|---|
|
|
原点相对于大脑屏幕左上角的 x 坐标,取值范围为 0 到 159。 |
|
|
原点相对于大脑屏幕左上角的 y 坐标,取值范围为 0 到 107。 |
此函数不返回值。
Notes默认原点位于屏幕左上角坐标 (0, 0)。
原点适用于坐标函数,例如
drawLine、drawRectangle、drawCircle和printAt。该原点设置将一直有效,直到再次更改或项目重置为止。
setClipRegion#
在屏幕上定义一个矩形区域,所有图形和文本都将限制在该区域内。该区域之外的任何内容都不会显示。
Available Functionsvoid setClipRegion(
int x,
int y,
int width,
int height );
范围 |
类型 |
描述 |
|---|---|---|
|
|
剪辑区域左上角的 x 坐标,取值范围为 0 到 159 的整数。 |
|
|
剪辑区域左上角的 y 坐标,取值范围为 0 到 107 的整数。 |
|
|
裁剪区域的宽度(以像素为单位),取值范围为 0 到 159 的整数。 |
|
|
裁剪区域的高度(以像素为单位),取值范围为 0 到 107 的整数。 |
此函数不返回值。
Notes即使绘图函数超出裁剪区域,它们仍然会执行,但只有区域内的部分是可见的。
x和y坐标是相对于当前屏幕原点的,可以使用setOrigin进行更改。剪辑区域仅适用于当前线程。
设置新的剪辑区域会替换当前线程之前设置的任何剪辑区域。
// Restrict text and drawings to a specific region
Brain.Screen.setClipRegion(0, 0, 120, 120);
Brain.Screen.drawRectangle(60, 60, 100, 100, red);
Brain.Screen.printAt(60, 60, "Cut off!");
drawPixel#
在 IQ(第一代)Brain 屏幕上,于指定的 x 和 y 像素位置绘制一个像素。
Available Functionsvoid drawPixel(
int x,
int y );
范围 |
类型 |
描述 |
|---|---|---|
|
|
像素绘制位置的 x 坐标,取值范围为 0 到 159 之间的整数。 |
|
|
像素绘制位置的 y 坐标,取值范围为 0 到 107 之间的整数。 |
此函数不返回值。
NotesIQ(第一代)Brain屏幕是单色显示屏,因此指定的颜色不会显示在屏幕上。
x和y坐标是相对于当前屏幕原点的,可以使用setOrigin进行设置。如果指定的像素位置在屏幕边界之外,则不会绘制该像素。
// Draw one pixel at the center
// of the screen
Brain.Screen.drawPixel(80, 50);
drawLine#
在 IQ(第一代)脑力测试屏幕上,画一条直线连接两点。
Available Functionsvoid drawLine(
int x1,
int y1,
int x2,
int y2 );
范围 |
类型 |
描述 |
|---|---|---|
|
|
直线的起始 x 坐标,取值范围为 0 到 159 的整数。 |
|
|
直线的起始 y 坐标,取值范围为 0 到 107 的整数。 |
|
|
直线的终点 x 坐标,取值范围为 0 到 159 的整数。 |
|
|
直线的终点 y 坐标,取值范围为 0 到 107 的整数。 |
此函数不返回值。
NotesIQ(第一代)Brain屏幕是单色显示屏,因此指定的颜色不会显示在屏幕上。
线条的宽度由当前笔宽决定,该笔宽通过
setPenWidth设置。x和y坐标是相对于当前屏幕原点的,可以使用setOrigin进行设置。如果线条的任何部分超出屏幕边界,则只绘制可见部分。
// Draw a line from the top left to
// bottom right of the screen
Brain.Screen.drawLine(0, 0, 159, 107);
drawRectangle#
在 IQ(第一代)Brain 屏幕上,于指定位置和大小绘制一个矩形。
Available Functions1 — 使用当前配置的 填充颜色 绘制并填充矩形。
void drawRectangle( int x, int y, int width, int height );
2 — 使用预定义或自定义颜色对象绘制并填充矩形。
void drawRectangle( int x, int y, int width, int height, const color& color );
3 — 使用十六进制颜色值绘制并填充矩形。
void drawRectangle( int x, int y, int width, int height, const char* color );
Parameters4 — 使用色调值绘制并填充矩形。
void drawRectangle( int x, int y, int width, int height, int hue );
范围 |
类型 |
描述 |
|---|---|---|
|
|
矩形左上角的 x 坐标,取值范围为 0 到 159 的整数。 |
|
|
矩形左上角的 y 坐标,取值范围为 0 到 107 的整数。 |
|
|
矩形的宽度,取值范围为 0 到 159 的整数。 |
|
|
矩形的高度,取值范围为 0 到 107 之间的整数。 |
|
|
使用
|
|
|
使用十六进制颜色值填充矩形(例如, |
|
|
使用 |
此函数不返回值。
NotesIQ(第一代)Brain屏幕是单色显示屏,因此指定的颜色不会显示在屏幕上。
轮廓粗细由当前笔宽决定,该笔宽通过
setPenWidth设置。x和y坐标是相对于当前屏幕原点的,可以使用setOrigin进行更改。如果矩形的任何部分位于屏幕边界之外,则只绘制可见部分。
// Draw a red rectangle on the screen
Brain.Screen.drawRectangle(25, 25, 100, 50, red);
drawCircle#
在 IQ(第一代)大脑屏幕上,按指定位置和半径画一个圆。
Available Functions1 — 使用当前配置的 填充颜色 绘制并填充一个圆。
void drawCircle( int x, int y, int radius );
2 — 使用预定义或自定义颜色对象绘制并填充一个圆。
void drawCircle( int x, int y, int radius, const color& color );
3 — 使用十六进制颜色值绘制并填充一个圆。
void drawCircle( int x, int y, int radius, const char* color );
Parameters4 — 使用色相值绘制并填充圆形。
void drawCircle( int x, int y, int radius, int hue );
范围 |
类型 |
描述 |
|---|---|---|
|
|
圆心的 x 坐标,取值范围为 0 到 159 之间的整数。 |
|
|
圆心的 y 坐标,取值范围为 0 到 107 的整数。 |
|
|
圆的半径,取值范围为 0 到 107 像素的整数。 |
|
|
使用
|
|
|
使用十六进制颜色值填充圆圈(例如, |
|
|
使用 |
此函数不返回值。
NotesIQ(第一代)Brain屏幕是单色显示屏,因此指定的颜色不会显示在屏幕上。
轮廓粗细由当前笔宽决定,该笔宽通过
setPenWidth设置。x和y坐标是相对于当前屏幕原点的,可以使用setOrigin进行更改。
// Draw a green circle on the screen
Brain.Screen.drawCircle(80, 50, 20, green);
render#
启用大脑屏幕的双缓冲功能。调用后,任何绘图功能(例如文本或形状)在项目剩余时间内都不会立即显示。相反,更新内容仅在再次使用 render 时才会显示。这可以实现更流畅、更可控的屏幕更新,但意味着在 render 之前,屏幕内容将不可见。
1 — 启用双缓冲或将后缓冲区渲染到屏幕。
bool render();
Parameters2 — 将后缓冲区渲染到屏幕上,并可控制垂直同步行为和可选的调度程序执行。
bool render( bool bVsyncWait, bool bRunScheduler = true );
范围 |
类型 |
描述 |
|---|---|---|
|
|
|
|
|
可选
|
返回一个布尔值指示缓冲区中保存的图形是否已成功渲染到屏幕上:
true— 图形已成功渲染到屏幕上。4false— 图形无法渲染到屏幕上
Notes
调用
render将需要render用于项目的其余部分。
Brain.Screen.render();
// Draw text to the back buffer
Brain.Screen.print("Render later...");
// Wait for a screen press to render drawings
while (!Brain.Screen.pressing()) {
wait(20, msec);
}
Brain.Screen.render();