diff options
Diffstat (limited to 'firmware/drivers/lcd-bitmap-common.c')
-rw-r--r-- | firmware/drivers/lcd-bitmap-common.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c index 24b302b6d4..c867b214b5 100644 --- a/firmware/drivers/lcd-bitmap-common.c +++ b/firmware/drivers/lcd-bitmap-common.c | |||
@@ -53,6 +53,116 @@ | |||
53 | extern void viewport_set_buffer(struct viewport *vp, | 53 | extern void viewport_set_buffer(struct viewport *vp, |
54 | struct frame_buffer_t *buffer, | 54 | struct frame_buffer_t *buffer, |
55 | const enum screen_type screen); /* viewport.c */ | 55 | const enum screen_type screen); /* viewport.c */ |
56 | |||
57 | /* | ||
58 | * In-viewport clipping functions: | ||
59 | * | ||
60 | * These clip a primitive (pixel, line, rect) given in | ||
61 | * viewport-relative coordinates to the current viewport, | ||
62 | * and translate it to screen coordinates. They return | ||
63 | * false if the resulting primitive would be off-screen. | ||
64 | */ | ||
65 | |||
66 | static bool LCDFN(clip_viewport_pixel)(int *x, int *y) | ||
67 | { | ||
68 | struct viewport *vp = LCDFN(current_viewport); | ||
69 | |||
70 | if(*x >= vp->width || *y >= vp->height) | ||
71 | return false; | ||
72 | |||
73 | *x += vp->x; | ||
74 | *y += vp->y; | ||
75 | return true; | ||
76 | } | ||
77 | |||
78 | static bool LCDFN(clip_viewport_hline)(int *x1, int *x2, int *y) | ||
79 | { | ||
80 | struct viewport *vp = LCDFN(current_viewport); | ||
81 | |||
82 | if (*y < 0 || *y > vp->height) | ||
83 | return false; | ||
84 | |||
85 | if (*x2 < *x1) { | ||
86 | int tmp = *x2; | ||
87 | *x2 = *x1; | ||
88 | *x1 = tmp; | ||
89 | } | ||
90 | |||
91 | if (*x1 < 0) | ||
92 | *x1 = 0; | ||
93 | else if (*x1 >= vp->width) | ||
94 | return false; | ||
95 | |||
96 | if (*x2 < 0) | ||
97 | return false; | ||
98 | else if (*x2 >= vp->width) | ||
99 | *x2 = vp->width - 1; | ||
100 | |||
101 | *x1 += vp->x; | ||
102 | *x2 += vp->x; | ||
103 | *y += vp->y; | ||
104 | return true; | ||
105 | } | ||
106 | |||
107 | static bool LCDFN(clip_viewport_vline)(int *x, int *y1, int *y2) | ||
108 | { | ||
109 | struct viewport *vp = LCDFN(current_viewport); | ||
110 | |||
111 | if (*x < 0 || *x > vp->width) | ||
112 | return false; | ||
113 | |||
114 | if (*y2 < *y1) { | ||
115 | int tmp = *y2; | ||
116 | *y2 = *y1; | ||
117 | *y1 = tmp; | ||
118 | } | ||
119 | |||
120 | if (*y1 < 0) | ||
121 | *y1 = 0; | ||
122 | else if (*y1 >= vp->height) | ||
123 | return false; | ||
124 | |||
125 | if (*y2 < 0) | ||
126 | return false; | ||
127 | else if (*y2 >= vp->height) | ||
128 | *y2 = vp->height - 1; | ||
129 | |||
130 | *x += vp->x; | ||
131 | *y1 += vp->y; | ||
132 | *y2 += vp->y; | ||
133 | return true; | ||
134 | } | ||
135 | |||
136 | static bool LCDFN(clip_viewport_rect)(int *x, int *y, int *width, int *height, | ||
137 | int *src_x, int *src_y) | ||
138 | { | ||
139 | struct viewport *vp = LCDFN(current_viewport); | ||
140 | |||
141 | if (*x < 0) { | ||
142 | *width += *x; | ||
143 | if (src_x) | ||
144 | *src_x -= *x; | ||
145 | *x = 0; | ||
146 | } | ||
147 | |||
148 | if (*y < 0) { | ||
149 | *height += *y; | ||
150 | if (src_y) | ||
151 | *src_y -= *y; | ||
152 | *y = 0; | ||
153 | } | ||
154 | |||
155 | if (*x + *width > vp->width) | ||
156 | *width = vp->width - *x; | ||
157 | |||
158 | if (*y + *height > vp->height) | ||
159 | *height = vp->height - *y; | ||
160 | |||
161 | *x += vp->x; | ||
162 | *y += vp->y; | ||
163 | return *width > 0 && *height > 0; | ||
164 | } | ||
165 | |||
56 | /* | 166 | /* |
57 | * draws the borders of the current viewport | 167 | * draws the borders of the current viewport |
58 | **/ | 168 | **/ |