def drawLogo(offset=0, max_height=display.height(), center=True): global cfg_logo try: info = display.pngInfo(cfg_logo) except: return 0 width = info[0] height = info[1] if width > display.width(): print("Image too large (x)") return if height > display.height(): print("Image too large (y)") x = int((display.width() - width) / 2) if center: if max_height - height < 0: #print("Not enough space for logo",max_height,height) #return 0 y = 0 else: y = int((max_height - height) / 2) + offset else: y = offset try: display.drawPng(x, y, cfg_logo) return height except BaseException as e: sys.print_exception(e) return 0
def drawApp(app, position, amount): drawTitle() positionText = "{}/{}".format(position+1, amount) if app["path"].startswith("/sd"): positionText = "SD "+positionText positionWidth = display.getTextWidth(positionText, "org18") display.drawText(display.width()-positionWidth-2, 0, positionText, 0x000000, "org18") titleWidth = display.getTextWidth(app["name"], "7x5") display.drawText((display.width()-titleWidth)//2,display.height()-10, app["name"], 0xFFFFFF, "7x5") try: icon_data = None if app["icon"]: if not app["icon"].startswith(b"\x89PNG"): with open(app["path"]+"/"+app["icon"], "rb") as icon_file: icon_data = icon_file.read() else: icon_data = app["icon"] if not icon_data: display.drawPng(display.width()//2-16,display.height()//2-16,default_icon) else: info = display.pngInfo(icon_data) if info[0] == 32 and info[1] == 32: display.drawPng(display.width()//2-16,display.height()//2-16,icon_data) else: drawMessageBox("Invalid icon size\nExpected 32x32!") except BaseException as e: sys.print_exception(e) drawMessageBox("Icon parsing error!") if not position < 1: display.drawText(0, display.height()//2-12, "<", 0xFFFFFF, "roboto_regular18") if not position >= (amount-1): display.drawText(display.width()-10, display.height()//2-12, ">", 0xFFFFFF, "roboto_regular18") display.flush(display.FLAG_LUT_FASTEST)
def drawApp(app, position, amount): display.drawFill(0x000000) display.drawRect(0, 0, display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "RECOVERY", 0x000000, "org18") positionText = "{}/{}".format(position + 1, amount) if app["path"].startswith("/sd"): positionText = "SD " + positionText positionWidth = display.getTextWidth(positionText, "org18") display.drawText(display.width() - positionWidth - 2, 0, positionText, 0x000000, "org18") titleWidth = display.getTextWidth(app["name"], "7x5") titleHeight = display.getTextHeight(app["name"], "7x5") display.drawText((display.width() - titleWidth) // 2, (display.height() - titleHeight) // 2, app["name"], 0xFFFFFF, "7x5") if not position < 1: display.drawText(0, display.height() // 2 - 12, "<", 0xFFFFFF, "roboto_regular18") if not position >= (amount - 1): display.drawText(display.width() - 10, display.height() // 2 - 12, ">", 0xFFFFFF, "roboto_regular18") display.flush(display.FLAG_LUT_FASTEST)
def uninstall(path): print("Uninstall", path) flist = os.listdir(path) print("files", flist) for i in range(len(flist)): f = flist[i] display.drawFill(0x000000) display.drawRect(0, 0, display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "UNINSTALL", 0x000000, "org18") drawMessageBox("Removing file...\n{}".format(f)) display.flush(display.FLAG_LUT_FASTEST) os.remove(path + "/" + f) display.drawFill(0x000000) display.drawRect(0, 0, display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "UNINSTALL", 0x000000, "org18") drawMessageBox("Removing folder...") display.flush(display.FLAG_LUT_FASTEST) os.rmdir(path) display.drawFill(0x000000) display.drawRect(0, 0, display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, "UNINSTALL", 0x000000, "org18") drawMessageBox("App removed!") display.flush(display.FLAG_LUT_FASTEST) time.sleep(2) showMenu()
def messageCentered(message, firstLineTitle=True, png=None): try: color = 0x000000 font1 = "Roboto_Regular18" font2 = "Roboto_Regular12" font1Height = 22 #display.getTextHeight(" ", font1) font2Height = 16 #display.getTextHeight(" ", font2) message = message.split("\n") lines = [] for i in range(len(message)): line = message[i] if len(line) < 1: lines.append("") else: if firstLineTitle and i == 0: lines.extend(lineSplit(line, display.width(), font1)) else: lines.extend(lineSplit(line, display.width(), font2)) pngSize = (0, 0) if png != None: try: pngSize = badge.png_info(png) pngSize = [pngSize[0], pngSize[1] + 8] #Little bit of extra offset except BaseException as e: print("Error in PNG height", e) textHeight = len(lines) * font2Height if firstLineTitle: textHeight -= font2Height textHeight += font1Height offset_y = (display.height() - pngSize[1] - textHeight) // 2 display.drawFill() #display.drawLine(0,display.height()//2,display.width()-1,display.height()//2,0) if png != None: try: display.drawPng((display.width() - pngSize[0]) // 2, offset_y, png) offset_y += pngSize[1] except BaseException as e: print("Error in PNG draw", e) for i in range(len(lines)): if firstLineTitle and i == 0: lineCentered(offset_y, lines[i], font1, color) offset_y += font1Height else: lineCentered(offset_y, lines[i], font2, color) offset_y += font2Height display.flush(display.FLAG_LUT_FASTEST) except BaseException as e: print("Error in messageCentered!", e)
def drawMessageBox(text): width = display.getTextWidth(text, "org18") height = display.getTextHeight(text, "org18") display.drawRect((display.width() - width - 4) // 2, (display.height() - height - 4) // 2, width + 2, height + 2, True, 0xFFFFFF) display.drawText((display.width() - width) // 2, (display.height() - height) // 2 - 2, text, 0x000000, "org18")
def drawTask(onSleep=False): global gui_redraw, cfg_nickname, gui_apps, gui_app_current, ota_available if gui_redraw or onSleep: gui_redraw = False display.drawFill(COLOR_BG) currHeight = 0 noLine = False if gui_app_current < 0: if cfg_logo: if cfg_nickname: # Logo and nickename enabled, first print nickname display.drawText((display.width()-display.getTextWidth(cfg_nick_text, "roboto_regular12"))//2, currHeight, cfg_nick_text, COLOR_FG, "roboto_regular12") currHeight += display.getTextHeight(cfg_nick_text, "roboto_regular12")#easydraw.nickname() currHeight += 4 display.drawLine(0, currHeight, display.width()-1, currHeight, COLOR_FG) currHeight += 4 #Print logo app_height = display.height()-16-currHeight logoHeight = drawLogo(currHeight, app_height, True) if logoHeight > 0: noLine = True if logoHeight < 1: #Logo enabled but failed to display title = "BADGE.TEAM" subtitle = "PLATFORM" logoHeight = display.getTextHeight(title, "permanentmarker22")+display.getTextHeight(subtitle, "fairlight12") display.drawText((display.width()-display.getTextWidth(title, "permanentmarker22"))//2, currHeight + (app_height - logoHeight)//2,title, COLOR_FG, "permanentmarker22") currHeight += display.getTextHeight(title, "permanentmarker22") display.drawText((display.width()-display.getTextWidth(subtitle, "fairlight12"))//2, currHeight + (app_height - logoHeight)//2,subtitle, COLOR_FG, "fairlight12") currHeight += display.getTextHeight(subtitle, "fairlight12") else: noLine = True display.drawPng(0,0,LOGO) else: display_app(currHeight) if onSleep: info = 'Sleeping...' #elif not rtc.isSet(): # info = "RTC not available" elif ota_available: info = "Update available!" #elif wifi_status_curr: # info = "WiFi connected" else: info = ""#'Press START' if not noLine: display.drawLine(0, display.height()-16, display.width(), display.height()-16, COLOR_FG) easydraw.disp_string_right_bottom(0, info) if len(gui_apps) > 0: drawPageIndicator(len(gui_apps), gui_app_current) if cfg_greyscale: display.flush(display.FLAG_LUT_GREYSCALE) else: display.flush(display.FLAG_LUT_NORMAL) return 1000
def start(): ugfx.input_init() ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.WHITE) # Instructions if orientation.isLandscape(): if display.width() > 128: x0 = int(display.width()/2) currentY = 20 display.drawText(x0+((display.width()-x0)//2)-(display.getTextWidth("BADGE.TEAM", "fairlight12")//2), currentY, "BADGE.TEAM\n", 0x000000, "fairlight12") currentY += display.getTextHeight("BADGE.TEAM", "fairlight12") display.drawText(x0+int((display.width()-x0)/2)-int(display.getTextWidth("ESP32 platform", "roboto_regular12")/2), currentY, "ESP32 platform\n", 0x000000, "roboto_regular12") display.drawLine(x0,0,x0,display.height()-1,0x000000) pixHeight = display.getTextHeight(" ", "roboto_regular12") currentY = pixHeight*5 lineY = display.height()-pixHeight*6-pixHeight//2 display.drawLine(x0, lineY, display.width()-1, lineY, 0x000000) display.drawText(x0+5, display.height()-pixHeight*6, "A: Run\n", 0x000000, "roboto_regular12") display.drawText(x0+5, display.height()-pixHeight*5, "START: Return to home\n", 0x000000, "roboto_regular12") display.drawText(x0+5, display.height()-pixHeight*4, "SELECT: Uninstall app\n", 0x000000, "roboto_regular12") lineY = display.height()-pixHeight*2-pixHeight//2 display.drawLine(x0, lineY, display.width()-1, lineY, 0x000000) display.drawText(x0+5, display.height()-pixHeight*2, consts.INFO_FIRMWARE_NAME, 0x000000, "roboto_regular12") display.drawText(x0+5, display.height()-pixHeight, "Build "+str(consts.INFO_FIRMWARE_BUILD), 0x000000, "roboto_regular12") else: pixHeight = display.getTextHeight(" ", "roboto_regular12") display.drawLine(0, display.height()-18*4, display.width(), display.height()-18*4, ugfx.BLACK) display.drawText(0, display.height()-pixHeight*6, "A: Run\n", 0x000000, "roboto_regular12") display.drawText(0, display.height()-pixHeight*5, "START: Home\n", 0x000000, "roboto_regular12") display.drawText(0, display.height()-pixHeight*4, "SELECT: Uninstall\n", 0x000000, "roboto_regular12") lineY = display.height()-pixHeight*2-pixHeight//2 display.drawLine(0, lineY, display.width()-1, lineY, 0x000000) display.drawText(0, display.height()-pixHeight*2, consts.INFO_FIRMWARE_NAME, 0x000000, "roboto_regular12") display.drawText(0, display.height()-pixHeight, "Build "+str(consts.INFO_FIRMWARE_BUILD), 0x000000, "roboto_regular12") global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_OK, input_a) ugfx.input_attach(ugfx.BTN_BACK, input_b) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_a) ugfx.input_attach(ugfx.JOY_LEFT, input_select) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE)
def nickname(y=5, font="freesansbold12", color=0x000000, unusedParameter=None): nick = machine.nvs_getstr("owner", "name") if not nick: return y lines = lineSplit(nick, display.width(), font) for i in range(len(lines)): line = lines[len(lines) - i - 1] display.font(font) pos_x = int((display.width() - display.get_string_width(line)) / 2) lineHeight = display.get_string_height(line) display.cursor(pos_x, y + lineHeight * (len(lines) - i - 1)) display.textColor(color) display.print(line) return len(lines) * lineHeight
def nickname(y = 5, font = "Roboto_Regular18", color = 0x000000, unusedParameter=None): nick = machine.nvs_getstr("owner", "name") if not nick: return y lines = lineSplit(nick, display.width(), font) for i in range(len(lines)): line = lines[len(lines)-i-1] pos_x = int((display.width()-display.getTextWidth(line, font)) / 2) lineHeight = display.getTextHeight(line, font) if font: display.drawText(pos_x, y+lineHeight*(len(lines)-i-1), line, color, font) else: display.drawText(pos_x, y+lineHeight*(len(lines)-i-1), line, color) return len(lines) * lineHeight
def lineSplit(message, width=None, font=version.font_default): message = message.split("\n") lines = [] line = "" if width == None: width = display.width() for messagePart in message: if line != "": lines.append(line) line = "" words = messagePart.split(" ") for word in words: wordLength = display.getTextWidth(word, font) lineLength = display.getTextWidth(line, font) if wordLength > width: lines.append(line) lines.append(word) line = "" elif lineLength + wordLength < width: if (line == ""): line = word else: line += " " + word else: lines.append(line) line = word if len(line) > 0: lines.append(line) return lines
def lineSplit(message, width=None, font=version.font_default): words = message.split(" ") lines = [] line = "" if width == None: width = display.width() for word in words: display.font(font) wordLength = display.get_string_width(word) lineLength = display.get_string_width(line) if wordLength > width: lines.append(line) lines.append(word) line = "" elif lineLength + wordLength < width: if (line == ""): line = word else: line += " " + word else: lines.append(line) line = word if len(line) > 0: lines.append(line) return lines
def start(): ugfx.set_lut(ugfx.LUT_FASTER) ugfx.clear(ugfx.WHITE) x0 = int(display.width()/2) display.drawText(x0+10, 0, "Recovery mode!", 0x000000, "roboto_regular12") global options global install_path options = None install_path = None ugfx.input_attach(ugfx.BTN_A, input_a) ugfx.input_attach(ugfx.BTN_B, input_b) ugfx.input_attach(ugfx.BTN_SELECT, input_select) ugfx.input_attach(ugfx.JOY_UP, input_other) ugfx.input_attach(ugfx.JOY_DOWN, input_other) ugfx.input_attach(ugfx.JOY_LEFT, input_other) ugfx.input_attach(ugfx.JOY_RIGHT, input_other) ugfx.input_attach(ugfx.BTN_START, input_other) populate_apps() populate_category() populate_options() # do a greyscale flush on start ugfx.flush(ugfx.GREYSCALE)
def demoThread(): global demoThreadRunning counter = 0 fpsTrig = False w, h, _, _ = display.pngInfo(mascot.snek) display.drawFill(0xFFFF00) prev = time.ticks_ms() av = [0] * 100 while demoThreadRunning: if counter > 100: fpsTrig = True current = time.ticks_ms() if (current - prev) > 0: fps = 1000 // (current - prev) else: fps = 0 _ = av.pop(0) av.append(fps) fps = 0 for i in range(len(av)): fps += av[i] fps = fps // len(av) display.drawRect(0, 0, display.width() - 1, 20, True, 0xFFFF00) if fpsTrig: display.drawText(0, 0, "{} fps".format(fps), 0x000000, "ocra16") else: display.drawText(0, 0, "Demo time!", 0x000000, "ocra16") my = (display.height() - h) // 2 - (round(math.sin(counter)) - 1) * 10 mx = (display.width() - w) // 2 - (round(math.cos(counter)) - 1) * 10 display.drawPng(mx, my, mascot.snek) #Draw squares display.drawRect(display.width() - 39 - (counter % display.width()), display.height() // 2 - 20, 40, 40, True, 0x00FF00) display.drawRect(counter % display.width(), display.height() // 2 - 10, 20, 20, True, 0xFF0000) #Flush to display display.flush() #Clear away the squares display.drawRect(display.width() - 39 - (counter % display.width()), display.height() // 2 - 20, 40, 40, True, 0xFFFF00) display.drawRect(counter % display.width(), display.height() // 2 - 10, 20, 20, True, 0xFFFF00) #Clear away the mascot display.drawRect(mx, my, w, h, True, 0xFFFF00) #Increment counter counter += 1 #time.sleep(0.01) prev = current drawNickname()
def drawNickname(): owner = machine.nvs_getstr("owner", "name") or "BADGE.TEAM" display.drawFill(0xFFFF00) x = (display.width()-display.getTextWidth(owner, "ocra16"))//2 y = (display.height()-display.getTextHeight(owner, "ocra16"))//2 display.drawText(x,y,owner,0x000000,"ocra16") display.flush() # Send the new buffer to the display display.backlight(0xFF) # Turn on backlight
def messageCentered(message, firstLineTitle=True, png=None): #try: if 1: font1 = "Roboto_Regular18" font2 = "Roboto_Regular12" color = 0x000000 display.fill(0xFFFFFF) parts = message.split("\n") lines = [] font = font1 for part in parts: if len(part) < 1: lines.append("") else: lines.extend(lineSplit(part, display.width(), font)) if firstLineTitle: font = font2 offset_y = int(display.height() / 2) #Half of the screen height offset_y -= 9 #Height of the first line divided by 2 if firstLineTitle: offset_y -= 6 * len(lines) - 1 #Height of font1 divided by 2 else: offset_y -= 9 * len(lines) - 1 #Height of font2 divided by 2 if png != None: try: img_info = badge.png_info(png) offset_y -= int(img_info[1] / 2) + 4 img_x = int((display.width() - img_info[0]) / 2) display.png(img_x, offset_y, png) offset_y += img_info[1] + 8 except: pass lineCentered(offset_y, lines[0], font1, color) offset_y += 18 for i in range(len(lines) - 1): if not firstLineTitle: lineCentered(offset_y, lines[i + 1], font1, color) offset_y += 18 else: lineCentered(offset_y, lines[i + 1], font2, color) offset_y += 12 display.flush()
def msg_nosplit(message, title='Loading...', reset=False): """Show a terminal style loading screen with title title can be optionaly set when resetting or first call """ global messageHistory, lastTitle num_lines = ((display.height() - 16) // display.getTextHeight(" ", version.font_default)) - 2 if reset: lastTitle = title try: messageHistory if reset: raise exception except: display.drawFill(0xFFFFFF) messageHistory = [] lastTitle = title lineHeight = int(display.getTextHeight(" ", version.font_default) / 2) + 5 if len(messageHistory) < num_lines: display.drawText(0, 16 + (len(messageHistory) * lineHeight), message, 0x000000, version.font_default) messageHistory.append(message) else: messageHistory.pop(0) messageHistory.append(message) display.drawRect(0, 16, display.width(), display.height() - 15, True, 0xFFFFFF) for i, message in enumerate(messageHistory): display.drawText(0, 16 + (i * lineHeight), message, 0x000000, version.font_default) display.drawRect(0, 0, display.width(), 14, True, 0) display.drawText(0, 0, lastTitle, 0xFFFFFF, "Roboto_Regular12") #h = display.getTextHeight(" ", version.font_header) #display.drawLine(0, h, display.width(), h, 0x000000) display.flush(display.FLAG_LUT_FASTEST) return len(messageHistory) >= num_lines - 1
def lineCentered(pos_y, line, font, color): if font: width = display.getTextWidth(line, font) else: width = display.getTextWidth(line) pos_x = int((display.width() - width) / 2) if font: display.drawText(pos_x, pos_y, line, color, font) else: display.drawText(pos_x, pos_y, line, color)
def msg_nosplit(message, title='Loading...', reset=False): """Show a terminal style loading screen with title title can be optionaly set when resetting or first call """ global messageHistory, lastTitle num_lines = ((display.height() - 11) // display.getTextHeight(" ", "7x5")) if reset: lastTitle = title try: messageHistory if reset: raise exception except: display.drawFill(0x000000) messageHistory = [] lastTitle = title lineHeight = display.getTextHeight(" ", "7x5") if len(messageHistory) < num_lines: display.drawText(0, 11 + (len(messageHistory) * lineHeight), message, 0xFFFFFF, "7x5") messageHistory.append(message) else: messageHistory.pop(0) messageHistory.append(message) display.drawRect(0, 11, display.width(), display.height() - 15, True, 0x000000) for i, message in enumerate(messageHistory): display.drawText(0, 11 + (i * lineHeight), message, 0xFFFFFF, "7x5") display.drawRect(0, 0, display.width(), 10, True, 0xFFFFFF) display.drawText(2, 0, lastTitle, 0x000000, "org18") display.flush(display.FLAG_LUT_FASTEST) return len(messageHistory) >= num_lines - 1
def drawMessageBox(text): global extended_menu oneFourthWidth = display.width() // 4 width = display.getTextWidth(text, "org18") height = display.getTextHeight(text, "org18") display.drawRect( (oneFourthWidth * (3 if extended_menu else 2) - width - 4) // 2, (display.height() - height - 4) // 2, width + 2, height + 2, True, 0xFFFFFF) display.drawText( (oneFourthWidth * (3 if extended_menu else 2) - width) // 2, (display.height() - height) // 2 - 2, text, 0x000000, "org18")
def populate_options(): global options if orientation.isLandscape(): if display.width() > 128: options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height()) else: options = ugfx.List(0,0,ugfx.width(),ugfx.height()) else: options = ugfx.List(0,0,ugfx.width(),int(ugfx.height()-18*4)) global currentListTitles for title in currentListTitles: options.add_item(title)
def draw(): global cx, cy, text, cursorPos, title, mode, xpos display.drawFill(0xFFFFFF) display.drawRect(0, 0, display.width(), 14, True, 0x000000) display.drawText(0, 0, title, 0xFFFFFF, keyFont) modeText = "keyboard" if mode == 1: modeText = "cursor" if mode == 2: modeText = "actions" if cursorPos > len(text): cursorPos = len(text) if cursorPos < 0: cursorPos = 0 textWithCursor = text[:cursorPos] + "|" + text[cursorPos:] textWithCursorLines = textWithCursor.split("\n") for i in range(len(textWithCursorLines)): display.drawText(0, 17 + i * 13, textWithCursorLines[i], 0x000000, textFont) offset = xpos if offset < 4: offset = 4 if offset > (len(charMap[mode]) - 4): offset = len(charMap[mode]) - 4 - 9 if mode < 7: for i in range(9): item = (offset - 4 + i) print(item, len(charMap[mode]), xpos) if xpos == item: display.drawRect(i * 14, display.height() - 14, 14, 14, True, 0x000000) display.drawText(i * 14 + 3, display.height() - 14, charMap[mode][item], 0xFFFFFF, keyFont) else: display.drawRect(i * 14, display.height() - 14, 14, 14, False, 0x000000) display.drawText(i * 14 + 3, display.height() - 14, charMap[mode][item], 0x000000, keyFont) display.flush(display.FLAG_LUT_FASTEST)
def start(app, status=False): if status: import term, easydraw, display if app == "" or app == "launcher": term.header(True, "Loading menu...") #easydraw.messageCentered("Loading the menu...", False, "/media/busy.png") else: term.header(True, "Loading application "+app+"...") #easydraw.messageCentered("Loading '"+app+"'...", False, "/media/busy.png") try: info = display.pngInfo("/media/busy.png") display.drawPng((display.width()-info[0])//2, (display.height()-info[1])//2, "/media/busy.png") except: easydraw.messageCentered("Loading...", False, "/media/busy.png") machine.RTC().write_string(app) reboot()
def msg_nosplit(message, title='Loading...', reset=False): global NUM_LINES """Show a terminal style loading screen with title title can be optionaly set when resetting or first call """ global messageHistory try: messageHistory if reset: raise exception except: display.greyscale(False) display.fill(0xFFFFFF) display.textColor(0x000000) display.font(version.font_header) display.cursor(0, 0) display.print(title) messageHistory = [] display.font(version.font_default) lineHeight = display.get_string_height(" ") if len(messageHistory) < NUM_LINES: display.textColor(0x000000) display.cursor(0, 19 + (len(messageHistory) * lineHeight)) display.print(message) messageHistory.append(message) else: messageHistory.pop(0) messageHistory.append(message) display.rect(0, 15, display.width(), display.height() - 15, True, 0xFFFFFF) for i, message in enumerate(messageHistory): display.textColor(0x000000) display.font(version.font_default) display.cursor(0, 19 + (i * lineHeight)) display.print(message) display.flush()
def drawLogo(offset=0, max_height=display.height(), center=True): global cfg_logo try: info = display.pngInfo(cfg_logo) except: return 0 width = info[0] height = info[1] x = int((display.width() - width) / 2) if center: if max_height - height < 0: y = 0 else: y = int((max_height - height) / 2) + offset else: y = offset try: display.drawPng(x, y, cfg_logo) return height except BaseException as e: sys.print_exception(e) return 0
def __drawThread(): global text, cursorPos, title, __drawChanged, active while active: if __drawChanged: __drawChanged = False display.drawFill(0xFFFFFF) display.drawRect(0, 0, display.width(), 14, True, 0) display.drawText(0, 0, title, 0xFFFFFF, "Roboto_Regular12") if cursorPos > len(text): cursorPos = len(text) if cursorPos < 0: cursorPos = 0 textWithCursor = text[:cursorPos] + "|" + text[cursorPos:] textWithCursorLines = textWithCursor.split("\n") for i in range(len(textWithCursorLines)): display.drawText(0, 17 + i * 13, textWithCursorLines[i], 0x000000, textFont) display.flush(display.FLAG_LUT_FASTEST) time.sleep(0.1)
def lineCentered(pos_y, line, font, color): display.font(font) pos_x = int((display.width() - display.get_string_width(line)) / 2) display.cursor(pos_x, pos_y) display.textColor(color) display.print(line)
def disp_string_right_bottom(y, s, font="freesans9"): display.font(font) l = display.get_string_width(s) display.cursor(display.width() - l, display.height() - (y + 1) * 14) display.textColor(0x000000) display.print(s)
def disp_string_right_bottom(y, s, font="Roboto_Regular12"): l = display.getTextWidth(s, font) display.drawText(display.width() - l, display.height() - (y + 1) * 14, s, 0x000000, font)
def draw(): global cx, cy, text, cursorPos, title, yOffset, mode display.drawFill(0xFFFFFF) display.drawRect(0, yOffset - 12, display.width(), 12, True, 0x000000) display.drawRect(0, yOffset, display.width(), display.height() - yOffset, False, 0x000000) modeText = "keyboard" if mode == 1: modeText = "cursor" if mode == 2: modeText = "actions" display.drawText(0, yOffset - 12, "[SELECT] " + modeText, 0xFFFFFF, "Roboto_Regular12") display.drawRect(0, 0, display.width(), 14, True, 0) display.drawText(0, 0, title, 0xFFFFFF, "Roboto_Regular12") if cursorPos > len(text): cursorPos = len(text) if cursorPos < 0: cursorPos = 0 textWithCursor = text[:cursorPos] + "|" + text[cursorPos:] textWithCursorLines = textWithCursor.split("\n") for i in range(len(textWithCursorLines)): display.drawText(0, 17 + i * 13, textWithCursorLines[i], 0x000000, textFont) for y in range(3): for x in range(10): xOffset = 0 width = 29 widthOffset = width if y == 1: xOffset = 6 if y == 2 and x == 0: width *= 2 if y == 2 and x == 1: continue if y == 1 and x == 0: width += xOffset xOffset = 0 if y == 2 and x == 9: width += 6 if x == 0 and y == 1 and shift == 4: width *= 2 if x == 1 and y == 1 and shift == 4: width = 0 selected = False if x == cx and y == cy: selected = True if width > 0: display.drawRect( x * widthOffset + xOffset, y * 20 + yOffset, width, 20, True, 0xFFFFFF, ) display.drawRect( x * widthOffset + xOffset, y * 20 + yOffset, width, 20, selected, 0x000000, ) color = 0 if selected: color = 0xFFFFFF offset = shift * 3 cxo = xOffset + charOffsetX # if x == 0 and y == 1: # cxo = xOffset+charOffsetXDouble display.drawText( x * widthOffset + cxo, y * 20 + yOffset + charOffsetY, charMap[y + offset][x], color, keyFont, ) if mode == 2: display.drawRect( 8, yOffset + 8, display.width() - 16, display.height() - yOffset - 16, True, 0xFFFFFF, ) display.drawRect( 8, yOffset + 8, display.width() - 16, display.height() - yOffset - 16, False, 0x000000, ) display.drawText(12, yOffset + 12, "Press A to accept input", 0x000000, "Roboto_Regular12") display.drawText(12, yOffset + 12 + 14, "Press B to cancel", 0x000000, "Roboto_Regular12") display.flush(display.FLAG_LUT_FASTEST)