2 Drawing a square
Next we are going to draw a small square in the center of the LCD display.
The display area is 128 X 128 pixels large (although the whole display is 160x128, but some display
area is reserved for application buttons).
Let's choose, for example, to draw a 32X32 square.
We need to add the following definition/declarations to the source code in Step1.c. They define the
size and location of the square on the screen. Place them near the top of the source code, in the
“Public variables” section:
#define SQUARE_WIDTH 32
int x = ( SCREEN_WIDTH - SQUARE_WIDTH ) / 2;
int y = ( SCREEN_HEIGHT - SQUARE_WIDTH ) / 2;
As we want to draw the square only once we can add the drawing code into the Application_Ini()
function (remember, Application_ini() is only called once when the application starts).
In the box below you will see the source code that draws the square.
Copy this block of code into the function Application_Ini() function body, in the “step1.c” file (replace
the “TODO: Write your application initialization function here” by this code:
//Draw my square
LCD_DrawRect( x, y, SQUARE_WIDTH, SQUARE_WIDTH, RGB_BLUE);
LCD_FillRect( x+1, y+1, SQUARE_WIDTH-2, SQUARE_WIDTH-2, RGB_YELLOW);
The first function LCD_DrawRect() will draw (in blue) the square periphery, and the second fills the
area inside the square (in yellow).
- 9 -CircleOS Tutorial for STM32-Primer2
__________________
website development services in bangalore