Skip to content

Commit

Permalink
Add UserWindow move and resize support. (Mudlet#1467)
Browse files Browse the repository at this point in the history
* add move & resize support for UserWindow instances.  

* changed resizeUserWindow to resizeWindow, to follow convention.
  • Loading branch information
itsTheFae authored Dec 23, 2017
1 parent 15a41e2 commit 3b02e6a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/TLuaInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2818,27 +2818,27 @@ int TLuaInterpreter::setBorderRight(lua_State* L)
return 0;
}

int TLuaInterpreter::resizeUserWindow(lua_State* L)
int TLuaInterpreter::resizeWindow(lua_State* L)
{
string luaSendText = "";
if (!lua_isstring(L, 1)) {
lua_pushstring(L, "resizeUserWindow: wrong argument type");
lua_pushstring(L, "resizeWindow: wrong argument type");
lua_error(L);
return 1;
} else {
luaSendText = lua_tostring(L, 1);
}
double x1;
if (!lua_isnumber(L, 2)) {
lua_pushstring(L, "resizeUserWindow: wrong argument type");
lua_pushstring(L, "resizeWindow: wrong argument type");
lua_error(L);
return 1;
} else {
x1 = lua_tonumber(L, 2);
}
double y1;
if (!lua_isnumber(L, 3)) {
lua_pushstring(L, "resizeUserWindow: wrong argument type");
lua_pushstring(L, "resizeWindow: wrong argument type");
lua_error(L);
return 1;
} else {
Expand Down Expand Up @@ -12055,7 +12055,7 @@ void TLuaInterpreter::initLuaGlobals()
lua_register(pGlobalLua, "startStopWatch", TLuaInterpreter::startStopWatch);
lua_register(pGlobalLua, "resetStopWatch", TLuaInterpreter::resetStopWatch);
lua_register(pGlobalLua, "closeUserWindow", TLuaInterpreter::closeUserWindow);
lua_register(pGlobalLua, "resizeWindow", TLuaInterpreter::resizeUserWindow);
lua_register(pGlobalLua, "resizeWindow", TLuaInterpreter::resizeWindow);
lua_register(pGlobalLua, "appendBuffer", TLuaInterpreter::appendBuffer);
lua_register(pGlobalLua, "setBackgroundImage", TLuaInterpreter::setBackgroundImage);
lua_register(pGlobalLua, "setBackgroundColor", TLuaInterpreter::setBackgroundColor);
Expand Down
2 changes: 1 addition & 1 deletion src/TLuaInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class TLuaInterpreter : public QThread
static int showUserWindow(lua_State*);
static int hideUserWindow(lua_State*);
static int closeUserWindow(lua_State*);
static int resizeUserWindow(lua_State*);
static int resizeWindow(lua_State*);
static int createStopWatch(lua_State*);
static int stopStopWatch(lua_State*);
static int getStopWatchTime(lua_State*);
Expand Down
24 changes: 22 additions & 2 deletions src/mudlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,12 +1642,22 @@ bool mudlet::resizeWindow(Host* pHost, const QString& name, int x1, int y1)
return true;
}

QMap<QString, TDockWidget*>& dockWindowMap = mHostDockConsoleMap[pHost];
QMap<QString, TConsole*>& dockWindowConsoleMap = mHostConsoleMap[pHost];
if (dockWindowConsoleMap.contains(name)) {
if (dockWindowConsoleMap.contains(name) && !dockWindowMap.contains(name)) {
dockWindowConsoleMap[name]->resize(x1, y1);
return true;
}

if (dockWindowMap.contains(name)) {
if (!dockWindowMap[name]->isFloating()) {
return false;
}

dockWindowMap[name]->resize(x1, y1);
return true;
}

return false;
}

Expand Down Expand Up @@ -1698,14 +1708,24 @@ bool mudlet::moveWindow(Host* pHost, const QString& name, int x1, int y1)
return true;
}

QMap<QString, TDockWidget*>& dockWindowMap = mHostDockConsoleMap[pHost];
QMap<QString, TConsole*>& dockWindowConsoleMap = mHostConsoleMap[pHost];
if (dockWindowConsoleMap.contains(name)) {
if (dockWindowConsoleMap.contains(name) && !dockWindowMap.contains(name)) {
dockWindowConsoleMap[name]->move(x1, y1);
dockWindowConsoleMap[name]->mOldX = x1;
dockWindowConsoleMap[name]->mOldY = y1;
return true;
}

if (dockWindowMap.contains(name)) {
if (!dockWindowMap[name]->isFloating()) {
dockWindowMap[name]->setFloating(true);
}

dockWindowMap[name]->move(x1, y1);
return true;
}

return false;
}

Expand Down

0 comments on commit 3b02e6a

Please sign in to comment.