bool AnsiWidget::drawHoverLink(MAEvent &event) { #if defined(_SDL) if (_front != _screens[MENU_SCREEN]) { int dx = _front->_x; int dy = _front->_y - _front->_scrollY; FormInput *active = NULL; if (_front->overlaps(event.point.x, event.point.y)) { List_each(FormInput *, it, _front->_inputs) { FormInput *widget = (FormInput *)(*it); if (widget->hasHover() && widget->overlaps(event.point, dx, dy)) { active = widget; break; } } }
char *System::getText(char *dest, int maxSize) { int x = _output->getX(); int y = _output->getY(); int w = EXTENT_X(maGetTextSize("YNM")); int h = _output->textHeight(); int charWidth = _output->getCharWidth(); FormInput *widget = new FormLineInput(NULL, NULL, maxSize, true, x, y, w, h); widget->setFocus(true); int bg = _output->getBackgroundColor(); int fg = _output->getColor(); if (bg != DEFAULT_BACKGROUND || fg != DEFAULT_FOREGROUND) { widget->setColor(bg, fg); } else { widget->setColor(FOCUS_COLOR, DEFAULT_FOREGROUND); } _output->addInput(widget); _output->redraw(); _state = kModalState; maShowVirtualKeyboard(); showCursor(kIBeam); while (isModal()) { MAEvent event = getNextEvent(); if (event.type == EVENT_TYPE_KEY_PRESSED) { dev_clrkb(); if (isModal()) { int sw = _output->getScreenWidth(); switch (event.key) { case SB_KEY_ENTER: _state = kRunState; break; case SB_KEY_MENU: break; default: if (widget->edit(event.key, sw, charWidth)) { _output->redraw(); } } } } } const char *result = widget->getText(); if (result) { strcpy(dest, result); } else { dest[0] = '\0'; } // paint the widget result onto the backing screen if (dest[0]) { _output->setXY(x, y); _output->print(dest); } showCursor(kArrow); _output->removeInput(widget); delete widget; return dest; }
void Runtime::optionsBox(StringList *items) { if (!_menuX) { _menuX = 2; } if (!_menuY) { _menuY = 2; } int width = 0; int charWidth = _output->getCharWidth(); _output->registerScreen(MENU_SCREEN); List_each(String *, it, *items) { char *str = (char *)(* it)->c_str(); int w = (strlen(str) * charWidth); if (w > width) { width = w; } } width += (charWidth * OPTIONS_BOX_WIDTH_EXTRA); int charHeight = _output->getCharHeight(); int textHeight = charHeight + (charHeight / 3); int height = textHeight * items->size(); if (_menuX + width >= _output->getWidth()) { _menuX = _output->getWidth() - width; } if (_menuY + height >= _output->getHeight()) { _menuY = _output->getHeight() - height; } int screenId = _output->insetMenuScreen(_menuX, _menuY, width, height); int y = 0; int index = 0; int selectedIndex = -1; int releaseCount = 0; List_each(String *, it, *items) { char *str = (char *)(* it)->c_str(); FormInput *item = new MenuButton(index, selectedIndex, str, 0, y, width, textHeight); _output->addInput(item); item->setColor(OPTIONS_BOX_BG, OPTIONS_BOX_FG); index++; y += textHeight; } _output->redraw(); while (selectedIndex == -1 && !isClosing()) { MAEvent ev = processEvents(true); if (ev.type == EVENT_TYPE_KEY_PRESSED && ev.key == 27) { break; } if (ev.type == EVENT_TYPE_POINTER_RELEASED && ++releaseCount == 2) { break; } } _output->removeInputs(); _output->selectScreen(screenId); _menuX = 2; _menuY = 2; if (selectedIndex != -1) { if (_systemMenu == NULL && isRunning() && !form_ui::optionSelected(selectedIndex)) { dev_clrkb(); dev_pushkey(selectedIndex); } else { MAEvent *maEvent = new MAEvent(); maEvent->type = EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED; maEvent->optionsBoxButtonIndex = selectedIndex; pushEvent(maEvent); } } else { delete [] _systemMenu; _systemMenu = NULL; } _output->redraw(); }