Esempio n. 1
0
void Graphics::drawUIString(const std::string& str, gfx::Color fg, gfx::Color bg, const gfx::Point& pt)
{
  she::ScopedSurfaceLock dst(m_surface);
  base::utf8_const_iterator it(str.begin()), end(str.end());
  int x = m_dx+pt.x;
  int y = m_dy+pt.y;
  int underscored_x;
  int underscored_w = -1;

  while (it != end) {
    if (*it == '&') {
      ++it;
      if (it != end && *it != '&') {
        underscored_x = x;
        underscored_w = m_font->charWidth(*it);
      }
    }
    dst->drawChar(m_font, fg, bg, x, y, *it);
    x += m_font->charWidth(*it);
    ++it;
  }

  if (underscored_w > 0) {
    y += m_font->height();
    dst->fillRect(fg,
      gfx::Rect(underscored_x, y, underscored_w, guiscale()));
  }
}
Esempio n. 2
0
UISystem::~UISystem()
{
  OverlayManager::destroyInstance();

  // finish theme
  set_theme(nullptr, guiscale());

  details::exitWidgets();

  _internal_set_mouse_display(nullptr);
  if (!update_custom_native_cursor(nullptr))
    update_mouse_overlay(nullptr);

  ASSERT(g_instance == this);
  g_instance = nullptr;
}
Esempio n. 3
0
void Entry::onPreferredSize(PreferredSizeEvent& ev)
{
  int w =
    + border_width.l
    + getFont()->charWidth('w') * MIN(m_maxsize, 6)
    + 2*guiscale()
    + border_width.r;

  w = MIN(w, ui::display_w()/2);

  int h =
    + border_width.t
    + getFont()->height()
    + border_width.b;

  ev.setPreferredSize(w, h);
}
Esempio n. 4
0
void Alert::processString(char* buf, std::vector<Widget*>& labels, std::vector<Widget*>& buttons)
{
  Box* box1, *box2, *box3, *box4, *box5;
  Grid* grid;
  bool title = true;
  bool label = false;
  bool separator = false;
  bool button = false;
  int align = 0;
  char *beg;
  int c, chr;

  // Process buffer
  c = 0;
  beg = buf;
  for (; ; c++) {
    if ((!buf[c]) ||
        ((buf[c] == buf[c+1]) &&
         ((buf[c] == '<') ||
          (buf[c] == '=') ||
          (buf[c] == '>') ||
          (buf[c] == '-') ||
          (buf[c] == '|')))) {
      if (title || label || separator || button) {
        chr = buf[c];
        buf[c] = 0;

        if (title) {
          setText(beg);
        }
        else if (label) {
          Label* label = new Label(beg);
          label->setAlign(align);
          labels.push_back(label);
        }
        else if (separator) {
          labels.push_back(new Separator("", HORIZONTAL));
        }
        else if (button) {
          char buttonId[256];
          Button* button_widget = new Button(beg);
          button_widget->setMinSize(gfx::Size(60*guiscale(), 0));
          buttons.push_back(button_widget);

          sprintf(buttonId, "button-%lu", buttons.size());
          button_widget->setId(buttonId);
          button_widget->Click.connect(Bind<void>(&Window::closeWindow, this, button_widget));
        }

        buf[c] = chr;
      }

      /* done */
      if (!buf[c])
        break;
      /* next widget */
      else {
        title = label = separator = button = false;
        beg = buf+c+2;
        align = 0;

        switch (buf[c]) {
          case '<': label=true; align=LEFT; break;
          case '=': label=true; align=CENTER; break;
          case '>': label=true; align=RIGHT; break;
          case '-': separator=true; break;
          case '|': button=true; break;
        }
        c++;
      }
    }
  }

  box1 = new Box(VERTICAL);
  box2 = new Box(VERTICAL);
  grid = new Grid(1, false);
  box3 = new Box(HORIZONTAL | HOMOGENEOUS);

  // To identify by the user
  box2->setId("labels");
  box3->setId("buttons");

  // Pseudo separators (only to fill blank space)
  box4 = new Box(0);
  box5 = new Box(0);
  m_progressPlaceholder = new Box(0);

  box4->setExpansive(true);
  box5->setExpansive(true);
  box4->noBorderNoChildSpacing();
  box5->noBorderNoChildSpacing();
  m_progressPlaceholder->noBorderNoChildSpacing();

  // Setup parent <-> children relationship

  addChild(box1);

  box1->addChild(box4); // Filler
  box1->addChild(box2); // Labels
  box1->addChild(m_progressPlaceholder);
  box1->addChild(box5); // Filler
  box1->addChild(grid); // Buttons

  grid->addChildInCell(box3, 1, 1, CENTER | BOTTOM);

  for (std::vector<Widget*>::iterator it = labels.begin(); it != labels.end(); ++it)
    box2->addChild(*it);

  for (std::vector<Widget*>::iterator it = buttons.begin(); it != buttons.end(); ++it)
    box3->addChild(*it);

  // Default button is the last one
  if (!buttons.empty())
    buttons[buttons.size()-1]->setFocusMagnet(true);
}