-
Notifications
You must be signed in to change notification settings - Fork 1
/
di_opaque_bitmap.h
60 lines (51 loc) · 2.72 KB
/
di_opaque_bitmap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// di_opaque_bitmap.h - Function declarations for drawing opaque bitmaps
//
// An opaque bitmap is a rectangle of fully opaque pixels of various colors.
//
// Copyright (c) 2023 Curtis Whitley
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#pragma once
#include "di_primitive.h"
class DiOpaqueBitmap: public DiPrimitiveXYWH {
public:
uint32_t m_words_per_line;
uint32_t m_bytes_per_line;
uint32_t m_words_per_position;
uint32_t m_bytes_per_position;
uint32_t* m_visible_start;
uint32_t m_pixels[1];
// Construct a dynamically-sized opaque bitmap. The m_pixels array gets sized during 'new'.
DiOpaqueBitmap(uint32_t width, uint32_t height, ScrollMode scroll_mode);
// Allocate an opaque bitmap. This takes 4x as much memory as the bitmap itself.
void* operator new(size_t size, uint32_t width, uint32_t height, ScrollMode scroll_mode);
// Set the position of the bitmap on the screen, and assume using pixels starting at line 0 in the bitmap.
void set_position(int32_t x, int32_t y);
// Set the position of the bitmap on the screen, and assume using pixels starting at the given line in the bitmap.
// This makes it possible to use a single (tall) bitmap to support animated sprites.
void set_position(int32_t x, int32_t y, uint32_t start_line, uint32_t height);
// Set a single pixel within the allocated bitmap. The upper 2 bits of the color
// are ignored. The lower 6 bits are the raw color.
void set_opaque_pixel(int32_t x, int32_t y, uint8_t color);
virtual void IRAM_ATTR paint(const DiPaintParams *params);
protected:
// Set a single pixel with an adjusted color value.
void set_pixel(int32_t x, int32_t y, uint8_t color);
};