Improving keyboard widget default renderer (thanks to TriZet)
This commit is contained in:
parent
a51e2b3511
commit
b89ce7c7b3
@ -7,6 +7,7 @@ FEATURE: Added support for numerous compilers
|
|||||||
FIX: Improving STM32LTDC driver
|
FIX: Improving STM32LTDC driver
|
||||||
FEATURE: Added support for NIOS-II platform
|
FEATURE: Added support for NIOS-II platform
|
||||||
FEATURE: Added Altera-MAX10-NEEK board support
|
FEATURE: Added Altera-MAX10-NEEK board support
|
||||||
|
FIX: Vastly improving keyboard widget default rendering
|
||||||
|
|
||||||
|
|
||||||
*** Release 2.4 ***
|
*** Release 2.4 ***
|
||||||
|
@ -403,9 +403,12 @@ void gwinKeyboardDraw_Normal(GWidgetObject *gw, void *param) {
|
|||||||
ucode key;
|
ucode key;
|
||||||
fixed fx, fy;
|
fixed fx, fy;
|
||||||
const GColorSet *pcol;
|
const GColorSet *pcol;
|
||||||
|
|
||||||
(void) param;
|
(void) param;
|
||||||
|
|
||||||
if (gw->g.vmt != (gwinVMT *)&keyboardVMT) return;
|
// Make sure that this is a keyboard widget object
|
||||||
|
if (gw->g.vmt != (gwinVMT *)&keyboardVMT)
|
||||||
|
return;
|
||||||
|
|
||||||
// Get the y parameters
|
// Get the y parameters
|
||||||
rows = NumKeyRows(gk->keyset);
|
rows = NumKeyRows(gk->keyset);
|
||||||
@ -422,21 +425,71 @@ void gwinKeyboardDraw_Normal(GWidgetObject *gw, void *param) {
|
|||||||
fx = FIXED(gk->w.g.width) / cols;
|
fx = FIXED(gk->w.g.width) / cols;
|
||||||
for (col = 0; col < cols; col=kcols) {
|
for (col = 0; col < cols; col=kcols) {
|
||||||
|
|
||||||
// Choose the color
|
// Get the correct color set
|
||||||
if (!(gk->w.g.flags & GWIN_FLG_SYSENABLED))
|
if (!(gk->w.g.flags & GWIN_FLG_SYSENABLED))
|
||||||
pcol = &gk->w.pstyle->disabled;
|
pcol = &gk->w.pstyle->disabled;
|
||||||
else if (gk->keyrow == row && gk->keycol == col)
|
|
||||||
pcol = &gk->w.pstyle->pressed;
|
|
||||||
else
|
else
|
||||||
pcol = &gk->w.pstyle->enabled;
|
pcol = &gk->w.pstyle->enabled;
|
||||||
|
|
||||||
// Get the key
|
// Get the key
|
||||||
key = UTF8CharAt(krow, col);
|
key = UTF8CharAt(krow, col);
|
||||||
|
|
||||||
// Amalgamate identical keys into one big key
|
// Fuse identical keys into one big key
|
||||||
kcols = col+1;
|
kcols = col+1;
|
||||||
while (UTF8CharAt(krow, kcols) == key)
|
while (UTF8CharAt(krow, kcols) == key)
|
||||||
kcols++;
|
kcols++;
|
||||||
|
|
||||||
|
// If quick update needed and keyboard already drawn (if not use this flag, then bug when screen touched before keyboard was drawn)
|
||||||
|
if ( (gk->w.g.flags & GKEYBOARD_FLG_QUICKUPDATE) && !(gk->w.g.flags & GWIN_FLG_BGREDRAW) ) {
|
||||||
|
|
||||||
|
// If key pressed
|
||||||
|
if ( (gk->keyrow != GKEY_BAD_ROWCOL) && (gk->keycol != GKEY_BAD_ROWCOL) ) {
|
||||||
|
|
||||||
|
// And previous key have
|
||||||
|
if ( (gk->lastkeyrow != GKEY_BAD_ROWCOL) && (gk->lastkeycol != GKEY_BAD_ROWCOL) ) {
|
||||||
|
|
||||||
|
if (gk->lastkeyrow == row && gk->lastkeycol == col) {
|
||||||
|
// If keyboard has no "disabled" color
|
||||||
|
if (pcol != &gk->w.pstyle->disabled)
|
||||||
|
pcol = &gk->w.pstyle->enabled;
|
||||||
|
gk->lastkeyrow = gk->lastkeycol = GKEY_BAD_ROWCOL;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no previous key
|
||||||
|
else {
|
||||||
|
|
||||||
|
if (gk->keyrow == row && gk->keycol == col) {
|
||||||
|
if (pcol != &gk->w.pstyle->disabled)
|
||||||
|
pcol = &gk->w.pstyle->pressed;
|
||||||
|
gk->lastkeyrow = row;
|
||||||
|
gk->lastkeycol = col;
|
||||||
|
}
|
||||||
|
else if (gk->lastkeyrow == row && gk->lastkeycol == col)
|
||||||
|
{
|
||||||
|
if (pcol != &gk->w.pstyle->disabled) pcol = &gk->w.pstyle->enabled;
|
||||||
|
}
|
||||||
|
else continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If key up, and need clear the previous key
|
||||||
|
else if ( (gk->lastkeyrow != GKEY_BAD_ROWCOL) && (gk->lastkeycol != GKEY_BAD_ROWCOL) )
|
||||||
|
{
|
||||||
|
if ( (gk->lastkeyrow == row) && (gk->lastkeycol == col) )
|
||||||
|
{
|
||||||
|
if (pcol != &gk->w.pstyle->disabled) pcol = &gk->w.pstyle->enabled;
|
||||||
|
}
|
||||||
|
else continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gk->lastkeyrow = gk->lastkeycol = GKEY_BAD_ROWCOL;
|
||||||
|
}
|
||||||
|
|
||||||
x = NONFIXED(fx * col + FIXED0_5);
|
x = NONFIXED(fx * col + FIXED0_5);
|
||||||
cx = NONFIXED(fx * kcols + FIXED0_5) - x;
|
cx = NONFIXED(fx * kcols + FIXED0_5) - x;
|
||||||
|
|
||||||
@ -446,8 +499,10 @@ void gwinKeyboardDraw_Normal(GWidgetObject *gw, void *param) {
|
|||||||
cap[UCode2UTF8((utf8 *)cap, key)] = 0;
|
cap[UCode2UTF8((utf8 *)cap, key)] = 0;
|
||||||
pcap = cap;
|
pcap = cap;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(*pcap) {
|
switch(*pcap) {
|
||||||
case '\001': // Shift (up arrow)
|
|
||||||
|
case '\001': // Shift (up-arrow)
|
||||||
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
||||||
|
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x +cx/4, gw->g.y+y+cy/2, gw->g.x+x+cx/2, gw->g.y+y +cy/4, pcol->text); /* / \ */
|
gdispGDrawLine(gw->g.display, gw->g.x+x +cx/4, gw->g.y+y+cy/2, gw->g.x+x+cx/2, gw->g.y+y +cy/4, pcol->text); /* / \ */
|
||||||
@ -457,8 +512,10 @@ switch(*pcap) {
|
|||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2-cx/6, gw->g.y+y+cy/2, gw->g.x+x+cx/2-cx/6, gw->g.y+y+cy -cy/3, pcol->text); /* || */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2-cx/6, gw->g.y+y+cy/2, gw->g.x+x+cx/2-cx/6, gw->g.y+y+cy -cy/3, pcol->text); /* || */
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy/2, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy -cy/3, pcol->text);
|
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy/2, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy -cy/3, pcol->text);
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2-cx/6, gw->g.y+y+cy -cy/3, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy -cy/3, pcol->text); /* _ */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2-cx/6, gw->g.y+y+cy -cy/3, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy -cy/3, pcol->text); /* _ */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case '\002': // Shift locked (up arrow - bold)
|
|
||||||
|
case '\002': // Shift locked (underlined up-arrow)
|
||||||
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
||||||
|
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x +cx/4, gw->g.y+y+cy/2, gw->g.x+x+cx/2, gw->g.y+y +cy/4, pcol->text); /* / \ */
|
gdispGDrawLine(gw->g.display, gw->g.x+x +cx/4, gw->g.y+y+cy/2, gw->g.x+x+cx/2, gw->g.y+y +cy/4, pcol->text); /* / \ */
|
||||||
@ -469,20 +526,27 @@ switch(*pcap) {
|
|||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy/2, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy -cy/3, pcol->text);
|
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy/2, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy -cy/3, pcol->text);
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2-cx/6, gw->g.y+y+cy -cy/3, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy -cy/3, pcol->text); /* _ */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2-cx/6, gw->g.y+y+cy -cy/3, gw->g.x+x+cx/2+cx/6, gw->g.y+y+cy -cy/3, pcol->text); /* _ */
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2-cx/5, gw->g.y+y+cy -cy/4, gw->g.x+x+cx/2+cx/5, gw->g.y+y+cy -cy/4, pcol->text); /* ___ */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+cx/2-cx/5, gw->g.y+y+cy -cy/4, gw->g.x+x+cx/2+cx/5, gw->g.y+y+cy -cy/4, pcol->text); /* ___ */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case '\t':
|
|
||||||
|
case '\t': // Tabulator
|
||||||
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
||||||
|
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+1, gw->g.y+y+1, gw->g.x+x+cx-1, gw->g.y+y+cy/2, pcol->text);
|
gdispGDrawLine(gw->g.display, gw->g.x+x+1, gw->g.y+y+1, gw->g.x+x+cx-1, gw->g.y+y+cy/2, pcol->text);
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+1, gw->g.y+y+cy-1, gw->g.x+x+cx-1, gw->g.y+y+cy/2, pcol->text);
|
gdispGDrawLine(gw->g.display, gw->g.x+x+1, gw->g.y+y+cy-1, gw->g.x+x+cx-1, gw->g.y+y+cy/2, pcol->text);
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+cx-1, gw->g.y+y+1, gw->g.x+x+cx-1, gw->g.y+y+cy-1, pcol->text);
|
gdispGDrawLine(gw->g.display, gw->g.x+x+cx-1, gw->g.y+y+1, gw->g.x+x+cx-1, gw->g.y+y+cy-1, pcol->text);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\b': // Backspace
|
case '\b': // Backspace
|
||||||
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
||||||
|
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/8, gw->g.y+y+cy/2, gw->g.x+x+cx/2, gw->g.y+y +cy/3, pcol->text); /* / */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/8, gw->g.y+y+cy/2, gw->g.x+x+cx/2, gw->g.y+y +cy/3, pcol->text); /* / */
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/8, gw->g.y+y+cy/2, gw->g.x+x+cx-cx/8, gw->g.y+y+cy/2, pcol->text); /* -- */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/8, gw->g.y+y+cy/2, gw->g.x+x+cx-cx/8, gw->g.y+y+cy/2, pcol->text); /* -- */
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/8, gw->g.y+y+cy/2, gw->g.x+x+cx/2, gw->g.y+y+cy -cy/3, pcol->text); /* \ */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/8, gw->g.y+y+cy/2, gw->g.x+x+cx/2, gw->g.y+y+cy -cy/3, pcol->text); /* \ */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\r': // Enter
|
case '\r': // Enter
|
||||||
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
gdispGFillArea(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->fill);
|
||||||
|
|
||||||
@ -490,12 +554,28 @@ switch(*pcap) {
|
|||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/3, gw->g.y+y+cy/2, gw->g.x+x+cx/3 +cx/8, gw->g.y+y+cy/3, pcol->text); /* / */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/3, gw->g.y+y+cy/2, gw->g.x+x+cx/3 +cx/8, gw->g.y+y+cy/3, pcol->text); /* / */
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/3, gw->g.y+y+cy/2, gw->g.x+x+(cx/3)*2, gw->g.y+y+cy/2, pcol->text); /* -- */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/3, gw->g.y+y+cy/2, gw->g.x+x+(cx/3)*2, gw->g.y+y+cy/2, pcol->text); /* -- */
|
||||||
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/3, gw->g.y+y+cy/2, gw->g.x+x+cx/3 +cx/8, gw->g.y+y+cy -cy/3, pcol->text); /* \ */
|
gdispGDrawLine(gw->g.display, gw->g.x+x+ cx/3, gw->g.y+y+cy/2, gw->g.x+x+cx/3 +cx/8, gw->g.y+y+cy -cy/3, pcol->text); /* \ */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
|
default: // Regular character
|
||||||
gdispGFillStringBox(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcap, gw->g.font, pcol->text, pcol->fill, justifyCenter);
|
gdispGFillStringBox(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcap, gw->g.font, pcol->text, pcol->fill, justifyCenter);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdispGDrawBox(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->text); // Frame
|
// Draw the frame (border around the entire widget)
|
||||||
|
gdispGDrawBox(gw->g.display, gw->g.x+x, gw->g.y+y, cx, cy, pcol->edge);
|
||||||
|
|
||||||
|
// If key up and we already cleared the previous key
|
||||||
|
if ( (gk->keyrow == GKEY_BAD_ROWCOL) && (gk->keycol == GKEY_BAD_ROWCOL) && (gk->lastkeyrow == row) && (gk->lastkeycol == col) ) {
|
||||||
|
gk->lastkeyrow = gk->lastkeycol = GKEY_BAD_ROWCOL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just quit the cycle if we did all the work in order not to waste any CPU time
|
||||||
|
if ( (row >= gk->keyrow && col >= gk->keycol) && (row >= gk->lastkeyrow && col >= gk->lastkeycol) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user