void gwinPutChar(GHandle gh, char c) { #define gcw ((GConsoleObject *)gh) uint8_t width, fy, fp; if (gh->vmt != &consoleVMT || !gh->font) return; fy = gdispGetFontMetric(gh->font, fontHeight); fp = gdispGetFontMetric(gh->font, fontCharPadding); #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif if (c == '\n') { gcw->cx = 0; gcw->cy += fy; // We use lazy scrolling here and only scroll when the next char arrives } else if (c == '\r') { // gcw->cx = 0; } else { width = gdispGetCharWidth(c, gh->font) + fp; if (gcw->cx + width >= gh->width) { gcw->cx = 0; gcw->cy += fy; } if (gcw->cy + fy > gh->height) { #if GDISP_NEED_SCROLL /* scroll the console */ gdispVerticalScroll(gh->x, gh->y, gh->width, gh->height, fy, gh->bgcolor); /* reset the cursor to the start of the last line */ gcw->cx = 0; gcw->cy = (((coord_t)(gh->height/fy))-1)*fy; #else /* clear the console */ gdispFillArea(gh->x, gh->y, gh->width, gh->height, gh->bgcolor); /* reset the cursor to the top of the window */ gcw->cx = 0; gcw->cy = 0; #endif } #if GWIN_CONSOLE_USE_CLEAR_LINES /* clear to the end of the line */ if (gcw->cx == 0) gdispFillArea(gh->x, gh->y + gcw->cy, gh->width, fy, gh->bgcolor); #endif #if GWIN_CONSOLE_USE_FILLED_CHARS gdispFillChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color, gh->bgcolor); #else gdispDrawChar(gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, gh->color); #endif /* update cursor */ gcw->cx += width; } #undef gcw }
void gwinTexteditDefaultDraw(GWidgetObject* gw, void* param) { const char* p; coord_t cpos, tpos; const GColorSet* pcol; (void)param; // Is it a valid handle? if (gw->g.vmt != (gwinVMT*)&texteditVMT) return; // Retrieve colors if ((gw->g.flags & GWIN_FLG_SYSENABLED)) pcol = &gw->pstyle->enabled; else pcol = &gw->pstyle->disabled; // Adjust the text position so the cursor fits in the window p = gw->text; if (!gw2obj->cursorPos) tpos = 0; else { for(cpos = gw2obj->cursorPos; ; p++, cpos--) { tpos = gdispGetStringWidthCount(p, gw->g.font, cpos); if (tpos < gw->g.width-(TEXT_PADDING_LEFT+CURSOR_PADDING_LEFT)) break; } } // Render background and string #if TEXT_PADDING_LEFT gdispGFillArea(gw->g.display, gw->g.x, gw->g.y, TEXT_PADDING_LEFT, gw->g.height, pcol->fill); #endif gdispGFillStringBox(gw->g.display, gw->g.x + TEXT_PADDING_LEFT, gw->g.y, gw->g.width-TEXT_PADDING_LEFT, gw->g.height, p, gw->g.font, pcol->text, pcol->fill, justifyLeft); // Render cursor (if focused) if (gwinGetFocus() == (GHandle)gw) { // Calculate cursor stuff // Draw cursor tpos += gw->g.x + CURSOR_PADDING_LEFT + TEXT_PADDING_LEFT + gdispGetFontMetric(gw->g.font, fontBaselineX)/2; cpos = (gw->g.height - gdispGetFontMetric(gw->g.font, fontHeight))/2 - CURSOR_EXTRA_HEIGHT; gdispGDrawLine(gw->g.display, tpos, gw->g.y + cpos, tpos, gw->g.y + gw->g.height - cpos, pcol->edge); } // Render border gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Render highlighted border if focused _gwidgetDrawFocusRect(gw, 0, 0, gw->g.width, gw->g.height); }
static void ListMouseSelect(GWidgetObject* gw, coord_t x, coord_t y) { const gfxQueueASyncItem* qi; int item, i; coord_t iheight; (void) x; iheight = gdispGetFontMetric(gw->g.font, fontHeight) + LST_VERT_PAD; // Handle click over the list area item = (gw2obj->top + y) / iheight; if (item < 0 || item >= gw2obj->cnt) return; for(qi = gfxQueueASyncPeek(&gw2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) { if ((gw->g.flags & GLIST_FLG_MULTISELECT)) { if (item == i) { qi2li->flags ^= GLIST_FLG_SELECTED; break; } } else { if (item == i) qi2li->flags |= GLIST_FLG_SELECTED; else qi2li->flags &=~ GLIST_FLG_SELECTED; } } _gwinUpdate(&gw->g); sendListEvent(gw, item); }
// a mouse down has occurred over the list area static void ListMouseDown(GWidgetObject* gw, coord_t x, coord_t y) { coord_t iheight, pgsz; // Save our mouse start position gw2obj->start_mouse_x = x; gw2obj->start_mouse_y = y; gw2obj->last_mouse_y = y; // For smooth scrolling, scrolling is done in the ListMouseMove and selection is done on ListMouseUp if (gw->g.flags & GLIST_FLG_SCROLLSMOOTH) return; // Some initial stuff iheight = gdispGetFontMetric(gw->g.font, fontHeight) + LST_VERT_PAD; pgsz = gw->g.height-2; // Handle click over the scroll bar if (x >= gw->g.width-(LST_SCROLLWIDTH+2) && (gw2obj->cnt > pgsz/iheight || (gw->g.flags & GLIST_FLG_SCROLLALWAYS))) { if (y < 2*LST_ARROW_SZ) { if (gw2obj->top > 0) { gw2obj->top -= iheight; if (gw2obj->top < 0) gw2obj->top = 0; _gwinUpdate(&gw->g); } } else if (y >= gw->g.height - 2*LST_ARROW_SZ) { if (gw2obj->top < gw2obj->cnt * iheight - pgsz) { gw2obj->top += iheight; if (gw2obj->top > gw2obj->cnt * iheight - pgsz) gw2obj->top = gw2obj->cnt * iheight - pgsz; _gwinUpdate(&gw->g); } } else if (y < gw->g.height/2) { if (gw2obj->top > 0) { if (gw2obj->top > pgsz) gw2obj->top -= pgsz; else gw2obj->top = 0; _gwinUpdate(&gw->g); } } else { if (gw2obj->top < gw2obj->cnt * iheight - pgsz) { if (gw2obj->top < gw2obj->cnt * iheight - 2*pgsz) gw2obj->top += pgsz; else gw2obj->top = gw2obj->cnt * iheight - pgsz; _gwinUpdate(&gw->g); } } return; } ListMouseSelect(gw, x, y); }
bool_t gwinConsoleSetBuffer(GHandle gh, bool_t onoff) { #define gcw ((GConsoleObject *)gh) if (gh->vmt != &consoleVMT) return FALSE; // Do we want the buffer turned off? if (!onoff) { if (gcw->buffer) { gfxFree(gcw->buffer); gcw->buffer = 0; } return FALSE; } // Is the buffer already on? if (gcw->buffer) return TRUE; // Get the number of characters that fit in the x direction #if GWIN_CONSOLE_HISTORY_AVERAGING gcw->bufsize = gh->width / ((2*gdispGetFontMetric(gh->font, fontMinWidth)+gdispGetFontMetric(gh->font, fontMaxWidth))/3); #else gcw->bufsize = gh->width / gdispGetFontMetric(gh->font, fontMinWidth); #endif gcw->bufsize++; // Allow space for a newline on each line. // Multiply by the number of lines gcw->bufsize *= gh->height / gdispGetFontMetric(gh->font, fontHeight); // Allocate the buffer if (!(gcw->buffer = gfxAlloc(gcw->bufsize))) return FALSE; // All good! gh->flags &= ~GCONSOLE_FLG_OVERRUN; gcw->bufpos = 0; return TRUE; #undef gcw }
msg_t lcdConsoleInit(GConsole *console, coord_t x0, coord_t y0, coord_t width, coord_t height, font_t font, pixel_t bkcolor, pixel_t color) { console->vmt = &vmt; /* read font, get height & padding */ console->fy = gdispGetFontMetric(font, fontHeight); console->fp = gdispGetFontMetric(font, fontCharPadding); /* calculate the size of the console as an integer multiple of characters height*/ console->sx = width; console->sy = (((int16_t)(height/console->fy))-1)*console->fy; console->cx = 0; console->cy = 0; console->x0 = x0; console->y0 = y0; console->bkcolor = bkcolor; console->color = color; console->font = font; gdispFillArea(x0, y0, x0 + width, y0 + height, console->bkcolor); return RDY_OK; }
static void HistoryuRedraw(GWindowObject *gh) { #define gcw ((GConsoleObject *)gh) // No redrawing if there is no history if (!gcw->buffer) return; // We are printing the buffer - don't store it again gh->flags |= GCONSOLE_FLG_NOSTORE; #if !GWIN_CONSOLE_USE_CLEAR_LINES // Clear the screen gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor); #endif // Reset the cursor gcw->cx = 0; gcw->cy = 0; // Reset the current attributes #if GWIN_CONSOLE_ESCSEQ gcw->currattr = gcw->startattr; #endif // Print the buffer gwinPutCharArray(gh, gcw->buffer, gcw->bufpos); #if GWIN_CONSOLE_USE_CLEAR_LINES // Clear the remaining space { coord_t y; y = gcw->cy; if (gcw->cx) y += gdispGetFontMetric(gh->font, fontHeight); if (y < gh->height) gdispGFillArea(gh->display, gh->x, gh->y+y, gh->width, gh->height-y, gh->bgcolor); } #endif // Turn back on storing of buffer contents gh->flags &= ~GCONSOLE_FLG_NOSTORE; #undef gcw }
static void ListMouseMove(GWidgetObject* gw, coord_t x, coord_t y) { int iheight, oldtop; (void) x; if (!(gw->g.flags & GLIST_FLG_SCROLLSMOOTH)) return; if (gw2obj->last_mouse_y != y) { oldtop = gw2obj->top; iheight = gdispGetFontMetric(gw->g.font, fontHeight) + LST_VERT_PAD; gw2obj->top -= y - gw2obj->last_mouse_y; if (gw2obj->top >= gw2obj->cnt * iheight - (gw->g.height-2)) gw2obj->top = gw2obj->cnt * iheight - (gw->g.height-2) - 1; if (gw2obj->top < 0) gw2obj->top = 0; gw2obj->last_mouse_y = y; if (oldtop != gw2obj->top) _gwinUpdate(&gw->g); } }
void gwinListViewItem(GHandle gh, int item) { coord_t iheight; // is it a valid handle? if (gh->vmt != (gwinVMT *)&listVMT) return; // watch out for an invalid item if (item < 0 || item >= gh2obj->cnt) return; // Work out a possible new top for the list iheight = gdispGetFontMetric(gh->font, fontHeight) + LST_VERT_PAD; gh2obj->top = iheight * item; // Adjust the list if (gh2obj->top > gh2obj->cnt * iheight - gh->height-2) gh2obj->top = gh2obj->cnt * iheight - gh->height-2; if (gh2obj->top < 0) gh2obj->top = 0; _gwinUpdate(gh); }
static void createWidgets(void) { gwinSetDefaultFont(gdispOpenFont("UI2")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); bHeight = gdispGetFontMetric(font, fontHeight)+2; // apply default settings GWidgetInit wi; wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; wi.g.show = TRUE; // create ICU1label wi.g.y = bHeight*2; wi.g.x = 0; wi.g.width = 160; wi.g.height = bHeight; wi.text = "ICU1:"; ICU1label = gwinLabelCreate(NULL, &wi); // ICU1vaule wi.g.y = bHeight*2; wi.g.x = 40; wi.g.width = 160; wi.g.height = bHeight; wi.text = "Status2"; ICU1value = gwinLabelCreate(NULL, &wi); // create ICU2label wi.g.y = bHeight*3; wi.g.x = 0; wi.g.width = 160; wi.g.height = bHeight; wi.text = "ICU2:"; ICU2label = gwinLabelCreate(NULL, &wi); // ICU2vaule wi.g.y = bHeight*3; wi.g.x = 40; wi.g.width = 160; wi.g.height = bHeight; wi.text = "000"; ICU2value = gwinLabelCreate(NULL, &wi); // create two status label //status 1 wi.g.y = sheight-bHeight; wi.g.x = 0; wi.g.width = 50; wi.g.height = bHeight; wi.text = "Status1"; ghStatus1 = gwinLabelCreate(NULL, &wi); // status 2 wi.g.y = sheight-bHeight; wi.g.x = 160; wi.g.width = 50; wi.g.height = bHeight; wi.text = "Status2"; ghStatus2 = gwinLabelCreate(NULL, &wi); // Brightness wi.g.y = sheight-(bHeight*2); wi.g.x = 0; wi.g.width = swidth; wi.g.height = bHeight; wi.text = "Brightness"; ghBrightness = gwinSliderCreate(NULL, &wi); gwinSliderSetRange(ghBrightness, 0, 100); gwinSliderSetPosition(ghBrightness, 50); gdispSetBacklight(50); // create ADC label // ADClabel1 wi.g.y = 0; wi.g.x = 0; wi.g.width = 50; wi.g.height = bHeight; wi.text = "ADC1:"; ADClabel = gwinLabelCreate(NULL, &wi); // ADClabel1 wi.g.y = 0; wi.g.x = 40; wi.g.width = 50; wi.g.height = bHeight; wi.text = "ADC value"; ADCvalue = gwinLabelCreate(NULL, &wi); // create ADC label // ADClabel1 wi.g.y = bHeight; wi.g.x = 0; wi.g.width = 70; wi.g.height = bHeight; wi.text = "Core temp:"; ADClabel2 = gwinLabelCreate(NULL, &wi); // ADClabel1 wi.g.y = bHeight; wi.g.x = 75; wi.g.width = 50; wi.g.height = bHeight; wi.text = "ADC value2"; ADCvalue2 = gwinLabelCreate(NULL, &wi); //create console button bWidth = gdispGetStringWidth("Console", font); wi.g.y = 10; //sheight-(bHeight*4); wi.g.x = swidth-70; wi.g.width = 50; wi.g.height = bHeight+4; wi.text = "Console"; ghConsole = gwinButtonCreate(NULL, &wi); //create console BMP button /* wi.g.x = swidth-85; wi.g.y = 40; wi.g.width = 84; wi.g.height = 23; ghbConsole = gwinImageCreate(NULL, &wi.g); gwinImageOpenMemory(ghbConsole, Console); gwinImageCache(ghbConsole); */ }
/*------------------------------------------------------------------------* * GINPUT Touch Driver Calibrator. * *------------------------------------------------------------------------*/ int main(void) { GSourceHandle gs; GEventMouse *pem; bool_t isFirstTime; bool_t isCalibrated; bool_t isTouch; bool_t isFinger; const char * isFingerText; const char * deviceText; GMouse * m; GMouseVMT * vmt; GMouseJitter * pjit; uint32_t calerr; gfxInit(); // Initialize the display // Get the display dimensions swidth = gdispGetWidth(); sheight = gdispGetHeight(); // Create our title font = gdispOpenFont("UI2"); gwinSetDefaultFont(font); bWidth = gdispGetStringWidth("Next", font); bHeight = gdispGetStringWidth("Prev", font); if (bHeight > bWidth) bWidth = bHeight; bWidth += 4; bWidth2 = gdispGetStringWidth("+", font)*2; bHeight = gdispGetStringWidth("-", font)*2; if (bHeight > bWidth2) bWidth2 = bHeight; bWidth2 += 4; bHeight = gdispGetFontMetric(font, fontHeight)*2+2; // Create our main display window { GWindowInit wi; gwinClearInit(&wi); wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight; ghc = gwinConsoleCreate(&gc, &wi); } // Initialize the listener geventListenerInit(&gl); // Copy the current mouse's VMT so we can play with it. m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, 0); if (!m) gfxHalt("No mouse instance 0"); vmt = gfxAlloc(sizeof(GMouseVMT)); if (!vmt) gfxHalt("Could not allocate memory for mouse VMT"); memcpy(vmt, m->d.vmt, sizeof(GMouseVMT)); // Swap VMT's on the current mouse to our RAM copy m->d.vmt = (const GDriverVMT *)vmt; // Listen for events gs = ginputGetMouse(0); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); // Get initial display settings for buttons isFirstTime = TRUE; isCalibrated = (vmt->d.flags & GMOUSE_VFLG_CALIBRATE) ? FALSE : TRUE; calerr = 0; /* * Test: Device Type */ StepDeviceType: DrawHeader("1. Device Type", isCalibrated, isCalibrated && !isFirstTime, isCalibrated); // Get the type of device and the current mode isTouch = (vmt->d.flags & GMOUSE_VFLG_TOUCH) ? TRUE : FALSE; isFinger = (m->flags & GMOUSE_FLG_FINGERMODE) ? TRUE : FALSE; pjit = isFinger ? &vmt->finger_jitter : &vmt->pen_jitter; isFingerText = isFinger ? "finger" : "pen"; deviceText = isTouch ? isFingerText : "mouse"; gwinPrintf(ghc, "This is detected as a %s device\n\n", isTouch ? "TOUCH" : "MOUSE"); gwinPrintf(ghc, "It is currently in %s mode\n\n", isFinger ? "FINGER" : "PEN"); if (!isCalibrated) gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText); else { gwinPrintf(ghc, "Press + for pen or - for finger.\n"); if (isFirstTime) gwinPrintf(ghc, "Press Next to continue.\n"); else gwinPrintf(ghc, "Press Next or Back to continue.\n"); } while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (isCalibrated) { switch (CheckButtons(pem)) { case BTN_NEXT: break; case BTN_PREV: if (!isFirstTime) goto StepDrawing; continue; case BTN_PLUS: m->flags &= ~GMOUSE_FLG_FINGERMODE; goto StepDeviceType; case BTN_MINUS: m->flags |= GMOUSE_FLG_FINGERMODE; goto StepDeviceType; default: continue; } break; } if ((pem->buttons & GMETA_MOUSE_UP)) break; } /* * Test: Mouse raw reading */ StepRawReading: DrawHeader("2. Raw Mouse Output", FALSE, FALSE, FALSE); if (isTouch) gwinPrintf(ghc, "Press and hold on the surface.\n\n"); else gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); gwinPrintf(ghc, "The raw values coming from your mouse driver will display.\n\n"); gwinPrintf(ghc, "Make sure the x and y values change as you move.\n\n"); gwinPrintf(ghc, "Release your %s to move on to the next test.\n", deviceText); // Make sure we are in uncalibrated mode m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP); // For this test turn on ALL mouse movement events geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); while(1) { // Always sleep a bit first to enable other events. We actually don't // mind missing events for this test. gfxSleepMilliseconds(100); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT); if ((pem->buttons & GMETA_MOUSE_UP)) break; } // Reset to calibrated condition if (isCalibrated) { m->flags |= GMOUSE_FLG_CLIP; if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) m->flags |= GMOUSE_FLG_CALIBRATE; } // Reset to just changed movements. geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); /* * Test: Calibration */ StepCalibrate: DrawHeader("3. Calibration Jitter", isCalibrated, isCalibrated, isCalibrated); if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) { gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n" "If the calibration repeatedly fails, increase the jitter for %s calibration and try again.\n\n", isFingerText); gwinPrintf(ghc, "Pressing the surface for longer gives more accurate results.\n\n"); if (calerr) gwinPrintf(ghc, "Last calibration error ^ 2 = %u\n", calerr); gwinPrintf(ghc, "Calibration jitter (%s) = %u\n", isFingerText, pjit->calibrate); if (isCalibrated) gwinPrintf(ghc, "Press + or - to adjust.\n"); } else { gwinPrintf(ghc, "This device does not need calibration.\n\n"); } if (isCalibrated) gwinPrintf(ghc, "Press Next or Back to continue.\n"); else gwinPrintf(ghc, "Press and release your %s to move on to start calibration.\n", deviceText); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (isCalibrated) { switch (CheckButtons(pem)) { case BTN_NEXT: break; case BTN_PREV: goto StepRawReading; case BTN_PLUS: gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, ++pjit->calibrate); continue; case BTN_MINUS: gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, --pjit->calibrate); continue; default: continue; } break; } if ((pem->buttons & GMETA_MOUSE_UP)) break; } // Calibrate if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) { calerr = ginputCalibrateMouse(0); if (calerr) goto StepCalibrate; isCalibrated = TRUE; } /* * Test: Mouse coords */ StepMouseCoords: DrawHeader("4. Show Mouse Coordinates", TRUE, TRUE, TRUE); if (isTouch) gwinPrintf(ghc, "Press and hold on the surface.\n\n"); else gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); gwinPrintf(ghc, "Check the coordinates against where it should be on the screen.\n\n"); gwinPrintf(ghc, "X should be 0 to %u\nY should be 0 to %u\n\n", swidth-1, sheight-1); gwinPrintf(ghc, "Press + to retry using extremes or - for normal calibration.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n"); // For this test normal mouse movement events geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); while(1) { // Always sleep a bit first to enable other events. We actually don't // mind missing events for this test. gfxSleepMilliseconds(100); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); switch (CheckButtons(pem)) { case BTN_NEXT: break; case BTN_PREV: goto StepCalibrate; case BTN_PLUS: vmt->d.flags |= GMOUSE_VFLG_CAL_EXTREMES; goto StepCalibrate; case BTN_MINUS: vmt->d.flags &= ~GMOUSE_VFLG_CAL_EXTREMES; goto StepCalibrate; default: gwinPrintf(ghc, "%u, %u\n", pem->x, pem->y); continue; } break; } // Reset to just changed movements. geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); /* * Test: Mouse movement jitter */ StepMovementJitter: DrawHeader("5. Movement Jitter", TRUE, TRUE, TRUE); if (isTouch) gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n"); else gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n"); gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your %s that " "new dots stop displaying.\nNew dots should only display when your %s is moving.\n\n" "Adjust %s movement jitter to the smallest value that this reliably works for.\n\n", deviceText, deviceText, isFingerText); gwinPrintf(ghc, "Movement jitter (%s) = %u\n", isFingerText, pjit->move); gwinPrintf(ghc, "Press + or - to adjust.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); switch (CheckButtons(pem)) { case BTN_NEXT: break; case BTN_PREV: goto StepMouseCoords; case BTN_PLUS: gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, ++pjit->move); continue; case BTN_MINUS: gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, --pjit->move); continue; default: if ((pem->buttons & GINPUT_MOUSE_BTN_LEFT)) gwinPrintf(ghc, "."); continue; } break; } /* * Test: Click Jitter */ StepClickJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "\n6. Click Jitter\n\n"); gwinSetColor(ghc, White); if (isTouch) gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n"); else gwinPrintf(ghc, "Click the mouse with the left and right buttons.\n\n"); gwinPrintf(ghc, "A yellow dash is a left (or short) click.\n" "A red x is a right (or long) click.\n\n" "Adjust %s click jitter to the smallest value that this reliably works for.\n" "Note: moving your %s during a click cancels it.\n\n", isFingerText, deviceText); gwinPrintf(ghc, "Click jitter (%s) = %u\n", isFingerText, pjit->click); gwinPrintf(ghc, "Press + or - to adjust.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); switch (CheckButtons(pem)) { case BTN_NEXT: break; case BTN_PREV: goto StepMovementJitter; case BTN_PLUS: gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, ++pjit->click); continue; case BTN_MINUS: gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, --pjit->click); continue; default: if ((pem->buttons & GMETA_MOUSE_CLICK)) { gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "-"); } if ((pem->buttons & GMETA_MOUSE_CXTCLICK)) { gwinSetColor(ghc, uRed); gwinPrintf(ghc, "x"); } continue; } break; } /* * Test: Polling frequency */ StepDrawing: gwinClear(ghc); gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "\n7. Drawing\n\n"); gwinSetColor(ghc, White); gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n"); gwinPrintf(ghc, "A green line will follow your %s.\n\n", deviceText); gwinPrintf(ghc, "Pressing Next will start the tests again but with the option of changing pen/finger mode.\n\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { if ((pem->buttons & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepClickJitter; } } gdispDrawPixel(pem->x, pem->y, uGreen); } // Can't let this really exit isFirstTime = FALSE; goto StepDeviceType; }
/*------------------------------------------------------------------------* * GINPUT Touch Driver Calibrator. * *------------------------------------------------------------------------*/ int main(void) { GSourceHandle gs; GEventMouse *pem; GMouse * m; GMouseVMT * vmt; gfxInit(); // Initialize the display // Get the display dimensions swidth = gdispGetWidth(); sheight = gdispGetHeight(); // Create our title font = gdispOpenFont("UI2"); gwinSetDefaultFont(font); bHeight = gdispGetFontMetric(font, fontHeight)+4; gdispFillStringBox(0, 0, swidth, bHeight, "Raw Touch Readings", font, Red, White, justifyCenter); // Create our main display writing window { GWindowInit wi; gwinClearInit(&wi); wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight; ghc = gwinConsoleCreate(&gc, &wi); } // Initialize the listener geventListenerInit(&gl); // Copy the current mouse's VMT so we can play with it. m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, 0); if (!m) gfxHalt("No mouse instance 0"); vmt = gfxAlloc(sizeof(GMouseVMT)); if (!vmt) gfxHalt("Could not allocate memory for mouse VMT"); memcpy(vmt, m->d.vmt, sizeof(GMouseVMT)); // Swap VMT's on the current mouse to our RAM copy m->d.vmt = (const GDriverVMT *)vmt; // Listen for events gs = ginputGetMouse(0); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); // Make sure we are in uncalibrated pen mode m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP|GMOUSE_FLG_FINGERMODE); // Pretend we are a mouse, turn off all touch processing, turn off move and click filtering vmt->d.flags &= ~(GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN); vmt->pen_jitter.move = 0; vmt->pen_jitter.click = 0; // For this test turn on ALL mouse movement events geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT); // Always sleep a bit first to enable other events. We actually don't mind missing events. gfxSleepMilliseconds(100); } }
/*------------------------------------------------------------------------* * GINPUT Touch Driver Calibrator. * *------------------------------------------------------------------------*/ int main(void) { GSourceHandle gs; GEventMouse *pem; coord_t swidth, sheight; GHandle ghc; GEventType deviceType; bool_t calibrated; coord_t bWidth, bHeight; gfxInit(); // Initialize the display // Get the display dimensions swidth = gdispGetWidth(); sheight = gdispGetHeight(); calibrated = FALSE; // Create our title font = gdispOpenFont("UI2"); gwinSetDefaultFont(font); bWidth = gdispGetStringWidth("Next", font); bHeight = gdispGetStringWidth("Prev", font); if (bHeight > bWidth) bWidth = bHeight; bWidth += 4; bHeight = gdispGetFontMetric(font, fontHeight)+2; gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Red, White, justifyLeft); // Create our main display window { GWindowInit wi; gwinClearInit(&wi); wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight; ghc = gwinConsoleCreate(&gc, &wi); } gwinClear(ghc); // Initialize the mouse in our special no calibration mode. geventListenerInit(&gl); gs = ginputGetMouse(9999); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); /* * Test: Device Type */ StepDeviceType: gwinClear(ghc); gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "\n1. DEVICE TYPE\n\n"); pem = (GEventMouse *)&gl.event; ginputGetMouseStatus(0, pem); deviceType = pem->type; gwinSetColor(ghc, White); gwinPrintf(ghc, "This is detected as a %s device\n\n", deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN")); if (calibrated) gwinPrintf(ghc, "Press Next or Back to continue.\n"); else if (deviceType == GEVENT_MOUSE) gwinPrintf(ghc, "Click the mouse button to move on to the next test.\n"); else gwinPrintf(ghc, "Press and release your finger to move on to the next test.\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (calibrated) { if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { if ((pem->meta & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepClickJitter; } } } else if ((pem->meta & GMETA_MOUSE_UP)) break; } /* * Test: Mouse raw reading jitter */ StepRawJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n"); gwinSetColor(ghc, White); if (deviceType == GEVENT_MOUSE) gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); else gwinPrintf(ghc, "Press and hold on the surface.\n\n"); gwinPrintf(ghc, "Numbers will display in this window.\n" "Ensure that values don't jump around very much when your finger is stationary.\n\n" "Increasing GINPUT_MOUSE_READ_CYCLES helps reduce jitter but increases CPU usage.\n\n"); if (calibrated) gwinPrintf(ghc, "Press Next or Back to continue.\n"); else if (deviceType == GEVENT_MOUSE) gwinPrintf(ghc, "Release the mouse button to move on to the next test.\n"); else gwinPrintf(ghc, "Release your finger to move on to the next test.\n"); // For this test turn on ALL mouse movement events geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); while(1) { // Always sleep a bit first to enable other events. We actually don't // mind missing events for this test. gfxSleepMilliseconds(100); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (calibrated) { if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { if ((pem->meta & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepDeviceType; } } } else if ((pem->meta & GMETA_MOUSE_UP)) break; gwinPrintf(ghc, "%u:%u z=%u b=0x%04x m=%04x\n", pem->x, pem->y, pem->z, pem->current_buttons, pem->meta); } // Reset to just changed movements. geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); /* * Test: Calibration */ StepCalibrate: gwinClear(ghc); gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n"); gwinSetColor(ghc, Gray); gwinPrintf(ghc, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n"); gwinSetColor(ghc, White); gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n" "If the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n"); if (calibrated) gwinPrintf(ghc, "Press Next to start the calibration.\n"); else if (deviceType == GEVENT_MOUSE) gwinPrintf(ghc, "Click the mouse button to start the calibration.\n"); else gwinPrintf(ghc, "Press and release your finger to start the calibration.\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (calibrated) { if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { if ((pem->meta & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepRawJitter; } } } else if ((pem->meta & GMETA_MOUSE_UP)) break; } // Calibrate ginputCalibrateMouse(0); calibrated = TRUE; // Calibration used the whole screen - re-establish our title and Next and Previous Buttons gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Green, White, justifyLeft); gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter); gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter); /* * Test: Mouse coords */ StepMouseCoords: gwinClear(ghc); gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "\n4. Show Mouse Coordinates\n\n"); gwinSetColor(ghc, White); if (deviceType == GEVENT_MOUSE) gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); else gwinPrintf(ghc, "Press and hold on the surface.\n\n"); gwinPrintf(ghc, "Numbers will display in this window.\n" "Check the coordinates against where it should be on the screen.\n\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n"); // For this test normal mouse movement events geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); while(1) { // Always sleep a bit first to enable other events. We actually don't // mind missing events for this test. gfxSleepMilliseconds(100); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { if ((pem->meta & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepCalibrate; } } if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) gwinPrintf(ghc, "%u:%u z=%u\n", pem->x, pem->y, pem->z); } // Reset to just changed movements. geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); /* * Test: Mouse movement jitter */ StepJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n"); gwinSetColor(ghc, White); if (deviceType == GEVENT_MOUSE) gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n"); else gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n"); gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your finger that " "new dots stop displaying.\nNew dots should only display when your finger is moving.\n\n" "Adjust GINPUT_MOUSE_MOVE_JITTER to the smallest value that this reliably works for.\n\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { if ((pem->meta & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepMouseCoords; } } if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) gwinPrintf(ghc, "."); } /* * Test: Polling frequency */ StepPolling: gwinClear(ghc); gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n"); gwinSetColor(ghc, White); gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n"); gwinPrintf(ghc, "A green line will follow your finger.\n" "Adjust GINPUT_MOUSE_POLL_PERIOD to the highest value that provides a line without " "gaps that are too big.\nDecreasing the value increases CPU usage.\n" "About 25 (millisecs) normally produces good results." "This test can be ignored for interrupt driven drivers.\n\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { if ((pem->meta & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepJitter; } } if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) gdispDrawPixel(pem->x, pem->y, Green); } /* * Test: Click Jitter */ StepClickJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n"); gwinSetColor(ghc, White); gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n"); gwinPrintf(ghc, "For a mouse click with the left and right buttons.\n\n"); gwinPrintf(ghc, "Dots will display in this window. A yellow dash is a left (or short) click. " "A red x is a right (or long) click.\n\n" "Adjust GINPUT_MOUSE_CLICK_JITTER to the smallest value that this reliably works for.\n" "Adjust GINPUT_MOUSE_CLICK_TIME to adjust distinguishing short vs long presses.\n" "TIME_INFINITE means there are no long presses (although a right mouse button will still work).\n\n" "Note: moving your finger (mouse) during a click cancels it.\n\n"); gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { if ((pem->meta & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepPolling; } } if ((pem->meta & GMETA_MOUSE_CLICK)) { gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "-"); } if ((pem->meta & GMETA_MOUSE_CXTCLICK)) { gwinSetColor(ghc, Red); gwinPrintf(ghc, "x"); } } // Can't let this really exit goto StepDeviceType; }
void gwinPutChar(GHandle gh, char c) { #define gcw ((GConsoleObject *)gh) uint8_t width, fy; if (gh->vmt != &consoleVMT || !gh->font) return; fy = gdispGetFontMetric(gh->font, fontHeight); #if GWIN_CONSOLE_ESCSEQ /** * Handle escape sequences * ESC color Change subsequent text color * color: "0" = black, "1" = red, "2" = green, "3" = yellow, "4" = blue, * "5" = magenta, "6" = cyan, "7" = white * ESC C Revert subsequent text color to the window default * ESC u Turn on underline * ESC U Turn off underline * ESC b Turn on bold * ESC B Turn off bold * ESC J Clear the window */ switch (gcw->escstate) { case 1: gcw->escstate = 0; if (ESCtoAttr(c, &gcw->currattr)) { if (gcw->cx == 0 && gcw->cy == 0) gcw->startattr = gcw->currattr; else { putCharInBuffer(gcw, 27); putCharInBuffer(gcw, c); } } else { switch(c) { case 'J': // Clear the console and reset the cursor clearBuffer(gcw); if (DrawStart(gh)) { gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor); DrawEnd(gh); } gcw->cx = 0; gcw->cy = 0; gcw->startattr = gcw->currattr; break; } } return; } #endif /** * Special Characters: * * Carriage returns and line feeds (\r & \n) are handled in unix terminal cooked mode; that is, * line feeds perform both actions and carriage-returns are ignored. * * if GWIN_CONSOLE_ESCSEQ is turned on then ESC is trapped ready for the escape command. * * All other characters are treated as printable. */ switch (c) { case '\n': // clear to the end of the line #if GWIN_CONSOLE_USE_CLEAR_LINES if (gcw->cx == 0 && gcw->cy+fy < gh->height && DrawStart(gh)) { gdispGFillArea(gh->display, gh->x, gh->y + gcw->cy, gh->width, fy, gh->bgcolor); DrawEnd(gh); } #endif // update the cursor gcw->cx = 0; gcw->cy += fy; putCharInBuffer(gcw, '\n'); // We use lazy scrolling here and only scroll when the next char arrives return; case '\r': // gcw->cx = 0; return; #if GWIN_CONSOLE_ESCSEQ case 27: // ESC gcw->escstate = 1; return; #endif } // Characters with no width are ignored if (!(width = gdispGetCharWidth(c, gh->font))) return; // Allow space for (very crude) bold #if GWIN_CONSOLE_ESCSEQ if ((gcw->currattr & ESC_BOLD)) width++; #endif // Do we need to go to the next line to fit this character? if (gcw->cx + width >= gh->width) { gcw->cx = 0; gcw->cy += fy; putCharInBuffer(gcw, '\n'); } // Do we need to scroll to fit this character? if (gcw->cy + fy > gh->height) { #if GWIN_CONSOLE_USE_HISTORY && GWIN_CONSOLE_BUFFER_SCROLLING if (gcw->buffer) { // Scroll the buffer and then redraw using the buffer scrollBuffer(gcw); if (DrawStart(gh)) { HistoryuRedraw(gh); DrawEnd(gh); } } else #endif #if GDISP_NEED_SCROLL { // Scroll the console using hardware scrollBuffer(gcw); if (DrawStart(gh)) { gdispGVerticalScroll(gh->display, gh->x, gh->y, gh->width, gh->height, fy, gh->bgcolor); DrawEnd(gh); } // Set the cursor to the start of the last line gcw->cx = 0; gcw->cy = (((coord_t)(gh->height/fy))-1)*fy; } #else { // Clear the console and reset the cursor clearBuffer(gcw); if (DrawStart(gh)) { gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor); DrawEnd(gh); } gcw->cx = 0; gcw->cy = 0; #if GWIN_CONSOLE_ESCSEQ gcw->startattr = gcw->currattr; #endif } #endif } // Save the char putCharInBuffer(gcw, c); // Draw the character if (DrawStart(gh)) { // If we are at the beginning of a new line clear the line #if GWIN_CONSOLE_USE_CLEAR_LINES if (gcw->cx == 0) gdispGFillArea(gh->display, gh->x, gh->y + gcw->cy, gh->width, fy, gh->bgcolor); #endif #if GWIN_CONSOLE_USE_FILLED_CHARS gdispGFillChar(gh->display, gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, ESCPrintColor(gcw), gh->bgcolor); #else gdispGDrawChar(gh->display, gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, ESCPrintColor(gcw)); #endif #if GWIN_CONSOLE_ESCSEQ // Draw the underline if ((gcw->currattr & ESC_UNDERLINE)) gdispGDrawLine(gh->display, gh->x + gcw->cx, gh->y + gcw->cy + fy - gdispGetFontMetric(gh->font, fontDescendersHeight), gh->x + gcw->cx + width + gdispGetFontMetric(gh->font, fontCharPadding), gh->y + gcw->cy + fy - gdispGetFontMetric(gh->font, fontDescendersHeight), ESCPrintColor(gcw)); // Bold (very crude) if ((gcw->currattr & ESC_BOLD)) gdispGDrawChar(gh->display, gh->x + gcw->cx + 1, gh->y + gcw->cy, c, gh->font, ESCPrintColor(gcw)); #endif DrawEnd(gh); } // Update the cursor gcw->cx += width + gdispGetFontMetric(gh->font, fontCharPadding); #undef gcw }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); ADC2status = 0; //write_to_backup_sram(0, 0, 0); startBlinker(); /* initialize and clear the display */ gfxInit(); ginputGetMouse(0); //ginputSetMouseCalibrationRoutines(0, mysave, myload, FALSE); //ginputGetMouse(0); // new ugfx do not need this gwinAttachMouse(0); geventListenerInit(&gl); gwinAttachListener(&gl); //geventAttachSource(&gl, mouse, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); //mouse = ginputGetMouse(0); //get screen size width = gdispGetWidth(); height = gdispGetHeight(); swidth = gdispGetWidth(); sheight = gdispGetHeight(); font = gdispOpenFont("UI2"); //startBlinker(); myADCinit(); ICUinit(); /* * Activates the serial driver 1 using the driver default configuration. * PA2(TX) and PA3(RX) are routed to USART2. */ sdStart(&SD2, NULL); palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL); //mouse = ginputGetMouse(0); font = gdispOpenFont("UI2"); gwinSetDefaultFont(font); gwinSetDefaultBgColor(Black); gwinSetDefaultColor(White); bHeight = gdispGetFontMetric(font, fontHeight)+2; #if BOOTSCREEN bootScreen(); #endif #ifdef LOGO gdispClear(Black); CreateLogo(); #endif // create main screen createWidgets(); chprintf( (BaseSequentialStream *)&SD2, "Main loop\r\n", NULL ); while (TRUE) { //get an event pe = geventEventWait(&gl, TIME_INFINITE); switch(pe->type) { case GEVENT_TOUCH: { pem = (GEventMouse *)pe; if ((pem->type & GMETA_MOUSE_CLICK)) { //gwinSetColor(ghc, Yellow); chprintf((BaseSequentialStream *)&SD2, "\r\n-touch-click"); } } case GEVENT_GWIN_BUTTON: if (((GEventGWinButton*)pe)->button == ghConsole) { gwinSetText(ghStatus2, "Console", TRUE); chprintf( (BaseSequentialStream *)&SD2, "\r\nConsole button", NULL ); }; break; case GEVENT_GWIN_SLIDER: if (((GEventGWinSlider*)pe)->slider == ghBrightness) { gdispSetBacklight(((GEventGWinSlider *)pe)->position); chprintf((BaseSequentialStream *)&SD2,"Slider %s = %d\r\n", gwinGetText(((GEventGWinSlider *)pe)->slider), ((GEventGWinSlider *)pe)->position); } break; default: break ; } } }
// Simple: single line with no wrapping static coord_t getheight(const char *text, font_t font, coord_t maxwidth) { (void) text; (void) maxwidth; return gdispGetFontMetric(font, fontHeight); }
void gwinListDefaultDraw(GWidgetObject* gw, void* param) { const gfxQueueASyncItem* qi; int i; coord_t x, y, iheight, iwidth; color_t fill; const GColorSet * ps; #if GWIN_NEED_LIST_IMAGES coord_t sy; #endif #if GDISP_NEED_CONVEX_POLYGON static const point upArrow[] = { {0, LST_ARROW_SZ}, {LST_ARROW_SZ, LST_ARROW_SZ}, {LST_ARROW_SZ/2, 0} }; static const point downArrow[] = { {0, 0}, {LST_ARROW_SZ, 0}, {LST_ARROW_SZ/2, LST_ARROW_SZ} }; #endif (void)param; // is it a valid handle? if (gw->g.vmt != (gwinVMT *)&listVMT) return; // don't render if render has been disabled if (!(gw->g.flags & GLIST_FLG_ENABLERENDER)) return; ps = (gw->g.flags & GWIN_FLG_SYSENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; iheight = gdispGetFontMetric(gw->g.font, fontHeight) + LST_VERT_PAD; x = 1; // the scroll area if (gw->g.flags & GLIST_FLG_SCROLLSMOOTH) { iwidth = gw->g.width - 2 - 4; if (gw2obj->cnt > 0) { int max_scroll_value = gw2obj->cnt * iheight - gw->g.height-2; if (max_scroll_value > 0) { int bar_height = (gw->g.height-2) * (gw->g.height-2) / (gw2obj->cnt * iheight); gdispGFillArea(gw->g.display, gw->g.x + gw->g.width-4, gw->g.y + 1, 2, gw->g.height-1, gw->pstyle->background); gdispGFillArea(gw->g.display, gw->g.x + gw->g.width-4, gw->g.y + gw2obj->top * ((gw->g.height-2)-bar_height) / max_scroll_value, 2, bar_height, ps->edge); } } } else if ((gw2obj->cnt > (gw->g.height-2) / iheight) || (gw->g.flags & GLIST_FLG_SCROLLALWAYS)) { iwidth = gw->g.width - (LST_SCROLLWIDTH+3); gdispGFillArea(gw->g.display, gw->g.x+iwidth+2, gw->g.y+1, LST_SCROLLWIDTH, gw->g.height-2, gdispBlendColor(ps->fill, gw->pstyle->background, 128)); gdispGDrawLine(gw->g.display, gw->g.x+iwidth+1, gw->g.y+1, gw->g.x+iwidth+1, gw->g.y+gw->g.height-2, ps->edge); #if GDISP_NEED_CONVEX_POLYGON gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+(LST_ARROW_SZ/2+1), upArrow, 3, ps->fill); gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+gw->g.height-(LST_ARROW_SZ+LST_ARROW_SZ/2+1), downArrow, 3, ps->fill); #else #warning "GWIN: Lists display better when GDISP_NEED_CONVEX_POLYGON is turned on" gdispGFillArea(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+(LST_ARROW_SZ/2+1), LST_ARROW_SZ, LST_ARROW_SZ, ps->fill); gdispGFillArea(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+gw->g.height-(LST_ARROW_SZ+LST_ARROW_SZ/2+1), LST_ARROW_SZ, LST_ARROW_SZ, ps->fill); #endif } else iwidth = gw->g.width - 2; #if GWIN_NEED_LIST_IMAGES if ((gw->g.flags & GLIST_FLG_HASIMAGES)) { x += iheight; iwidth -= iheight; } #endif // Find the top item for (qi = gfxQueueASyncPeek(&gw2obj->list_head), i = iheight - 1; i < gw2obj->top && qi; qi = gfxQueueASyncNext(qi), i+=iheight); // the list frame gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, ps->edge); // Set the clipping region so we do not override the frame. #if GDISP_NEED_CLIP gdispGSetClip(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2); #endif // Draw until we run out of room or items for (y = 1-(gw2obj->top%iheight); y < gw->g.height-2 && qi; qi = gfxQueueASyncNext(qi), y += iheight) { fill = (qi2li->flags & GLIST_FLG_SELECTED) ? ps->fill : gw->pstyle->background; gdispGFillArea(gw->g.display, gw->g.x+1, gw->g.y+y, iwidth, iheight, fill); #if GWIN_NEED_LIST_IMAGES if ((gw->g.flags & GLIST_FLG_HASIMAGES)) { // Clear the image area if (qi2li->pimg && gdispImageIsOpen(qi2li->pimg)) { // Calculate which image sy = (qi2li->flags & GLIST_FLG_SELECTED) ? 0 : (iheight-LST_VERT_PAD); if (!(gw->g.flags & GWIN_FLG_SYSENABLED)) sy += 2*(iheight-LST_VERT_PAD); while (sy > qi2li->pimg->height) sy -= iheight-LST_VERT_PAD; // Draw the image gdispImageSetBgColor(qi2li->pimg, fill); gdispGImageDraw(gw->g.display, qi2li->pimg, gw->g.x+1, gw->g.y+y, iheight-LST_VERT_PAD, iheight-LST_VERT_PAD, 0, sy); } } #endif gdispGFillStringBox(gw->g.display, gw->g.x+x+LST_HORIZ_PAD, gw->g.y+y, iwidth-LST_HORIZ_PAD, iheight, qi2li->text, gw->g.font, ps->text, fill, justifyLeft); } // Fill any remaining item space if (y < gw->g.height-1) gdispGFillArea(gw->g.display, gw->g.x+1, gw->g.y+y, iwidth, gw->g.height-1-y, gw->pstyle->background); }