Skip to content

Commit

Permalink
Added function WindowGetImageAlpha
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Jun 3, 2010
1 parent a7df93e commit 934c9d7
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 18 deletions.
4 changes: 4 additions & 0 deletions OtherTypes.h
Expand Up @@ -1389,6 +1389,10 @@ class CMiniWindow
double Opacity,
long SrcLeft, long SrcTop);

long GetImageAlpha(LPCTSTR ImageId,
long Left, long Top, long Right, long Bottom,
long SrcLeft, long SrcTop);

};

typedef map<string, CMiniWindow *> MiniWindowMap;
Expand Down
2 changes: 2 additions & 0 deletions doc.cpp
Expand Up @@ -608,6 +608,7 @@ BEGIN_DISPATCH_MAP(CMUSHclientDoc, CDocument)
DISP_FUNCTION(CMUSHclientDoc, "FlashIcon", FlashIcon, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CMUSHclientDoc, "WindowHotspotTooltip", WindowHotspotTooltip, VT_I4, VTS_BSTR VTS_BSTR VTS_BSTR)
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)
DISP_FUNCTION(CMUSHclientDoc, "WindowGetImageAlpha", WindowGetImageAlpha, VT_I4, VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4)
DISP_PROPERTY_PARAM(CMUSHclientDoc, "NormalColour", GetNormalColour, SetNormalColour, VT_I4, VTS_I2)
DISP_PROPERTY_PARAM(CMUSHclientDoc, "BoldColour", GetBoldColour, SetBoldColour, VT_I4, VTS_I2)
DISP_PROPERTY_PARAM(CMUSHclientDoc, "CustomColourText", GetCustomColourText, SetCustomColourText, VT_I4, VTS_I2)
Expand Down Expand Up @@ -8151,3 +8152,4 @@ static bool bInPluginListChanged = false;


} // end CMUSHclientDoc::PluginListChanged

1 change: 1 addition & 0 deletions doc.h
Expand Up @@ -2617,6 +2617,7 @@ class CMUSHclientDoc : public CDocument
afx_msg void FlashIcon();
afx_msg long WindowHotspotTooltip(LPCTSTR Name, LPCTSTR HotspotId, LPCTSTR TooltipText);
afx_msg long WindowDrawImageAlpha(LPCTSTR Name, LPCTSTR ImageId, long Left, long Top, long Right, long Bottom, double Opacity, long SrcLeft, long SrcTop);
afx_msg long WindowGetImageAlpha(LPCTSTR Name, LPCTSTR ImageId, long Left, long Top, long Right, long Bottom, long SrcLeft, long SrcTop);
afx_msg long GetNormalColour(short WhichColour);
afx_msg void SetNormalColour(short WhichColour, long nNewValue);
afx_msg long GetBoldColour(short WhichColour);
Expand Down
118 changes: 118 additions & 0 deletions miniwindow.cpp
Expand Up @@ -3952,3 +3952,121 @@ long CMiniWindow::DrawImageAlpha(LPCTSTR ImageId,


} // end of CMiniWindow::DrawImageAlpha

long CMiniWindow::GetImageAlpha(LPCTSTR ImageId,
long Left, long Top, long Right, long Bottom,
long SrcLeft, long SrcTop)
{

// constrain to what we actually have
if (Left < 0)
Left = 0;
if (Top < 0)
Top = 0;
if (Right > m_iWidth)
Right = m_iWidth;
if (Bottom > m_iHeight)
Bottom = m_iHeight;

// image to be merged
ImageMapIterator it = m_Images.find (ImageId);

if (it == m_Images.end ())
return eImageNotInstalled;

CBitmap * bitmap = it->second;


BITMAP bi;
bitmap->GetBitmap(&bi);

// can't do it unless we have alpha channel
if (bi.bmBitsPixel != 32)
return eImageNotInstalled;

// calculate size of desired rectangle
long iWidth = FixRight (Right) - Left;
long iHeight = FixBottom (Bottom) - Top;

// constrain to what we actually have
if (SrcLeft < 0)
SrcLeft = 0;
if (SrcTop < 0)
SrcTop = 0;

if (iWidth <= 0 || iHeight <= 0) // sanity check
return eOK;

// merge layer (from image id)
CDC A_DC;
A_DC.CreateCompatibleDC(&dc);

BITMAPINFO bmi;
ZeroMemory (&bmi, sizeof bmi);

bmi.bmiHeader.biSize = sizeof bmi;
bmi.bmiHeader.biWidth = iWidth;
bmi.bmiHeader.biHeight = iHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = iHeight * BytesPerLine (iWidth, 32);

unsigned char * pA = NULL;

HBITMAP hbmA = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**) &pA, NULL, 0);

HBITMAP hOldAbmp = (HBITMAP) SelectObject(A_DC.m_hDC, hbmA);

CDC bmDC; // for loading bitmaps into
bmDC.CreateCompatibleDC(&dc);

//copy part from image to upper layer
CBitmap *pOldbmp = bmDC.SelectObject(bitmap);
A_DC.BitBlt (0, 0, iWidth, iHeight, &bmDC, SrcLeft, SrcTop, SRCCOPY);
bmDC.SelectObject(pOldbmp);


// base image (from miniwindow)

CDC B_DC;
B_DC.CreateCompatibleDC(&dc);
CBitmap B_bmp;

unsigned char * pB = NULL;

HBITMAP hbmB = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**) &pB, NULL, 0);

HBITMAP hOldBbmp = (HBITMAP) SelectObject(B_DC.m_hDC, hbmB);


long count = bmi.bmiHeader.biSizeImage;
long perline = BytesPerLine (iWidth, 24);

long i;

// copy alpha channel into window

for (i = 0; i < count; i += 4)
{
pB [i] = pA [i + 3];
pB [i + 1] = pA [i + 3];
pB [i + 2] = pA [i + 3];
}


// copy result back

dc.BitBlt (Left, Top, iWidth, iHeight, &B_DC, 0, 0, SRCCOPY);


SelectObject(A_DC.m_hDC, hOldAbmp);
SelectObject(B_DC.m_hDC, hOldBbmp);

DeleteObject (hbmA);
DeleteObject (hbmB);

return eOK;


} // end of CMiniWindow::GetImageAlpha
11 changes: 1 addition & 10 deletions mushclient.clw
Expand Up @@ -2,7 +2,7 @@

[General Info]
Version=1
LastClass=CFunctionListDlg
LastClass=CMUSHclientDoc
LastTemplate=CDialog
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "mushclient.h"
Expand Down Expand Up @@ -1339,15 +1339,6 @@ Filter=D
VirtualFilter=dWC
LastObject=CCompleteWordDlg

[CLS:CLuaInputEditDlg]
Type=0
HeaderFile=LuaInputEditDlg.h
ImplementationFile=LuaInputEditDlg.cpp
BaseClass=CDialog
Filter=D
LastObject=CLuaInputEditDlg
VirtualFilter=dWC

[CLS:CKeyNameDlg]
Type=0
HeaderFile=KeyNameDlg.h
Expand Down
1 change: 1 addition & 0 deletions mushclient.cnt
Expand Up @@ -532,6 +532,7 @@
3 WindowFont=FNC_WindowFont
3 WindowFontInfo=FNC_WindowFontInfo
3 WindowFontList=FNC_WindowFontList
3 WindowGetImageAlpha=FNC_WindowGetImageAlpha
3 WindowGetPixel=FNC_WindowGetPixel
3 WindowImageFromWindow=FNC_WindowImageFromWindow
3 WindowImageInfo=FNC_WindowImageInfo
Expand Down
17 changes: 9 additions & 8 deletions mushclient.odl
Expand Up @@ -70,14 +70,14 @@ library MUSHclient
[id(44)] long SetCommand(BSTR Message);
[id(45)] BSTR GetNotes();
[id(46)] void SetNotes(BSTR Message);
[id(398), propget] long NormalColour(short WhichColour);
[id(398), propput] void NormalColour(short WhichColour, long nNewValue);
[id(399), propget] long BoldColour(short WhichColour);
[id(399), propput] void BoldColour(short WhichColour, long nNewValue);
[id(400), propget] long CustomColourText(short WhichColour);
[id(400), propput] void CustomColourText(short WhichColour, long nNewValue);
[id(401), propget] long CustomColourBackground(short WhichColour);
[id(401), propput] void CustomColourBackground(short WhichColour, long nNewValue);
[id(399), propget] long NormalColour(short WhichColour);
[id(399), propput] void NormalColour(short WhichColour, long nNewValue);
[id(400), propget] long BoldColour(short WhichColour);
[id(400), propput] void BoldColour(short WhichColour, long nNewValue);
[id(401), propget] long CustomColourText(short WhichColour);
[id(401), propput] void CustomColourText(short WhichColour, long nNewValue);
[id(402), propget] long CustomColourBackground(short WhichColour);
[id(402), propput] void CustomColourBackground(short WhichColour, long nNewValue);
[id(47)] void Redraw();
[id(48)] long ResetTimer(BSTR TimerName);
[id(49)] void SetOutputFont(BSTR FontName, short PointSize);
Expand Down Expand Up @@ -429,6 +429,7 @@ library MUSHclient
[id(395)] void FlashIcon();
[id(396)] long WindowHotspotTooltip(BSTR Name, BSTR HotspotId, BSTR TooltipText);
[id(397)] long WindowDrawImageAlpha(BSTR Name, BSTR ImageId, long Left, long Top, long Right, long Bottom, double Opacity, long SrcLeft, long SrcTop);
[id(398)] long WindowGetImageAlpha(BSTR Name, BSTR ImageId, long Left, long Top, long Right, long Bottom, long SrcLeft, long SrcTop);
//}}AFX_ODL_METHOD

};
Expand Down
1 change: 1 addition & 0 deletions scripting/functionlist.cpp
Expand Up @@ -386,6 +386,7 @@ const char * sFunctions [] = {
"WindowFont",
"WindowFontInfo",
"WindowFontList",
"WindowGetImageAlpha",
"WindowGetPixel",
"WindowGradient",
"WindowHotspotInfo",
Expand Down
20 changes: 20 additions & 0 deletions scripting/lua_methods.cpp
Expand Up @@ -5583,6 +5583,25 @@ static int L_WindowFontList (lua_State *L)
return pushVariant (L, v); // number of result fields
} // end of L_WindowFontList

//----------------------------------------
// world.WindowGetImageAlpha
//----------------------------------------
static int L_WindowGetImageAlpha (lua_State *L)
{
CMUSHclientDoc *pDoc = doc (L);
lua_pushnumber (L, pDoc->WindowGetImageAlpha (
my_checkstring (L, 1), // Name
my_checkstring (L, 2), // ImageId
my_checknumber (L, 3), // Left
my_checknumber (L, 4), // Top
my_checknumber (L, 5), // Right
my_checknumber (L, 6), // Bottom
my_optnumber (L, 7, 0), // SrcLeft
my_optnumber (L, 8, 0) // SrcTop
));
return 1; // number of result fields
} // end of L_WindowGetImageAlpha

//----------------------------------------
// world.WindowGetPixel
//----------------------------------------
Expand Down Expand Up @@ -6411,6 +6430,7 @@ static const struct luaL_reg worldlib [] =
{"WindowFont", L_WindowFont},
{"WindowFontInfo", L_WindowFontInfo},
{"WindowFontList", L_WindowFontList},
{"WindowGetImageAlpha", L_WindowGetImageAlpha},
{"WindowGetPixel", L_WindowGetPixel},
{"WindowGradient", L_WindowGradient},
{"WindowHotspotInfo", L_WindowHotspotInfo},
Expand Down
12 changes: 12 additions & 0 deletions scripting/methods.cpp
Expand Up @@ -14669,6 +14669,18 @@ long CMUSHclientDoc::WindowDrawImageAlpha(LPCTSTR Name, LPCTSTR ImageId, long Le

} // end of CMUSHclientDoc::WindowDrawImageAlpha

long CMUSHclientDoc::WindowGetImageAlpha(LPCTSTR Name, LPCTSTR ImageId, long Left, long Top, long Right, long Bottom, long SrcLeft, long SrcTop)
{
MiniWindowMapIterator it = m_MiniWindows.find (Name);

if (it == m_MiniWindows.end ())
return eNoSuchWindow;

return it->second->GetImageAlpha (ImageId, Left, Top, Right, Bottom,
SrcLeft, SrcTop);

} // end of CMUSHclientDoc::WindowGetImageAlpha


/*

Expand Down

0 comments on commit 934c9d7

Please sign in to comment.