Exemple #1
0
int CLuaInstCCText::CCTextScroll(lua_State *L)
{
	lua_assert(lua_istable(L,1));
	CLuaCCText *D = CCTextCheck(L, 1);
	if (!D) return 0;

	std::string tmp = "true";
	tableLookup(L, "dir", tmp);
	bool scrollDown = (tmp == "down" || tmp == "1");
	lua_Integer pages = 1;
	tableLookup(L, "pages", pages);

	//get the textbox instance from lua object and use CTexBbox scroll methods
	CTextBox* ctb = D->ct->getCTextBoxObject();
	if (ctb) {
		if (pages == -1)
			pages = ctb->getPages();
		ctb->enableBackgroundPaint(true);
		if (scrollDown)
			ctb->scrollPageDown(pages);
		else
			ctb->scrollPageUp(pages);
		ctb->enableBackgroundPaint(false);
	}
	return 0;
}
int CLuaInstProgressWindow::CProgressWindowSetTitle(lua_State *L)
{
	lua_assert(lua_istable(L,1));
	CLuaCProgressWindow *D = CProgressWindowCheck(L, 1);
	if (!D) return 0;

	std::string name = "";
	tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name);

	D->w->setTitle(name);
	return 0;
}
int CLuaInstProgressWindow::CProgressWindowHide(lua_State *L)
{
	lua_assert(lua_istable(L,1));
	CLuaCProgressWindow *D = CProgressWindowCheck(L, 1);
	if (!D) return 0;

	bool tmp1 = false;
	std::string tmp2 = "false";
	if ((tableLookup(L, "no_restore", tmp1)) || (tableLookup(L, "no_restore", tmp2)))
		obsoleteHideParameter(L);

	D->w->hide();
	return 0;
}
int CLuaInstProgressWindow::CProgressWindowPaint(lua_State *L)
{
	lua_assert(lua_istable(L,1));
	CLuaCProgressWindow *D = CProgressWindowCheck(L, 1);
	if (!D) return 0;

	bool do_save_bg = true;
	if (!tableLookup(L, "do_save_bg", do_save_bg)) {
		std::string tmp = "true";
		if (tableLookup(L, "do_save_bg", tmp))
			paramBoolDeprecated(L, tmp.c_str());
		do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes");
	}
	D->w->paint(do_save_bg);
	return 0;
}
Exemple #5
0
int CLuaInstCCText::CCTextEnableUTF8(lua_State *L)
{
	lua_assert(lua_istable(L,1));
	CLuaCCText *D = CCTextCheck(L, 1);
	if (!D) return 0;

	bool utf8_encoded = true;
	if (!tableLookup(L, "utf8_encoded", utf8_encoded)) {
		std::string tmp = "true";
		if (tableLookup(L, "utf8_encoded", tmp))
			paramBoolDeprecated(L, tmp.c_str());
		utf8_encoded = (tmp == "true" || tmp == "1" || tmp == "yes");
	}
	D->ct->enableUTF8(utf8_encoded);
	return 0;
}
Exemple #6
0
int CLuaInstCCText::CCTextSetText(lua_State *L)
{
	lua_assert(lua_istable(L,1));
	CLuaCCText *D = CCTextCheck(L, 1);
	if (!D) return 0;

	std::string text = "";
	lua_Integer mode = D->mode;
	lua_Integer font_text = D->font_text;
	tableLookup(L, "text", text);
	tableLookup(L, "mode", mode);
	tableLookup(L, "font_text", font_text);

	D->ct->setText(text, mode, g_Font[font_text]);
	return 0;
}
Exemple #7
0
/*
 * Load Train Data (Signatures and respective names) from a directory
 * Returns the number of signatures read
 * TODO: make this windows compatible
 */
TrainData *Database::loadTrainDataFromDir(string dir, int *n)
{
	Sig sig;
	vector<string> files = vector<string>();
	string fname, temp;
	char buf[1024];
	unsigned int ii;
	TrainData *data;

    getFileList(dir, files);
    
    data = new TrainData [files.size()];
    getcwd(buf, 1024);		// save current dir
//    cout << "Changing CWD to " << dir << "." << endl;
    chdir(dir.c_str());		// change current dir to data dir
    for (ii = 0; ii < files.size(); ii++) {
        fname = files[ii];
//        cout << "Reading " << fname << "." << endl;
        sig.load(fname);
        data[ii].name = filenameToName(files[ii]);	// Get Name from sig file
        data[ii].sigArr = sig.toArray();			// convert sig to array
        data[ii].value = (double) tableLookup(data[ii].name);	/* get value
        														 * (table index)
        														 */
    }
//    cout << "Back to previous CWD." << endl;
    chdir(buf);			// change back to original working dir
//    cout << "Read a total of " << ii << " files." << endl;
    *n = ii;
    return data;
}
Exemple #8
0
int CLuaInstCCText::CCTextHide(lua_State *L)
{
	lua_assert(lua_istable(L,1));
	CLuaCCText *D = CCTextCheck(L, 1);
	if (!D) return 0;

	bool tmp1 = false;
	std::string tmp2 = "false";
	if ((tableLookup(L, "no_restore", tmp1)) || (tableLookup(L, "no_restore", tmp2)))
		obsoleteHideParameter(L);

	if (D->parent) {
		D->ct->setText("", D->mode, g_Font[D->font_text]);
		D->ct->paint();
	} else
		D->ct->hide();
	return 0;
}
Exemple #9
0
int CLuaInstCCHeader::CCHeaderPaint(lua_State *L)
{
	lua_assert(lua_istable(L,1));
	CLuaCCHeader *D = CCHeaderCheck(L, 1);
	if (!D) return 0;

	bool do_save_bg = true;
	tableLookup(L, "do_save_bg", do_save_bg);

	D->ch->paint(do_save_bg);
	return 0;
}
int CLuaInstProgressWindow::CProgressWindowShowStatusInternal(lua_State *L, bool local)
{
	lua_assert(lua_istable(L,1));
	CLuaCProgressWindow *D = CProgressWindowCheck(L, 1);
	if (!D) return 0;

	lua_Unsigned prog;
	std::string statusText  = std::string();
	lua_Integer max 	= 100 ;

	tableLookup(L, "prog", prog);
	tableLookup(L, "statusText", statusText);
	tableLookup(L, "max", max);

	if (local)
		D->w->showLocalStatus(prog, max, statusText);
	else
		D->w->showGlobalStatus(prog, max, statusText);

	return 0;
}
int CLuaInstProgressWindow::CProgressWindowNew(lua_State *L)
{
	lua_assert(lua_istable(L,1));

	std::string name = "";
	tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name);

	CLuaCProgressWindow **udata = (CLuaCProgressWindow **) lua_newuserdata(L, sizeof(CLuaCProgressWindow *));
	*udata = new CLuaCProgressWindow();

#if 0
	/* Enable when pu/fb-setmode branch is merged in master */
	(*udata)->w = new CProgressWindow(name);
#else
	(*udata)->w = new CProgressWindow();
	(*udata)->w->setTitle(name);
#endif

	luaL_getmetatable(L, "cprogresswindow");
	lua_setmetatable(L, -2);
	return 1;
}
Exemple #12
0
int CLuaInstCCText::CCTextSetCenterPos(lua_State *L)
{
	lua_assert(lua_istable(L,1));
	CLuaCCText *D = CCTextCheck(L, 1);
	if (!D) return 0;
	lua_Integer  tmp_along_mode, along_mode = CC_ALONG_X | CC_ALONG_Y;
	tableLookup(L, "along_mode", tmp_along_mode);

	if (tmp_along_mode & CC_ALONG_X || tmp_along_mode & CC_ALONG_Y)
		along_mode=tmp_along_mode;

	D->ct->setCenterPos(along_mode);
	return 0;
}
Exemple #13
0
int CLuaInstCCHeader::CCHeaderNew(lua_State *L)
{
	lua_assert(lua_istable(L,1));

	CLuaCCWindow* parent = NULL;
	lua_Integer x=10, y=10, dx=100, dy=100;
	lua_Integer buttons = 0;
	lua_Integer shadow_mode = CC_SHADOW_OFF;

	std::string caption, icon;
	lua_Unsigned color_frame  = (lua_Unsigned)COL_FRAME_PLUS_0;
	lua_Unsigned color_body   = (lua_Unsigned)COL_MENUCONTENT_PLUS_0;
	lua_Unsigned color_shadow = (lua_Unsigned)COL_SHADOW_PLUS_0;

	tableLookup(L, "parent",       (void**)&parent);
	tableLookup(L, "x",            x);
	tableLookup(L, "y",            y);
	tableLookup(L, "dx",           dx);
	tableLookup(L, "dy",           dy);
	tableLookup(L, "caption",      caption);
	tableLookup(L, "icon",         icon);
	tableLookup(L, "shadow_mode",  shadow_mode);
	tableLookup(L, "color_frame",  color_frame);
	tableLookup(L, "color_body" ,  color_body);
	tableLookup(L, "color_shadow", color_shadow);

	color_frame  = checkMagicMask(color_frame);
	color_body   = checkMagicMask(color_body);
	color_shadow = checkMagicMask(color_shadow);

	CComponentsForm* pw = (parent && parent->w) ? parent->w->getBodyObject() : NULL;
	CLuaCCHeader **udata = (CLuaCCHeader **) lua_newuserdata(L, sizeof(CLuaCCHeader *));
	*udata = new CLuaCCHeader();
	(*udata)->ch = new CComponentsHeader((const int&)x, (const int&)y, (const int&)dx, (const int&)dy,
					     caption, (std::string)"", (const int&)buttons,
					     (CComponentsForm*)parent, (int)shadow_mode,
					     (fb_pixel_t)color_frame, (fb_pixel_t)color_body, (fb_pixel_t)color_shadow);
	(*udata)->parent = pw;
	luaL_getmetatable(L, LUA_HEADER_CLASSNAME);
	lua_setmetatable(L, -2);
	return 1;
}
Exemple #14
0
int CLuaInstCCText::CCTextNew(lua_State *L)
{
	lua_assert(lua_istable(L,1));

	CLuaCCWindow* parent = NULL;
	lua_Integer x=10, y=10, dx=-1, dy=-1;
	std::string text = "";
	std::string tmpMode       = "";
	lua_Integer mode          = CTextBox::AUTO_WIDTH;
	lua_Integer font_text     = SNeutrinoSettings::FONT_TYPE_MENU;
	lua_Unsigned color_text   = (lua_Unsigned)COL_MENUCONTENT_TEXT;
	lua_Unsigned color_frame  = (lua_Unsigned)COL_FRAME_PLUS_0;
	lua_Unsigned color_body   = (lua_Unsigned)COL_MENUCONTENT_PLUS_0;
	lua_Unsigned color_shadow = (lua_Unsigned)COL_SHADOW_PLUS_0;

	tableLookup(L, "parent",    (void**)&parent);
	tableLookup(L, "x",         x);
	tableLookup(L, "y",         y);
	tableLookup(L, "dx",        dx);
	tableLookup(L, "dy",        dy);
	tableLookup(L, "text",      text);
	tableLookup(L, "mode",      tmpMode);
	tableLookup(L, "font_text", font_text);
	if (font_text >= SNeutrinoSettings::FONT_TYPE_COUNT || font_text < 0)
		font_text = SNeutrinoSettings::FONT_TYPE_MENU;

	lua_Integer shadow_mode = CC_SHADOW_OFF;
	if (!tableLookup(L, "has_shadow", shadow_mode)) {
		std::string tmp1 = "false";
		if (tableLookup(L, "has_shadow", tmp1))
			paramBoolDeprecated(L, tmp1.c_str());
		shadow_mode = (tmp1 == "true" || tmp1 == "1" || tmp1 == "yes");
	}

	tableLookup(L, "color_text",   color_text);
	tableLookup(L, "color_frame",  color_frame);
	tableLookup(L, "color_body",   color_body);
	tableLookup(L, "color_shadow", color_shadow);

	color_text   = checkMagicMask(color_text);
	color_frame  = checkMagicMask(color_frame);
	color_body   = checkMagicMask(color_body);
	color_shadow = checkMagicMask(color_shadow);

	if (!tmpMode.empty()) {
		table_key txt_align[] = {
			{ "ALIGN_AUTO_WIDTH",		CTextBox::AUTO_WIDTH },
			{ "ALIGN_AUTO_HIGH",		CTextBox::AUTO_HIGH },
			{ "ALIGN_SCROLL",		CTextBox::SCROLL },
			{ "ALIGN_CENTER",		CTextBox::CENTER },
			{ "ALIGN_RIGHT",		CTextBox::RIGHT },
			{ "ALIGN_TOP",			CTextBox::TOP },
			{ "ALIGN_BOTTOM",		CTextBox::BOTTOM },
			{ "ALIGN_NO_AUTO_LINEBREAK",	CTextBox::NO_AUTO_LINEBREAK },
			{ "DECODE_HTML",		0 },
			{ NULL,				0 }
		};
		mode = 0;
		for (int i = 0; txt_align[i].name; i++) {
			if (tmpMode.find(txt_align[i].name) != std::string::npos)
				mode |= txt_align[i].code;
		}
		if (tmpMode.find("DECODE_HTML") != std::string::npos)
			htmlEntityDecode(text);
	}

	CComponentsForm* pw = (parent && parent->w) ? parent->w->getBodyObject() : NULL;
	if(pw){
		if(dy < 1)
			dy = pw->getHeight();
		if(dx < 1)
			dx = pw->getWidth();
	}
	if(dx < 1)
		dx = 100;
	if(dy < 1)
		dy = 100;

	CLuaCCText **udata = (CLuaCCText **) lua_newuserdata(L, sizeof(CLuaCCText *));
	*udata = new CLuaCCText();
	(*udata)->ct = new CComponentsText(x, y, dx, dy, text, mode, g_Font[font_text], 0 /*TODO: style not passed*/, pw, shadow_mode, (fb_pixel_t)color_text, (fb_pixel_t)color_frame, (fb_pixel_t)color_body, (fb_pixel_t)color_shadow);
	(*udata)->parent = pw;
	(*udata)->mode = mode;
	(*udata)->font_text = font_text;
	luaL_getmetatable(L, "ctext");
	lua_setmetatable(L, -2);
	return 1;
}