Beispiel #1
0
void Label::SetImage(LPCTSTR imageFile)
{
    if (mImage)
    {
        // Free existing image, if there is one
        DeleteBitmap(mImage);
        mImage = NULL;
    }
    
    // Load the new image
    mImage = LoadLSImage(imageFile, NULL);
    
    // Force a repaint
    Repaint();
}
Beispiel #2
0
void Label::ReadConfig()
{
    // Background and Borders
    TCHAR backgroundImageFile[MAX_PATH];
    
    mBackgroundColor = GetRCColor(mName, "BackgroundColor", RGB(255, 255, 255));
    GetRCString(mName, "BackgroundImage", backgroundImageFile, NULL, MAX_PATH);
    mBackgroundImage = LoadLSImage(backgroundImageFile, NULL);
    mBackgroundImageBorderTop = GetRCInt(mName, "BackgroundImageBorderTop", 0);
    mBackgroundImageBorderRight = GetRCInt(mName, "BackgroundImageBorderRight", 0);
    mBackgroundImageBorderBottom = GetRCInt(mName, "BackgroundImageBorderBottom", 0);
    mBackgroundImageBorderLeft = GetRCInt(mName, "BackgroundImageBorderLeft", 0);
    mBackgroundImageTile = GetRCEnum(mName, "BackgroundImageTile", gBackgroundImageTileEnum);
    mBorderColorTop = GetRCColor(mName, "BorderColorTop", RGB(0, 0, 0));
    mBorderColorRight = GetRCColor(mName, "BorderColorRight", RGB(0, 0, 0));
    mBorderColorBottom = GetRCColor(mName, "BorderColorBottom", RGB(0, 0, 0));
    mBorderColorLeft = GetRCColor(mName, "BorderColorLeft", RGB(0, 0, 0));
    mBorderTop = GetRCInt(mName, "BorderTop", 0);
    mBorderRight = GetRCInt(mName, "BorderRight", 0);
    mBorderBottom = GetRCInt(mName, "BorderBottom", 0);
    mBorderLeft = GetRCInt(mName, "BorderLeft", 0);
    
    // Font
    TCHAR fontName[LF_FACESIZE];
    int fontHeight;
    bool fontBold;
    bool fontItalic;
    bool fontUnderline;
    
    GetRCString(mName, "Font", fontName, "Arial", LF_FACESIZE);
    fontHeight = GetRCInt(mName, "FontHeight", 15);
    fontBold = GetRCBoolDef(mName, "FontBold", FALSE);
    fontItalic = GetRCBoolDef(mName, "FontItalic", FALSE);
    fontUnderline = GetRCBoolDef(mName, "FontUnderline", FALSE);
    mFont = CreateSimpleFont(fontName, fontHeight, fontBold, fontItalic, fontUnderline);
    mFontColor = GetRCColor(mName, "FontColor", RGB(0, 0, 0));
    mFontShadow = GetRCBoolDef(mName, "FontShadow", FALSE);
    mFontShadowColor = GetRCColor(mName, "FontShadowColor", RGB(128, 128, 128));
    mFontShadowOffsetX = GetRCInt(mName, "FontShadowOffsetX", 1);
    mFontShadowOffsetY = GetRCInt(mName, "FontShadowOffsetY", 1);
    
    // Layout
    mAlign = GetRCEnum(mName, "Align", gAlignEnum);
    mImagePosition = GetRCEnum(mName, "ImagePosition", gImagePositionEnum);
    mImageTextGap = GetRCInt(mName, "ImageTextGap", 4);
    mPaddingLeft = GetRCInt(mName, "PaddingLeft", 0);
    mPaddingTop = GetRCInt(mName, "PaddingTop", 0);
    mPaddingRight = GetRCInt(mName, "PaddingRight", 0);
    mPaddingBottom = GetRCInt(mName, "PaddingBottom", 0);
    mVerticalAlign = GetRCEnum(mName, "VerticalAlign", gVerticalAlignEnum);
    
    // Content
    TCHAR imageFile[MAX_PATH];
    
    GetRCString(mName, "Image", imageFile, NULL, MAX_PATH);
    mImage = LoadLSImage(imageFile, NULL);
    GetRCString(mName, "Text", mText, NULL, MAX_TEXT);
    
    // Position and Size
    mAlwaysOnTop = GetRCBoolDef(mName, "AlwaysOnTop", FALSE);
    mVisible = !GetRCBoolDef(mName, "StartHidden", FALSE);
    mX = GetRCInt(mName, "X", 0);
    mY = GetRCInt(mName, "Y", 0);
    mWidth = GetRCInt(mName, "Width", 64);
    mHeight = GetRCInt(mName, "Height", 64);
}
Beispiel #3
0
//
// HBITMAP LoadLSImage(LPCSTR pszImage, LPCSTR pszFile)
//
// Takes strings of the form:
//   File.bmp
//   .extract
//   .extract=file.exe[,3]
HBITMAP LoadLSImage(LPCSTR pszImage, LPCSTR pszFile)
{
    HBITMAP hbmReturn = NULL;
    
    if (pszImage != NULL)
    {
        if (_stricmp(pszImage, ".none") != 0)
        {
            char szImage[MAX_PATH];
            StringCchCopy(szImage, MAX_PATH, pszImage);
            
            // Bitmap merging by Thedd
            //  Thedd - pic1.bmp|pic2.bmp merges the images. Works recursively,
            //  so pic1.bmp|.extract=whatever.dll,3|pic2.bmp also works etc...
            // bitmap merging by grd
            LPSTR pszSecondImage = strchr(szImage, '|');
            if (pszSecondImage)
            {
                HDC hdcFirst, hdcSecond, hdcResult;
                HBITMAP hbmFirst, hbmFirstOld;
                HBITMAP hbmSecond, hbmSecondOld;
                HBITMAP    hbmResult, hbmResultOld;
                HBRUSH hbrTransparent;
                RECT rc;
                int wdtFirst, hgtFirst;
                int wdtSecond, hgtSecond;
                int wdtResult, hgtResult;
                
                // get the position after the [|] character
                *pszSecondImage = '\0';
                ++pszSecondImage;
                
                // load the two bitmaps
                hbmFirst = LoadLSImage(szImage, pszFile);
                hbmSecond = LoadLSImage(pszSecondImage, pszFile);
                
                // if the second one is NULL, then there's no merging to do and
                if (hbmSecond != NULL)
                {
                    // create mem dcs for the bitmaps
                    hdcFirst = CreateCompatibleDC(NULL);
                    hdcSecond = CreateCompatibleDC(NULL);
                    
                    // select the bitmaps
                    hbmFirstOld = (HBITMAP)SelectObject(hdcFirst, hbmFirst);
                    hbmSecondOld = (HBITMAP)SelectObject(hdcSecond, hbmSecond);
                    
                    // get the bitmap sizes..
                    GetLSBitmapSize(hbmFirst, &wdtFirst, &hgtFirst);
                    GetLSBitmapSize(hbmSecond, &wdtSecond, &hgtSecond);
                    
                    // in earlier version of bitmap merge, those were painted on
                    // to each other now let's paint both images to a new one
                    
                    // and we support different sized images!! therefore:
                    wdtResult = std::max(wdtFirst, wdtSecond);
                    hgtResult = std::max(hgtFirst, hgtSecond);
                    
                    // create another dc, compatible with second dc
                    hdcResult = CreateCompatibleDC(hdcSecond);
                    
                    // create a new bitmap for the new dc and select it
                    hbmResult = CreateCompatibleBitmap(hdcSecond,
                        wdtResult, hgtResult);
                    hbmResultOld = (HBITMAP)SelectObject(hdcResult, hbmResult);
                    
                    rc.top = 0;
                    rc.left = 0;
                    rc.right = wdtResult;
                    rc.bottom = hgtResult;
                    
                    // paint the background in transparent color...
                    hbrTransparent = CreateSolidBrush(RGB(255, 0, 255));
                    FillRect(hdcResult, &rc, hbrTransparent);
                    DeleteObject(hbrTransparent);
                    
                    // first "standard blit" the second image into the new one:
                    BitBlt(hdcResult, (wdtResult - wdtSecond) / 2,
                        (hgtResult - hgtSecond) / 2, wdtSecond, hgtSecond,
                        hdcSecond, 0, 0, SRCCOPY);
                    
                    // Secondly "tranparent blit" the first image over the
                    // second one Since TransparentBltLS double buffers the
                    // painting to reduce flicker and we are using only memory
                    // DC's in this function, we will just call
                    // TransparentBltLSWorker and shave off a few BitBlt calls
                    TransparentBltLSWorker(hdcResult, wdtFirst, hgtFirst,
                        hdcFirst, 0, 0, RGB(255, 0, 255));
                    
                    // deselect the bitmap from the dc and delete the dc to get
                    // the image
                    SelectObject(hdcResult, hbmResultOld);
                    DeleteDC(hdcResult);
                    
                    // delete all used objects
                    SelectObject(hdcFirst, hbmFirstOld);
                    DeleteObject(hbmFirst);
                    DeleteDC(hdcFirst);
                    
                    SelectObject(hdcSecond, hbmSecondOld);
                    DeleteObject(hbmSecond);
                    DeleteDC(hdcSecond);
                    
                    hbmReturn = hbmResult;
                }
                else
                {
                    hbmReturn = hbmFirst;
                }
            }
            else
            {
                if (!_strnicmp(szImage, ".extract", 8 /*strlen(".extract")*/))
                {
                    HICON hIcon = NULL;
                    
                    hIcon = LoadLSIcon(szImage, pszFile);
                    
                    if (hIcon)
                    {
                        hbmReturn = BitmapFromIcon(hIcon);
                        DestroyIcon(hIcon);
                    }
                }
                else
                {
                    // Append the image name to the LiteStep image path and
                    // attempt to load the image.
                    char szExpandedImage[MAX_PATH];
                    
                    VarExpansionEx(szExpandedImage, szImage, MAX_PATH);
                    LSGetImagePath(szImage, MAX_PATH);
                    PathAppend(szImage, szExpandedImage);
                    
                    if (PathMatchSpec(szImage, "*.png"))
                    {
                        hbmReturn = LoadFromPNG(szImage);
                    }
                    else
                    {
                        hbmReturn = (HBITMAP)LoadImage(
                            NULL, szImage, IMAGE_BITMAP, 0, 0,
                            LR_DEFAULTCOLOR | LR_LOADFROMFILE);
                    }
                    
                    // If that fails, treat the image as a fully qualified path
                    // and try loading it
                    if (hbmReturn == NULL)
                    {
                        if (PathMatchSpec(szExpandedImage, "*.png"))
                        {
                            hbmReturn = LoadFromPNG(szExpandedImage);
                        }
                        else
                        {
                            hbmReturn = (HBITMAP)LoadImage(
                                NULL, szExpandedImage, IMAGE_BITMAP, 0, 0,
                                LR_DEFAULTCOLOR | LR_LOADFROMFILE);
                        }
                    }
                }
            }
        }
    }
    
    return hbmReturn;
}