Skip to content

Commit

Permalink
Added WindowResize and WindowMoveHotspot
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Aug 19, 2010
1 parent 77a1d28 commit d24d7a1
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 15 deletions.
7 changes: 6 additions & 1 deletion OtherTypes.h
Expand Up @@ -1196,7 +1196,7 @@ class CMiniWindow

CDC dc; // our offscreen device context
CBitmap * m_oldBitmap; // bitmap originally found in CMyMemDC
CBitmap m_Bitmap; // where it all happens
CBitmap * m_Bitmap; // where it all happens
FontMap m_Fonts; // all the fonts they want
ImageMap m_Images; // other images they may want to blt onto the window

Expand Down Expand Up @@ -1406,6 +1406,11 @@ class CMiniWindow
long Left, long Top, long Right, long Bottom,
long SrcLeft, long SrcTop);

long Resize(long Width, long Height, long BackgroundColour);

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


};

typedef map<string, CMiniWindow *> MiniWindowMap;
Expand Down
2 changes: 2 additions & 0 deletions doc.cpp
Expand Up @@ -602,6 +602,8 @@ BEGIN_DISPATCH_MAP(CMUSHclientDoc, CDocument)
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_FUNCTION(CMUSHclientDoc, "WindowScrollwheelHandler", WindowScrollwheelHandler, VT_I4, VTS_BSTR VTS_BSTR VTS_BSTR)
DISP_FUNCTION(CMUSHclientDoc, "WindowResize", WindowResize, VT_I4, VTS_BSTR VTS_I4 VTS_I4 VTS_I4)
DISP_FUNCTION(CMUSHclientDoc, "WindowMoveHotspot", WindowMoveHotspot, VT_I4, VTS_BSTR VTS_BSTR 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
2 changes: 2 additions & 0 deletions doc.h
Expand Up @@ -2668,6 +2668,8 @@ class CMUSHclientDoc : public CDocument
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 WindowScrollwheelHandler(LPCTSTR Name, LPCTSTR HotspotId, LPCTSTR MoveCallback);
afx_msg long WindowResize(LPCTSTR Name, long Width, long Height, long BackgroundColour);
afx_msg long WindowMoveHotspot(LPCTSTR Name, LPCTSTR HotspotId, long Left, long Top, long Right, long Bottom);
afx_msg long GetNormalColour(short WhichColour);
afx_msg void SetNormalColour(short WhichColour, long nNewValue);
afx_msg long GetBoldColour(short WhichColour);
Expand Down
86 changes: 80 additions & 6 deletions miniwindow.cpp
Expand Up @@ -16,6 +16,7 @@
// constructor
CMiniWindow::CMiniWindow () :
m_oldBitmap (NULL),
m_Bitmap (NULL),
m_iWidth (0), m_iHeight (0),
m_iPosition (0), m_iFlags (0),
m_iBackgroundColour (0), m_bShow (false),
Expand All @@ -34,12 +35,14 @@ CMiniWindow::~CMiniWindow () // destructor
{

// get rid of old one if any
if ((HBITMAP) m_Bitmap)
if (m_Bitmap)
{
dc.SelectObject(m_oldBitmap); // swap old one back
m_Bitmap.DeleteObject (); // delete the one we made
m_Bitmap->DeleteObject (); // delete the one we made
delete m_Bitmap;
}


// delete our fonts
for (FontMapIterator fit = m_Fonts.begin ();
fit != m_Fonts.end ();
Expand Down Expand Up @@ -145,15 +148,17 @@ void CMiniWindow::Create (long Left, long Top, long Width, long Height,
m_iBackgroundColour = BackgroundColour;

// get rid of old one if any
if ((HBITMAP) m_Bitmap)
if (m_Bitmap)
{
dc.SelectObject(m_oldBitmap); // swap old one back
m_Bitmap.DeleteObject ();
m_Bitmap->DeleteObject ();
}

m_Bitmap = new CBitmap;

// CreateBitmap with zero-dimensions creates a monochrome bitmap, so force to be at least 1x1
m_Bitmap.CreateBitmap (MAX (m_iWidth, 1), MAX (m_iHeight, 1), 1, GetDeviceCaps(dc, BITSPIXEL), NULL);
m_oldBitmap = dc.SelectObject (&m_Bitmap);
m_Bitmap->CreateBitmap (MAX (m_iWidth, 1), MAX (m_iHeight, 1), 1, GetDeviceCaps(dc, BITSPIXEL), NULL);
m_oldBitmap = dc.SelectObject (m_Bitmap);
dc.SetWindowOrg(0, 0);

dc.FillSolidRect (0, 0, m_iWidth, m_iHeight, m_iBackgroundColour);
Expand Down Expand Up @@ -4131,3 +4136,72 @@ long CMiniWindow::ScrollwheelHandler(CMUSHclientDoc * pDoc, LPCTSTR HotspotId, s


} // end of CMiniWindow::ScrollwheelHandler


// resize a window

long CMiniWindow::Resize(long Width, long Height, long BackgroundColour)
{

// no change to size? wow, that was easy ...
if (Width == m_iWidth && Height == m_iHeight)
return eOK;

// remember new width and height

m_iWidth = Width ;
m_iHeight = Height;

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

// select original bitmap out of device context
dc.SelectObject(m_oldBitmap);

// save old bitmap for copying from
CBitmap * previousWindowBitmap = m_Bitmap;

// select into new device context
CBitmap * pOldbmp = bmDC.SelectObject (previousWindowBitmap);

// make new bitmap for different size
m_Bitmap = new CBitmap;

// CreateBitmap with zero-dimensions creates a monochrome bitmap, so force to be at least 1x1
m_Bitmap->CreateBitmap (MAX (m_iWidth, 1), MAX (m_iHeight, 1), 1, GetDeviceCaps(dc, BITSPIXEL), NULL);
m_oldBitmap = dc.SelectObject (m_Bitmap);
dc.SetWindowOrg(0, 0);

// fill with requested border colour
dc.FillSolidRect (0, 0, m_iWidth, m_iHeight, BackgroundColour);

// copy old contents back
dc.BitBlt (0, 0, m_iWidth, m_iHeight, &bmDC, 0, 0, SRCCOPY);
bmDC.SelectObject(pOldbmp);

// done with previous bitmap from this miniwindow
previousWindowBitmap->DeleteObject ();
delete previousWindowBitmap;

return eOK;

} // end of CMiniWindow::Resize



// move a hotspot (maybe the window was resized)

long CMiniWindow::MoveHotspot(LPCTSTR HotspotId,
long Left, long Top, long Right, long Bottom)
{

HotspotMapIterator it = m_Hotspots.find (HotspotId);

if (it == m_Hotspots.end ())
return eHotspotNotInstalled;

it->second->m_rect = CRect (Left, Top, FixRight (Right), FixBottom (Bottom));

return eOK;
} // end of CMiniWindow::MoveHotspot

2 changes: 2 additions & 0 deletions mushclient.cnt
Expand Up @@ -547,9 +547,11 @@
3 WindowLoadImage=FNC_WindowLoadImage
3 WindowMenu=FNC_WindowMenu
3 WindowMergeImageAlpha=FNC_WindowMergeImageAlpha
3 WindowMoveHotspot=FNC_WindowMoveHotspot
3 WindowPolygon=FNC_WindowPolygon
3 WindowPosition=FNC_WindowPosition
3 WindowRectOp=FNC_WindowRectOp
3 WindowResize=FNC_WindowResize
3 WindowScrollwheelHandler=FNC_WindowScrollwheelHandler
3 WindowSetPixel=FNC_WindowSetPixel
3 WindowShow=FNC_WindowShow
Expand Down
18 changes: 10 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(400), propget] long NormalColour(short WhichColour);
[id(400), propput] void NormalColour(short WhichColour, long nNewValue);
[id(401), propget] long BoldColour(short WhichColour);
[id(401), propput] void BoldColour(short WhichColour, long nNewValue);
[id(402), propget] long CustomColourText(short WhichColour);
[id(402), propput] void CustomColourText(short WhichColour, long nNewValue);
[id(403), propget] long CustomColourBackground(short WhichColour);
[id(403), propput] void CustomColourBackground(short WhichColour, long nNewValue);
[id(402), propget] long NormalColour(short WhichColour);
[id(402), propput] void NormalColour(short WhichColour, long nNewValue);
[id(403), propget] long BoldColour(short WhichColour);
[id(403), propput] void BoldColour(short WhichColour, long nNewValue);
[id(404), propget] long CustomColourText(short WhichColour);
[id(404), propput] void CustomColourText(short WhichColour, long nNewValue);
[id(405), propget] long CustomColourBackground(short WhichColour);
[id(405), 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 @@ -431,6 +431,8 @@ library MUSHclient
[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);
[id(399)] long WindowScrollwheelHandler(BSTR Name, BSTR HotspotId, BSTR MoveCallback);
[id(400)] long WindowResize(BSTR Name, long Width, long Height, long BackgroundColour);
[id(401)] long WindowMoveHotspot(BSTR Name, BSTR HotspotId, long Left, long Top, long Right, long Bottom);
//}}AFX_ODL_METHOD

};
Expand Down
2 changes: 2 additions & 0 deletions scripting/functionlist.cpp
Expand Up @@ -407,8 +407,10 @@ tInternalFunctionsTable InternalFunctionsTable [] = {
{ "WindowLoadImage" , "( WindowName , ImageId , FileName )" } ,
{ "WindowMenu" , "( WindowName , Left , Top , Items )" } ,
{ "WindowMergeImageAlpha" , "( WindowName , ImageId , MaskId , Left , Top , Right , Bottom , Mode , Opacity , SrcLeft , SrcTop , SrcRight , SrcBottom )" } ,
{ "WindowMoveHotspot" , "( WindowName , HotspotId , Left , Top , Right , Bottom )" },
{ "WindowPolygon" , "( WindowName , Points , PenColour , PenStyle , PenWidth , BrushColour , BrushStyle , Close , Winding )" } ,
{ "WindowPosition" , "( WindowName , Left , Top , Position , Flags )" } ,
{ "WindowResize", "( WindowName , Width , Height , BackgroundColour )" },
{ "WindowRectOp" , "( WindowName , Action , Left , Top , Right , Bottom , Colour1 , Colour2 )" } ,
{ "WindowScrollwheelHandler" , "( WindowName , HotspotId , MoveCallback )" } ,
{ "WindowSetPixel" , "( WindowName , x , y , Colour )" } ,
Expand Down
36 changes: 36 additions & 0 deletions scripting/lua_methods.cpp
Expand Up @@ -6147,6 +6147,23 @@ static int L_WindowMergeImageAlpha (lua_State *L)
} // end of L_WindowMergeImageAlpha


//----------------------------------------
// world.WindowMoveHotspot
//----------------------------------------
static int L_WindowMoveHotspot (lua_State *L)
{
CMUSHclientDoc *pDoc = doc (L);
lua_pushnumber (L, pDoc->WindowMoveHotspot (
my_checkstring (L, 1), // Name
my_checkstring (L, 2), // HotspotId
my_checknumber (L, 3), // Left
my_checknumber (L, 4), // Top
my_checknumber (L, 5), // Right
my_checknumber (L, 6) // Bottom
));
return 1; // number of result fields
} // end of L_WindowMoveHotspot

//----------------------------------------
// world.WindowPolygon
//----------------------------------------
Expand Down Expand Up @@ -6203,6 +6220,23 @@ static int L_WindowRectOp (lua_State *L)
return 1; // number of result fields
} // end of L_WindowRectOp


//----------------------------------------
// world.WindowResize
//----------------------------------------
static int L_WindowResize (lua_State *L)
{
CMUSHclientDoc *pDoc = doc (L);
lua_pushnumber (L, pDoc->WindowResize (
my_checkstring (L, 1), // Name
my_checknumber (L, 2), // Width
my_checknumber (L, 3), // Height
my_checknumber (L, 4) // Background Colour
));

return 1; // number of result fields
} // end of L_WindowResize

//----------------------------------------
// world.WindowScrollwheelHandler
//----------------------------------------
Expand Down Expand Up @@ -6748,9 +6782,11 @@ static const struct luaL_reg worldlib [] =
{"WindowLoadImageMemory", L_WindowLoadImageMemory},
{"WindowMenu", L_WindowMenu},
{"WindowMergeImageAlpha", L_WindowMergeImageAlpha},
{"WindowMoveHotspot", L_WindowMoveHotspot},
{"WindowPolygon", L_WindowPolygon},
{"WindowPosition", L_WindowPosition},
{"WindowRectOp", L_WindowRectOp},
{"WindowResize", L_WindowResize},
{"WindowScrollwheelHandler", L_WindowScrollwheelHandler},
{"WindowSetPixel", L_WindowSetPixel},
{"WindowShow", L_WindowShow},
Expand Down
26 changes: 26 additions & 0 deletions scripting/methods.cpp
Expand Up @@ -14864,6 +14864,32 @@ long CMUSHclientDoc::WindowGetImageAlpha(LPCTSTR Name, LPCTSTR ImageId, long Lef
} // end of CMUSHclientDoc::WindowGetImageAlpha



long CMUSHclientDoc::WindowResize(LPCTSTR Name, long Width, long Height, long BackgroundColour)
{

if (Width < 0 || Height < 0)
return eBadParameter;

MiniWindowMapIterator it = m_MiniWindows.find (Name);

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

return it->second->Resize (Width, Height, BackgroundColour);
} // end of CMUSHclientDoc::WindowResize


long CMUSHclientDoc::WindowMoveHotspot(LPCTSTR Name, LPCTSTR HotspotId, long Left, long Top, long Right, long Bottom)
{
MiniWindowMapIterator it = m_MiniWindows.find (Name);

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

return it->second->MoveHotspot (HotspotId, Left, Top, Right, Bottom);
} // end of CMUSHclientDoc::WindowMoveHotspot

/*

======================================================================
Expand Down

0 comments on commit d24d7a1

Please sign in to comment.