add color settings
This commit is contained in:
parent
eff33f57a1
commit
d30dfa5d57
@ -26,7 +26,9 @@
|
|||||||
"watchface": true
|
"watchface": true
|
||||||
},
|
},
|
||||||
"messageKeys": [
|
"messageKeys": [
|
||||||
"dummy"
|
"BACKGROUND_COLOR",
|
||||||
|
"DIGIT_COLOR",
|
||||||
|
"FRAME_COLOR"
|
||||||
],
|
],
|
||||||
"capabilities": [ "configurable" ],
|
"capabilities": [ "configurable" ],
|
||||||
"resources": {
|
"resources": {
|
||||||
|
|||||||
@ -4,9 +4,10 @@
|
|||||||
using namespace Pebble;
|
using namespace Pebble;
|
||||||
|
|
||||||
// TODO move this to pebble-cpp
|
// TODO move this to pebble-cpp
|
||||||
bool operator==(const GColor8& lhs, const GColor8& rhs) { return lhs.argb == rhs.argb; }
|
bool operator==(const GColor& lhs, const GColor& rhs) { return gcolor_equal(lhs, rhs); }
|
||||||
bool operator!=(const GColor8& lhs, const GColor8& rhs) { return lhs.argb != rhs.argb; }
|
bool operator!=(const GColor& lhs, const GColor& rhs) { return !gcolor_equal(lhs, rhs); }
|
||||||
|
|
||||||
|
namespace bitmaps {
|
||||||
namespace {
|
namespace {
|
||||||
GOwnedBitmap digitsBitmap;
|
GOwnedBitmap digitsBitmap;
|
||||||
GOwnedBitmap digitBitmaps[10];
|
GOwnedBitmap digitBitmaps[10];
|
||||||
@ -16,7 +17,7 @@ namespace {
|
|||||||
GColor* frameColor;
|
GColor* frameColor;
|
||||||
|
|
||||||
|
|
||||||
int get_palette_size(GBitmapBase& bitmap){
|
int GetPaletteSize(GBitmapBase& bitmap){
|
||||||
switch (bitmap.GetFormat()) {
|
switch (bitmap.GetFormat()) {
|
||||||
case GBitmapFormat1BitPalette: return 2;
|
case GBitmapFormat1BitPalette: return 2;
|
||||||
case GBitmapFormat2BitPalette: return 4;
|
case GBitmapFormat2BitPalette: return 4;
|
||||||
@ -25,14 +26,14 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GColor* find_color(GBitmapBase& bitmap, GColor color) {
|
GColor* FindColor(GBitmapBase& bitmap, GColor color) {
|
||||||
GColor* palette = bitmap.GetPalette();
|
GColor* palette = bitmap.GetPalette();
|
||||||
if (palette == nullptr) {
|
if (palette == nullptr) {
|
||||||
ERROR("Palette is null");
|
ERROR("Palette is null");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int paletteSize = get_palette_size(bitmap);
|
int paletteSize = GetPaletteSize(bitmap);
|
||||||
if (paletteSize == 0) {
|
if (paletteSize == 0) {
|
||||||
ERROR("Expected GBitmapFormat[124]BitPalette, got: %d", digitsBitmap.GetFormat());
|
ERROR("Expected GBitmapFormat[124]BitPalette, got: %d", digitsBitmap.GetFormat());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -48,7 +49,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_bitmaps() {
|
void Init() {
|
||||||
digitsBitmap = GOwnedBitmap::CreateWithResource(RESOURCE_ID_DIGITS);
|
digitsBitmap = GOwnedBitmap::CreateWithResource(RESOURCE_ID_DIGITS);
|
||||||
auto size = digitsBitmap.GetBounds().size;
|
auto size = digitsBitmap.GetBounds().size;
|
||||||
uint16_t w = size.w / 10;
|
uint16_t w = size.w / 10;
|
||||||
@ -59,11 +60,11 @@ void init_bitmaps() {
|
|||||||
|
|
||||||
frameBitmap = GOwnedBitmap::CreateWithResource(RESOURCE_ID_FRAME);
|
frameBitmap = GOwnedBitmap::CreateWithResource(RESOURCE_ID_FRAME);
|
||||||
|
|
||||||
digitColor = find_color(digitsBitmap, GColorBlack);
|
digitColor = FindColor(digitsBitmap, GColorBlack);
|
||||||
frameColor = find_color(frameBitmap, GColorBlack);
|
frameColor = FindColor(frameBitmap, GColorBlack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinit_bitmaps() {
|
void DeInit() {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
digitBitmaps[i] = GOwnedBitmap();
|
digitBitmaps[i] = GOwnedBitmap();
|
||||||
}
|
}
|
||||||
@ -73,26 +74,27 @@ void deinit_bitmaps() {
|
|||||||
frameColor = nullptr;
|
frameColor = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBitmapBase& get_digit_bitmap(uint16_t digit) {return digitBitmaps[digit];}
|
GBitmapBase& GetDigitBitmap(uint16_t digit) {return digitBitmaps[digit];}
|
||||||
GBitmapBase& get_frame_bitmap() {return frameBitmap;}
|
GBitmapBase& GetFrameBitmap() {return frameBitmap;}
|
||||||
|
|
||||||
|
|
||||||
void set_digit_color(GColor color) {
|
void SetDigitColor(GColor color) {
|
||||||
if (digitColor != nullptr) *digitColor = color;
|
if (digitColor != nullptr) *digitColor = color;
|
||||||
}
|
}
|
||||||
void set_frame_color(GColor color) {
|
void SetFrameColor(GColor color) {
|
||||||
if (frameColor != nullptr) *frameColor = color;
|
if (frameColor != nullptr) *frameColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_palette(GBitmapBase& bitmap) {
|
void PrintPalette(GBitmapBase& bitmap) {
|
||||||
int paletteSize = get_palette_size(bitmap);
|
int paletteSize = GetPaletteSize(bitmap);
|
||||||
if (paletteSize == 0) {
|
if (paletteSize == 0) {
|
||||||
ERROR("Expected GBitmapFormat[124]BitPalette, got: %d", digitsBitmap.GetFormat());
|
ERROR("Expected GBitmapFormat[124]BitPalette, got: %d", digitsBitmap.GetFormat());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DEBUG("%d colors:", paletteSize);
|
DEBUG("%d colors:", paletteSize);
|
||||||
GColor8* palette = bitmap.GetPalette();
|
GColor* palette = bitmap.GetPalette();
|
||||||
for (int i = 0; i < paletteSize; i++) {
|
for (int i = 0; i < paletteSize; i++) {
|
||||||
DEBUG("* 0x%02X = argb(%d,%d,%d,%d)", palette[i].argb, palette[i].a, palette[i].r, palette[i].g, palette[i].b);
|
DEBUG("* 0x%02X = argb(%d,%d,%d,%d)", palette[i].argb, palette[i].a, palette[i].r, palette[i].g, palette[i].b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
#include <pebble-cpp/pebble.hpp>
|
#include <pebble-cpp/pebble.hpp>
|
||||||
|
|
||||||
void init_bitmaps();
|
namespace bitmaps {
|
||||||
void deinit_bitmaps();
|
void Init();
|
||||||
Pebble::GBitmapBase& get_digit_bitmap(uint16_t digit);
|
void DeInit();
|
||||||
Pebble::GBitmapBase& get_frame_bitmap();
|
Pebble::GBitmapBase& GetDigitBitmap(uint16_t digit);
|
||||||
void set_digit_color(GColor color);
|
Pebble::GBitmapBase& GetFrameBitmap();
|
||||||
void set_frame_color(GColor color);
|
void SetDigitColor(GColor color);
|
||||||
void print_palette(Pebble::GBitmapBase& bitmap);
|
void SetFrameColor(GColor color);
|
||||||
|
void PrintPalette(Pebble::GBitmapBase& bitmap);
|
||||||
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
#include "digit_layer.hpp"
|
#include "digit_layer.hpp"
|
||||||
#include "bitmaps.hpp"
|
|
||||||
#include <@rebble/sdk-c-utils/macros.h>
|
#include <@rebble/sdk-c-utils/macros.h>
|
||||||
|
#include "bitmaps.hpp"
|
||||||
|
|
||||||
using namespace Pebble;
|
using namespace Pebble;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void draw_digit(const Pebble::GContext& ctx, const Pebble::GRect& bounds, const uint16_t digit) {
|
void draw_digit(const Pebble::GContext& ctx, const Pebble::GRect& bounds, const uint16_t digit) {
|
||||||
Pebble::GBitmapBase& bitmap = get_digit_bitmap(digit);
|
Pebble::GBitmapBase& bitmap = bitmaps::GetDigitBitmap(digit);
|
||||||
auto rect = bitmap.GetBounds();
|
auto rect = bitmap.GetBounds();
|
||||||
rect.Align(bounds, GAlignCenter, false);
|
rect.Align(bounds, GAlignCenter, false);
|
||||||
ctx.DrawBitmapInRect(bitmap, rect);
|
ctx.DrawBitmapInRect(bitmap, rect);
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include "pebble_bitmap_layer.hpp"
|
#include "pebble_bitmap_layer.hpp"
|
||||||
#include "digit_layer.hpp"
|
#include "digit_layer.hpp"
|
||||||
#include "bitmaps.hpp"
|
#include "bitmaps.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
|
||||||
using namespace Pebble;
|
using namespace Pebble;
|
||||||
|
|
||||||
@ -13,8 +14,6 @@ class MainWindow : public AppWindow, public TickTimer {
|
|||||||
Pebble::BitmapLayer frameLayer;
|
Pebble::BitmapLayer frameLayer;
|
||||||
protected:
|
protected:
|
||||||
void OnLoad() {
|
void OnLoad() {
|
||||||
init_bitmaps();
|
|
||||||
|
|
||||||
auto bounds = this->GetBounds();
|
auto bounds = this->GetBounds();
|
||||||
int16_t w2 = bounds.size.w / 2;
|
int16_t w2 = bounds.size.w / 2;
|
||||||
int16_t h = bounds.size.h;
|
int16_t h = bounds.size.h;
|
||||||
@ -32,12 +31,7 @@ protected:
|
|||||||
this->AddChild(this->digitLayers[i]);
|
this->AddChild(this->digitLayers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// print_palette(get_digit_bitmap(0));
|
this->frameLayer.SetBitmap(bitmaps::GetFrameBitmap());
|
||||||
// print_palette(get_frame_bitmap());
|
|
||||||
// set_frame_color(GColorPictonBlue);
|
|
||||||
// print_palette(get_digit_bitmap(0));
|
|
||||||
// print_palette(get_frame_bitmap());
|
|
||||||
this->frameLayer.SetBitmap(get_frame_bitmap());
|
|
||||||
this->frameLayer.SetFrame(bounds);
|
this->frameLayer.SetFrame(bounds);
|
||||||
this->frameLayer.SetCompositingMode(GCompOpSet);
|
this->frameLayer.SetCompositingMode(GCompOpSet);
|
||||||
this->AddChild(this->frameLayer);
|
this->AddChild(this->frameLayer);
|
||||||
@ -48,14 +42,6 @@ protected:
|
|||||||
TickTimerStart(MINUTE_UNIT);
|
TickTimerStart(MINUTE_UNIT);
|
||||||
#endif
|
#endif
|
||||||
UpdateTime(false);
|
UpdateTime(false);
|
||||||
|
|
||||||
this->SetBackgroundColor(GColorBlack);
|
|
||||||
set_digit_color(GColorVividCerulean);
|
|
||||||
set_frame_color(GColorPictonBlue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnUnload() {
|
|
||||||
deinit_bitmaps();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateTime(bool animate=true) {
|
void UpdateTime(bool animate=true) {
|
||||||
@ -78,9 +64,35 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
void ApplySettings() {
|
||||||
|
|
||||||
|
Pebble::Window window = window_stack_get_top_window();
|
||||||
|
window.SetBackgroundColor(settings::GetBackgroundColor());
|
||||||
|
window.MarkDirty();
|
||||||
|
|
||||||
|
bitmaps::SetDigitColor(settings::GetDigitColor());
|
||||||
|
bitmaps::SetFrameColor(settings::GetFrameColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleMsg(DictionaryIterator *iter, void *context) {
|
||||||
|
settings::HandleMsg(iter);
|
||||||
|
ApplySettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MAIN {
|
MAIN {
|
||||||
|
bitmaps::Init();
|
||||||
|
settings::Load();
|
||||||
|
app_message_register_inbox_received(HandleMsg);
|
||||||
|
app_message_open(64, 64); // inbox, outbox
|
||||||
|
|
||||||
MainWindow window;
|
MainWindow window;
|
||||||
window.StackPush(true);
|
window.StackPush(true);
|
||||||
|
ApplySettings();
|
||||||
|
|
||||||
app_event_loop();
|
app_event_loop();
|
||||||
|
|
||||||
|
bitmaps::DeInit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
44
src/c/settings.cpp
Normal file
44
src/c/settings.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "settings.hpp"
|
||||||
|
|
||||||
|
// Built-in GColorFromRGBA doesn't seem to work in C++11 :(
|
||||||
|
#undef GColorFromRGBA
|
||||||
|
GColor8 GColorFromRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) {
|
||||||
|
GColor8 res;
|
||||||
|
res.a = alpha >> 6;
|
||||||
|
res.r = red >> 6;
|
||||||
|
res.g = green >> 6;
|
||||||
|
res.b = blue >> 6;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace settings {
|
||||||
|
namespace {
|
||||||
|
GColor backgroundColor = GColorWhite;
|
||||||
|
GColor digitColor = GColorBlack;
|
||||||
|
GColor frameColor = GColorBlack;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Save() {
|
||||||
|
persist_write_data(MESSAGE_KEY_BACKGROUND_COLOR, &backgroundColor, sizeof(GColor));
|
||||||
|
persist_write_data(MESSAGE_KEY_DIGIT_COLOR, &digitColor, sizeof(GColor));
|
||||||
|
persist_write_data(MESSAGE_KEY_FRAME_COLOR, &frameColor, sizeof(GColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Load() {
|
||||||
|
persist_read_data(MESSAGE_KEY_BACKGROUND_COLOR, &backgroundColor, sizeof(GColor));
|
||||||
|
persist_read_data(MESSAGE_KEY_DIGIT_COLOR, &digitColor, sizeof(GColor));
|
||||||
|
persist_read_data(MESSAGE_KEY_FRAME_COLOR, &frameColor, sizeof(GColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleMsg(DictionaryIterator *iter) {
|
||||||
|
|
||||||
|
if (auto tuple = dict_find(iter, MESSAGE_KEY_BACKGROUND_COLOR)) backgroundColor = GColorFromHEX(tuple->value->int32);
|
||||||
|
if (auto tuple = dict_find(iter, MESSAGE_KEY_DIGIT_COLOR)) digitColor = GColorFromHEX(tuple->value->int32);
|
||||||
|
if (auto tuple = dict_find(iter, MESSAGE_KEY_FRAME_COLOR)) frameColor = GColorFromHEX(tuple->value->int32);
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
GColor GetBackgroundColor() {return backgroundColor; }
|
||||||
|
GColor GetDigitColor() {return digitColor; }
|
||||||
|
GColor GetFrameColor() {return frameColor; }
|
||||||
|
}
|
||||||
12
src/c/settings.hpp
Normal file
12
src/c/settings.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pebble-cpp/pebble.hpp>
|
||||||
|
|
||||||
|
namespace settings {
|
||||||
|
void Save();
|
||||||
|
void Load();
|
||||||
|
void HandleMsg(DictionaryIterator *iter);
|
||||||
|
GColor GetBackgroundColor();
|
||||||
|
GColor GetDigitColor();
|
||||||
|
GColor GetFrameColor();
|
||||||
|
}
|
||||||
@ -1,10 +1,36 @@
|
|||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
"type": "heading",
|
type: "section",
|
||||||
"defaultValue": "Example Header Item"
|
items: [
|
||||||
|
{
|
||||||
|
type: "heading",
|
||||||
|
defaultValue: "Colors",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "text",
|
label: "Background Color",
|
||||||
"defaultValue": "Example text item."
|
messageKey: "BACKGROUND_COLOR",
|
||||||
}
|
type: "color",
|
||||||
|
defaultValue: "#FFFFFF",
|
||||||
|
allowGray: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Digit Color",
|
||||||
|
messageKey: "DIGIT_COLOR",
|
||||||
|
type: "color",
|
||||||
|
defaultValue: "#000000",
|
||||||
|
allowGray: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Frame Color",
|
||||||
|
messageKey: "FRAME_COLOR",
|
||||||
|
type: "color",
|
||||||
|
defaultValue: "#00000",
|
||||||
|
allowGray: true,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "submit",
|
||||||
|
defaultValue: "Save Settings",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
@ -1,4 +1,3 @@
|
|||||||
var Clay = require('pebble-clay');
|
var Clay = require('pebble-clay');
|
||||||
var clayConfig = require('./config');
|
var clayConfig = require('./config');
|
||||||
var clay = new Clay(clayConfig);
|
var clay = new Clay(clayConfig);
|
||||||
console.log('Loaded clay!');
|
|
||||||
Loading…
x
Reference in New Issue
Block a user