Skip to content

Commit 934c9d7

Browse files
committed
Added function WindowGetImageAlpha
1 parent a7df93e commit 934c9d7

File tree

10 files changed

+169
-18
lines changed

10 files changed

+169
-18
lines changed

OtherTypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,10 @@ class CMiniWindow
13891389
double Opacity,
13901390
long SrcLeft, long SrcTop);
13911391

1392+
long GetImageAlpha(LPCTSTR ImageId,
1393+
long Left, long Top, long Right, long Bottom,
1394+
long SrcLeft, long SrcTop);
1395+
13921396
};
13931397

13941398
typedef map<string, CMiniWindow *> MiniWindowMap;

doc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ BEGIN_DISPATCH_MAP(CMUSHclientDoc, CDocument)
608608
DISP_FUNCTION(CMUSHclientDoc, "FlashIcon", FlashIcon, VT_EMPTY, VTS_NONE)
609609
DISP_FUNCTION(CMUSHclientDoc, "WindowHotspotTooltip", WindowHotspotTooltip, VT_I4, VTS_BSTR VTS_BSTR VTS_BSTR)
610610
DISP_FUNCTION(CMUSHclientDoc, "WindowDrawImageAlpha", WindowDrawImageAlpha, VT_I4, VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_R8 VTS_I4 VTS_I4)
611+
DISP_FUNCTION(CMUSHclientDoc, "WindowGetImageAlpha", WindowGetImageAlpha, VT_I4, VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4)
611612
DISP_PROPERTY_PARAM(CMUSHclientDoc, "NormalColour", GetNormalColour, SetNormalColour, VT_I4, VTS_I2)
612613
DISP_PROPERTY_PARAM(CMUSHclientDoc, "BoldColour", GetBoldColour, SetBoldColour, VT_I4, VTS_I2)
613614
DISP_PROPERTY_PARAM(CMUSHclientDoc, "CustomColourText", GetCustomColourText, SetCustomColourText, VT_I4, VTS_I2)
@@ -8151,3 +8152,4 @@ static bool bInPluginListChanged = false;
81518152

81528153

81538154
} // end CMUSHclientDoc::PluginListChanged
8155+

doc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,7 @@ class CMUSHclientDoc : public CDocument
26172617
afx_msg void FlashIcon();
26182618
afx_msg long WindowHotspotTooltip(LPCTSTR Name, LPCTSTR HotspotId, LPCTSTR TooltipText);
26192619
afx_msg long WindowDrawImageAlpha(LPCTSTR Name, LPCTSTR ImageId, long Left, long Top, long Right, long Bottom, double Opacity, long SrcLeft, long SrcTop);
2620+
afx_msg long WindowGetImageAlpha(LPCTSTR Name, LPCTSTR ImageId, long Left, long Top, long Right, long Bottom, long SrcLeft, long SrcTop);
26202621
afx_msg long GetNormalColour(short WhichColour);
26212622
afx_msg void SetNormalColour(short WhichColour, long nNewValue);
26222623
afx_msg long GetBoldColour(short WhichColour);

miniwindow.cpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,3 +3952,121 @@ long CMiniWindow::DrawImageAlpha(LPCTSTR ImageId,
39523952

39533953

39543954
} // end of CMiniWindow::DrawImageAlpha
3955+
3956+
long CMiniWindow::GetImageAlpha(LPCTSTR ImageId,
3957+
long Left, long Top, long Right, long Bottom,
3958+
long SrcLeft, long SrcTop)
3959+
{
3960+
3961+
// constrain to what we actually have
3962+
if (Left < 0)
3963+
Left = 0;
3964+
if (Top < 0)
3965+
Top = 0;
3966+
if (Right > m_iWidth)
3967+
Right = m_iWidth;
3968+
if (Bottom > m_iHeight)
3969+
Bottom = m_iHeight;
3970+
3971+
// image to be merged
3972+
ImageMapIterator it = m_Images.find (ImageId);
3973+
3974+
if (it == m_Images.end ())
3975+
return eImageNotInstalled;
3976+
3977+
CBitmap * bitmap = it->second;
3978+
3979+
3980+
BITMAP bi;
3981+
bitmap->GetBitmap(&bi);
3982+
3983+
// can't do it unless we have alpha channel
3984+
if (bi.bmBitsPixel != 32)
3985+
return eImageNotInstalled;
3986+
3987+
// calculate size of desired rectangle
3988+
long iWidth = FixRight (Right) - Left;
3989+
long iHeight = FixBottom (Bottom) - Top;
3990+
3991+
// constrain to what we actually have
3992+
if (SrcLeft < 0)
3993+
SrcLeft = 0;
3994+
if (SrcTop < 0)
3995+
SrcTop = 0;
3996+
3997+
if (iWidth <= 0 || iHeight <= 0) // sanity check
3998+
return eOK;
3999+
4000+
// merge layer (from image id)
4001+
CDC A_DC;
4002+
A_DC.CreateCompatibleDC(&dc);
4003+
4004+
BITMAPINFO bmi;
4005+
ZeroMemory (&bmi, sizeof bmi);
4006+
4007+
bmi.bmiHeader.biSize = sizeof bmi;
4008+
bmi.bmiHeader.biWidth = iWidth;
4009+
bmi.bmiHeader.biHeight = iHeight;
4010+
bmi.bmiHeader.biPlanes = 1;
4011+
bmi.bmiHeader.biBitCount = 32;
4012+
bmi.bmiHeader.biCompression = BI_RGB;
4013+
bmi.bmiHeader.biSizeImage = iHeight * BytesPerLine (iWidth, 32);
4014+
4015+
unsigned char * pA = NULL;
4016+
4017+
HBITMAP hbmA = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**) &pA, NULL, 0);
4018+
4019+
HBITMAP hOldAbmp = (HBITMAP) SelectObject(A_DC.m_hDC, hbmA);
4020+
4021+
CDC bmDC; // for loading bitmaps into
4022+
bmDC.CreateCompatibleDC(&dc);
4023+
4024+
//copy part from image to upper layer
4025+
CBitmap *pOldbmp = bmDC.SelectObject(bitmap);
4026+
A_DC.BitBlt (0, 0, iWidth, iHeight, &bmDC, SrcLeft, SrcTop, SRCCOPY);
4027+
bmDC.SelectObject(pOldbmp);
4028+
4029+
4030+
// base image (from miniwindow)
4031+
4032+
CDC B_DC;
4033+
B_DC.CreateCompatibleDC(&dc);
4034+
CBitmap B_bmp;
4035+
4036+
unsigned char * pB = NULL;
4037+
4038+
HBITMAP hbmB = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**) &pB, NULL, 0);
4039+
4040+
HBITMAP hOldBbmp = (HBITMAP) SelectObject(B_DC.m_hDC, hbmB);
4041+
4042+
4043+
long count = bmi.bmiHeader.biSizeImage;
4044+
long perline = BytesPerLine (iWidth, 24);
4045+
4046+
long i;
4047+
4048+
// copy alpha channel into window
4049+
4050+
for (i = 0; i < count; i += 4)
4051+
{
4052+
pB [i] = pA [i + 3];
4053+
pB [i + 1] = pA [i + 3];
4054+
pB [i + 2] = pA [i + 3];
4055+
}
4056+
4057+
4058+
// copy result back
4059+
4060+
dc.BitBlt (Left, Top, iWidth, iHeight, &B_DC, 0, 0, SRCCOPY);
4061+
4062+
4063+
SelectObject(A_DC.m_hDC, hOldAbmp);
4064+
SelectObject(B_DC.m_hDC, hOldBbmp);
4065+
4066+
DeleteObject (hbmA);
4067+
DeleteObject (hbmB);
4068+
4069+
return eOK;
4070+
4071+
4072+
} // end of CMiniWindow::GetImageAlpha

mushclient.clw

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[General Info]
44
Version=1
5-
LastClass=CFunctionListDlg
5+
LastClass=CMUSHclientDoc
66
LastTemplate=CDialog
77
NewFileInclude1=#include "stdafx.h"
88
NewFileInclude2=#include "mushclient.h"
@@ -1339,15 +1339,6 @@ Filter=D
13391339
VirtualFilter=dWC
13401340
LastObject=CCompleteWordDlg
13411341

1342-
[CLS:CLuaInputEditDlg]
1343-
Type=0
1344-
HeaderFile=LuaInputEditDlg.h
1345-
ImplementationFile=LuaInputEditDlg.cpp
1346-
BaseClass=CDialog
1347-
Filter=D
1348-
LastObject=CLuaInputEditDlg
1349-
VirtualFilter=dWC
1350-
13511342
[CLS:CKeyNameDlg]
13521343
Type=0
13531344
HeaderFile=KeyNameDlg.h

mushclient.cnt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@
532532
3 WindowFont=FNC_WindowFont
533533
3 WindowFontInfo=FNC_WindowFontInfo
534534
3 WindowFontList=FNC_WindowFontList
535+
3 WindowGetImageAlpha=FNC_WindowGetImageAlpha
535536
3 WindowGetPixel=FNC_WindowGetPixel
536537
3 WindowImageFromWindow=FNC_WindowImageFromWindow
537538
3 WindowImageInfo=FNC_WindowImageInfo

mushclient.odl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ library MUSHclient
7070
[id(44)] long SetCommand(BSTR Message);
7171
[id(45)] BSTR GetNotes();
7272
[id(46)] void SetNotes(BSTR Message);
73-
[id(398), propget] long NormalColour(short WhichColour);
74-
[id(398), propput] void NormalColour(short WhichColour, long nNewValue);
75-
[id(399), propget] long BoldColour(short WhichColour);
76-
[id(399), propput] void BoldColour(short WhichColour, long nNewValue);
77-
[id(400), propget] long CustomColourText(short WhichColour);
78-
[id(400), propput] void CustomColourText(short WhichColour, long nNewValue);
79-
[id(401), propget] long CustomColourBackground(short WhichColour);
80-
[id(401), propput] void CustomColourBackground(short WhichColour, long nNewValue);
73+
[id(399), propget] long NormalColour(short WhichColour);
74+
[id(399), propput] void NormalColour(short WhichColour, long nNewValue);
75+
[id(400), propget] long BoldColour(short WhichColour);
76+
[id(400), propput] void BoldColour(short WhichColour, long nNewValue);
77+
[id(401), propget] long CustomColourText(short WhichColour);
78+
[id(401), propput] void CustomColourText(short WhichColour, long nNewValue);
79+
[id(402), propget] long CustomColourBackground(short WhichColour);
80+
[id(402), propput] void CustomColourBackground(short WhichColour, long nNewValue);
8181
[id(47)] void Redraw();
8282
[id(48)] long ResetTimer(BSTR TimerName);
8383
[id(49)] void SetOutputFont(BSTR FontName, short PointSize);
@@ -429,6 +429,7 @@ library MUSHclient
429429
[id(395)] void FlashIcon();
430430
[id(396)] long WindowHotspotTooltip(BSTR Name, BSTR HotspotId, BSTR TooltipText);
431431
[id(397)] long WindowDrawImageAlpha(BSTR Name, BSTR ImageId, long Left, long Top, long Right, long Bottom, double Opacity, long SrcLeft, long SrcTop);
432+
[id(398)] long WindowGetImageAlpha(BSTR Name, BSTR ImageId, long Left, long Top, long Right, long Bottom, long SrcLeft, long SrcTop);
432433
//}}AFX_ODL_METHOD
433434

434435
};

scripting/functionlist.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ const char * sFunctions [] = {
386386
"WindowFont",
387387
"WindowFontInfo",
388388
"WindowFontList",
389+
"WindowGetImageAlpha",
389390
"WindowGetPixel",
390391
"WindowGradient",
391392
"WindowHotspotInfo",

scripting/lua_methods.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5583,6 +5583,25 @@ static int L_WindowFontList (lua_State *L)
55835583
return pushVariant (L, v); // number of result fields
55845584
} // end of L_WindowFontList
55855585

5586+
//----------------------------------------
5587+
// world.WindowGetImageAlpha
5588+
//----------------------------------------
5589+
static int L_WindowGetImageAlpha (lua_State *L)
5590+
{
5591+
CMUSHclientDoc *pDoc = doc (L);
5592+
lua_pushnumber (L, pDoc->WindowGetImageAlpha (
5593+
my_checkstring (L, 1), // Name
5594+
my_checkstring (L, 2), // ImageId
5595+
my_checknumber (L, 3), // Left
5596+
my_checknumber (L, 4), // Top
5597+
my_checknumber (L, 5), // Right
5598+
my_checknumber (L, 6), // Bottom
5599+
my_optnumber (L, 7, 0), // SrcLeft
5600+
my_optnumber (L, 8, 0) // SrcTop
5601+
));
5602+
return 1; // number of result fields
5603+
} // end of L_WindowGetImageAlpha
5604+
55865605
//----------------------------------------
55875606
// world.WindowGetPixel
55885607
//----------------------------------------
@@ -6411,6 +6430,7 @@ static const struct luaL_reg worldlib [] =
64116430
{"WindowFont", L_WindowFont},
64126431
{"WindowFontInfo", L_WindowFontInfo},
64136432
{"WindowFontList", L_WindowFontList},
6433+
{"WindowGetImageAlpha", L_WindowGetImageAlpha},
64146434
{"WindowGetPixel", L_WindowGetPixel},
64156435
{"WindowGradient", L_WindowGradient},
64166436
{"WindowHotspotInfo", L_WindowHotspotInfo},

scripting/methods.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14669,6 +14669,18 @@ long CMUSHclientDoc::WindowDrawImageAlpha(LPCTSTR Name, LPCTSTR ImageId, long Le
1466914669

1467014670
} // end of CMUSHclientDoc::WindowDrawImageAlpha
1467114671

14672+
long CMUSHclientDoc::WindowGetImageAlpha(LPCTSTR Name, LPCTSTR ImageId, long Left, long Top, long Right, long Bottom, long SrcLeft, long SrcTop)
14673+
{
14674+
MiniWindowMapIterator it = m_MiniWindows.find (Name);
14675+
14676+
if (it == m_MiniWindows.end ())
14677+
return eNoSuchWindow;
14678+
14679+
return it->second->GetImageAlpha (ImageId, Left, Top, Right, Bottom,
14680+
SrcLeft, SrcTop);
14681+
14682+
} // end of CMUSHclientDoc::WindowGetImageAlpha
14683+
1467214684

1467314685
/*
1467414686

0 commit comments

Comments
 (0)