Phoenard
PHNPalette.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 "PHNDisplayHardware.h"
32 #include <utility/PHNUtils.h>
33 
34 #ifndef _PHN_PALETTE_H_
35 #define _PHN_PALETTE_H_
36 
43 class PHN_Palette {
44 public:
48  PHN_Palette(const color_t* colors, int colorCount);
50  void setAll(const color_t* colors, int colorCount);
52  void set(int index, color_t color);
54  color_t get(int index) const;
56  int count() const { return _colorData.dataSize / sizeof(color_t); }
58  color_t* data() const { return (color_t*) _colorData.data; }
59 
60 private:
61  DataBuffer _colorData;
62 
63 };
64 
65 // Macro to quickly turn a list of colors into a PHNPalette instance
70 #define PALETTE(...) PHN_Palette((const color_t[]) {__VA_ARGS__}, sizeof((const color_t[]) {__VA_ARGS__}) / sizeof(color_t))
71 
72 // Default constants for use in widgets and whatnot
73 // PALETTE([BACKGROUND], [FRAME/FOREGROUND], [CONTENT/TEXT])
78 #define PALETTE_NORMAL PALETTE(WHITE, RED, BLACK)
79 #define PALETTE_PRESSED PALETTE(YELLOW, RED, BLACK)
80 #define PALETTE_CLICKED PALETTE(BLUE, RED, WHITE)
81 
82 
83 #endif
A color Palette that can store up to 256 colors.
Definition: PHNPalette.h:43
PHN_Palette()
Constructs a new empty palette.
Definition: PHNPalette.h:46
Maintains data stored on the heap and frees it when the class is destructed.
Definition: DataBuffer.h:44
int count() const
Gets how many colors are stored inside this palette.
Definition: PHNPalette.h:56
void set(int index, color_t color)
Sets a single color at an index in the palette.
Definition: PHNPalette.cpp:40
Low-level utility functions for working with the display.
color_t * data() const
Gets access to the raw color_t array data stored.
Definition: PHNPalette.h:58
uint16_t color_t
Definition of the 16-bit 565 color type.
Definition: PHNDisplayHardware.h:97
Various utility functions for use all-around.
void setAll(const color_t *colors, int colorCount)
Sets all the colors for the palette at once.
Definition: PHNPalette.cpp:32