From d24d7a1c84b12d202ee7a3729594ec80ea2c6bfa Mon Sep 17 00:00:00 2001 From: Nick Gammon Date: Thu, 19 Aug 2010 13:24:52 +1000 Subject: [PATCH] Added WindowResize and WindowMoveHotspot --- OtherTypes.h | 7 +++- doc.cpp | 2 + doc.h | 2 + miniwindow.cpp | 86 +++++++++++++++++++++++++++++++++++--- mushclient.cnt | 2 + mushclient.odl | 18 ++++---- scripting/functionlist.cpp | 2 + scripting/lua_methods.cpp | 36 ++++++++++++++++ scripting/methods.cpp | 26 ++++++++++++ 9 files changed, 166 insertions(+), 15 deletions(-) diff --git a/OtherTypes.h b/OtherTypes.h index 3c0c0973..c01191cb 100644 --- a/OtherTypes.h +++ b/OtherTypes.h @@ -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 @@ -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 MiniWindowMap; diff --git a/doc.cpp b/doc.cpp index 22d9e202..05cc0d79 100644 --- a/doc.cpp +++ b/doc.cpp @@ -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) diff --git a/doc.h b/doc.h index 7280931f..f36203c7 100644 --- a/doc.h +++ b/doc.h @@ -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); diff --git a/miniwindow.cpp b/miniwindow.cpp index 98d87ed3..d10fa58c 100644 --- a/miniwindow.cpp +++ b/miniwindow.cpp @@ -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), @@ -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 (); @@ -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); @@ -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 + diff --git a/mushclient.cnt b/mushclient.cnt index 2a42f801..defadf12 100644 --- a/mushclient.cnt +++ b/mushclient.cnt @@ -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 diff --git a/mushclient.odl b/mushclient.odl index 51195119..b285dc42 100644 --- a/mushclient.odl +++ b/mushclient.odl @@ -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); @@ -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 }; diff --git a/scripting/functionlist.cpp b/scripting/functionlist.cpp index 6d3abd43..9f40e006 100644 --- a/scripting/functionlist.cpp +++ b/scripting/functionlist.cpp @@ -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 )" } , diff --git a/scripting/lua_methods.cpp b/scripting/lua_methods.cpp index 32c852f2..75cc15ae 100644 --- a/scripting/lua_methods.cpp +++ b/scripting/lua_methods.cpp @@ -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 //---------------------------------------- @@ -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 //---------------------------------------- @@ -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}, diff --git a/scripting/methods.cpp b/scripting/methods.cpp index 7d5c985b..57c18f6f 100644 --- a/scripting/methods.cpp +++ b/scripting/methods.cpp @@ -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 + /* ======================================================================