Exemplo n.º 1
0
bool
WndForm::OnMouseDown(PixelScalar x, PixelScalar y)
{
  if (ContainerWindow::OnMouseDown(x, y))
    return true;

  if (!dragging && !IsMaximised()) {
    dragging = true;
    Invalidate();

    const PixelRect position = GetPosition();
    last_drag.x = position.left + x;
    last_drag.y = position.top + y;
    SetCapture();
    return true;
  }

  return false;
}
Exemplo n.º 2
0
void
WndForm::OnPaint(Canvas &canvas)
{
  const SingleWindow &main_window = GetMainWindow();
  gcc_unused const bool is_active = main_window.IsTopDialog(*this);

#ifdef ENABLE_OPENGL
  if (!IsDithered() && !IsMaximised() && is_active) {
    /* draw a shade around the current dialog to emphasise it */
    const ScopeAlphaBlend alpha_blend;

    const PixelRect rc = GetClientRect();
    const PixelScalar size = Layout::VptScale(4);

    const RasterPoint vertices[8] = {
      { rc.left, rc.top },
      { rc.right, rc.top },
      { rc.right, rc.bottom },
      { rc.left, rc.bottom },
      { rc.left - size, rc.top - size },
      { rc.right + size, rc.top - size },
      { rc.right + size, rc.bottom + size },
      { rc.left - size, rc.bottom + size },
    };

    const ScopeVertexPointer vp(vertices);

    static constexpr Color inner_color = COLOR_BLACK.WithAlpha(192);
    static constexpr Color outer_color = COLOR_BLACK.WithAlpha(16);
    static constexpr Color colors[8] = {
      inner_color,
      inner_color,
      inner_color,
      inner_color,
      outer_color,
      outer_color,
      outer_color,
      outer_color,
    };

    const ScopeColorPointer cp(colors);

    static constexpr GLubyte indices[] = {
      0, 4, 1, 4, 5, 1,
      1, 5, 2, 5, 6, 2,
      2, 6, 3, 6, 7, 3,
      3, 7, 0, 7, 4, 0,
    };

    glDrawElements(GL_TRIANGLES, ARRAY_SIZE(indices),
                   GL_UNSIGNED_BYTE, indices);
  }
#endif

  ContainerWindow::OnPaint(canvas);

  // Get window coordinates
  PixelRect rcClient = GetClientRect();

  // Draw the borders
  if (!IsMaximised()) {
#ifndef USE_GDI
    if (IsDithered())
      canvas.DrawOutlineRectangle(rcClient.left, rcClient.top,
                                  rcClient.right - 1, rcClient.bottom - 1,
                                  COLOR_BLACK);
    else
#endif
      canvas.DrawRaisedEdge(rcClient);
  }

  if (!caption.empty()) {
    // Set the colors
    canvas.SetTextColor(COLOR_WHITE);

    // Set the titlebar font and font-size
    canvas.Select(*look.caption.font);

    // JMW todo add here icons?

#ifdef EYE_CANDY
    if (!IsDithered() && is_active) {
      canvas.SetBackgroundTransparent();
      canvas.Stretch(title_rect.left, title_rect.top,
                     title_rect.right - title_rect.left,
                     title_rect.bottom - title_rect.top,
                     look.caption.background_bitmap);

      // Draw titlebar text
      canvas.DrawText(title_rect.left + Layout::GetTextPadding(),
                      title_rect.top, caption.c_str());
    } else {
#endif
      canvas.SetBackgroundColor(is_active
                                ? look.caption.background_color
                                : look.caption.inactive_background_color);
      canvas.DrawOpaqueText(title_rect.left + Layout::GetTextPadding(),
                            title_rect.top, title_rect, caption.c_str());
#ifdef EYE_CANDY
    }
#endif
  }

  if (dragging) {
#ifdef ENABLE_OPENGL
    const ScopeAlphaBlend alpha_blend;
    canvas.DrawFilledRectangle(0, 0, canvas.GetWidth(), canvas.GetHeight(),
                               COLOR_YELLOW.WithAlpha(80));
#elif defined(USE_GDI)
    canvas.InvertRectangle(title_rect);
#else
    canvas.InvertRectangle(GetClientRect());
#endif
  }
}
Exemplo n.º 3
0
void
WndForm::OnPaint(Canvas &canvas)
{
  const SingleWindow &main_window = GetMainWindow();
  gcc_unused const bool is_active = main_window.IsTopDialog(*this);

#ifdef ENABLE_OPENGL
  if (!IsMaximised() && is_active) {
    /* draw a shade around the current dialog to emphasise it */
    GLEnable blend(GL_BLEND);
    glEnableClientState(GL_COLOR_ARRAY);

    const PixelRect rc = GetClientRect();
    const PixelScalar size = Layout::SmallScale(4);

    const RasterPoint vertices[8] = {
      { rc.left, rc.top },
      { rc.right, rc.top },
      { rc.right, rc.bottom },
      { rc.left, rc.bottom },
      { rc.left - size, rc.top - size },
      { rc.right + size, rc.top - size },
      { rc.right + size, rc.bottom + size },
      { rc.left - size, rc.bottom + size },
    };

    glVertexPointer(2, GL_VALUE, 0, vertices);

    static constexpr Color inner_color = COLOR_BLACK.WithAlpha(192);
    static constexpr Color outer_color = COLOR_BLACK.WithAlpha(16);
    static constexpr Color colors[8] = {
      inner_color,
      inner_color,
      inner_color,
      inner_color,
      outer_color,
      outer_color,
      outer_color,
      outer_color,
    };

#ifdef HAVE_GLES
    glColorPointer(4, GL_FIXED, 0, colors);
#else
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
#endif

    static constexpr GLubyte indices[] = {
      0, 4, 1, 4, 5, 1,
      1, 5, 2, 5, 6, 2,
      2, 6, 3, 6, 7, 3,
      3, 7, 0, 7, 4, 0,
    };

    glDrawElements(GL_TRIANGLES, ARRAY_SIZE(indices),
                   GL_UNSIGNED_BYTE, indices);

    glDisableClientState(GL_COLOR_ARRAY);
  }
#endif

  ContainerWindow::OnPaint(canvas);

  // Get window coordinates
  PixelRect rcClient = GetClientRect();

  // Draw the borders
  canvas.DrawRaisedEdge(rcClient);

  if (!caption.empty()) {
    // Set the colors
    canvas.SetTextColor(COLOR_WHITE);

    // Set the titlebar font and font-size
    canvas.Select(*look.caption.font);

    // JMW todo add here icons?

#ifdef EYE_CANDY
    canvas.SetBackgroundTransparent();
    canvas.Stretch(title_rect.left, title_rect.top,
                   title_rect.right - title_rect.left,
                   title_rect.bottom - title_rect.top,
                   look.caption.background_bitmap);

    // Draw titlebar text
    canvas.DrawText(title_rect.left + Layout::FastScale(2), title_rect.top,
                    caption.c_str());
#else
    canvas.SetBackgroundColor(is_active
                              ? look.caption.background_color
                              : look.caption.inactive_background_color);
    canvas.DrawOpaqueText(title_rect.left + Layout::FastScale(2),
                          title_rect.top, title_rect, caption.c_str());
#endif
  }

  if (dragging) {
#ifdef ENABLE_OPENGL
    GLEnable blend(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    canvas.DrawFilledRectangle(0, 0, canvas.GetWidth(), canvas.GetHeight(),
                               COLOR_YELLOW.WithAlpha(80));
#elif defined(USE_GDI)
    ::InvertRect(canvas, &title_rect);
#endif
  }
}