diff --git a/examples/example1/src/main.d b/examples/example1/src/main.d index c132388b..39512412 100644 --- a/examples/example1/src/main.d +++ b/examples/example1/src/main.d @@ -24,6 +24,13 @@ extern (C) int UIAppMain(string[] args) { // select translation file - for english language i18n.load("en.ini"); //"ru.ini", "en.ini" + + DrawBufRef img = imageCache.get("C:\\projects\\d\\dlangui\\res\\mdpi\\btn_radio_on_holo_light.png"); + ColorDrawBuf buf = cast(ColorDrawBuf)img.get; + //GrayDrawBuf gbuf = cast(GrayDrawBuf)img.get; + uint * row = buf.scanLine(0); + Log.d("btn_radio_on_holo_light pixels: ", row[0], row[1], row[2]); + // create window Window window = Platform.instance.createWindow("My Window", null); diff --git a/src/dlangui/graphics/images.d b/src/dlangui/graphics/images.d index a658b0fe..4898ff96 100644 --- a/src/dlangui/graphics/images.d +++ b/src/dlangui/graphics/images.d @@ -41,6 +41,7 @@ ColorDrawBuf loadImage(string filename) { scope(exit) { f.close(); } return loadImage(f); } catch (Exception e) { + Log.e("exception while loading image from file ", filename); return null; } } @@ -111,7 +112,17 @@ static if (USE_FREEIMAGE) { //get the image width and height, and size per pixel int width = FreeImage_GetWidth(dib); int height = FreeImage_GetHeight(dib); - int pixelSize = FreeImage_GetBPP(dib)/8; + int bpp = FreeImage_GetBPP(dib); + int pixelSize = (bpp + 7)/8; + FREE_IMAGE_COLOR_TYPE colorType = FreeImage_GetColorType(dib); + int transparentIndex = 0; + int transparencyCount = 0; + RGBQUAD * palette = null; + if (colorType == FIC_PALETTE) { + palette = FreeImage_GetPalette(dib); + transparentIndex = FreeImage_GetTransparentIndex(dib); + transparencyCount = FreeImage_GetTransparencyCount(dib); + } int size = width*height*pixelSize; ColorDrawBuf res = new ColorDrawBuf(width, height); @@ -124,28 +135,42 @@ static if (USE_FREEIMAGE) { dst = res.scanLine(i); src = data + (ii * width) * pixelSize; for( int j = 0; j < width; ++j, ++dst, src += pixelSize ) { - a = 0; - switch (pixelSize) { - case 4: - a = src[3] ^ 255; - // fall through - goto case; - case 3: - r = src[2]; - g = src[1]; - b = src[0]; - break; - case 2: - // todo: do something better - r = g = src[1]; - b = src[0]; - break; - default: - case 1: - r = g = b = src[0]; - break; - } - dst[0] = (a << 24) | (r << 16) | (g << 8) | b; + if (colorType == FIC_PALETTE) { + ubyte index = src[0]; + if (transparentIndex >= 0 && index >= transparentIndex && index < transparentIndex + transparencyCount) { + dst[0] = 0xFFFFFFFF; + } else { + RGBQUAD pcolor = palette[index]; + a = pcolor.rgbReserved; + r = pcolor.rgbRed; + g = pcolor.rgbGreen; + b = pcolor.rgbBlue; + dst[0] = (a << 24) | (r << 16) | (g << 8) | b; + } + } else { + a = 0; + switch (pixelSize) { + case 4: + a = src[3] ^ 255; + // fall through + goto case; + case 3: + r = src[2]; + g = src[1]; + b = src[0]; + break; + case 2: + // todo: do something better + r = g = src[1]; + b = src[0]; + break; + default: + case 1: + r = g = b = src[0]; + break; + } + dst[0] = (a << 24) | (r << 16) | (g << 8) | b; + } } } FreeImage_CloseMemory(hmem); diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d index 18d8dfdc..9e09c070 100644 --- a/src/dlangui/widgets/styles.d +++ b/src/dlangui/widgets/styles.d @@ -702,10 +702,10 @@ Theme createDefaultTheme() { menuItem.createState(State.Hovered, State.Hovered).backgroundColor(0xC0FFFF00); Style transparentButtonBackground = res.createSubstyle("TRANSPARENT_BUTTON_BACKGROUND").padding(Rect(4,2,4,2)); //.backgroundColor(0xE0E080) ; - transparentButtonBackground.createState(State.Focused, State.Focused).backgroundColor(0x40C0C000); + transparentButtonBackground.createState(State.Focused, State.Focused).backgroundColor(0xC0C0C000); transparentButtonBackground.createState(State.Pressed, State.Pressed).backgroundColor(0x4080C000); - transparentButtonBackground.createState(State.Selected, State.Selected).backgroundColor(0x00F8F9Fa); - transparentButtonBackground.createState(State.Hovered, State.Hovered).backgroundColor(0xC0FFFF00); + //transparentButtonBackground.createState(State.Selected, State.Selected).backgroundColor(0x00F8F9Fa); + transparentButtonBackground.createState(State.Hovered, State.Hovered).backgroundColor(0xD0FFFF00); Style poopupMenu = res.createSubstyle("POPUP_MENU").backgroundImageId("popup_menu_background_normal");