2012-01-23 06:36:15 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 Matt King, Birunthan Mohanathas
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2011-07-05 13:41:05 +00:00
|
|
|
#include "../../StdAfx.h"
|
|
|
|
#include "../LuaManager.h"
|
|
|
|
#include "../../Rainmeter.h"
|
|
|
|
#include "../../MeterWindow.h"
|
|
|
|
#include "../../MeterString.h"
|
|
|
|
|
|
|
|
static int MeterWindow_MoveWindow(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
|
|
|
int x = (int)tolua_tonumber(L, 2, 0);
|
|
|
|
int y = (int)tolua_tonumber(L, 3, 0);
|
|
|
|
|
|
|
|
self->MoveWindow(x, y);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_FadeWindow(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
|
|
|
int from = (int)tolua_tonumber(L, 2, 0);
|
|
|
|
int to = (int)tolua_tonumber(L, 3, 0);
|
|
|
|
self->FadeWindow(from, to);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_GetSkinName(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
|
|
|
const std::wstring& val = self->GetSkinName();
|
2011-09-03 16:45:29 +00:00
|
|
|
LuaManager::PushWide(L, val.c_str());
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_GetSkinIniFile(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
|
|
|
const std::wstring& val = self->GetSkinIniFile();
|
2011-09-03 16:45:29 +00:00
|
|
|
LuaManager::PushWide(L, val.c_str());
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_GetW(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
|
|
|
int val = (int)self->GetW();
|
2011-07-27 10:42:35 +00:00
|
|
|
lua_pushnumber(L, (lua_Number)val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_GetH(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
|
|
|
int val = (int)self->GetH();
|
2011-07-27 10:42:35 +00:00
|
|
|
lua_pushnumber(L, (lua_Number)val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_GetX(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
|
|
|
int val = (int)self->GetX();
|
2011-07-27 10:42:35 +00:00
|
|
|
lua_pushnumber(L, (lua_Number)val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_GetY(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
|
|
|
int val = (int)self->GetY();
|
2011-07-27 10:42:35 +00:00
|
|
|
lua_pushnumber(L, (lua_Number)val);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_MakePathAbsolute(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
2011-11-28 14:13:20 +00:00
|
|
|
std::wstring path = LuaManager::ToWide(L, 2);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
2011-11-28 14:13:20 +00:00
|
|
|
self->MakePathAbsolute(path);
|
|
|
|
LuaManager::PushWide(L, path.c_str());
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_GetMeter(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
2011-09-03 16:45:29 +00:00
|
|
|
const std::wstring meterName = LuaManager::ToWide(L, 2);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
CMeter* meter = self->GetMeter(meterName);
|
|
|
|
if (!meter)
|
|
|
|
{
|
|
|
|
std::wstring error = L"Script: No such meter as ";
|
|
|
|
error += meterName;
|
|
|
|
Log(LOG_ERROR, error.c_str());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-08 15:19:05 +00:00
|
|
|
tolua_pushusertype(L, meter, "CMeter");
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_GetMeasure(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
2011-09-03 16:45:29 +00:00
|
|
|
const std::wstring measureName = LuaManager::ToWide(L, 2);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
CMeasure* val = self->GetMeasure(measureName);
|
|
|
|
tolua_pushusertype(L, (void*)val, "CMeasure");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-07-06 20:12:05 +00:00
|
|
|
static int MeterWindow_GetVariable(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
2011-09-03 16:45:29 +00:00
|
|
|
std::wstring strTmp = LuaManager::ToWide(L, 2);
|
2011-07-06 20:12:05 +00:00
|
|
|
|
|
|
|
if (self->GetParser().GetVariable(strTmp, strTmp))
|
|
|
|
{
|
2011-09-03 16:45:29 +00:00
|
|
|
LuaManager::PushWide(L, strTmp.c_str());
|
2011-07-06 20:12:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-05 13:41:05 +00:00
|
|
|
static int MeterWindow_ReplaceVariables(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
2011-09-03 16:45:29 +00:00
|
|
|
std::wstring strTmp = LuaManager::ToWide(L, 2);
|
2011-07-06 20:12:05 +00:00
|
|
|
|
|
|
|
self->GetParser().ReplaceVariables(strTmp);
|
2011-09-03 16:45:29 +00:00
|
|
|
LuaManager::PushWide(L, strTmp.c_str());
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MeterWindow_Bang(lua_State* L)
|
|
|
|
{
|
|
|
|
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
|
2011-09-03 16:45:29 +00:00
|
|
|
std::wstring strTmp = LuaManager::ToWide(L, 2);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
2011-07-06 20:12:05 +00:00
|
|
|
CConfigParser& parser = self->GetParser();
|
|
|
|
parser.ReplaceVariables(strTmp);
|
|
|
|
self->GetMainObject()->ExecuteCommand(strTmp.c_str(), self);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaManager::RegisterMeterWindow(lua_State* L)
|
|
|
|
{
|
|
|
|
tolua_usertype(L, "CMeterWindow");
|
2011-07-29 17:18:21 +00:00
|
|
|
tolua_cclass(L, "CMeterWindow", "CMeterWindow", "", NULL);
|
2011-07-05 13:41:05 +00:00
|
|
|
|
|
|
|
tolua_beginmodule(L, "CMeterWindow");
|
|
|
|
tolua_function(L, "MoveWindow", MeterWindow_MoveWindow);
|
|
|
|
tolua_function(L, "FadeWindow", MeterWindow_FadeWindow);
|
|
|
|
tolua_function(L, "GetSkinName", MeterWindow_GetSkinName);
|
|
|
|
tolua_function(L, "GetSkinIniFile", MeterWindow_GetSkinIniFile);
|
|
|
|
tolua_function(L, "GetW", MeterWindow_GetW);
|
|
|
|
tolua_function(L, "GetH", MeterWindow_GetH);
|
|
|
|
tolua_function(L, "GetX", MeterWindow_GetX);
|
|
|
|
tolua_function(L, "GetY", MeterWindow_GetY);
|
|
|
|
tolua_function(L, "MakePathAbsolute", MeterWindow_MakePathAbsolute);
|
|
|
|
tolua_function(L, "GetMeter", MeterWindow_GetMeter);
|
|
|
|
tolua_function(L, "GetMeasure", MeterWindow_GetMeasure);
|
2011-07-06 20:12:05 +00:00
|
|
|
tolua_function(L, "GetVariable", MeterWindow_GetVariable);
|
2011-07-05 13:41:05 +00:00
|
|
|
tolua_function(L, "ReplaceVariables", MeterWindow_ReplaceVariables);
|
|
|
|
tolua_function(L, "Bang", MeterWindow_Bang);
|
|
|
|
tolua_endmodule(L);
|
|
|
|
}
|