Skip to content

Commit bfc9f2d

Browse files
committed
Added WindowTranslateImage
1 parent 6ba2f42 commit bfc9f2d

File tree

9 files changed

+155
-9
lines changed

9 files changed

+155
-9
lines changed

OtherTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,7 @@ class CMiniWindow
14111411

14121412
long MoveHotspot(LPCTSTR HotspotId, long Left, long Top, long Right, long Bottom);
14131413

1414+
long TranslateImage(LPCTSTR ImageId, float Left, float Top, short Mode, float Mxx, float Mxy, float Myx, float Myy);
14141415

14151416
};
14161417

doc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ BEGIN_DISPATCH_MAP(CMUSHclientDoc, CDocument)
604604
DISP_FUNCTION(CMUSHclientDoc, "WindowScrollwheelHandler", WindowScrollwheelHandler, VT_I4, VTS_BSTR VTS_BSTR VTS_BSTR)
605605
DISP_FUNCTION(CMUSHclientDoc, "WindowResize", WindowResize, VT_I4, VTS_BSTR VTS_I4 VTS_I4 VTS_I4)
606606
DISP_FUNCTION(CMUSHclientDoc, "WindowMoveHotspot", WindowMoveHotspot, VT_I4, VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 VTS_I4 VTS_I4)
607+
DISP_FUNCTION(CMUSHclientDoc, "WindowTranslateImage", WindowTranslateImage, VT_I4, VTS_BSTR VTS_BSTR VTS_R4 VTS_R4 VTS_I2 VTS_R4 VTS_R4 VTS_R4 VTS_R4)
607608
DISP_PROPERTY_PARAM(CMUSHclientDoc, "NormalColour", GetNormalColour, SetNormalColour, VT_I4, VTS_I2)
608609
DISP_PROPERTY_PARAM(CMUSHclientDoc, "BoldColour", GetBoldColour, SetBoldColour, VT_I4, VTS_I2)
609610
DISP_PROPERTY_PARAM(CMUSHclientDoc, "CustomColourText", GetCustomColourText, SetCustomColourText, VT_I4, VTS_I2)
@@ -8249,3 +8250,4 @@ static bool bInPluginListChanged = false;
82498250

82508251
} // end CMUSHclientDoc::PluginListChanged
82518252

8253+

doc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,6 +2670,7 @@ class CMUSHclientDoc : public CDocument
26702670
afx_msg long WindowScrollwheelHandler(LPCTSTR Name, LPCTSTR HotspotId, LPCTSTR MoveCallback);
26712671
afx_msg long WindowResize(LPCTSTR Name, long Width, long Height, long BackgroundColour);
26722672
afx_msg long WindowMoveHotspot(LPCTSTR Name, LPCTSTR HotspotId, long Left, long Top, long Right, long Bottom);
2673+
afx_msg long WindowTranslateImage(LPCTSTR Name, LPCTSTR ImageId, float Left, float Top, short Mode, float Mxx, float Mxy, float Myx, float Myy);
26732674
afx_msg long GetNormalColour(short WhichColour);
26742675
afx_msg void SetNormalColour(short WhichColour, long nNewValue);
26752676
afx_msg long GetBoldColour(short WhichColour);

miniwindow.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,7 @@ long CMiniWindow::DrawImage(LPCTSTR ImageId,
13001300
dc.SetBkMode (TRANSPARENT);
13011301

13021302
dc.SetStretchBltMode (HALFTONE); // looks better when squashed
1303+
SetBrushOrgEx(dc.m_hDC, 0, 0, NULL); // as recommended after SetStretchBltMode
13031304

13041305
BITMAP bi;
13051306
bitmap->GetBitmap(&bi);
@@ -4207,3 +4208,108 @@ long CMiniWindow::MoveHotspot(LPCTSTR HotspotId,
42074208
return eOK;
42084209
} // end of CMiniWindow::MoveHotspot
42094210

4211+
4212+
4213+
long CMiniWindow::TranslateImage(LPCTSTR ImageId, float Left, float Top, short Mode, float Mxx, float Mxy, float Myx, float Myy)
4214+
{
4215+
4216+
ImageMapIterator it = m_Images.find (ImageId);
4217+
4218+
if (it == m_Images.end ())
4219+
return eImageNotInstalled;
4220+
4221+
CBitmap * bitmap = it->second;
4222+
4223+
dc.SetBkMode (TRANSPARENT);
4224+
4225+
BITMAP bi;
4226+
bitmap->GetBitmap(&bi);
4227+
4228+
CDC bmDC;
4229+
bmDC.CreateCompatibleDC(&dc);
4230+
CBitmap *pOldbmp = bmDC.SelectObject(bitmap);
4231+
4232+
long iWidth = bi.bmWidth;
4233+
long iHeight = bi.bmHeight;
4234+
4235+
if (iWidth <= 0 || iHeight <= 0) // Sanity Claus
4236+
{
4237+
bmDC.SelectObject(pOldbmp);
4238+
return eOK;
4239+
}
4240+
4241+
// need advanced mode to do SetWorldTransform successfully
4242+
if (SetGraphicsMode (dc.m_hDC, GM_ADVANCED) == 0)
4243+
{
4244+
bmDC.SelectObject (pOldbmp);
4245+
return eBadParameter;
4246+
}
4247+
4248+
// x' = x * Mxx + y * Mxy + Dx,
4249+
// y' = x * Myx + y * Myy + Dy,
4250+
4251+
XFORM xform;
4252+
xform.eM11 = Mxx;
4253+
xform.eM12 = Mxy;
4254+
xform.eM21 = Myx;
4255+
xform.eM22 = Myy;
4256+
xform.eDx = Left;
4257+
xform.eDy = Top;
4258+
4259+
if (SetWorldTransform (dc.m_hDC, &xform) == 0)
4260+
{
4261+
bmDC.SelectObject(pOldbmp);
4262+
return eBadParameter;
4263+
}
4264+
4265+
switch (Mode)
4266+
{
4267+
case 1: dc.BitBlt (0, 0, iWidth, iHeight, &bmDC, 0, 0, SRCCOPY);
4268+
break; // straight copy
4269+
4270+
case 3: // transparency, nom nom nom!
4271+
{
4272+
COLORREF crOldBack = dc.SetBkColor (RGB (255, 255, 255)); // white
4273+
COLORREF crOldText = dc.SetTextColor (RGB (0, 0, 0)); // black
4274+
CDC dcTrans; // transparency mask
4275+
4276+
4277+
// Create a memory dc for the mask
4278+
dcTrans.CreateCompatibleDC(&dc);
4279+
4280+
// Create the mask bitmap for the subset of the main image
4281+
CBitmap bitmapTrans;
4282+
bitmapTrans.CreateBitmap(iWidth, iHeight, 1, 1, NULL);
4283+
4284+
// Select the mask bitmap into the appropriate dc
4285+
CBitmap* pOldBitmapTrans = dcTrans.SelectObject(&bitmapTrans);
4286+
4287+
// Our transparent pixel will be at 0,0 (top left corner) of original image (not subimage)
4288+
COLORREF crOldBackground = bmDC.SetBkColor (::GetPixel (bmDC, 0, 0));
4289+
4290+
// Build mask based on transparent colour at location 0, 0
4291+
dcTrans.BitBlt (0, 0, iWidth, iHeight, &bmDC, 0, 0, SRCCOPY);
4292+
4293+
// Do the work
4294+
dc.BitBlt (Left, Top, iWidth, iHeight, &bmDC, 0, 0, SRCINVERT);
4295+
dc.BitBlt (Left, Top, iWidth, iHeight, &dcTrans, 0, 0, SRCAND);
4296+
dc.BitBlt (Left, Top, iWidth, iHeight, &bmDC, 0, 0, SRCINVERT);
4297+
4298+
// Restore settings
4299+
dcTrans.SelectObject(pOldBitmapTrans);
4300+
dc.SetBkColor(crOldBack);
4301+
dc.SetTextColor(crOldText);
4302+
bmDC.SetBkColor(crOldBackground);
4303+
}
4304+
break;
4305+
4306+
default: return eBadParameter;
4307+
} // end of switch
4308+
4309+
bmDC.SelectObject(pOldbmp);
4310+
4311+
// reset to identity transformation
4312+
ModifyWorldTransform(dc.m_hDC, &xform, MWT_IDENTITY);
4313+
4314+
return eOK;
4315+
} // end of CMiniWindow::TranslateImage

mushclient.cnt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@
557557
3 WindowShow=FNC_WindowShow
558558
3 WindowText=FNC_WindowText
559559
3 WindowTextWidth=FNC_WindowTextWidth
560+
3 WindowTranslateImage=FNC_WindowTranslateImage
560561
3 WindowWrite=FNC_WindowWrite
561562
3 WorldAddress=FNC_WorldAddress
562563
3 WorldName=FNC_WorldName

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(402), propget] long NormalColour(short WhichColour);
74-
[id(402), propput] void NormalColour(short WhichColour, long nNewValue);
75-
[id(403), propget] long BoldColour(short WhichColour);
76-
[id(403), propput] void BoldColour(short WhichColour, long nNewValue);
77-
[id(404), propget] long CustomColourText(short WhichColour);
78-
[id(404), propput] void CustomColourText(short WhichColour, long nNewValue);
79-
[id(405), propget] long CustomColourBackground(short WhichColour);
80-
[id(405), propput] void CustomColourBackground(short WhichColour, long nNewValue);
73+
[id(403), propget] long NormalColour(short WhichColour);
74+
[id(403), propput] void NormalColour(short WhichColour, long nNewValue);
75+
[id(404), propget] long BoldColour(short WhichColour);
76+
[id(404), propput] void BoldColour(short WhichColour, long nNewValue);
77+
[id(405), propget] long CustomColourText(short WhichColour);
78+
[id(405), propput] void CustomColourText(short WhichColour, long nNewValue);
79+
[id(406), propget] long CustomColourBackground(short WhichColour);
80+
[id(406), 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);
@@ -433,6 +433,7 @@ library MUSHclient
433433
[id(399)] long WindowScrollwheelHandler(BSTR Name, BSTR HotspotId, BSTR MoveCallback);
434434
[id(400)] long WindowResize(BSTR Name, long Width, long Height, long BackgroundColour);
435435
[id(401)] long WindowMoveHotspot(BSTR Name, BSTR HotspotId, long Left, long Top, long Right, long Bottom);
436+
[id(402)] long WindowTranslateImage(BSTR Name, BSTR ImageId, float Left, float Top, short Mode, float Mxx, float Mxy, float Myx, float Myy);
436437
//}}AFX_ODL_METHOD
437438

438439
};

scripting/functionlist.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ tInternalFunctionsTable InternalFunctionsTable [] = {
417417
{ "WindowShow" , "( WindowName , Show )" } ,
418418
{ "WindowText" , "( WindowName , FontId , Text , Left , Top , Right , Bottom , Colour , Unicode )" } ,
419419
{ "WindowTextWidth" , "( WindowName , FontId , Text , Unicode )" } ,
420-
{ "WindowWrite" , "( WindowName , FileName )" } ,
420+
{ "WindowTranslateImage" , "( WindowName , ImageId , Left , Top , Mode , Mxx , Mxy , Myx , Myy ) " },
421+
{ "WindowWrite" , "( WindowName , FileName )" } ,
421422
{ "WorldAddress" , "( )" } ,
422423
{ "WorldName" , "( )" } ,
423424
{ "WorldPort" , "( )" } ,

scripting/lua_methods.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6315,6 +6315,26 @@ static int L_WindowTextWidth (lua_State *L)
63156315
return 1; // number of result fields
63166316
} // end of WindowTextWidth
63176317

6318+
//----------------------------------------
6319+
// world.WindowTranslateImage
6320+
//----------------------------------------
6321+
static int L_WindowTranslateImage (lua_State *L)
6322+
{
6323+
CMUSHclientDoc *pDoc = doc (L);
6324+
lua_pushnumber (L, pDoc->WindowTranslateImage (
6325+
my_checkstring (L, 1), // Name
6326+
my_checkstring (L, 2), // ImageId
6327+
my_checknumber (L, 3), // Left
6328+
my_checknumber (L, 4), // Top
6329+
my_checknumber (L, 5), // Mode
6330+
my_checknumber (L, 6), // Mxx
6331+
my_checknumber (L, 7), // Mxy
6332+
my_checknumber (L, 8), // Myx
6333+
my_checknumber (L, 9) // Myy
6334+
));
6335+
return 1; // number of result fields
6336+
} // end of L_WindowTranslateImage
6337+
63186338
//----------------------------------------
63196339
// world.WindowWrite
63206340
//----------------------------------------
@@ -6792,6 +6812,7 @@ static const struct luaL_reg worldlib [] =
67926812
{"WindowShow", L_WindowShow},
67936813
{"WindowText", L_WindowText},
67946814
{"WindowTextWidth", L_WindowTextWidth},
6815+
{"WindowTranslateImage", L_WindowTranslateImage},
67956816
{"WindowWrite", L_WindowWrite},
67966817
{"WorldAddress", L_WorldAddress},
67976818
{"WorldName", L_WorldName},

scripting/methods.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14890,6 +14890,18 @@ long CMUSHclientDoc::WindowMoveHotspot(LPCTSTR Name, LPCTSTR HotspotId, long Lef
1489014890
return it->second->MoveHotspot (HotspotId, Left, Top, Right, Bottom);
1489114891
} // end of CMUSHclientDoc::WindowMoveHotspot
1489214892

14893+
14894+
long CMUSHclientDoc::WindowTranslateImage(LPCTSTR Name, LPCTSTR ImageId, float Left, float Top, short Mode, float Mxx, float Mxy, float Myx, float Myy)
14895+
{
14896+
MiniWindowMapIterator it = m_MiniWindows.find (Name);
14897+
14898+
if (it == m_MiniWindows.end ())
14899+
return eNoSuchWindow;
14900+
14901+
return it->second->TranslateImage (ImageId, Left, Top, Mode, Mxx, Mxy, Myx, Myy);
14902+
}
14903+
14904+
1489314905
/*
1489414906
1489514907
======================================================================

0 commit comments

Comments
 (0)