PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Simple Libraries
Display
libsimplegfx
drawCopy.c
1
/*
2
* @file drawCopy.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 helper-library 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 This library should not be called on its own - it is called by the display's
22
* library.
23
* If fonts are installed, they occupy EEPROM addresses 40576 to 63359.
24
*/
25
26
#include "simplegfx.h"
27
28
29
void
drawCopy(
screen_t
*dev,
int
x
,
int
y,
int
w,
int
h,
int
x0,
int
y0) {
30
31
32
33
34
int
dh = getDisplayHeight(dev);
35
int
dw = getDisplayWidth(dev);
36
if
((
x
>= -w) && (
x
< dw) &&
37
(y >= -h) && (y < dh) &&
38
(x0 >= -w) && (x0 < dw) &&
39
(y0 >= -h) && (y0 < dh)) {
// X & Y coords in bounds?
40
if
(y < 0) {
// Clip top
41
h += y;
42
y = 0;
43
}
44
if
((y + h) > dh) {
// Clip bottom
45
h = (dh - y);
46
}
47
if
(
x
< 0) {
// Clip left
48
w +=
x
;
49
x
= 0;
50
}
51
if
((
x
+ w) > dw) {
// Clip right
52
w = (dw -
x
);
53
}
54
55
if
(y0 < 0) {
// Clip top
56
h += y0;
57
y0 = 0;
58
}
59
if
((y0 + h) > dh) {
// Clip bottom
60
h = (dh - y0);
61
}
62
if
(x0 < 0) {
// Clip left
63
w += x0;
64
x0 = 0;
65
}
66
if
((x0 + w) > dw) {
// Clip right
67
w = (dw - x0);
68
}
69
70
int
x1 =
x
+ w;
71
int
y1 = y + h;
72
int
x2 = x0 + w;
73
int
y2 = y0 + h;
74
75
if
(dev->
deviceCopyRect
) {
76
switch
(dev->
rotation
) {
77
case
0:
78
dev->
deviceCopyRect
(dev,
x
, y, x1 - 1, y1 - 1, x0, y0);
79
break
;
80
case
1:
81
dev->
deviceCopyRect
(dev, dev->
width
- y1,
x
, dev->
width
- y - 1, x1 - 1, dev->
width
- y2, x0);
82
break
;
83
case
2:
84
dev->
deviceCopyRect
(dev, dev->
width
- x1, dev->
height
- y1, dev->
width
-
x
- 1, dev->
height
- y - 1, dev->
width
- x2, dev->
height
- y2);
85
break
;
86
case
3:
87
dev->
deviceCopyRect
(dev, y, dev->
height
- x1, y1 - 1, dev->
height
-
x
- 1, y0, dev->
height
- x2);
88
break
;
89
}
90
91
}
else
{
92
93
int
tmp = 0;
94
switch
(dev->
rotation
) {
95
case
0:
96
x1--;
97
y1--;
98
x2 = x0 + w - 1;
99
break
;
100
case
1:
101
tmp =
x
;
102
x
= dev->
width
- y1;
103
y = tmp;
104
tmp = x1;
105
x1 = dev->
width
- y - 1;
106
y1 = tmp - 1;
107
tmp = x0;
108
x0 = dev->
width
- y2;
109
y0 = tmp;
110
x2 = x0 + w - 1;
111
break
;
112
case
2:
113
tmp =
x
;
114
x
= dev->
width
- x1 + 1;
115
x1 = dev->
width
- tmp;
116
tmp = y;
117
y = dev->
height
- y1 + 1;
118
y1 = dev->
height
- tmp;
119
x0 = dev->
width
- x2 + 1;
120
y0 = dev->
height
- y2 + 1;
121
x2 = x0 + w - 1;
122
break
;
123
case
3:
124
x
= y;
125
y = dev->
height
- x1 + 1;
126
x1 = y1;
127
y1 = dev->
height
-
x
;
128
x0 = y0;
129
y0 = dev->
height
- x2 + 1;
130
x2 = x0 + w;
131
break
;
132
}
133
134
unsigned
int
i = 0, j = 0, k = 0, l = 0;
135
if
(dev->
color_depth
== 1) {
136
char
tmp_img[((w * h) >> 3) + 7];
137
memset(tmp_img, 0,
sizeof
(tmp_img));
138
//print("x=%d, y=%d, w=%d, h=%d\r", x, y, w, h);
139
for
(j = y; j < y1; j++) {
140
for
(i =
x
; i < x1; i++) {
141
unsigned
char
b = dev->
image_ptr
[(i + j * dev->
width
) >> 3] & (0b10000000 >> (i & 7));
142
if
(b) {
143
tmp_img[(k >> 3)] |= (0b10000000 >> (k & 7));
144
//print(".");
145
}
else
{
146
//print(" ");
147
}
148
print
(
"%b"
, !!b);
149
k++;
150
}
151
print
(
"%d\r"
, k);
152
}
153
i = x0;
154
j = y0;
155
for
(l = 0; l < k; l++) {
156
unsigned
char
b = tmp_img[(l >> 3)] & (0b10000000 >> (l & 7));
157
//print("%d", !!b);
158
if
(b) dev->
image_ptr
[(i + j * dev->
width
) >> 3] |= (0b10000000 >> (i & 7));
159
else
dev->
image_ptr
[(i + j * dev->
width
) >> 3] &= ~(0b10000000 >> (i & 7));
160
i++;
161
if
(i == x2) {
// 1 to subtract off width, 1 to account for the i++ right before the test
162
i = x0;
163
j++;
164
}
165
}
166
}
167
}
168
}
169
}
screen_st::height
int height
Definition:
simplegfx.h:116
screen_st::color_depth
char color_depth
Definition:
simplegfx.h:131
screen_st::rotation
int rotation
Definition:
simplegfx.h:119
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
screen_st::image_ptr
char * image_ptr
Definition:
simplegfx.h:183
x
int x
Definition:
07 Box and Lines.c:13
screen_st::deviceCopyRect
void(* deviceCopyRect)(struct screen_st *, int x, int y, int x0, int y0, int x1, int y1)
Definition:
simplegfx.h:225
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