Exemple #1
0
void
ButtonWindow::OnPaint(Canvas &canvas)
{
  const bool focused = HasCursorKeys() ? HasFocus() : down;

  if (focused) {
    Pen pen(Layout::Scale(1), COLOR_BLACK);
    canvas.Select(pen);
    canvas.SelectHollowBrush();
    canvas.Rectangle(-1, -1, canvas.GetWidth(), canvas.GetHeight());
  }

  PixelRect rc(2, 2, canvas.GetWidth() - 4, canvas.GetHeight() - 4);

  if (down) {
    rc.left += Layout::FastScale(1);
    rc.top += Layout::FastScale(1);
  }

  canvas.DrawButton(GetClientRect(), down);

  canvas.SetTextColor(IsEnabled()
                      ? (IsDithered() && down ? COLOR_WHITE : COLOR_BLACK)
                      : COLOR_GRAY);
  canvas.SetBackgroundTransparent();

  unsigned style = GetTextStyle();
  if (IsDithered())
    style |= DT_UNDERLINE;

  canvas.DrawFormattedText(&rc, text.c_str(), style);
}
Exemple #2
0
inline void
TabMenuDisplay::PaintMainMenuItems(Canvas &canvas,
                                   const unsigned CaptionStyle) const
{
  PaintMainMenuBorder(canvas);

  const bool is_focused = !HasCursorKeys() || HasFocus();

  unsigned main_menu_index = 0;
  for (auto i = main_menu_buttons.begin(),
         end = main_menu_buttons.end(); i != end;
       ++i, ++main_menu_index) {
    const bool isDown = main_menu_index == down_index.main_index &&
      !down_index.IsSub() && !drag_off_button;

    const bool is_selected = isDown ||
      main_menu_index == GetPageMainIndex(cursor);

    canvas.SetTextColor(look.list.GetTextColor(is_selected, is_focused,
                                               isDown));
    canvas.SetBackgroundColor(look.list.GetBackgroundColor(is_selected,
                                                           is_focused,
                                                           isDown));

    const PixelRect &rc = GetMainMenuButtonSize(main_menu_index);
    TabDisplay::PaintButton(canvas, CaptionStyle,
                            gettext(GetGroupCaption(main_menu_index)),
                            rc,
                            nullptr, isDown, false);
  }
}
void
TabDisplay::OnPaint(Canvas &canvas)
{
  canvas.Clear(COLOR_BLACK);
  canvas.Select(*look.button.font);

  const unsigned CaptionStyle = DT_CENTER | DT_NOCLIP
      | DT_WORDBREAK;

  const bool is_focused = !HasCursorKeys() || HasFocus();
  for (unsigned i = 0; i < buttons.size(); i++) {
    const TabButton &button = *buttons[i];

    const bool is_down = dragging && i == down_index && !drag_off_button;
    const bool is_selected = i == tab_bar.GetCurrentPage();

    canvas.SetTextColor(look.list.GetTextColor(is_selected, is_focused,
                                               is_down));
    canvas.SetBackgroundColor(look.list.GetBackgroundColor(is_selected,
                                                           is_focused,
                                                           is_down));

    const PixelRect &rc = GetButtonSize(i);
    PaintButton(canvas, CaptionStyle, button.caption, rc, button.bitmap,
                is_down, is_selected);
  }
}
Exemple #4
0
inline void
TabMenuDisplay::PaintSubMenuItems(Canvas &canvas) const
{
  const MainMenuButton &main_button =
    GetMainMenuButton(GetPageMainIndex(cursor));

  PaintSubMenuBorder(canvas, main_button);

  assert(main_button.first_page_index < buttons.size());
  assert(main_button.last_page_index < buttons.size());

  const bool is_focused = !HasCursorKeys() || HasFocus();

  for (unsigned first_page_index = main_button.first_page_index,
         last_page_index = main_button.last_page_index,
         page_index = first_page_index;
       page_index <= last_page_index; ++page_index) {
    const unsigned sub_index = page_index - first_page_index;

    const bool is_pressed = sub_index == down_index.sub_index &&
      !drag_off_button;

    const bool is_cursor = page_index == cursor;
    const bool is_selected = is_pressed || is_cursor;

    buttons[page_index].Draw(canvas, look,
                             is_focused, is_pressed, is_selected);
  }
}
Exemple #5
0
void
CheckBoxControl::OnPaint(Canvas &canvas)
{
  const auto &cb_look = look->check_box;

  const bool focused = HasCursorKeys() && HasFocus();

  if (focused)
    canvas.Clear(cb_look.focus_background_brush);
  else if (HaveClipping())
    canvas.Clear(look->background_brush);

  const auto &state_look = IsEnabled()
    ? (pressed
       ? cb_look.pressed
       : (focused
          ? cb_look.focused
          : cb_look.standard))
    : cb_look.disabled;

  unsigned size = canvas.GetHeight() - 4;

  canvas.Select(state_look.box_brush);
  canvas.Select(state_look.box_pen);
  canvas.Rectangle(2, 2, size, size);

  if (checked) {
    canvas.Select(state_look.check_brush);
    canvas.SelectNullPen();

    BulkPixelPoint check_mark[] = {
      {-8, -2},
      {-3, 6},
      {7, -9},
      {8, -5},
      {-3, 9},
      {-9, 2},
    };

    unsigned top = canvas.GetHeight() / 2;
    for (unsigned i = 0; i < ARRAY_SIZE(check_mark); ++i) {
      check_mark[i].x = (check_mark[i].x * (int)size) / 24 + top;
      check_mark[i].y = (check_mark[i].y * (int)size) / 24 + top;
    }

    canvas.DrawPolygon(check_mark, ARRAY_SIZE(check_mark));
  }

  canvas.Select(*cb_look.font);
  canvas.SetTextColor(state_look.text_color);
  canvas.SetBackgroundTransparent();
  canvas.DrawText(canvas.GetHeight() + 2, 2, caption.c_str());
}
Exemple #6
0
void
Button::OnPaint(Canvas &canvas)
{
  assert(renderer != nullptr);

  const bool pressed = down;
  const bool focused = HasCursorKeys()
    ? HasFocus() || (selected && !HasPointer())
    : pressed;

  renderer->DrawButton(canvas, GetClientRect(),
                       IsEnabled(), focused, pressed);
}
Exemple #7
0
void
InfoBoxWindow::OnSetFocus()
{
  // Call the parent function
  PaintWindow::OnSetFocus();

  // Start the focus-auto-return timer
  // to automatically return focus back to MapWindow if idle
  focus_timer.Schedule(HasCursorKeys() ? FOCUS_TIMEOUT_MAX : 1100);

  // Redraw fast to paint the selector
  Invalidate();
}
Exemple #8
0
void
TabDisplay::OnPaint(Canvas &canvas)
{
  canvas.Clear(COLOR_BLACK);

  const bool is_focused = !HasCursorKeys() || HasFocus();
  for (unsigned i = 0; i < buttons.size(); i++) {
    const TabButton &button = *buttons[i];

    const bool is_down = dragging && i == down_index && !drag_off_button;
    const bool is_selected = i == pager.GetCurrentIndex();

    button.Draw(canvas, look, is_focused, is_down, is_selected);
  }
}
Exemple #9
0
void
WndButton::OnPaint(Canvas &canvas)
{
  const bool pressed = IsDown();
  const bool focused = HasCursorKeys() ? HasFocus() : pressed;

  PixelRect rc = canvas.GetRect();
  renderer.DrawButton(canvas, rc, focused, pressed);

  // If button has text on it
  const tstring caption = GetText();
  if (caption.empty())
    return;

  rc = renderer.GetDrawingRect(rc, pressed);

  canvas.SetBackgroundTransparent();
  if (!IsEnabled())
    canvas.SetTextColor(look.button.disabled.color);
  else if (focused)
    canvas.SetTextColor(look.button.focused.foreground_color);
  else
    canvas.SetTextColor(look.button.standard.foreground_color);

  canvas.Select(*(look.button.font));

#ifndef USE_GDI
  canvas.DrawFormattedText(&rc, caption.c_str(), GetTextStyle());
#else
  unsigned style = DT_CENTER | DT_NOCLIP | DT_WORDBREAK;

  PixelRect text_rc = rc;
  canvas.DrawFormattedText(&text_rc, caption.c_str(), style | DT_CALCRECT);
  text_rc.right = rc.right;

  PixelScalar offset = rc.bottom - text_rc.bottom;
  if (offset > 0) {
    offset /= 2;
    text_rc.top += offset;
    text_rc.bottom += offset;
  }

  canvas.DrawFormattedText(&text_rc, caption.c_str(), style);
#endif
}
Exemple #10
0
void
ListControl::DrawItems(Canvas &canvas, unsigned start, unsigned end) const
{
  PixelRect rc = item_rect(start);

  canvas.SetBackgroundColor(look.list.background_color);
  canvas.SetBackgroundTransparent();
  canvas.Select(*look.list.font);

#ifdef ENABLE_OPENGL
  /* enable clipping */
  const PixelRect scissor_rc(0, 0, scroll_bar.GetLeft(GetSize()),
                             canvas.GetHeight());
  GLCanvasScissor scissor(scissor_rc);
#endif

  unsigned last_item = std::min(length, end);

  const bool focused = !HasCursorKeys() || HasFocus();

  for (unsigned i = start; i < last_item; i++) {
    const bool selected = i == cursor;
    const bool pressed = selected && drag_mode == DragMode::CURSOR;

    canvas.DrawFilledRectangle(rc,
                               look.list.GetBackgroundColor(selected,
                                                            focused,
                                                            pressed));

    canvas.SetTextColor(look.list.GetTextColor(selected, focused, pressed));

    if (item_renderer != nullptr)
      item_renderer->OnPaintItem(canvas, rc, i);

    if (focused && selected)
      canvas.DrawFocusRectangle(rc);

    rc.Offset(0, rc.bottom - rc.top);
  }

  /* paint the bottom part below the last item */
  rc.bottom = canvas.GetHeight();
  if (rc.bottom > rc.top)
    canvas.DrawFilledRectangle(rc, look.list.background_color);
}
Exemple #11
0
inline void
TabMenuDisplay::PaintMainMenuItems(Canvas &canvas) const
{
  PaintMainMenuBorder(canvas);

  const bool is_focused = !HasCursorKeys() || HasFocus();

  unsigned main_menu_index = 0;
  for (auto i = main_menu_buttons.begin(),
         end = main_menu_buttons.end(); i != end;
       ++i, ++main_menu_index) {
    const bool isDown = main_menu_index == down_index.main_index &&
      !down_index.IsSub() && !drag_off_button;

    const bool is_selected = isDown ||
      main_menu_index == GetPageMainIndex(cursor);

    main_menu_buttons[main_menu_index].Draw(canvas, look,
                                            is_focused, isDown, is_selected);
  }
}
Exemple #12
0
inline void
TabMenuDisplay::PaintSubMenuItems(Canvas &canvas,
                                  const unsigned CaptionStyle) const
{
  const MainMenuButton &main_button =
    GetMainMenuButton(GetPageMainIndex(cursor));

  PaintSubMenuBorder(canvas, main_button);

  assert(main_button.first_page_index < buttons.size());
  assert(main_button.last_page_index < buttons.size());

  const bool is_focused = !HasCursorKeys() || HasFocus();

  for (unsigned first_page_index = main_button.first_page_index,
         last_page_index = main_button.last_page_index,
         page_index = first_page_index;
       page_index <= last_page_index; ++page_index) {
    const unsigned sub_index = page_index - first_page_index;

    const bool is_pressed = sub_index == down_index.sub_index &&
      !drag_off_button;

    const bool is_cursor = page_index == cursor;
    const bool is_selected = is_pressed || is_cursor;

    canvas.SetTextColor(look.list.GetTextColor(is_selected, is_focused,
                                               is_pressed));
    canvas.SetBackgroundColor(look.list.GetBackgroundColor(is_selected,
                                                           is_focused,
                                                           is_pressed));

    const PixelRect &rc = GetSubMenuButtonSize(page_index);
    TabDisplay::PaintButton(canvas, CaptionStyle,
                            gettext(pages[page_index].menu_caption),
                            rc,
                            nullptr, is_cursor,
                            false);
  }
}
Exemple #13
0
void
DigitEntry::OnPaint(Canvas &canvas)
{
    assert(cursor < length);

    const bool focused = HasCursorKeys() && HasFocus();

    if (HaveClipping())
        canvas.Clear(look.background_color);

    canvas.Select(look.text_font);
    canvas.SetBackgroundOpaque();

    const unsigned text_height = look.text_font.GetHeight();
    const int y = (top + bottom - text_height) / 2;

    PixelRect rc;
    rc.top = top;
    rc.bottom = bottom;

    TCHAR buffer[4];

    for (unsigned i = 0; i < length; ++i) {
        const Column &c = columns[i];

        rc.left = c.left;
        rc.right = c.right;

        if (focused && i == cursor) {
            canvas.SetTextColor(look.list.focused.text_color);
            canvas.SetBackgroundColor(look.list.focused.background_color);
        } else if (c.IsEditable()) {
            canvas.SetTextColor(look.list.text_color);
            canvas.SetBackgroundColor(look.list.background_color);
        } else {
            canvas.SetTextColor(look.list.text_color);
            canvas.SetBackgroundColor(look.background_color);
        }

        const TCHAR *text = buffer;
        buffer[1] = _T('\0');

        switch (c.type) {
        case Column::Type::DIGIT:
        case Column::Type::DIGIT6:
            assert(c.value < 10);
            buffer[0] = _T('0') + c.value;
            break;

        case Column::Type::HOUR:
            assert(c.value < 24);
            _stprintf(buffer, _T("%02u"), c.value);
            break;

        case Column::Type::DIGIT36:
            assert(c.value < 36);
            _stprintf(buffer, _T("%02u"), c.value);
            break;

        case Column::Type::DIGIT19:
            assert(c.value < 19);
            _stprintf(buffer, _T("%02u"), c.value);
            break;

        case Column::Type::SIGN:
            buffer[0] = c.IsNegative() ? _T('-') : _T('+');
            break;

        case Column::Type::DECIMAL_POINT:
            buffer[0] = _T('.');
            break;

        case Column::Type::COLON:
            buffer[0] = _T(':');
            break;

        case Column::Type::NORTH_SOUTH:
            buffer[0] = c.IsNegative() ? _T('S') : _T('N');
            break;

        case Column::Type::EAST_WEST:
            buffer[0] = c.IsNegative() ? _T('W') : _T('E');
            break;

        case Column::Type::DEGREES:
            text = _T("°");
            break;

        case Column::Type::APOSTROPHE:
            text = _T("'");
            break;

        case Column::Type::QUOTE:
            text = _T("\"");
            break;

        case Column::Type::UNIT:
            // TODO: render unit symbol?
            text = Units::unit_descriptors[c.value].name;
            break;
        }

        if (c.IsEditable() && !valid)
            buffer[0] = _T('\0');

        const int x = (c.left + c.right - canvas.CalcTextWidth(text)) / 2;

        canvas.DrawOpaqueText(x, y, rc, text);
    }

    canvas.SetBackgroundTransparent();
    canvas.SetTextColor(look.text_color);

    unsigned control_height = Layout::GetMaximumControlHeight();

    PixelRect plus_rc(0, top - control_height, 0, top);
    PixelRect minus_rc(0, bottom, 0, bottom + control_height);

    for (unsigned i = 0; i < length; ++i) {
        const Column &c = columns[i];
        if (!c.IsEditable())
            continue;

        plus_rc.left = minus_rc.left = c.left;
        plus_rc.right = minus_rc.right = c.right;

        button_renderer.DrawButton(canvas, plus_rc, false, false);
        button_renderer.DrawButton(canvas, minus_rc, false, false);

        canvas.SelectNullPen();
        canvas.Select(look.button.standard.foreground_brush);

        SymbolRenderer::DrawArrow(canvas, plus_rc, SymbolRenderer::UP);
        SymbolRenderer::DrawArrow(canvas, minus_rc, SymbolRenderer::DOWN);
    }
}
Exemple #14
0
bool
ListControl::OnMouseDown(PixelScalar x, PixelScalar y)
{
  // End any previous drag
  scroll_bar.DragEnd(this);
  drag_end();

#ifndef _WIN32_WCE
  kinetic_timer.Cancel();
#endif

  RasterPoint Pos;
  Pos.x = x;
  Pos.y = y;

  // If possible -> Give focus to the Control
  const bool had_focus = !HasCursorKeys() || HasFocus();
  if (!had_focus)
    SetFocus();

  if (scroll_bar.IsInsideSlider(Pos)) {
    // if click is on scrollbar handle
    // -> start mouse drag
    scroll_bar.DragBegin(this, Pos.y);
  } else if (scroll_bar.IsInside(Pos)) {
    // if click in scroll bar up/down/pgup/pgdn
    if (scroll_bar.IsInsideUpArrow(Pos.y))
      // up
      MoveOrigin(-1);
    else if (scroll_bar.IsInsideDownArrow(Pos.y))
      // down
      MoveOrigin(1);
    else if (scroll_bar.IsAboveSlider(Pos.y))
      // page up
      MoveOrigin(-(int)items_visible);
    else if (scroll_bar.IsBelowSlider(Pos.y))
      // page down
      MoveOrigin(items_visible);
  } else {
    // if click in ListBox area
    // -> select appropriate item

    int index = ItemIndexAt(y);
    // If mouse was clicked outside the list items -> cancel
    if (index < 0)
      return false;

    drag_y = GetPixelOrigin() + y;
    drag_y_window = y;

    if (had_focus && (unsigned)index == GetCursorIndex() &&
        CanActivateItem()) {
      drag_mode = DragMode::CURSOR;
      Invalidate_item(cursor);
    } else {
      // If item was not selected before
      // -> select it
      SetCursorIndex(index);
      drag_mode = DragMode::SCROLL;
    }
#ifndef _WIN32_WCE
    if (UsePixelPan())
      kinetic.MouseDown(GetPixelOrigin());
#endif
    SetCapture();
  }

  return true;
}