BitmapPtr BmpTextureMover::moveTextureToBmp(GLTexture& tex, int mipmapLevel)
{
    GLContext* pContext = GLContext::getCurrent();
    unsigned fbo = pContext->genFBO();
    glproc::BindFramebuffer(GL_FRAMEBUFFER, fbo);
    glproc::FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
                                 tex.getID(), mipmapLevel);
    FBO::checkError("BmpTextureMover::moveTextureToBmp");
    IntPoint size = tex.getMipmapSize(mipmapLevel);
    BitmapPtr pBmp(new Bitmap(size, getPF()));
    if (GLContext::getMain()->isGLES() && getPF() == B5G6R5) {
        BitmapPtr pTmpBmp(new Bitmap(size, R8G8B8));
        glReadPixels(0, 0, size.x, size.y, GL_RGB, GL_UNSIGNED_BYTE, pTmpBmp->getPixels());
        FilterFlipRGB().applyInPlace(pTmpBmp);
        pBmp->copyPixels(*pTmpBmp);
    } else {
        int glPixelFormat = tex.getGLFormat(getPF());
        glReadPixels(0, 0, size.x, size.y, glPixelFormat, tex.getGLType(getPF()),
                     pBmp->getPixels());
    }
    GLContext::checkError("BmpTextureMover::moveTextureToBmp: glReadPixels()");
    glproc::FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
                                 0, 0);
    pContext->returnFBOToCache(fbo);
    glproc::BindFramebuffer(GL_FRAMEBUFFER, 0);
    return pBmp;

}
Beispiel #2
0
void StandardShader::generateWhiteTexture()
{
    BitmapPtr pBmp(new Bitmap(glm::vec2(1,1), I8));
    *(pBmp->getPixels()) = 255;
    m_pWhiteTex = GLTexturePtr(new GLTexture(IntPoint(1,1), I8));
    m_pWhiteTex->moveBmpToTexture(pBmp);
}
Beispiel #3
0
BitmapPtr SVG::internalRenderElement(const SVGElementPtr& pElement, 
        const glm::vec2& renderSize, const glm::vec2& size)
{
    glm::vec2 pos = pElement->getPos();
    glm::vec2 scale(renderSize.x/size.x, renderSize.y/size.y);
    IntPoint boundingBox = IntPoint(renderSize) + 
            IntPoint(int(scale.x+0.5), int(scale.y+0.5));
    BitmapPtr pBmp(new Bitmap(boundingBox, B8G8R8A8));
    FilterFill<Pixel32>(Pixel32(0,0,0,0)).applyInPlace(pBmp);

    cairo_surface_t* pSurface;
    cairo_t* pCairo;
    pSurface = cairo_image_surface_create_for_data(pBmp->getPixels(), 
            CAIRO_FORMAT_ARGB32, boundingBox.x, boundingBox.y, 
            pBmp->getStride());
    pCairo = cairo_create(pSurface);
    cairo_scale(pCairo, scale.x, scale.y);
    cairo_translate(pCairo, -pos.x, -pos.y);
    rsvg_handle_render_cairo_sub(m_pRSVG, pCairo, pElement->getUnescapedID().c_str()); 

    FilterUnmultiplyAlpha().applyInPlace(pBmp);

    cairo_surface_destroy(pSurface);
    cairo_destroy(pCairo);
   
    if (!BitmapLoader::get()->isBlueFirst()) {
        FilterFlipRGB().applyInPlace(pBmp);
    }

    return pBmp;
}
Beispiel #4
0
BitmapPtr BitmapLoader::load(const UTF8String& sFName, PixelFormat pf) const
{
    AVG_ASSERT(s_pBitmapLoader != 0);
    GError* pError = 0;
    GdkPixbuf* pPixBuf;
    {
        ScopeTimer timer(GDKPixbufProfilingZone);
        pPixBuf = gdk_pixbuf_new_from_file(sFName.c_str(), &pError);
    }
    if (!pPixBuf) {
        string sErr = pError->message;
        g_error_free(pError);
        throw Exception(AVG_ERR_FILEIO, sErr);
    }
    IntPoint size = IntPoint(gdk_pixbuf_get_width(pPixBuf), 
            gdk_pixbuf_get_height(pPixBuf));
    
    PixelFormat srcPF;
    if (gdk_pixbuf_get_has_alpha(pPixBuf)) {
        srcPF = R8G8B8A8;
    } else {
        srcPF = R8G8B8;
    }
    if (pf == NO_PIXELFORMAT) {
        if (m_bBlueFirst) {
            if (srcPF == R8G8B8A8) {
                pf = B8G8R8A8;
            } else if (srcPF == R8G8B8) {
                pf = B8G8R8X8;
            }
        } else {
            if (srcPF == R8G8B8A8) {
                pf = R8G8B8A8;
            } else if (srcPF == R8G8B8) {
                pf = R8G8B8X8;
            }
        }
    }
    BitmapPtr pBmp(new Bitmap(size, pf, sFName));
    {
        ScopeTimer timer(ConvertProfilingZone);

        int stride = gdk_pixbuf_get_rowstride(pPixBuf);
        guchar* pSrc = gdk_pixbuf_get_pixels(pPixBuf);
        BitmapPtr pSrcBmp(new Bitmap(size, srcPF, pSrc, stride, false));
        {
            ScopeTimer timer(RGBFlipProfilingZone);
            if (pixelFormatIsBlueFirst(pf) != pixelFormatIsBlueFirst(srcPF)) {
                FilterFlipRGB().applyInPlace(pSrcBmp);
            }
        }
        pBmp->copyPixels(*pSrcBmp);
    }
    g_object_unref(pPixBuf);
    return pBmp;
}
////
// Initialization Routine
////
bool CGameLauncher::setupMenu()
{
    m_mustquit      = false;
    mDonePatchSelection = false;
    m_chosenGame    = -1;
    m_ep1slot       = -1;
    mLauncherDialog.initEmptyBackground();
    mSelection      = -1;

    bool gamesDetected = false;

    // TODO: Put that scanning into a separate so we can show a loading menu
    // Scan for games...
    m_DirList.clear();
    m_Entries.clear();

    gLogging.ftextOut("Game Autodetection Started<br>" );

    // Process any custom labels
    getLabels();

    // Scan VFS DIR_ROOT for exe's
    gamesDetected |= scanExecutables(DIR_ROOT);
    mGameScanner.setPermilage(100);

    // Recursivly scan into DIR_GAMES subdir's for exe's
    gamesDetected |= scanSubDirectories(DIR_GAMES, DEPTH_MAX_GAMES, 200, 900);

    mpSelList = new CGUITextSelectionList();

    // Save any custom labels
    putLabels();

    // Create an empty Bitmap control
    mLauncherDialog.addControl( new CGUIBitmap(),
                                GsRect<float>(0.51f, 0.07f, 0.48f, 0.48f) );

    mCurrentBmp = std::dynamic_pointer_cast< CGUIBitmap >
                  ( mLauncherDialog.getControlList().back() );

    mpPrevievBmpVec.resize(m_Entries.size());

	std::vector<GameEntry>::iterator it = m_Entries.begin();
    unsigned int i=0;
    for( ; it != m_Entries.end() ; it++	)
    {
    	mpSelList->addText(it->name);

        // And try to add a preview bitmap
        std::string fullfilename = "preview.bmp";
        fullfilename = getResourceFilename(fullfilename, it->path, false);
        fullfilename = GetFullFileName(fullfilename);

        if(IsFileAvailable(fullfilename))
        {
            SDL_Surface *pPrimBmp = SDL_LoadBMP(GetFullFileName(fullfilename).c_str());
            std::shared_ptr<SDL_Surface> bmpSfcPtr( pPrimBmp );
            std::shared_ptr<GsBitmap> pBmp(new GsBitmap(bmpSfcPtr));
            mpPrevievBmpVec[i] = pBmp;
        }
        i++;
    }

    mpSelList->setConfirmButtonEvent(new GMStart());
    mpSelList->setBackButtonEvent(new GMQuit());

    mLauncherDialog.addControl(new CGUIText("Pick a Game"), GsRect<float>(0.0f, 0.0f, 1.0f, 0.05f));
    mLauncherDialog.addControl(new GsButton( "x", new GMQuit() ), GsRect<float>(0.0f, 0.0f, 0.07f, 0.07f) );
    mLauncherDialog.addControl(mpSelList, GsRect<float>(0.01f, 0.07f, 0.49f, 0.79f));


    mLauncherDialog.addControl(new GsButton( "Start >", new GMStart() ), GsRect<float>(0.65f, 0.865f, 0.3f, 0.07f) );

#ifdef DBFUSION

    GsButton *fusionShellBtn = new GsButton( "DosFusion Shell >", new GMDBFusionStart() );
    GsButton *fusionBtn = new GsButton( "DosFusion! >", new GMDosGameFusionStart() );

    if(disallowDBFusion)
    {
        fusionShellBtn->enable(false);
        fusionBtn->enable(false);
    }

    mLauncherDialog.addControl( fusionShellBtn, GsRect<float>(0.01f, 0.865f, 0.3f, 0.07f) );
    mLauncherDialog.addControl( fusionBtn, GsRect<float>(0.35f, 0.865f, 0.3f, 0.07f) );
#endif



#ifdef DOWNLOADER
    GsButton *downloadBtn = new GsButton( "New Stuff", new GMDownloadDlgOpen() );
    mLauncherDialog.addControl( downloadBtn, GsRect<float>(0.35f, 0.865f, 0.3f, 0.07f) );
#endif

    mpEpisodeText = new CGUIText("Game");
    mpVersionText = new CGUIText("Version");
    mLauncherDialog.addControl(mpEpisodeText, GsRect<float>(0.5f, 0.75f, 0.5f, 0.05f));
    mLauncherDialog.addControl(mpVersionText, GsRect<float>(0.5f, 0.80f, 0.5f, 0.05f));

    // This way it goes right to the selection list.
    mLauncherDialog.setSelection(2);

    mGameScanner.setPermilage(1000);

    gLogging.ftextOut("Game Autodetection Finished<br>" );
    // Banner. TODO: Create a class for that...
    CGUIBanner *banner = new CGUIBanner("Commander Genius " CGVERSION "\n"
                    "By Gerstrong,\n"
                    "Hagel,\n"
                    "Tulip,\n"
                    "NY00123,\n"
                    "Pelya,\n"
					"and the CG Contributors\n");
    mLauncherDialog.addControl( banner, GsRect<float>(0.0f, 0.95f, 1.0f, 0.05f) );

    if(!gamesDetected)
        return false;

    const std::string gameDir = gArgs.getValue("dir");
    if(!gameDir.empty())
    {
        int chosenGame = 0;
        bool found=false;

        // Check if the given parameter makes one game start.
        for( GameEntry &entry : m_Entries)
        {
            if(entry.path == gameDir)
            {
                // found!
                m_chosenGame = chosenGame;
                gLogging.textOut("Launching game from directory: \"" + gameDir + "\"\n");
                gArgs.removeTag("dir");

                setupModsDialog();
                // Nothing else to do, break the loop
                found = true;
                break;
            }
            chosenGame++;
        }

        if(!found)
        {
            const std::string err = "The game from directory: \"" + gameDir + "\" cannot the launched." +
                    "Maybe it's missing or not compatible. Please check if you can run that through the game launcher.\n";

            gLogging.textOut(err);

            showMessageBox("Given path :\"" + gameDir + "\" unknown.\nPlease check the CGLog File!");
        }
    }

    return true;
}
LRESULT AeroControlBase::StaticWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_SETTEXT:
    case WM_ENABLE:
    case WM_STYLECHANGED:
        {
            LRESULT res = DefSubclassProc(hWnd, uMsg, wParam, lParam);
            InvalidateRgn(hWnd, NULL, FALSE);
            return res;
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);

            if(hdc)
            {
                HDC hdcPaint = NULL;
                RECT rcClient;
                VERIFY(GetClientRect(hWnd, &rcClient));

                LONG_PTR dwStyle = GetWindowLongPtr(hWnd, GWL_STYLE);
                LONG_PTR dwStyleEx = GetWindowLongPtr(hWnd, GWL_EXSTYLE);

                HTHEME hTheme = OpenThemeData(NULL, L"ControlPanelStyle");
                if(hTheme)
                {
                    HPAINTBUFFER hBufferedPaint = NULL;
                    if (dwStyleEx & WS_EX_TRANSPARENT)
                    {
                        BP_PAINTPARAMS paintParams = {0};
                        paintParams.cbSize = sizeof(paintParams);
                        paintParams.dwFlags = BPPF_ERASE;
                        BLENDFUNCTION blendf = {0};
                        blendf.BlendOp = AC_SRC_OVER;
                        blendf.AlphaFormat = AC_SRC_ALPHA;
                        blendf.SourceConstantAlpha = 255;
                        paintParams.pBlendFunction = &blendf;
                        hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, &paintParams, &hdcPaint);
                    }
                    else
                        hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, NULL, &hdcPaint);

                    if (hdcPaint)
                    {
                        VERIFY(PatBlt(hdcPaint, 0, 0, RECTWIDTH(rcClient), RECTHEIGHT(rcClient), BLACKNESS));
                        VERIFY(S_OK==BufferedPaintSetAlpha(hBufferedPaint, &ps.rcPaint, 0x00));
                        LONG_PTR dwStaticStyle = dwStyle&0x1F;


                        if(dwStaticStyle==SS_ICON || dwStaticStyle==SS_BITMAP)
                        {
                            bool bIcon = dwStaticStyle==SS_ICON;
                            HANDLE hBmpIco = (HANDLE)SendMessage(hWnd, STM_GETIMAGE, bIcon ? IMAGE_ICON:IMAGE_BITMAP, NULL);
                            if(hBmpIco)
                            {
                                std::unique_ptr<Bitmap> pBmp( bIcon ? new Bitmap((HICON)hBmpIco) : new Bitmap((HBITMAP)hBmpIco, NULL) );
                                std::unique_ptr<Graphics> myGraphics( new Graphics(hdcPaint) );
                                std::unique_ptr<CachedBitmap> pcbmp( new CachedBitmap(pBmp.get(), myGraphics.get()) );
                                VERIFY(Ok==myGraphics->DrawCachedBitmap(pcbmp.get(), 0,0));
                            }
                        }
                        else if(SS_BLACKRECT==dwStaticStyle || SS_GRAYRECT==dwStaticStyle || SS_WHITERECT==dwStaticStyle)
                        {
                            ARGB argb = 0L;
                            switch (dwStaticStyle)
                            {
                            case SS_BLACKRECT:
                                argb = 0xFF000000;
                                break;
                            case SS_GRAYRECT:
                                argb = 0xFF808080;
                                break;
                            case SS_WHITERECT:
                                argb = 0xFFFFFFFF;
                                break;
                            default:
                                ASSERT(0);
                                break;
                            }
                            Color clr(argb);

                            FillRect(&rcClient, hdcPaint, clr);
                        }
                        else if(SS_BLACKFRAME==dwStaticStyle || SS_GRAYFRAME==dwStaticStyle || SS_WHITEFRAME==dwStaticStyle)
                        {
                            ARGB argb = 0L;
                            switch (dwStaticStyle)
                            {
                            case SS_BLACKFRAME:
                                argb = 0xFF000000;
                                break;
                            case SS_GRAYFRAME:
                                argb = 0xFF808080;
                                break;
                            case SS_WHITEFRAME:
                                argb = 0xFFFFFFFF;
                                break;
                            }
                            Color clr(argb);

                            DrawRect(&rcClient, hdcPaint, DashStyleSolid, clr, 1.0);
                        }
                        else
                        {
                            DTTOPTS DttOpts = {sizeof(DTTOPTS)};
                            DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                            DttOpts.crText   = RGB(255, 255, 255);
                            DttOpts.iGlowSize = 12; // Default value

                            VERIFY(DetermineGlowSize(&DttOpts.iGlowSize));

                            HFONT hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                            if(hFontOld)
                                hFontOld = (HFONT) SelectObject(hdcPaint, hFontOld);
                            int iLen = GetWindowTextLength(hWnd);

                            if(iLen)
                            {
                                iLen+=5; // 1 for terminating zero, 4 for DT_MODIFYSTRING
                                LPWSTR szText = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*iLen);
                                if(szText)
                                {
                                    iLen = GetWindowTextW(hWnd, szText, iLen);
                                    if(iLen)
                                    {
                                        DWORD dwFlags = DT_WORDBREAK;

                                        switch (dwStaticStyle)
                                        {
                                        case SS_CENTER:
                                            dwFlags |= DT_CENTER;
                                            break;
                                        case SS_RIGHT:
                                            dwFlags |= DT_RIGHT;
                                            break;
                                        case SS_LEFTNOWORDWRAP:
                                            dwFlags &= ~DT_WORDBREAK;
                                            break;
                                        }

                                        if(dwStyle & SS_CENTERIMAGE)
                                        {
                                            dwFlags |= DT_VCENTER;
                                            dwFlags &= ~DT_WORDBREAK;
                                        }

                                        if(dwStyle & SS_ENDELLIPSIS)
                                            dwFlags |= DT_END_ELLIPSIS|DT_MODIFYSTRING;
                                        else if(dwStyle & SS_PATHELLIPSIS)
                                            dwFlags |= DT_PATH_ELLIPSIS|DT_MODIFYSTRING;
                                        else if(dwStyle & SS_WORDELLIPSIS)
                                            dwFlags |= DT_WORD_ELLIPSIS|DT_MODIFYSTRING;

                                        if (dwStyleEx&WS_EX_RIGHT)
                                            dwFlags |= DT_RIGHT;

                                        if(dwStyle & SS_NOPREFIX)
                                            dwFlags |= DT_NOPREFIX;

                                        VERIFY(S_OK==DrawThemeTextEx(hTheme, hdcPaint, 0, 0,
                                            szText, -1, dwFlags, &rcClient, &DttOpts));

                                        if(dwStyle&SS_SUNKEN || dwStyle&WS_BORDER)
                                            DrawRect(&rcClient, hdcPaint, DashStyleSolid, Color(0xFF, 0,0,0), 1.0);
                                    }
                                    VERIFY(!LocalFree(szText));
                                }
                            }

                            if (hFontOld)
                            {
                                SelectObject(hdcPaint, hFontOld);
                                hFontOld    = NULL;
                            }
                        }

                        VERIFY(S_OK==EndBufferedPaint(hBufferedPaint, TRUE));
                    }

                    VERIFY(S_OK==CloseThemeData(hTheme));
                }
            }

            EndPaint(hWnd, &ps);
            return 0;
        }
        break;
    case WM_NCDESTROY:
    case WM_DESTROY:
        RemoveWindowSubclass(hWnd, SubclassProc, Static);
        subclassedControls.erase(hWnd);
        break;
    }

    return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}