示例#1
0
void ImageResource::RenderPreview(wxPaintDC & dc, wxPanel & previewPanel, gd::Project & project)
{
    wxLogNull noLog; //We take care of errors.

    wxSize size = previewPanel.GetSize();

    //Checkerboard background
    dc.SetBrush(gd::CommonBitmapProvider::Get()->transparentBg);
    dc.DrawRectangle(0,0, size.GetWidth(), size.GetHeight());

    wxString fullFilename = GetAbsoluteFile(project);

    if ( !wxFile::Exists(fullFilename) )
        return;

    wxBitmap bmp( fullFilename, wxBITMAP_TYPE_ANY);
    if ( bmp.GetWidth() != 0 && bmp.GetHeight() != 0 && (bmp.GetWidth() > previewPanel.GetSize().x || bmp.GetHeight() > previewPanel.GetSize().y) )
    {
        //Rescale to fit in previewPanel
        float xFactor = static_cast<float>(previewPanel.GetSize().x)/static_cast<float>(bmp.GetWidth());
        float yFactor = static_cast<float>(previewPanel.GetSize().y)/static_cast<float>(bmp.GetHeight());
        float factor = std::min(xFactor, yFactor);

        wxImage image = bmp.ConvertToImage();
        if ( bmp.GetWidth()*factor >= 5 && bmp.GetHeight()*factor >= 5)
            bmp = wxBitmap(image.Scale(bmp.GetWidth()*factor, bmp.GetHeight()*factor));
    }

    //Display image in the center
    if ( bmp.IsOk() )
        dc.DrawBitmap(bmp,
                      (size.GetWidth() - bmp.GetWidth()) / 2,
                      (size.GetHeight() - bmp.GetHeight()) / 2,
                      true /* use mask */);
}
示例#2
0
    ExampleFrame(
      wxApp& app,
      wxWindow* parent,
      const wxString& title,
      ExampleInfoDisplay* info_disp,
      wxGLContext* context)
      : wxFrame(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize)
      , info_display(info_disp)
      , main_panel(
          new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize))
      , gl_canvas(
          new ExampleGLCanvas((wxEvtHandler*)this, (wxWindow*)main_panel))
      , gl_context(context)
      , frame_no(0)
      , fps_frame_no(0)
      , fps_time(0.0)
      , prim_count(0.0)
      , idle_call_count(0) {
        assert(info_display);
        assert(gl_canvas);
        assert(gl_context);

        wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL);
        main_panel->SetClientSize(800, 600);
        main_sizer->Add(main_panel, 1, wxEXPAND);

        wxStatusBar* status_bar = new wxStatusBar(this);
        main_sizer->Add(status_bar, 0, wxEXPAND);

        wxBoxSizer* gl_sizer = new wxBoxSizer(wxVERTICAL);
        gl_sizer->Add(gl_canvas, 1, wxEXPAND);
        main_panel->SetSizer(gl_sizer);

        SetSize(
          main_panel->GetSize().GetWidth(),
          main_panel->GetSize().GetHeight() +
            status_bar->GetSize().GetHeight());
        SetSizer(main_sizer);
        Layout();
        Show();

        gl_context->SetCurrent(*gl_canvas);

        // TODO: this won't work very well in "UNICODE" builds
        oglplus::ExampleParams params(app.argc, (char**)app.argv);
        example = oglplus::makeExample(params);
        os_clock.reset();

        HandleResize();

        Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(ExampleFrame::OnClose));
        Connect(wxEVT_MOTION, wxMouseEventHandler(ExampleFrame::OnMouseEvent));
        Connect(wxEVT_SIZE, wxSizeEventHandler(ExampleFrame::OnResize));
        SetExtraStyle(wxWS_EX_PROCESS_IDLE);
        wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
        Connect(wxEVT_IDLE, wxIdleEventHandler(ExampleFrame::OnIdle));
    }