Skip to content

Commit

Permalink
Enhancements for SDL
Browse files Browse the repository at this point in the history
- Fix: SDL2 using mouse
- Fix: SDL2 controls more reponsive
- Change: SDL2 renderer change for better performance
- Fix: XSlider control tick drawing
- Change: Makefile added GSLC_LDLIB_EXTRA variable
  • Loading branch information
ImpulseAdventure committed Mar 18, 2017
1 parent b15e695 commit dfd68be
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 42 deletions.
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ A lightweight GUI framework suitable for embedded displays
- Pure C library, no dynamic memory allocation
- Widgets: text, images, buttons, checkboxes, radio buttons, sliders, etc. plus extensions and multiple pages.
- Platform-independent GUI core currently supports: SDL1.2, SDL2.0, Adafruit-GFX
- Typical target: Raspberry Pi, Arduino, Cortex M0 (Feather M0), LINUX
- Typical displays: PiTFT, Waveshare, Adafruit TFT 2.2" / 2.8"
- Typical target: Raspberry Pi, Arduino, Cortex M0 (Feather M0), LINUX, Beaglebone Black
- Typical displays: PiTFT, Waveshare, Adafruit TFT 2.2" / 2.8" / 1.44', OLED 0.96"
- Supports touchscreen control
- No GUIslice installation -- just add include files and go!
- LINUX Dependencies: sdl, sdl-ttf, optional: tslib
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ A lightweight GUI framework suitable for embedded displays
- Pure C library, no dynamic memory allocation
- Widgets: text, images, buttons, checkboxes, radio buttons, sliders, etc. plus extensions and multiple pages.
- Platform-independent GUI core currently supports: SDL1.2, SDL2.0, Adafruit-GFX
- Typical target: Raspberry Pi, Arduino, Cortex M0 (Feather M0), LINUX
- Typical displays: PiTFT, Waveshare, Adafruit TFT 2.2" / 2.8"
- Typical target: Raspberry Pi, Arduino, Cortex M0 (Feather M0), LINUX, Beaglebone Black
- Typical displays: PiTFT, Waveshare, Adafruit TFT 2.2" / 2.8" / 1.44', OLED 0.96"
- Supports touchscreen control
- No GUIslice installation -- just add include files and go!
- LINUX Dependencies: sdl, sdl-ttf, optional: tslib
Expand Down
Binary file modified docs/GUIslice_config_guide.xlsx
Binary file not shown.
Binary file modified docs/GUIslice_ref.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "GUIslice"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.8.5
PROJECT_NUMBER = 0.8.6

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
48 changes: 30 additions & 18 deletions src/GUIslice.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// - Calvin Hass
// - http://www.impulseadventure.com/elec/guislice-gui.html
//
// - Version 0.8.5 (2017/03/13)
// - Version 0.8.6 (2017/03/17)
// =======================================================================
//
// The MIT License
Expand Down Expand Up @@ -48,7 +48,7 @@
#include <stdarg.h> // For va_*

// Version definition
#define GUISLICE_VER "0.8.5"
#define GUISLICE_VER "0.8.6"


// ========================================================================
Expand Down Expand Up @@ -299,22 +299,34 @@ void gslc_Update(gslc_tsGui* pGui)
int16_t nTouchX = 0;
int16_t nTouchY = 0;
uint16_t nTouchPress = 0;
bool bTouchEvent = false;

// Poll for touchscreen presses
bTouchEvent = gslc_GetTouch(pGui,&nTouchX,&nTouchY,&nTouchPress);

if (bTouchEvent) {
// Track and handle the touch events
// - Handle the events on the current page
gslc_TrackTouch(pGui,pGui->pCurPage,nTouchX,nTouchY,nTouchPress);

#ifdef DBG_TOUCH
// Highlight current touch for coordinate debug
gslc_tsRect rMark = gslc_ExpandRect((gslc_tsRect){(int16_t)nTouchX,(int16_t)nTouchY,1,1},1,1);
gslc_DrawFrameRect(pGui,rMark,GSLC_COL_YELLOW);
#endif
}
bool bTouchEvent = true;

// Handle touchscreen presses
// - We clear the event queue here so that we don't fall behind
// - In the time it takes to update the display, several mouse /
// finger events may have occurred. If we only handle a single
// motion event per display update, then we may experience very
// lagging responsiveness from the controls.
// - Instead, we drain the even queue before proceeding on to the
// display update, giving rise to a much more responsive GUI.
// - Note that SDL2 may synchronize the RenderPresent call to
// the VSYNC, which will effectively insert a delay into the
// gslc_PageRedrawGo() call below. It might be possible to
// adjust this blocking behavior via SDL_RENDERER_PRESENTVSYNC.
do {
bTouchEvent = gslc_GetTouch(pGui,&nTouchX,&nTouchY,&nTouchPress);
if (bTouchEvent) {
// Track and handle the touch events
// - Handle the events on the current page
gslc_TrackTouch(pGui,pGui->pCurPage,nTouchX,nTouchY,nTouchPress);

#ifdef DBG_TOUCH
// Highlight current touch for coordinate debug
gslc_tsRect rMark = gslc_ExpandRect((gslc_tsRect){(int16_t)nTouchX,(int16_t)nTouchY,1,1},1,1);
gslc_DrawFrameRect(pGui,rMark,GSLC_COL_YELLOW);
#endif
}
} while (bTouchEvent);

// Issue a timer tick to all pages
uint8_t nPageInd;
Expand Down
2 changes: 1 addition & 1 deletion src/GUIslice.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// - Calvin Hass
// - http://www.impulseadventure.com/elec/guislice-gui.html
//
// - Version 0.8.5 (2017/03/13)
// - Version 0.8.6 (2017/03/17)
// =======================================================================
//
// The MIT License
Expand Down
12 changes: 7 additions & 5 deletions src/GUIslice_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ extern "C" {
// Graphics display driver-specific additional configuration
#if defined(DRV_DISP_SDL1)
// Define default device paths for framebuffer & touchscreen
#define GSLC_DEV_FB "/dev/fb1"
#define GSLC_DEV_TOUCH "/dev/input/touchscreen"
#define GSLC_DEV_FB "/dev/fb1"
#define GSLC_DEV_TOUCH "/dev/input/touchscreen"
#define GSLC_DEV_VID_DRV "fbcon"
// Enable SDL startup workaround? (1 to enable, 0 to disable)
#define DRV_SDL_FIX_START 1
// Show SDL mouse (1 to show, 0 to hide)
Expand All @@ -87,11 +88,12 @@ extern "C" {
// - Raspberry Pi can support hardware acceleration onto fb0
// - To use SDL2.0 with hardware acceleration with such displays,
// use fb0 as the target and then run fbcp to mirror fb0 to fb1
#define GSLC_DEV_FB "/dev/fb0"
#define GSLC_DEV_TOUCH "/dev/input/touchscreen"
#define GSLC_DEV_FB "/dev/fb0"
#define GSLC_DEV_TOUCH ""
#define GSLC_DEV_VID_DRV "x11"

// Show SDL mouse (1 to show, 0 to hide)
#define DRV_SDL_MOUSE_SHOW 0
#define DRV_SDL_MOUSE_SHOW 1

#define GSLC_LOCAL_STR 1

Expand Down
26 changes: 26 additions & 0 deletions src/GUIslice_drv_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,32 @@ bool gslc_DrvGetTouch(gslc_tsGui* pGui,int16_t* pnX,int16_t* pnY,uint16_t* pnPre
*pnY = (int16_t)nY;
(*pnPress) = 0;
bRet = true;

// SDL2 defines touch events instead of reusing mouse events
#if defined(DRV_DISP_SDL2)
} else if (sEvent.type == SDL_FINGERMOTION) {
*pnX = (int16_t)(sEvent.tfinger.x);
*pnY = (int16_t)(sEvent.tfinger.y);
// For FINGERMOTION, we want to return the previous state of
// the touch pressure in pnPress as FINGERMOTION is called during
// both up and down states.
// Note that we can't simply leave pnPress as-is since it
// doesn't retain its state in the caller.
*pnPress = pGui->nTouchLastPress;
bRet = true;
} else if (sEvent.type == SDL_FINGERDOWN) {
*pnX = (int16_t)(sEvent.tfinger.x);
*pnY = (int16_t)(sEvent.tfinger.y);
(*pnPress) = 1;
bRet = true;
} else if (sEvent.type == SDL_FINGERUP) {
*pnX = (int16_t)(sEvent.tfinger.x);
*pnY = (int16_t)(sEvent.tfinger.y);
(*pnPress) = 0;
bRet = true;
#endif

}
} // SDL_PollEvent()

Expand Down
19 changes: 13 additions & 6 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
##
## Makefile for GUIslice library
## - Calvin Hass
## - http://www.impulseadventure.com/elec/
## - http://www.impulseadventure.com/elec/guislice-gui.html
##
## NOTE: This Makefile handles both SDL1.2 and SDL2 compilation.
## A simpler Makefile can be used if this flexibility is
## not required.

DEBUG = -O3
CC = gcc
Expand All @@ -26,25 +29,29 @@ GSLC_CORE = ../src/GUIslice.c ../src/GUIslice_ex.c
GSLC_DRV := SDL1
#GSLC_DRV := SDL2

# Define any extra linker settings
# - For tslib (GUIslice_config.h has #define DRV_TOUCH_TSLIB), add "-lts"
#GSLC_LDLIB_EXTRA :=
GSLC_LDLIB_EXTRA := -lts

# === SDL1.2 ===
ifeq (SDL1,${GSLC_DRV})
$(info GUIslice driver mode: SDL1)
GSLC_SRCS = ../src/GUIslice_drv_sdl.c
# - Add "-lts" if GUIslice_config.h: #define DRV_TOUCH_TSLIB
LDLIBS = -lSDL -lSDL_ttf -lts
# - Add extra linker libraries if needed
LDLIBS = -lSDL -lSDL_ttf ${GSLC_LDLIB_EXTRA}
endif

# === SDL2.0 ===
ifeq (SDL2,${GSLC_DRV})
$(info GUIslice driver mode: SDL2)
GSLC_SRCS = ../src/GUIslice_drv_sdl.c
# - Add "-lts" if GUIslice_config.h: #define DRV_TOUCH_TSLIB
LDLIBS = -lSDL2 -lSDL2_ttf -lts
# - Add extra linker libraries if needed
LDLIBS = -lSDL2 -lSDL2_ttf ${GSLC_LDLIB_EXTRA}
endif

# === Adafruit-GFX ===
# TBD
# No makefile for Arduino as most users will use the IDE for compilation

# ---------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/gslc-ex01.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void UserInitEnv()
#if defined(DRV_DISP_SDL1) || defined(DRV_DISP_SDL2)
setenv((char*)"FRAMEBUFFER",GSLC_DEV_FB,1);
setenv((char*)"SDL_FBDEV",GSLC_DEV_FB,1);
setenv((char*)"SDL_VIDEODRIVER",(char*)"fbcon",1);
setenv((char*)"SDL_VIDEODRIVER",GSLC_DEV_VID_DRV,1);
#endif

#if defined(DRV_TOUCH_TSLIB)
Expand Down
2 changes: 1 addition & 1 deletion tests/gslc-ex02.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void UserInitEnv()
#if defined(DRV_DISP_SDL1) || defined(DRV_DISP_SDL2)
setenv((char*)"FRAMEBUFFER",GSLC_DEV_FB,1);
setenv((char*)"SDL_FBDEV",GSLC_DEV_FB,1);
setenv((char*)"SDL_VIDEODRIVER",(char*)"fbcon",1);
setenv((char*)"SDL_VIDEODRIVER",GSLC_DEV_VID_DRV,1);
#endif

#if defined(DRV_TOUCH_TSLIB)
Expand Down
2 changes: 1 addition & 1 deletion tests/gslc-ex03.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void UserInitEnv()
#if defined(DRV_DISP_SDL1) || defined(DRV_DISP_SDL2)
setenv((char*)"FRAMEBUFFER",GSLC_DEV_FB,1);
setenv((char*)"SDL_FBDEV",GSLC_DEV_FB,1);
setenv((char*)"SDL_VIDEODRIVER",(char*)"fbcon",1);
setenv((char*)"SDL_VIDEODRIVER",GSLC_DEV_VID_DRV,1);
#endif

#if defined(DRV_TOUCH_TSLIB)
Expand Down
2 changes: 1 addition & 1 deletion tests/gslc-ex04.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void UserInitEnv()
#if defined(DRV_DISP_SDL1) || defined(DRV_DISP_SDL2)
setenv((char*)"FRAMEBUFFER",GSLC_DEV_FB,1);
setenv((char*)"SDL_FBDEV",GSLC_DEV_FB,1);
setenv((char*)"SDL_VIDEODRIVER",(char*)"fbcon",1);
setenv((char*)"SDL_VIDEODRIVER",GSLC_DEV_VID_DRV,1);
#endif

#if defined(DRV_TOUCH_TSLIB)
Expand Down
2 changes: 1 addition & 1 deletion tests/gslc-ex05.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void UserInitEnv()
#if defined(DRV_DISP_SDL1) || defined(DRV_DISP_SDL2)
setenv((char*)"FRAMEBUFFER",GSLC_DEV_FB,1);
setenv((char*)"SDL_FBDEV",GSLC_DEV_FB,1);
setenv((char*)"SDL_VIDEODRIVER",(char*)"fbcon",1);
setenv((char*)"SDL_VIDEODRIVER",GSLC_DEV_VID_DRV,1);
#endif

#if defined(DRV_TOUCH_TSLIB)
Expand Down
2 changes: 1 addition & 1 deletion tests/gslc-ex06.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void UserInitEnv()
#if defined(DRV_DISP_SDL1) || defined(DRV_DISP_SDL2)
setenv((char*)"FRAMEBUFFER",GSLC_DEV_FB,1);
setenv((char*)"SDL_FBDEV",GSLC_DEV_FB,1);
setenv((char*)"SDL_VIDEODRIVER",(char*)"fbcon",1);
setenv((char*)"SDL_VIDEODRIVER",GSLC_DEV_VID_DRV,1);
#endif

#if defined(DRV_TOUCH_TSLIB)
Expand Down
2 changes: 1 addition & 1 deletion tests/gslc-ex07.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void UserInitEnv()
#if defined(DRV_DISP_SDL1) || defined(DRV_DISP_SDL2)
setenv((char*)"FRAMEBUFFER",GSLC_DEV_FB,1);
setenv((char*)"SDL_FBDEV",GSLC_DEV_FB,1);
setenv((char*)"SDL_VIDEODRIVER",(char*)"fbcon",1);
setenv((char*)"SDL_VIDEODRIVER",GSLC_DEV_VID_DRV,1);
#endif

#if defined(DRV_TOUCH_TSLIB)
Expand Down

0 comments on commit dfd68be

Please sign in to comment.