PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Simple Libraries
Display
libsimplegfx
fillRect.c
1
/*
2
* @file fillRect.c
3
*
4
* @author Matthew Matz
5
*
6
* @version 0.5
7
*
8
* @copyright Copyright (C) Parallax, Inc. 2019. See end of file for
9
* terms of use (MIT License).
10
*
11
* @brief This is a driver that allows the Propeller Multicore Microcontroller to
12
* draw text, shapes, and bitmap files on various screens and displays.
13
*
14
* @detail This helper-library allows the Propeller Multicore Microcontroller to
15
* draw pixels, lines, circles, recatngles, rounded rectagles, triangles, formatted text
16
* in multiple fonts, bitmap images stored on an SD card on various screens and displays.
17
* At Parallax, we would like to thank Adafruit Industries as parts of this library
18
* were dervied from the Adafruit GFX library for Arduino. Please submit bug reports,
19
* suggestions, and improvements to this code to editor@parallax.com.
20
*
21
* @note If fonts are installed, they occupy EEPROM addresses 40576 to 63359.
22
*/
23
24
25
#include "simplegfx.h"
26
27
28
// Draw a filled rectangle
29
void
fillRect(
screen_t
*dev,
int
x
,
int
y,
int
w,
int
h,
int
color) {
30
if
(dev->
deviceFillRect
) {
31
int
dh = getDisplayHeight(dev);
32
int
dw = getDisplayWidth(dev);
33
if
((
x
>= -w) && (
x
< dw) &&
34
(y >= -h) && (y < dh)) {
// X & Y coord in bounds?
35
if
(y < 0) {
// Clip top
36
h += y;
37
y = 0;
38
}
39
if
((y + h) > dh) {
// Clip bottom
40
h = (dh - y);
41
}
42
if
(
x
< 0) {
// Clip left
43
w +=
x
;
44
x
= 0;
45
}
46
if
((
x
+ w) > dw) {
// Clip right
47
w = (dw -
x
);
48
}
49
int
x1 =
x
+ w;
50
int
y1 = y + h;
51
switch
(dev->
rotation
) {
52
case
0:
53
dev->
deviceFillRect
(dev,
x
, y, x1 - 1, y1 - 1, color);
54
break
;
55
case
1:
56
dev->
deviceFillRect
(dev, dev->
width
- y1,
x
, dev->
width
- y - 1, x1 - 1, color);
57
break
;
58
case
2:
59
dev->
deviceFillRect
(dev, dev->
width
- x1, dev->
height
- y1, dev->
width
-
x
- 1, dev->
height
- y - 1, color);
60
break
;
61
case
3:
62
dev->
deviceFillRect
(dev, y, dev->
height
- x1, y1 - 1, dev->
height
-
x
- 1, color);
63
break
;
64
}
65
}
66
}
else
{
67
for
(
int
idx = y; idx < y + h; idx++) {
68
drawFastHLine(dev,
x
, idx, w, color);
69
}
70
}
71
}
72
screen_st::height
int height
Definition:
simplegfx.h:116
screen_st::rotation
int rotation
Definition:
simplegfx.h:119
screen_st::deviceFillRect
void(* deviceFillRect)(struct screen_st *, int x, int y, int w, int h, int color)
Definition:
simplegfx.h:222
x
int x
Definition:
07 Box and Lines.c:13
screen_st::width
int width
Definition:
simplegfx.h:113
screen_st
Definition:
simplegfx.h:111
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17