コード例 #1
0
ファイル: art_aui.cpp プロジェクト: AaronDP/wxWidgets
void wxRibbonAUIArtProvider::DrawToolGroupBackground(
                    wxDC& dc,
                    wxWindow* WXUNUSED(wnd),
                    const wxRect& rect)
{
    dc.SetPen(m_toolbar_border_pen);
    dc.SetBrush(*wxTRANSPARENT_BRUSH);
    dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
    wxRect bg_rect(rect);
    bg_rect.Deflate(1);
    dc.GradientFillLinear(bg_rect, m_tool_background_colour,
        m_tool_background_gradient_colour, wxSOUTH);
}
コード例 #2
0
ファイル: art_metro.cpp プロジェクト: eranif/codelite
void wxRibbonMetroArtProvider::DrawTool(wxDC& dc, wxWindow* WXUNUSED(wnd), const wxRect& rect, const wxBitmap& bitmap,
                                        wxRibbonButtonKind kind, long state)
{
    if(kind == wxRIBBON_BUTTON_TOGGLE) {
        if(state & wxRIBBON_TOOLBAR_TOOL_TOGGLED) state ^= wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK;
    }

    wxRect bg_rect(rect);
    bg_rect.Deflate(1);
    if((state & wxRIBBON_TOOLBAR_TOOL_LAST) == 0) bg_rect.width++;

    bool is_split_hybrid = (kind == wxRIBBON_BUTTON_HYBRID &&
                            (state & (wxRIBBON_TOOLBAR_TOOL_HOVER_MASK | wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)));

    dc.SetPen(m_toolbar_border_pen);

    if(state & wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK) {
        dc.SetBrush(m_tool_background_colour);
        dc.DrawRectangle(rect);
    } else if(state & wxRIBBON_TOOLBAR_TOOL_HOVER_MASK) {
        dc.SetBrush(m_tool_hover_background_colour);
        dc.DrawRectangle(rect);
    }

    // remove the highlight from the non-active split part of the hybrid
    if(is_split_hybrid) {
        wxRect nonrect(bg_rect);
        if(state & (wxRIBBON_TOOLBAR_TOOL_DROPDOWN_HOVERED | wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE)) {
            nonrect.width -= 8;
        } else {
            nonrect.x += nonrect.width - 8;
            nonrect.width = 7;
        }
        dc.SetPen(*wxTRANSPARENT_PEN);
        dc.SetBrush(m_page_background_top_gradient_colour);
        dc.DrawRectangle(nonrect.x, nonrect.y, nonrect.width, nonrect.height);
    }

    // Foreground
    int avail_width = bg_rect.GetWidth();
    if(kind & wxRIBBON_BUTTON_DROPDOWN) {
        avail_width -= 8;
        if(is_split_hybrid) {
            dc.SetPen(m_toolbar_border_pen);
            dc.DrawLine(rect.x + avail_width + 1, rect.y, rect.x + avail_width + 1, rect.y + rect.height);
        }
        dc.DrawBitmap(m_toolbar_drop_bitmap, bg_rect.x + avail_width + 2, bg_rect.y + (bg_rect.height / 2) - 2, true);
    }
    dc.DrawBitmap(bitmap, bg_rect.x + (avail_width - bitmap.GetWidth()) / 2,
                  bg_rect.y + (bg_rect.height - bitmap.GetHeight()) / 2, true);
}
コード例 #3
0
ファイル: dialog.cpp プロジェクト: huzongyao/AndroidSuperTux
int
Dialog::get_button_at(const Vector& mouse_pos) const
{
  Rectf bg_rect(Vector(SCREEN_WIDTH/2 - m_text_size.width/2,
                       SCREEN_HEIGHT/2 - m_text_size.height/2),
                Sizef(m_text_size.width,
                      m_text_size.height + 44));

  for(int i = 0; i < static_cast<int>(m_buttons.size()); ++i)
  {
    float segment_width = bg_rect.get_width() / m_buttons.size();
    float button_width = segment_width;
    float button_height = 24.0f;
    Vector pos(bg_rect.p1.x + segment_width/2.0f + i * segment_width,
               bg_rect.p2.y - 12);
    Rectf button_rect(Vector(pos.x - button_width/2, pos.y - button_height/2),
                      Vector(pos.x + button_width/2, pos.y + button_height/2));
    if (button_rect.contains(mouse_pos))
    {
      return i;
    }
  }
  return -1;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: Dgame/Gravity
int main() {
    sdl::Window wnd("Gravity", sdl::Vector2i(100, 100), 640, 480);
    sdl::Renderer renderer(wnd, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

    sdl::Event event;

    Sprite quad("images/rect.png", renderer);
    Level lvl(renderer);

    sdl::Texture bg(renderer, "images/background.png");
    sdl::Rect bg_rect(0, 0, wnd.width(), wnd.height());

    Font font("font/arial.ttf", 12);
    font.setPosition(32, wnd.height() - 32);

    bool running = true;
    while (running && lvl.isValid()) {
        while (sdl::PollEvent(&event)) {
            if (event.type == SDL_QUIT)
                running = false;
            else if (event.type == SDL_KEYDOWN) {
                if (!lvl.timer.isRunning())
                    lvl.timer.start();

                switch (event.keyboard.key) {
                    case SDLK_ESCAPE:
                        running = false;
                    break;
                    case SDLK_LEFT:
                        quad.setMovement(-MOVE, 0);
                    break;
                    case SDLK_RIGHT:
                        quad.setMovement(MOVE, 0);
                    break;
                    case SDLK_UP:
                        quad.setMovement(0, -MOVE);
                    break;
                    case SDLK_DOWN:
                        quad.setMovement(0, MOVE);
                    break;
                    case SDLK_SPACE:
                        quad.stopMovement();
                    break;
                }
            }
        }

        renderer.clear(&sdl::Color::White);
        renderer.copy(bg, &bg_rect);

        if (DeadFrames == 0) {
            if (check_tile(lvl, quad))
                quad.drawOn(renderer);
        } else {
            DeadFrames--;

            renderer.setDrawColor(sdl::Color::Black);
            const sdl::Vector2i& movement = quad.getMovement();

            for (sdl::Vector2i& vec : Fragments) {
                renderer.drawPoint(vec);

                const i16_t rx = Dist(Gen);
                const i16_t ry = Dist(Gen);

                vec.x += rx + movement.x;
                vec.y += ry + movement.y;
            }

            if (DeadFrames == 0) {
                quad.stopMovement();
            }
        }

        lvl.render();

        font.format(renderer, "%d s %d ms, Deaths: %d", lvl.timer.getTicks() / 1000, lvl.timer.getTicks() % 1000, Deaths);

        renderer.present();
    }
}
コード例 #5
0
ファイル: dialog.cpp プロジェクト: huzongyao/AndroidSuperTux
void
Dialog::draw(DrawingContext& ctx)
{
  Rectf bg_rect(Vector(SCREEN_WIDTH/2 - m_text_size.width/2,
                       SCREEN_HEIGHT/2 - m_text_size.height/2),
                Sizef(m_text_size.width,
                      m_text_size.height + 44));

  // draw background rect
  ctx.draw_filled_rect(bg_rect.grown(12.0f),
                       Color(0.2f, 0.3f, 0.4f, 0.8f),
                       16.0f,
                       LAYER_GUI-10);

  ctx.draw_filled_rect(bg_rect.grown(8.0f),
                       Color(0.6f, 0.7f, 0.8f, 0.5f),
                       16.0f,
                       LAYER_GUI-10);

  // draw text
  ctx.draw_text(Resources::normal_font, m_text,
                Vector(bg_rect.p1.x + bg_rect.get_width()/2.0f,
                       bg_rect.p1.y),
                ALIGN_CENTER, LAYER_GUI);

  // draw HL line
  ctx.draw_filled_rect(Vector(bg_rect.p1.x, bg_rect.p2.y - 35),
                       Vector(bg_rect.get_width(), 4),
                       Color(0.6f, 0.7f, 1.0f, 1.0f), LAYER_GUI);
  ctx.draw_filled_rect(Vector(bg_rect.p1.x, bg_rect.p2.y - 35),
                       Vector(bg_rect.get_width(), 2),
                       Color(1.0f, 1.0f, 1.0f, 1.0f), LAYER_GUI);

  // draw buttons
  for(int i = 0; i < static_cast<int>(m_buttons.size()); ++i)
  {
    float segment_width = bg_rect.get_width() / m_buttons.size();
    float button_width = segment_width;
    float button_height = 24.0f;
    Vector pos(bg_rect.p1.x + segment_width/2.0f + i * segment_width,
               bg_rect.p2.y - 12);

    if (i == m_selected_button)
    {
      float blink = (sinf(real_time * M_PI * 1.0f)/2.0f + 0.5f) * 0.5f + 0.25f;
      ctx.draw_filled_rect(Rectf(Vector(pos.x - button_width/2, pos.y - button_height/2),
                                 Vector(pos.x + button_width/2, pos.y + button_height/2)).grown(2.0f),
                           Color(1.0f, 1.0f, 1.0f, blink),
                           14.0f,
                           LAYER_GUI-10);
      ctx.draw_filled_rect(Rectf(Vector(pos.x - button_width/2, pos.y - button_height/2),
                                 Vector(pos.x + button_width/2, pos.y + button_height/2)),
                           Color(1.0f, 1.0f, 1.0f, 0.5f),
                           12.0f,
                           LAYER_GUI-10);
    }

    ctx.draw_text(Resources::normal_font, m_buttons[i].text,
                  Vector(pos.x, pos.y - int(Resources::normal_font->get_height()/2)),
                  ALIGN_CENTER, LAYER_GUI,
                  i == m_selected_button ? ColorScheme::Menu::active_color : ColorScheme::Menu::default_color);
  }
}
コード例 #6
0
ファイル: EC_ChatBubble.cpp プロジェクト: A-K/naali
QPixmap EC_ChatBubble::GetChatBubblePixmap()
{
    if (renderer_.expired())
        return 0;

///\todo    Resize the chat bubble and font size according to the render window size and distance
///         avatar's distance from the camera.
//    const int minWidth =
//    const int minHeight =
//    Ogre::Viewport* viewport = renderer_.lock()->GetViewport();
//    const int max_width = viewport->getActualWidth()/4;
//    int max_height = viewport->getActualHeight()/10;

    // Create transparent pixmap
    QPixmap pixmap(bubble_max_rect_.size());
    pixmap.fill(Qt::transparent);

    // Gather chat log and calculate the bounding rect size.
    /*
    QStringListIterator it(messages_);
    QString fullChatLog;
    while(it.hasNext())
    {
        // Add spaces to too long words (usually just spam) so that wordwrap done later works better.
        ///\todo    Make the logic more intelligent and better. Not critical as normal words aren't
        ///         that often longer than ~20 characters.
        QString rawChatEntry = it.next();
        if (rawChatEntry.length() > 21 && !rawChatEntry.contains(' '))
        {
            int split_idx = rawChatEntry.length()/2;
            QString substr1 = rawChatEntry.mid(0, split_idx+1);
            QString substr2 = rawChatEntry.mid(split_idx, rawChatEntry.length()-substr1.length());
            fullChatLog.append(substr1);
            fullChatLog.append(" ");
            fullChatLog.append(substr2);
        }
        else
        {
            fullChatLog.append(rawChatEntry);
        }

        if (it.hasNext())
            fullChatLog.append('\n');

        // Set padding for text.
        // Make the font size temporarily bigger when calculating bounding rect
        // so we get padding without need to modify the rect itself.
        //QFont origFont = painter.font();
        //painter.setFont(QFont(origFont.family(), origFont.pointSize()+12));
    }
    */

    // Create painter
    QPainter painter(&pixmap);
    painter.setFont(font_);

    // Get padding from font metrics
    QFontMetrics metric(painter.font());
    int padding = metric.averageCharWidth();

    // Text rect
    QRect text_boundaries(padding, padding, bubble_max_rect_.width()-(2*padding), bubble_max_rect_.height()-(2*padding));
    QRect text_rect = painter.boundingRect(text_boundaries, Qt::AlignCenter | Qt::TextWordWrap, current_message_ /*fullChatLog*/);
    
    // Background rect
    int bg_left = text_rect.x() - (padding/2);
    if (bg_left < 0)
        bg_left = 0;
    int bg_top = text_rect.y() - (padding/2);
    if (bg_top < 0)
        bg_top = 0;
    int bg_width = text_rect.width() + (padding);
    if (bg_width > bubble_max_rect_.width())
        bg_width = bubble_max_rect_.width();
    int bg_height = text_rect.height() + (padding);
    if (bg_height > bubble_max_rect_.height())
        bg_height = bubble_max_rect_.height();

    QRect bg_rect(bg_left, bg_top, bg_width, bg_height); 

    // Background color
    QLinearGradient grad(bg_rect.topLeft(), bg_rect.bottomLeft());
    grad.setColorAt(0, QColor(39, 92, 206, 255));
    grad.setColorAt(1, bubbleColor_);
    QBrush brush(grad);

    // Draw rounded rect
    painter.setBrush(brush);
    painter.setPen(QColor(39, 92, 206, 255));
    painter.drawRoundedRect(bg_rect, 20.0, 20.0);

    // Draw text
    painter.setPen(textColor_);
    painter.drawText(text_rect, Qt::AlignCenter | Qt::TextWordWrap, current_message_);

    return pixmap;
}
コード例 #7
0
ファイル: art_aui.cpp プロジェクト: AaronDP/wxWidgets
void wxRibbonAUIArtProvider::DrawTool(
            wxDC& dc,
            wxWindow* WXUNUSED(wnd),
            const wxRect& rect,
            const wxBitmap& bitmap,
            wxRibbonButtonKind kind,
            long state)
{
    if(kind == wxRIBBON_BUTTON_TOGGLE)
    {
        if(state & wxRIBBON_TOOLBAR_TOOL_TOGGLED)
            state ^= wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK;
    }

    wxRect bg_rect(rect);
    bg_rect.Deflate(1);
    if((state & wxRIBBON_TOOLBAR_TOOL_LAST) == 0)
        bg_rect.width++;
    bool is_custom_bg = (state & (wxRIBBON_TOOLBAR_TOOL_HOVER_MASK |
        wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)) != 0;
    bool is_split_hybrid = kind == wxRIBBON_BUTTON_HYBRID && is_custom_bg;

    // Background
    if(is_custom_bg)
    {
        dc.SetPen(*wxTRANSPARENT_PEN);
        dc.SetBrush(m_tool_hover_background_brush);
        dc.DrawRectangle(bg_rect.x, bg_rect.y, bg_rect.width, bg_rect.height);
        if(state & wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK)
        {
            wxRect active_rect(bg_rect);
            if(kind == wxRIBBON_BUTTON_HYBRID)
            {
                active_rect.width -= 8;
                if(state & wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE)
                {
                    active_rect.x += active_rect.width;
                    active_rect.width = 8;
                }
            }
            dc.SetBrush(m_tool_active_background_brush);
            dc.DrawRectangle(active_rect.x, active_rect.y, active_rect.width,
                active_rect.height);
        }
    }

    // Border
    if(is_custom_bg)
        dc.SetPen(m_toolbar_hover_borden_pen);
    else
        dc.SetPen(m_toolbar_border_pen);
    if((state & wxRIBBON_TOOLBAR_TOOL_FIRST) == 0)
    {
        wxColour existing;
        if(!dc.GetPixel(rect.x, rect.y + 1, &existing) ||
            existing != m_toolbar_hover_borden_pen.GetColour())
        {
            dc.DrawLine(rect.x, rect.y + 1, rect.x, rect.y + rect.height - 1);
        }
    }
    if(is_custom_bg)
    {
        wxRect border_rect(bg_rect);
        border_rect.Inflate(1);
        dc.SetBrush(*wxTRANSPARENT_BRUSH);
        dc.DrawRectangle(border_rect.x, border_rect.y, border_rect.width,
            border_rect.height);
    }

    // Foreground
    int avail_width = bg_rect.GetWidth();
    if(kind & wxRIBBON_BUTTON_DROPDOWN)
    {
        avail_width -= 8;
        if(is_split_hybrid)
        {
            dc.DrawLine(rect.x + avail_width + 1, rect.y,
                rect.x + avail_width + 1, rect.y + rect.height);
        }
        dc.DrawBitmap(m_toolbar_drop_bitmap, bg_rect.x + avail_width + 2,
            bg_rect.y + (bg_rect.height / 2) - 2, true);
    }
    dc.DrawBitmap(bitmap, bg_rect.x + (avail_width - bitmap.GetWidth()) / 2,
        bg_rect.y + (bg_rect.height - bitmap.GetHeight()) / 2, true);
}
コード例 #8
0
ファイル: art_aui.cpp プロジェクト: AaronDP/wxWidgets
void wxRibbonAUIArtProvider::DrawButtonBarButton(
                        wxDC& dc,
                        wxWindow* WXUNUSED(wnd),
                        const wxRect& rect,
                        wxRibbonButtonKind kind,
                        long state,
                        const wxString& label,
                        const wxBitmap& bitmap_large,
                        const wxBitmap& bitmap_small)
{
    if(kind == wxRIBBON_BUTTON_TOGGLE)
    {
        kind = wxRIBBON_BUTTON_NORMAL;
        if(state & wxRIBBON_BUTTONBAR_BUTTON_TOGGLED)
            state ^= wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK;
    }

    if(state & (wxRIBBON_BUTTONBAR_BUTTON_HOVER_MASK
        | wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK))
    {
        dc.SetPen(m_button_bar_hover_border_pen);

        wxRect bg_rect(rect);
        bg_rect.Deflate(1);

        if(kind == wxRIBBON_BUTTON_HYBRID)
        {
            switch(state & wxRIBBON_BUTTONBAR_BUTTON_SIZE_MASK)
            {
            case wxRIBBON_BUTTONBAR_BUTTON_LARGE:
                {
                    int iYBorder = rect.y + bitmap_large.GetHeight() + 4;
                    wxRect partial_bg(rect);
                    if(state & wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED)
                    {
                        partial_bg.SetBottom(iYBorder - 1);
                    }
                    else
                    {
                        partial_bg.height -= (iYBorder - partial_bg.y + 1);
                        partial_bg.y = iYBorder + 1;
                    }
                    dc.DrawLine(rect.x, iYBorder, rect.x + rect.width, iYBorder);
                    bg_rect.Intersect(partial_bg);
                }
                break;
            case wxRIBBON_BUTTONBAR_BUTTON_MEDIUM:
                {
                    int iArrowWidth = 9;
                    if(state & wxRIBBON_BUTTONBAR_BUTTON_NORMAL_HOVERED)
                    {
                        bg_rect.width -= iArrowWidth;
                        dc.DrawLine(bg_rect.x + bg_rect.width,
                            rect.y, bg_rect.x + bg_rect.width,
                            rect.y + rect.height);
                    }
                    else
                    {
                        --iArrowWidth;
                        bg_rect.x += bg_rect.width - iArrowWidth;
                        bg_rect.width = iArrowWidth;
                        dc.DrawLine(bg_rect.x - 1, rect.y,
                            bg_rect.x - 1, rect.y + rect.height);
                    }
                }
                break;
            case wxRIBBON_BUTTONBAR_BUTTON_SMALL:
                break;
            }
        }

        dc.SetBrush(*wxTRANSPARENT_BRUSH);
        dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);

        dc.SetPen(*wxTRANSPARENT_PEN);
        if(state & wxRIBBON_BUTTONBAR_BUTTON_ACTIVE_MASK)
            dc.SetBrush(m_button_bar_active_background_brush);
        else
            dc.SetBrush(m_button_bar_hover_background_brush);
        dc.DrawRectangle(bg_rect.x, bg_rect.y, bg_rect.width, bg_rect.height);
    }

    dc.SetFont(m_button_bar_label_font);
    dc.SetTextForeground(state & wxRIBBON_BUTTONBAR_BUTTON_DISABLED
                            ? m_button_bar_label_disabled_colour
                            : m_button_bar_label_colour);
    DrawButtonBarButtonForeground(dc, rect, kind, state, label, bitmap_large,
        bitmap_small);
}
コード例 #9
0
ファイル: dialog.cpp プロジェクト: HybridDog/supertux
void
Dialog::draw(DrawingContext& context)
{
  Rectf bg_rect(Vector(static_cast<float>(m_passive ?
                                          (static_cast<float>(context.get_width()) - m_text_size.width - 20.0f) :
                                          static_cast<float>(context.get_width()) / 2.0f - m_text_size.width / 2.0f),
                       static_cast<float>(m_passive ?
                                          (static_cast<float>(context.get_height()) - m_text_size.height - 65.0f) :
                                          (static_cast<float>(context.get_height()) / 2.0f - m_text_size.height / 2.0f))),
                Sizef(m_text_size.width,
                      m_text_size.height + 44));

  // draw background rect
  context.color().draw_filled_rect(bg_rect.grown(12.0f),
                                     Color(0.2f, 0.3f, 0.4f, m_passive ? 0.3f : 0.8f),
                                     16.0f,
                                     LAYER_GUI-10);

  context.color().draw_filled_rect(bg_rect.grown(8.0f),
                                     Color(0.6f, 0.7f, 0.8f, m_passive ? 0.2f : 0.5f),
                                     16.0f,
                                     LAYER_GUI-10);

  // draw text
  context.color().draw_text(Resources::normal_font, m_text,
                              Vector(bg_rect.get_left() + bg_rect.get_width()/2.0f,
                                     bg_rect.get_top()),
                              ALIGN_CENTER, LAYER_GUI);
  if (m_passive)
    return;

  // draw HL line
  context.color().draw_filled_rect(Rectf(Vector(bg_rect.get_left(), bg_rect.get_bottom() - 35),
                                         Sizef(bg_rect.get_width(), 4)),
                                   Color(0.6f, 0.7f, 1.0f, 1.0f), LAYER_GUI);
  context.color().draw_filled_rect(Rectf(Vector(bg_rect.get_left(), bg_rect.get_bottom() - 35),
                                         Sizef(bg_rect.get_width(), 2)),
                                   Color(1.0f, 1.0f, 1.0f, 1.0f), LAYER_GUI);

  // draw buttons
  for (int i = 0; i < static_cast<int>(m_buttons.size()); ++i)
  {
    float segment_width = bg_rect.get_width() / static_cast<float>(m_buttons.size());
    float button_width = segment_width;
    Vector pos(bg_rect.get_left() + segment_width/2.0f + static_cast<float>(i) * segment_width,
               bg_rect.get_bottom() - 12);

    if (i == m_selected_button)
    {
      float button_height = 24.0f;
      float blink = (sinf(g_real_time * math::PI * 1.0f)/2.0f + 0.5f) * 0.5f + 0.25f;
      context.color().draw_filled_rect(Rectf(Vector(pos.x - button_width/2, pos.y - button_height/2),
                                               Vector(pos.x + button_width/2, pos.y + button_height/2)).grown(2.0f),
                                         Color(1.0f, 1.0f, 1.0f, blink),
                                         14.0f,
                                         LAYER_GUI-10);
      context.color().draw_filled_rect(Rectf(Vector(pos.x - button_width/2, pos.y - button_height/2),
                                               Vector(pos.x + button_width/2, pos.y + button_height/2)),
                                         Color(1.0f, 1.0f, 1.0f, 0.5f),
                                         12.0f,
                                         LAYER_GUI-10);
    }

    context.color().draw_text(Resources::normal_font, m_buttons[i].text,
                              Vector(pos.x, pos.y - static_cast<float>(int(Resources::normal_font->get_height() / 2))),
                              ALIGN_CENTER, LAYER_GUI,
                              i == m_selected_button ? ColorScheme::Menu::active_color : ColorScheme::Menu::default_color);
  }
}