Phoenard
PHNImage.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 This file is part of the Phoenard Arduino library
5 Copyright (c) 2014 Phoenard
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
31 #include "PHNDisplay.h"
32 #include "PHNPalette.h"
33 
34 #ifndef _PHN_IMAGE_H_
35 #define _PHN_IMAGE_H_
36 
48 class PHN_Image {
49 public:
51  PHN_Image() {}
53  PHN_Image(void (*drawFunc)(int, int, int, int, PHN_Image&), uint32_t data);
55  PHN_Image(void (*drawFunc)(int, int, int, int, PHN_Image&), const char* text);
57  PHN_Image(void (*drawFunc)(int, int, int, int, PHN_Image&), const void* data, int dataSize);
59  PHN_Image(const PHN_Image &value);
60 
62  const PHN_Palette &palette() { return _palette; }
64  const color_t color(uint8_t index) { return _palette.get(index); }
66  const void setPalette(const PHN_Palette &palette) { _palette = palette; }
68  const void* data() const { return _data.data; }
70  const char* text() const { return (const char*) _data.data; }
72  const uint32_t data_int() const { return *((uint32_t*) _data.data); }
74  const void* data_ptr() const { return (void*) data_int(); }
76  const int dataSize() { return _data.dataSize; }
77 
79  void setData(const void* data, int dataSize) { _data.set(data, dataSize); }
81  void setData(const char* text) { _data.set((const void*) text, strlen(text)); }
83  void draw(int x, int y, int width, int height) { _drawFunc(x, y, width, height, *this); }
84 
85 private:
86  PHN_Palette _palette;
87  DataBuffer _data;
88  void (*_drawFunc)(int, int, int, int, PHN_Image&);
89 };
90 
91 // Draw functions (not shown in doxygen)
93 void text_image_draw_func(int x, int y, int width, int height, PHN_Image &img);
94 void flash_image_draw_func(int x, int y, int width, int height, PHN_Image &img);
95 void flash_indexed_image_draw_func(int x, int y, int width, int height, PHN_Image &img);
97 
99 #define TEXT_Image(text) PHN_Image(text_image_draw_func, text)
100 #define FLASH_Image(data) PHN_Image(flash_image_draw_func, (uint32_t) (data))
102 #define FLASH_MAPPED_Image(data) PHN_Image(flash_indexed_image_draw_func, (uint32_t) (data))
104 
105 #endif
A color Palette that can store up to 256 colors.
Definition: PHNPalette.h:43
const void setPalette(const PHN_Palette &palette)
Sets a new palette of colors set for the image.
Definition: PHNImage.h:66
PHN_Image()
Null constructor used for copying one image to another.
Definition: PHNImage.h:51
const PHN_Palette & palette()
Gets the palette of colors set for the image.
Definition: PHNImage.h:62
Stores the information needed to draw an image to screen.
Definition: PHNImage.h:48
Maintains data stored on the heap and frees it when the class is destructed.
Definition: DataBuffer.h:44
const void * data_ptr() const
Gets the data associated with the image as a memory pointer.
Definition: PHNImage.h:74
Contains the PHN_Display used for drawing, touch input and widgets.
const void * data() const
Gets the data associated with the image.
Definition: PHNImage.h:68
color_t get(int index) const
Gets a single color set at the index, BLACK if index out of range.
Definition: PHNPalette.cpp:36
const char * text() const
Gets the data associated with the image as text.
Definition: PHNImage.h:70
void setData(const char *text)
Sets new data associated with the image using a null-terminated String.
Definition: PHNImage.h:81
const color_t color(uint8_t index)
Gets a color in the palette of colors set for the image.
Definition: PHNImage.h:64
uint16_t color_t
Definition of the 16-bit 565 color type.
Definition: PHNDisplayHardware.h:97
const int dataSize()
Gets the byte size of the data associated with the image.
Definition: PHNImage.h:76
void setData(const void *data, int dataSize)
Sets new data associated with the image.
Definition: PHNImage.h:79
const uint32_t data_int() const
Gets the data associated with the image as an integer.
Definition: PHNImage.h:72
void draw(int x, int y, int width, int height)
Calls the draw function to draw in the rectangle specified.
Definition: PHNImage.h:83
Contains the PHN_Palette, a color container, and several palette macros.
void set(const void *data, int dataSize)
Sets new data to be stored, the data is copied into this buffer.
Definition: DataBuffer.cpp:49