Skip to content

Commit

Permalink
EGE 库:修复使用颜色时多余的转换。
Browse files Browse the repository at this point in the history
Signed-off-by: FrankHB <frankhb1989@gmail.com>
  • Loading branch information
FrankHB committed Feb 1, 2014
1 parent 54a7a7e commit fa73c87
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 30 deletions.
1 change: 1 addition & 0 deletions Compatibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Code::Blocks 。
typedef 类型名 color_t 从 unsigned int 改为 YSLib::Drawing::PixelType 。
使用 YCLib 提供的 YSLib::Drawing::MonoType 表示颜色分量。
使用 YSLib::Drawing::PixelType::Integer 表示颜色对应的整数类型。
* 注意布局同 ::COLORREF ,相对原有实现红色和蓝色分量交换,修复了 <wingdi.h> 中 RGB 等宏的参数红色和蓝色分量相反的问题。
宏 RGBTOBGR 、EGERGB 、EGERGBA 、EGEARGB 、EGEACOLOR 、EGECOLORA 、EGEGET_R 、EGEGET_G 、EGEGET_B 、EGEGET_A 、EGEGRAY 、EGEGRAYA 和 EGEAGRAY 变更为 ege 命名空间内的函数。
函数 savepng 的表示是否使用 alpha 的参数被忽略。

Expand Down
6 changes: 3 additions & 3 deletions EGE/include/ege/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ class EGEAPI button : public egeControlBase
_font_height = 12;
strcpy(_face, "宋体");
_line_color = BLACK;
_bg_color = RGB(100, 100, 100);
_bg_color = EGERGB(100, 100, 100);
_text_color = BLACK;
_shadow_color = RGB(50, 50, 50);
_shadow_color = EGERGB(50, 50, 50);
updatesidewidth();

_on_click = {};
Expand Down Expand Up @@ -244,7 +244,7 @@ class EGEAPI button : public egeControlBase
line(_side_width - 1, geth() - _side_width, 0, geth());
//line(getw()-_side_width, geth()-_side_width, getw(), geth());
//line(0,0, _side_width, _side_width);
setbkcolor_f(RGB(_alpha, _alpha, _alpha), filter());
setbkcolor_f(EGERGB(_alpha, _alpha, _alpha), filter());
cleardevice(filter());
}
//attributes
Expand Down
2 changes: 1 addition & 1 deletion EGE/include/ege/colorbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RGBTOBGR(YSLib::Drawing::MonoType color)
yconstfn color_t::Trait::IntegerType
EGERGB(YSLib::Drawing::MonoType r, YSLib::Drawing::MonoType g, YSLib::Drawing::MonoType b)
{
return (r << 16) | (g << 8) | b;
return (b << 16) | (g << 8) | r;
}

yconstfn color_t::Trait::IntegerType
Expand Down
15 changes: 4 additions & 11 deletions EGE/include/ege/label.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,17 @@ class EGEAPI label : public egeControlBase
setbkcolor_f(BLACK, filter());
cleardevice(filter());
if(m_alpha < 0xFF)
{
setcolor(RGB(m_alpha, m_alpha, m_alpha), filter());
}
setcolor(EGERGB(m_alpha, m_alpha, m_alpha), filter());
else
{
setcolor(0xFFFFFF, filter());
}
setbkmode(TRANSPARENT, filter());
setfont(m_fontheight, 0, m_face, filter());
outtextrect(0, 0, getw(), geth(), m_caption, filter());
}
else
else if(m_alpha < 0xFF)
{
if(m_alpha < 0xFF)
{
setbkcolor_f(RGB(m_alpha, m_alpha, m_alpha), filter());
cleardevice(filter());
}
setbkcolor_f(RGB(m_alpha, m_alpha, m_alpha), filter());
cleardevice(filter());
}
}
protected:
Expand Down
6 changes: 3 additions & 3 deletions EGE/include/ege/sys_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ class EGEAPI sys_edit : public egeControlBase
if(message == WM_CTLCOLOREDIT)
{
const auto dc = ::HDC(wParam);
const auto br(::CreateSolidBrush(RGBTOBGR(m_bgcolor)));
const auto br(::CreateSolidBrush(m_bgcolor));

::SetBkColor(dc, RGBTOBGR(m_bgcolor));
::SetTextColor(dc, RGBTOBGR(m_color));
::SetBkColor(dc, m_bgcolor);
::SetTextColor(dc, m_color);
::DeleteObject(m_hBrush);
m_hBrush = br;
return ::LRESULT(br);
Expand Down
21 changes: 9 additions & 12 deletions EGE/src/ege/gapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ setlinestyle(int linestyle, unsigned short upattern, int thickness, IMAGE* pimg)

::LOGPEN lpen{0, ::POINT(), COLORREF()};

lpen.lopnColor = RGBTOBGR(getcolor(pimg));
lpen.lopnColor = getcolor(pimg);
img.m_linestyle.thickness = thickness;
img.m_linewidth = float(thickness);
img.m_linestyle.linestyle = linestyle;
Expand Down Expand Up @@ -184,7 +184,7 @@ setfillstyle(int pattern, color_t color, IMAGE* pimg)
::LOGBRUSH lbr{0, COLORREF(), ::UINT_PTR()};

img.m_fillcolor = color;
lbr.lbColor = RGBTOBGR(color);
lbr.lbColor = color;
//::SetBkColor(img.getdc(), color);
if(pattern < SOLID_FILL)
lbr.lbHatch = BS_NULL;
Expand Down Expand Up @@ -266,7 +266,6 @@ setcolor(color_t color, IMAGE* pimg)
::HPEN hpen;

img->m_color = color;
color = RGBTOBGR(color);
lPen.lopnColor = color;
lPen.lopnStyle = img->m_linestyle.linestyle;
lPen.lopnWidth.x = img->m_linestyle.thickness;
Expand Down Expand Up @@ -323,7 +322,6 @@ setfillcolor(color_t color, IMAGE* pimg)
::LOGBRUSH lbr{0, COLORREF(), ::ULONG_PTR()};

img.m_fillcolor = color;
color = RGBTOBGR(color);
lbr.lbColor = color;
lbr.lbHatch = BS_SOLID;
::HBRUSH hbr = ::CreateBrushIndirect(&lbr);
Expand All @@ -342,7 +340,7 @@ setbkcolor(color_t color, IMAGE* pimg)
color_t col = img->m_bk_color;

img->m_bk_color = color;
::SetBkColor(img->getdc(), RGBTOBGR(color));
::SetBkColor(img->getdc(), color);
for(int n = 0; n < size; n++, p++)
if(*p == col)
*p = color;
Expand All @@ -358,7 +356,7 @@ setbkcolor_f(color_t color, IMAGE* pimg)
if(img->getdc())
{
img->m_bk_color = color;
::SetBkColor(img->getdc(), RGBTOBGR(color));
::SetBkColor(img->getdc(), color);
}
}

Expand All @@ -367,7 +365,7 @@ setfontbkcolor(color_t color, IMAGE* pimg)
{
if(const auto img = CONVERT_IMAGE(pimg))
if(img->getdc())
::SetBkColor(img->getdc(), RGBTOBGR(color));
::SetBkColor(img->getdc(), color);
}

void
Expand Down Expand Up @@ -434,7 +432,7 @@ putpixels(int nPoint, int* pPoints, IMAGE* pimg)
{
x = pPoints[0], y = pPoints[1], c = pPoints[2];
if(!(x < 0 || y < 0 || x >= w || y >= h))
pb[y * tw + x] = RGBTOBGR(c);
pb[y * tw + x] = c;
}
}

Expand All @@ -445,7 +443,7 @@ putpixels_f(int nPoint, int* pPoints, IMAGE* pimg)
const int tw(img.GetWidth());

for(int n = 0; n < nPoint; ++n, pPoints += 3)
img.getbuffer()[pPoints[1] * tw + pPoints[0]] = RGBTOBGR(pPoints[2]);
img.getbuffer()[pPoints[1] * tw + pPoints[0]] = pPoints[2];
}


Expand Down Expand Up @@ -893,15 +891,14 @@ void
floodfill(int x, int y, int border, IMAGE* pimg)
{
if(const auto img = CONVERT_IMAGE(pimg))
::FloodFill(img->getdc(), x, y, RGBTOBGR(border));
::FloodFill(img->getdc(), x, y, border);
}

void
floodfillsurface(int x, int y, color_t areacolor, IMAGE* pimg)
{
if(const auto img = CONVERT_IMAGE(pimg))
::ExtFloodFill(img->getdc(), x, y, RGBTOBGR(areacolor),
FLOODFILLSURFACE);
::ExtFloodFill(img->getdc(), x, y, areacolor, FLOODFILLSURFACE);
}

} // namespace ege;
Expand Down

0 comments on commit fa73c87

Please sign in to comment.