Ejemplo n.º 1
0
void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
{
  wxFont small_font(6, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
  const wxColour font_color{0xB8B8B8};

  g_controller_interface.UpdateInput();

  GamepadPage* const current_page =
      static_cast<GamepadPage*>(m_pad_notebook->GetPage(m_pad_notebook->GetSelection()));

  wxMemoryDC dc;
  auto lock = ControllerEmu::GetStateLock();
  for (ControlGroupBox* g : current_page->control_groups)
  {
    // Only if this control group has a bitmap
    if (!g->static_bitmap)
      continue;

    wxBitmap bitmap(g->static_bitmap->GetBitmap());
    // NOTE: Selecting the bitmap inherits the bitmap's ScaleFactor onto the DC as well.
    dc.SelectObjectAsSource(bitmap);
    dc.SetBackground(*wxWHITE_BRUSH);
    dc.Clear();

#ifdef __WXGTK20__
    int dc_height = 0;
    dc.SetFont(small_font);
    dc.GetTextExtent(g->control_group->name, nullptr, &dc_height);
#endif

    std::unique_ptr<wxGraphicsContext> gc{wxGraphicsContext::Create(dc)};
    gc->DisableOffset();
    gc->SetFont(small_font, font_color);

#ifdef __WXGTK20__
    double gc_height = 0;
    gc->GetTextExtent(g->control_group->name, nullptr, &gc_height);
    // On GTK2, wx creates a new empty Cairo/Pango context for the graphics context instead
    // of reusing the wxMemoryDC one, this causes it to forget the screen DPI so fonts stop
    // scaling, we need to scale it manually instead.
    if (std::ceil(gc_height) < dc_height)
    {
      wxFont fixed_font(small_font);
      fixed_font.SetPointSize(static_cast<int>(fixed_font.GetPointSize() * g->m_scale));
      gc->SetFont(fixed_font, font_color);
    }
#endif

    DrawControlGroupBox(gc.get(), g);
    DrawBorder(gc.get(), g->m_scale);

    // label for sticks and stuff
    if (g->HasBitmapHeading())
      gc->DrawText(StrToWxStr(g->control_group->name).Upper(), 4 * g->m_scale, 2 * g->m_scale);

    gc.reset();
    dc.SelectObject(wxNullBitmap);
    g->static_bitmap->SetBitmap(bitmap);
  }
}
Ejemplo n.º 2
0
void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
{
    wxFont small_font(6, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);

    g_controller_interface.UpdateInput();

    // don't want game thread updating input when we are using it here
    std::unique_lock<std::recursive_mutex> lk(g_controller_interface.update_lock, std::try_to_lock);
    if (!lk.owns_lock())
        return;

    GamepadPage* const current_page = (GamepadPage*)m_pad_notebook->GetPage(m_pad_notebook->GetSelection());

    for (ControlGroupBox* g : current_page->control_groups)
    {
        // if this control group has a bitmap
        if (g->static_bitmap)
        {
            wxMemoryDC dc;
            wxBitmap bitmap(g->static_bitmap->GetBitmap());
            dc.SelectObject(bitmap);
            dc.Clear();

            dc.SetFont(small_font);
            dc.SetTextForeground(0xC0C0C0);

            // label for sticks and stuff
            if (64 == bitmap.GetHeight())
                dc.DrawText(StrToWxStr(g->control_group->name).Upper(), 4, 2);

            DrawControlGroupBox(dc, g);

            // box outline
            // Windows XP color
            dc.SetPen(wxPen("#7f9db9"));
            dc.SetBrush(*wxTRANSPARENT_BRUSH);
            dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());

            dc.SelectObject(wxNullBitmap);
            g->static_bitmap->SetBitmap(bitmap);
        }
    }
}