コード例 #1
0
// commence runtime state
void Controller::setRunning(bool running) {
  if (running) {
    dev_fgcolor = -DEFAULT_FOREGROUND;
    dev_bgcolor = -DEFAULT_BACKGROUND;
    os_graf_mx = _output->getWidth();
    os_graf_my = _output->getHeight();

    os_ver = 1;
    os_color = 1;
    os_color_depth = 16;
    setsysvar_str(SYSVAR_OSNAME, "MoSync");

    dev_clrkb();
    ui_reset();

    _runMode = run_state;
    _loadPath.empty();
    _output->reset();

    _lastEventTime = maGetMilliSecondCount();
    _eventTicks = 0;
    _drainError = false;
  } else {
    _runMode = init_state;
  }
}
コード例 #2
0
char *Controller::getText(char *dest, int maxSize) {
  int x = _output->getX();
  int y = _output->getY();
  int w = EXTENT_X(maGetTextSize("YNM"));
  int h = _output->textHeight();

  dest[0] = '\0';
  _runMode = modal_state;
  IFormWidget *formWidget = _output->createLineInput(dest, maxSize, x, y, w, h);
  _output->redraw();
  maShowVirtualKeyboard();

  while (isModal()) {
    MAEvent event = processEvents(EVENT_WAIT_INFINITE, EVENT_TYPE_KEY_PRESSED);
    if (event.type == EVENT_TYPE_KEY_PRESSED) {
      dev_clrkb();
      if (isModal()) {
        if (event.key == 10) {
          _runMode = run_state;
        } else {
          _output->edit(formWidget, event.key);
        }
      }
    }
  }

  // paint the widget result onto the backing screen
  if (dest[0]) {
    _output->print(dest);
  }

  delete formWidget;
  return dest;
}
コード例 #3
0
ファイル: system.cpp プロジェクト: smallbasic/SmallBASIC
void System::handleEvent(MAEvent &event) {
  switch (event.type) {
  case EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED:
    if (_systemMenu != NULL) {
      handleMenu(event);
    } else if (isRunning()) {
      if (!form_ui::optionSelected(event.optionsBoxButtonIndex)) {
        dev_clrkb();
        dev_pushkey(event.optionsBoxButtonIndex);
      }
    }
    break;
  case EVENT_TYPE_SCREEN_CHANGED:
    resize();
    break;
  case EVENT_TYPE_POINTER_PRESSED:
    _touchX = _touchCurX = event.point.x;
    _touchY = _touchCurY = event.point.y;
    if (_output->overMenu(_touchX, _touchY)) {
      showMenu();
    } else {
      dev_pushkey(SB_KEY_MK_PUSH);
      _buttonPressed = _output->pointerTouchEvent(event);
      showCursor(get_focus_edit() != NULL ? kIBeam : kHand);
    }
    break;
  case EVENT_TYPE_POINTER_DRAGGED:
    _touchCurX = event.point.x;
    _touchCurY = event.point.y;
    _output->pointerMoveEvent(event);
    if (_output->hasHover() ||
        _output->overMenu(_touchCurX, _touchCurY)) {
      showCursor(kHand);
    } else if (_output->hasMenu()) {
      showCursor(kArrow);
    } else if (get_focus_edit()) {
      showCursor(kIBeam);
    } else {
      showCursor(kArrow);
    }
    break;
  case EVENT_TYPE_POINTER_RELEASED:
    _buttonPressed = false;
    _touchX = _touchY = _touchCurX = _touchCurY = -1;
    _output->pointerReleaseEvent(event);
    showCursor(get_focus_edit() != NULL ? kIBeam : kArrow);
    break;
  default:
    // no event
    _output->flush(false);
    break;
  }
}
コード例 #4
0
ファイル: system.cpp プロジェクト: smallbasic/SmallBASIC
void System::setRunning(bool running) {
  if (running) {
    dev_fgcolor = -DEFAULT_FOREGROUND;
    dev_bgcolor = -DEFAULT_BACKGROUND;
    setDimensions();
    dev_clrkb();
    _output->setAutoflush(!opt_show_page);
    if (_mainBas || isNetworkLoad() || !isEditEnabled()) {
      _loadPath.clear();
    }
    _userScreenId = -1;
  } else {
    osd_clear_sound_queue();
    if (!isClosing() && !isRestart() && !isBack()) {
      _state = kActiveState;
      _output->setAutoflush(true);
    }
  }
}
コード例 #5
0
ファイル: system.cpp プロジェクト: smallbasic/SmallBASIC
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;
}
コード例 #6
0
ファイル: runtime.cpp プロジェクト: MarcusWellby/SmallBASIC
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();
}