Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw color images from RAM / Flash #101

Merged
merged 5 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions examples/arduino/ex28_ard_btn_img_flash/ex28_ard_btn_img_flash.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//
// GUIslice Library Examples
// - Calvin Hass
// - https://www.impulseadventure.com/elec/guislice-gui.html
// - https://github.com/ImpulseAdventure/GUIslice
// - Example 28 (Arduino):
// - Accept touch input, graphic button (from FLASH)
// - Expected behavior: Clicking on button terminates program
// - Based on Example 03
//
// ARDUINO NOTES:
// - GUIslice_config.h must be edited to match the pinout connections
// between the Arduino CPU and the display controller (see ADAGFX_PIN_*).
// - IMPORTANT: This sketch uses graphics located in FLASH memory. Users must
// convert images from their native format (eg. BMP, PNG, etc.) into a
// C array. Please refer to the following guide for details:
// https://github.com/ImpulseAdventure/GUIslice/wiki/Display-Images-from-FLASH
// The converted file must be included in the sketch as shown below.
// - This example assumes that two image files have been created and
// imported: "exit_n24.bmp" and "exit_g24.bmp"
// representing the quit button normal and glowing states. Reference
// 24-bit BMP versions of these files have been included in /arduino/res


#include "GUIslice.h"
#include "GUIslice_drv.h"

extern "C" const unsigned short exit_n24[] PROGMEM;
extern "C" const unsigned short exit_g24[] PROGMEM;

// Enumerations for pages, elements, fonts, images
enum {E_PG_MAIN};
enum {E_ELEM_BOX,E_ELEM_BTN_QUIT};

bool m_bQuit = false;

// Instantiate the GUI
#define MAX_PAGE 1
#define MAX_ELEM_PG_MAIN 2

gslc_tsGui m_gui;
gslc_tsDriver m_drv;
gslc_tsPage m_asPage[MAX_PAGE];
gslc_tsElem m_asPageElem[MAX_ELEM_PG_MAIN];
gslc_tsElemRef m_asPageElemRef[MAX_ELEM_PG_MAIN];

// Define debug message function
static int16_t DebugOut(char ch) { if (ch == (char)'\n') Serial.println(""); else Serial.write(ch); return 0; }

// Button callbacks
bool CbBtnQuit(void* pvGui,void *pvElem,gslc_teTouch eTouch,int16_t nX,int16_t nY)
{
if (eTouch == GSLC_TOUCH_UP_IN) {
m_bQuit = true;
}
return true;
}


bool InitOverlays()
{
gslc_tsElemRef* pElemRef = NULL;

gslc_PageAdd(&m_gui,E_PG_MAIN,m_asPageElem,MAX_ELEM_PG_MAIN,m_asPageElemRef,MAX_ELEM_PG_MAIN);

// Background flat color
gslc_SetBkgndColor(&m_gui,GSLC_COL_GRAY_DK2);

// Create background box
pElemRef = gslc_ElemCreateBox(&m_gui,E_ELEM_BOX,E_PG_MAIN,(gslc_tsRect){10,50,300,150});
gslc_ElemSetCol(&m_gui,pElemRef,GSLC_COL_WHITE,GSLC_COL_BLACK,GSLC_COL_BLACK);

// Create Quit button with image label
pElemRef = gslc_ElemCreateBtnImg(&m_gui,E_ELEM_BTN_QUIT,E_PG_MAIN,(gslc_tsRect){258,70,32,32},
gslc_GetImageFromProg((const unsigned char*)exit_n24,GSLC_IMGREF_FMT_BMP24),
gslc_GetImageFromProg((const unsigned char*)exit_g24,GSLC_IMGREF_FMT_BMP24),
&CbBtnQuit);
gslc_ElemSetFillEn(&m_gui,pElemRef,true); // On slow displays disable transparency to prevent full redraw

return true;
}

void setup()
{
// Initialize debug output
Serial.begin(9600);
gslc_InitDebug(&DebugOut);
//delay(1000); // NOTE: Some devices require a delay after Serial.begin() before serial port can be used

// Initialize
if (!gslc_Init(&m_gui,&m_drv,m_asPage,MAX_PAGE,NULL,0)) { return; }

// Create the graphic elements
InitOverlays();

// Start up display on main page
gslc_SetPageCur(&m_gui,E_PG_MAIN);

m_bQuit = false;
}

void loop()
{
// Periodically call GUIslice update function
gslc_Update(&m_gui);

// In a real program, we would detect the button press and take an action.
// For this Arduino demo, we will pretend to exit by emulating it with an
// infinite loop. Note that interrupts are not disabled so that any debug
// messages via Serial have an opportunity to be transmitted.
if (m_bQuit) {
gslc_Quit(&m_gui);
while (1) { }
}

}

82 changes: 82 additions & 0 deletions examples/arduino/ex28_ard_btn_img_flash/exit_g24.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Generated by : ImageConverter 565 Online
// Generated from : exit_g24.png
// Image Size : 32x32 pixels
// Memory usage : 2048 bytes

// Please refer to https://github.com/ImpulseAdventure/GUIslice/wiki/Display-Images-from-FLAS
// for details on how to generate this file.

#include "GUIslice.h"
#include "GUIslice_config.h"
#if (GSLC_USE_PROGMEM)
#include <avr/pgmspace.h>
#endif

const unsigned short exit_g24[1024+2] GSLC_PMEM ={
32, // Height of image
32, // Width of image
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5000, 0x5000, 0x5000, 0x5000, 0x5000, 0x5000, 0x5000, // 0x0030 (48) pixels
0x5000, 0x5000, 0x5000, 0x5000, 0x5000, 0x5000, 0x4800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0040 (64) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5001, 0x5000, 0x6000, 0x5000, 0x5800, 0x5800, 0x5800, 0x5800, // 0x0050 (80) pixels
0x5800, 0x5800, 0x5800, 0x5800, 0x5800, 0x4800, 0x3800, 0x4003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0060 (96) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5001, 0x5000, 0x6000, 0x5000, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, // 0x0070 (112) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x4000, 0x3800, 0x4003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0080 (128) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5001, 0x5000, 0x6000, 0x5000, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, // 0x0090 (144) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x4000, 0x3800, 0x4003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00A0 (160) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5001, 0x5000, 0x6000, 0x4800, 0x4000, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, // 0x00B0 (176) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4000, 0x3800, 0x4003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00C0 (192) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x5001, 0x5000, 0x6000, 0x4800, 0x48C3, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, // 0x00D0 (208) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0x50C3, 0x4800, 0x4000, 0x3800, 0x4003, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00E0 (224) pixels
0x0000, 0x0000, 0x0000, 0x5001, 0x5000, 0x6000, 0x4800, 0x4882, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, // 0x00F0 (240) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0x5082, 0x4800, 0x4000, 0x3800, 0x4003, 0x0000, 0x0000, 0x0000, // 0x0100 (256) pixels
0x0000, 0x0000, 0x5001, 0x5000, 0x6000, 0x4800, 0x48C3, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, // 0x0110 (272) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0x50C3, 0x4800, 0x4000, 0x3800, 0x4003, 0x0000, 0x0000, // 0x0120 (288) pixels
0x0000, 0x5001, 0x5000, 0x6000, 0x5000, 0x4000, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, // 0x0130 (304) pixels
0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4000, 0x3800, 0x4003, 0x0000, // 0x0140 (320) pixels
0x0000, 0x5000, 0x6000, 0x5000, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, // 0x0150 (336) pixels
0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x5000, 0x4800, 0x3800, 0x3800, 0x0000, // 0x0160 (352) pixels
0x0000, 0x5000, 0x5000, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, // 0x0170 (368) pixels
0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x3000, 0x3000, 0x0000, // 0x0180 (384) pixels
0x0000, 0x5000, 0x5800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5082, // 0x0190 (400) pixels
0x5082, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x3000, 0x3000, 0x0000, // 0x01A0 (416) pixels
0x0000, 0x5000, 0x5800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, // 0x01B0 (432) pixels
0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x3000, 0x3000, 0x0000, // 0x01C0 (448) pixels
0x0000, 0x5000, 0x5800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, // 0x01D0 (464) pixels
0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x3000, 0x3000, 0x0000, // 0x01E0 (480) pixels
0x0000, 0x5000, 0x5800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5082, 0xF800, 0xF800, 0xF800, // 0x01F0 (496) pixels
0xF800, 0xF800, 0xF800, 0x5082, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x3000, 0x3000, 0x0000, // 0x0200 (512) pixels
0x0000, 0x5000, 0x5800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5082, 0xF800, 0xF800, 0xF800, // 0x0210 (528) pixels
0xF800, 0xF800, 0xF800, 0x5082, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x3000, 0x3000, 0x0000, // 0x0220 (544) pixels
0x0000, 0x5000, 0x5800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, // 0x0230 (560) pixels
0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x3000, 0x3000, 0x0000, // 0x0240 (576) pixels
0x0000, 0x5000, 0x5800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, // 0x0250 (592) pixels
0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x3000, 0x3000, 0x0000, // 0x0260 (608) pixels
0x0000, 0x5000, 0x5800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5082, // 0x0270 (624) pixels
0x5082, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x3000, 0x3000, 0x0000, // 0x0280 (640) pixels
0x0000, 0x5000, 0x5800, 0x5000, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, // 0x0290 (656) pixels
0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x3800, 0x3000, 0x0000, // 0x02A0 (672) pixels
0x0000, 0x5000, 0x4800, 0x4800, 0x5000, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, // 0x02B0 (688) pixels
0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x5000, 0x4800, 0x2800, 0x3000, 0x0000, // 0x02C0 (704) pixels
0x0000, 0x4001, 0x3000, 0x4000, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, // 0x02D0 (720) pixels
0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x5000, 0x4800, 0x2000, 0x1800, 0x2801, 0x0000, // 0x02E0 (736) pixels
0x0000, 0x0000, 0x4002, 0x3800, 0x4000, 0x4800, 0x50C3, 0xF800, 0xF800, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, // 0x02F0 (752) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0xF800, 0xF800, 0x58C3, 0x4800, 0x2000, 0x1800, 0x2801, 0x0000, 0x0000, // 0x0300 (768) pixels
0x0000, 0x0000, 0x0000, 0x4002, 0x3800, 0x4000, 0x4800, 0x5082, 0xF800, 0xF800, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, // 0x0310 (784) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0xF800, 0xF800, 0x5082, 0x4000, 0x2000, 0x1800, 0x2801, 0x0000, 0x0000, 0x0000, // 0x0320 (800) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x4002, 0x3800, 0x4000, 0x4800, 0x50C3, 0x5104, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, // 0x0330 (816) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5104, 0x58C3, 0x4000, 0x2000, 0x1800, 0x2801, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0340 (832) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4002, 0x3800, 0x4000, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, // 0x0350 (848) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x2000, 0x1800, 0x2801, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0360 (864) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4002, 0x3800, 0x4000, 0x4800, 0x5000, 0x5000, 0x5000, 0x5000, 0x5000, 0x5000, // 0x0370 (880) pixels
0x5000, 0x5000, 0x5000, 0x5000, 0x4800, 0x5000, 0x4800, 0x2000, 0x1800, 0x2801, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0380 (896) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4002, 0x3800, 0x4000, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, 0x4800, // 0x0390 (912) pixels
0x4800, 0x4800, 0x4800, 0x4800, 0x5000, 0x4800, 0x2000, 0x1800, 0x2801, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x03A0 (928) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4002, 0x3800, 0x3800, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, // 0x03B0 (944) pixels
0x3000, 0x3000, 0x3000, 0x3000, 0x3800, 0x2800, 0x1800, 0x2801, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x03C0 (960) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4002, 0x3800, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, // 0x03D0 (976) pixels
0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x2801, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x03E0 (992) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x03F0 (1008) pixels
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0400 (1024) pixels
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading