예제 #1
0
파일: ui_lua.cpp 프로젝트: rikus--/Epiar
/**\brief Append an option to this Dropdown
 * \note Tables of strings will be flattened and added
 */
int UI_Lua::AddOption(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n < 2)
		return luaL_error(L, "Got %d arguments expected at least 2 (self OPTION [OPTION ...])", n);

	Widget *widget = checkWidget(L, 1);
	luaL_argcheck(L, widget->GetMask() & WIDGET_DROPDOWN, 1, "`Dropdown' expected.");
	Dropdown *dropdown = (Dropdown*)widget;

	// Add the options
	for(int arg = 2; arg <= n; ++arg){
		if( lua_istable(L, arg) ) {
			// Tables can be lists of strings
			list<string>::iterator i;
			list<string> values = Lua::getStringListField( arg );
			for(i = values.begin(); i != values.end(); ++i) {
				dropdown->AddOption( (*i) );
			}
		} else {
			// Everything else is converted into a string
			string option = lua_tostring(L, arg);
			dropdown->AddOption( option );
		}
	}

	return 0;
}
예제 #2
0
/**\brief Tests if point is within a rectangle.
 */
int Widget::GetAbsX( void ) {
	int absx = GetX();
	Widget* theParent = parent;
	while( theParent != NULL ) {
		assert( theParent->GetMask() & WIDGET_CONTAINER );
		absx += theParent->GetX();
		theParent = theParent->parent;
	}
	return absx;
}
예제 #3
0
파일: ui_lua.cpp 프로젝트: rikus--/Epiar
/** \brief Set Widget Text
 *  \todo This should support more widget types.
 */
int UI_Lua::setText(lua_State *L){
	int n = lua_gettop(L);  // Number of arguments
	if (n != 2)
		return luaL_error(L, "Got %d arguments expected 2 (self, text)", n);

	Widget *widget = checkWidget(L,1);
	string text = luaL_checkstring(L, 2);

	int mask = widget->GetMask();
	mask &= ~WIDGET_CONTAINER; // Turn off the Container flag.
	switch( mask ) {
		// These Widget types currently support setText
		case WIDGET_LABEL:
			((Label*)(widget))->SetText( text );
			break;
		case WIDGET_TEXTBOX:
			((Textbox*)(widget))->SetText( text );
			break;

		case WIDGET_BUTTON:
			((Button*)(widget))->SetText( text );
			break;
		case WIDGET_DROPDOWN:
			((Dropdown*)(widget))->SetText( text );
			break;
		// TODO These Widget Types do not currently accept setText, but they should.
		case WIDGET_TAB:
		case WIDGET_WINDOW:
			return luaL_error(L, "Epiar does not currently calling setText on Widgets of type '%s'.", (widget)->GetType().c_str() );
			break;

		// These Widget Types can't accept setText.
		case WIDGET_TABS:
		case WIDGET_FRAME:
		case WIDGET_SLIDER:
		case WIDGET_PICTURE:
		case WIDGET_CHECKBOX:
		case WIDGET_SCROLLBAR:
		case WIDGET_CONTAINER:
		default:
			return luaL_error(L, "Cannot setText to Widget of type '%s'.", (widget)->GetType().c_str() );
	}

	return 0;
}