예제 #1
0
int jiveL_slider_draw(lua_State *L) {

	/* stack is:
	 * 1: widget
	 * 2: surface
	 * 3: layer
	 */

	SliderWidget *peer = jive_getpeer(L, 1, &sliderPeerMeta);
	JiveSurface *srf = tolua_tousertype(L, 2, 0);
	bool drawLayer = luaL_optinteger(L, 3, JIVE_LAYER_ALL) & peer->w.layer;

	if (!drawLayer) {
		return 0;
	}

	if (peer->bg) {
		jive_tile_blit(peer->bg, srf, peer->w.bounds.x + peer->slider_x, peer->w.bounds.y + peer->slider_y, peer->w.bounds.w, peer->w.bounds.h);
	}

	if (peer->tile) {
		int height, width;
		int range, value, size;
		int x, y, w, h;
		Uint16 tw, th;

		height = peer->w.bounds.h - peer->w.padding.top - peer->w.padding.bottom;
		width = peer->w.bounds.w - peer->w.padding.left - peer->w.padding.right;
	
		lua_getfield(L, 1, "range");
		range = lua_tointeger(L, -1);

		lua_getfield(L, 1, "value");
		value = lua_tointeger(L, -1);
		lua_pop(L, 2);

		lua_getfield(L, 1, "size");
		size = lua_tointeger(L, -1);
		lua_pop(L, 2);

		jive_tile_get_min_size(peer->tile, &tw, &th);

		if (peer->horizontal) {
			width -= tw;
			x = (width / (float)(range - 1)) * (value - 1);
			w = (width / (float)(range - 1)) * (size - 1) + tw;
			y = 0;
			h = height;
			peer->pill_x = peer->w.bounds.x + peer->slider_x + peer->w.padding.left + (w - tw);
			peer->pill_y = peer->w.bounds.y + peer->slider_y + peer->w.padding.top + y;
		}
		else {
			height -= th;
			x = 0;
			w = width;
			y = (height / (float)(range - 1)) * (value - 1);
			h = (height / (float)(range - 1)) * (size - 1) + th;
			peer->pill_x = peer->w.bounds.x + peer->slider_x + peer->w.padding.left + x;
			peer->pill_y = peer->w.bounds.y + peer->slider_y + peer->w.padding.top + (h - th);
		}

		jive_tile_blit(peer->tile, srf, peer->w.bounds.x + peer->slider_x + peer->w.padding.left + x, peer->w.bounds.y + peer->slider_y + peer->w.padding.top + y, w, h);

		if (peer->pill_img) {
			jive_surface_blit(peer->pill_img, srf, peer->pill_x, peer->pill_y);
		}
	}

	return 0;
}
예제 #2
0
int jiveL_textinput_draw(lua_State *L) {
	Uint16 offset_x, offset_y, offset_cursor_y;
	JiveSurface *tsrf;

	/* stack is:
	 * 1: widget
	 * 2: surface
	 * 3: layer
	 */

	TextinputWidget *peer = jive_getpeer(L, 1, &textinputPeerMeta);
	JiveSurface *srf = *(JiveSurface **)lua_touserdata(L, 2);
	bool drawLayer = luaL_optinteger(L, 3, JIVE_LAYER_ALL) & peer->w.layer;

	const char *text;
	size_t cursor, text_len;
	int indent;
	SDL_Rect pop_clip, new_clip;
	Uint16 text_h, text_x, text_y, text_cy, text_w, cursor_x, cursor_w, cursor_h;
	const char *validchars, *validchars_end;
	unsigned int len_1, len_2, len_3;
	unsigned int text_offset, cursor_offset, cursor_width;
	int i;


	/* get value as string */
	lua_getfield(L, 1, "value");
	lua_getglobal(L, "tostring");
	lua_getfield(L, 1, "value");
	lua_call(L, 1, 1);

	text = lua_tostring(L, -1);

	lua_getfield(L, 1, "cursor");
	cursor = lua_tointeger(L, -1);

	lua_getfield(L, 1, "cursorWidth");
	cursor_width = lua_tointeger(L, -1);
	if (cursor_width > strlen(text)) {
		cursor_width = strlen(text);
	}
	if (cursor_width == 0) {
		cursor--;
	}

	lua_getfield(L, 1, "indent");
	indent = lua_tointeger(L, -1);
	text += indent;
	cursor -= indent;

	text_len = strlen(text);

	/* calculate positions */
	text_h = peer->char_height;
	text_x = peer->w.bounds.x + peer->w.padding.left;
	text_y = peer->w.bounds.y + peer->w.padding.top + ((peer->w.bounds.h - peer->w.padding.top - peer->w.padding.bottom - text_h) / 2);
	text_cy = text_y + (peer->char_height / 2);
	text_w = peer->w.bounds.w - peer->w.padding.left - peer->w.padding.right;

	if (peer->cursor_tile) {
		jive_tile_get_min_size(peer->cursor_tile, &cursor_w, &cursor_h);
	} else {
		//doesn't work well, but at least doesn't crash jive, really cursorImg needs to be set
		cursor_w = 0;
		cursor_h = 0;
//temp test values
//		cursor_w = 55;
//		cursor_h = 54;
	}

	/* measure text */
	len_1 = jive_font_nwidth(peer->font, text, cursor - cursor_width);
	len_2 = jive_font_nwidth(peer->cursor_font, text + cursor - cursor_width, cursor_width);
	len_3 = (cursor < text_len) ? jive_font_width(peer->font, text + cursor) : 0;

	if (cursor_w < len_2) {
		cursor_w = len_2;
	}

	/* move ident if cursor is off stage right */
	while (len_1 + cursor_w > text_w) {
		indent++;
		text++;
		text_len--;
		cursor--;

		len_1 = jive_font_nwidth(peer->font, text, cursor - cursor_width);
		len_2 = jive_font_nwidth(peer->cursor_font, text + cursor - cursor_width, cursor_width);
		len_3 = (cursor < text_len) ? jive_font_width(peer->font, text + cursor) : 0;
	}

	/* move ident if cursor is off stage left and fill out space if indent present*/
	while (indent > 0 && (len_1 <= 0 || len_1 + len_2 + len_3 < text_w)) {

		indent--;
		text--;
		text_len++;
		cursor++;

		len_1 = jive_font_nwidth(peer->font, text, cursor - cursor_width);
		len_2 = jive_font_nwidth(peer->cursor_font, text + cursor - cursor_width, cursor_width);
		len_3 = (cursor < text_len) ? jive_font_width(peer->font, text + cursor) : 0;
	}

	/* keep cursor fixed distance from stage right */
	if (len_1 > text_w - ceil(cursor_w * 1.5)) {
		int d = (text_w - ceil(cursor_w * 1.5)) - len_1;

		text_x += d;
	}

#if 0
	/* keep cursor fixed distance from stage left */
	if (len_1 < ceil(cursor_w * 1.5)) {
		int d = (cursor_w) - len_1;

		if (len_1 > d) {
			text_x += d;
		}
	}
#endif

	lua_pushinteger(L, indent);
	lua_setfield(L, 1, "indent");

	text_offset = jive_font_offset(peer->font);
	cursor_offset = jive_font_offset(peer->cursor_font);

	cursor_x = text_x + len_1;


	offset_y = peer->char_offset_y + (((cursor_h / 2) - jive_font_height(peer->font)) / 2) - text_offset;
	offset_cursor_y = peer->char_offset_y + (((cursor_h / 2) - jive_font_height(peer->cursor_font)) / 2) - cursor_offset;

	/* Valid characters */
	jive_getmethod(L, 1, "_getChars");
	lua_pushvalue(L, 1);
	lua_call(L, 1, 1);

	validchars = lua_tostring(L, -1);
	validchars_end = validchars + strlen(validchars) - 1;

	//jive_surface_boxColor(srf, peer->w.bounds.x, peer->w.bounds.y, peer->w.bounds.x + peer->w.bounds.w, peer->w.bounds.y + peer->w.bounds.h, 0xFF00007F); // XXXX

	/* background clip */
	new_clip.x = peer->w.bounds.x;
	new_clip.y = peer->w.bounds.y;
	new_clip.w = peer->w.bounds.w;
	new_clip.h = peer->w.bounds.h;
	jive_surface_push_clip(srf, &new_clip, &pop_clip);

	/* draw wheel */
	if (drawLayer && peer->wheel_tile && strlen(validchars)) {
		int w = cursor_w;
		int h = peer->w.bounds.h - peer->w.padding.top - peer->w.padding.bottom;
		jive_tile_blit_centered(peer->wheel_tile, srf, cursor_x + (w / 2), peer->w.bounds.y + peer->w.padding.top + (h / 2), w, h);
	}

	/* draw background */
	if (drawLayer && peer->bg_tile) {
		jive_tile_blit_centered(peer->bg_tile, srf, peer->w.bounds.x + (peer->w.bounds.w / 2), text_y + (text_h / 2), peer->w.bounds.w, text_h);
	}


	/* draw cursor */
	if (drawLayer && peer->cursor_tile) {
		jive_tile_blit_centered(peer->cursor_tile, srf, cursor_x + (cursor_w / 2), text_cy, cursor_w, text_h);
	}

	jive_surface_set_clip(srf, &pop_clip);


	/* content clip */
	new_clip.x = peer->w.bounds.x + peer->w.padding.left;
	new_clip.y = peer->w.bounds.y + peer->w.padding.top;
	new_clip.w = peer->w.bounds.w - peer->w.padding.left - peer->w.padding.right;
	new_clip.h = peer->w.bounds.h - peer->w.padding.top - peer->w.padding.bottom;
	jive_surface_push_clip(srf, &new_clip, &pop_clip);

	/* draw text label */
	if (drawLayer && peer->font) {
	  
		if (peer->is_sh) {
			/* pre-cursor */
			tsrf = jive_font_ndraw_text(peer->font, peer->sh, text, cursor - cursor_width);
			jive_surface_blit(tsrf, srf, text_x + 1, text_y + offset_y + 1);
			jive_surface_free(tsrf);

			/* cursor */
			tsrf = jive_font_ndraw_text(peer->cursor_font, peer->sh, text + cursor - cursor_width, cursor_width);
			jive_surface_blit(tsrf, srf, cursor_x + (cursor_w - len_2) / 2 + 1, text_y + offset_cursor_y + 1);
			jive_surface_free(tsrf);

			/* post-cursor */
			if (cursor < text_len) {
				tsrf = jive_font_draw_text(peer->font, peer->sh, text + cursor);
				jive_surface_blit(tsrf, srf, cursor_x + cursor_w + 1, text_y + offset_y + 1);
				jive_surface_free(tsrf);
			}
		}

		/* pre-cursor */
		tsrf = jive_font_ndraw_text(peer->font, peer->fg, text, cursor - cursor_width);
		jive_surface_blit(tsrf, srf, text_x, text_y + offset_y);
		jive_surface_free(tsrf);

		/* cursor */
		tsrf = jive_font_ndraw_text(peer->cursor_font, peer->cursor_color, text + cursor - cursor_width, cursor_width);
		jive_surface_blit(tsrf, srf, cursor_x + (cursor_w - len_2) / 2, text_y + offset_cursor_y);
		jive_surface_free(tsrf);

		/* post-cursor */
		if (cursor < text_len) {
			tsrf = jive_font_draw_text(peer->font, peer->fg, text + cursor);
			jive_surface_blit(tsrf, srf, cursor_x + cursor_w, text_y + offset_y);
			jive_surface_free(tsrf);
		}

		if ((cursor > text_len || cursor == 0) && peer->enter_tile) {
			/* draw enter in cursor */
			jive_tile_blit_centered(peer->enter_tile, srf, text_x + len_1 + (cursor_w / 2), text_cy, 0, 0);
		}
/*
		//removed per the whims of the ui guys
		else if (peer->enter_tile) {
			//draw enter
			Uint16 cw, ch;

			x = len_1 + cursor_w + len_3;
			jive_tile_get_min_size(peer->enter_tile, &cw, &ch);
			jive_tile_blit_centered(peer->enter_tile, srf, text_x + x + (cw / 2), text_cy, 0, 0);
		}
*/
	}

	if (drawLayer) {
		const char *ptr_up, *ptr_down, *ptr;

		if (cursor > 1 && cursor > text_len) {
			/* new char, keep cursor near the last letter */
			ptr_up = strchr(validchars, text[cursor - 2]) - 1;
			ptr_down = ptr_up + 1;
		}
		else {
			ptr_up = strchr(validchars, text[cursor - 1]) - 1;
			ptr_down = ptr_up + 2;
		}

		/* Draw wheel up */
		ptr = ptr_up;
		for (i=1; i <= (peer->w.bounds.h - peer->w.padding.top - peer->w.padding.bottom) / 2 / peer->wheel_char_height; i++) {
			if (ptr < validchars) {
				ptr = validchars_end;
			}
			else if (ptr > validchars_end) {
				ptr = validchars;
			}

			offset_x = (cursor_w - jive_font_nwidth(peer->wheel_font, ptr, 1)) / 2;
			
			tsrf = jive_font_ndraw_text(peer->wheel_font, peer->wh, ptr, 1);
			jive_surface_blit(tsrf, srf, cursor_x + offset_x, text_cy - (cursor_h / 2) + (-i * peer->wheel_char_height) + jive_font_miny_char(peer->wheel_font, ptr[0]) - peer->wheel_char_offset_y);
			jive_surface_free(tsrf);

			ptr--; // FIXME utf8
		}
		
		/* Draw wheel down */
		ptr = ptr_down;
		for (i=1; i <= (peer->w.bounds.h - peer->w.padding.top - peer->w.padding.bottom) / 2 / peer->wheel_char_height; i++) {
			if (ptr < validchars) {
				ptr = validchars_end;
			}
			else if (ptr > validchars_end) {
				ptr = validchars;
			}

			offset_x = (cursor_w - jive_font_nwidth(peer->wheel_font, ptr, 1)) / 2;
			
			tsrf = jive_font_ndraw_text(peer->wheel_font, peer->wh, ptr, 1);
			jive_surface_blit(tsrf, srf, cursor_x + offset_x, text_cy + (cursor_h / 2) + ((i - 1) * peer->wheel_char_height) );
			jive_surface_free(tsrf);

			ptr++; // FIXME utf8
		}
	}

	/* draw wheel mask */
	if (drawLayer && peer->wheel_mask_tile && strlen(validchars)) {
		int w = cursor_w;
		int h = peer->w.bounds.h - peer->w.padding.top - peer->w.padding.bottom;
		jive_tile_blit_centered(peer->wheel_mask_tile, srf, cursor_x + (w / 2), peer->w.bounds.y + peer->w.padding.top + (h / 2), w, h);
	}


	jive_surface_set_clip(srf, &pop_clip);

	lua_pop(L, 4);

	return 0;
}
예제 #3
0
int jiveL_textarea_draw(lua_State *L) {
	char *text;
	Uint16 y;
	int i, top_line, visible_lines, bottom_line, num_lines;
	Sint16 old_pixel_offset_x, old_pixel_offset_y, new_pixel_offset_y;
	int y_offset = 0;
	bool is_menu_child = false;

	/* stack is:
	 * 1: widget
	 * 2: surface
	 * 3: layer
	 */

	TextareaWidget *peer = jive_getpeer(L, 1, &textareaPeerMeta);
	JiveSurface *srf = tolua_tousertype(L, 2, 0);
	bool drawLayer = luaL_optinteger(L, 3, JIVE_LAYER_ALL) & peer->w.layer;
	SDL_Rect pop_clip, new_clip;

	if (!drawLayer || peer->num_lines == 0) {
		return 0;
	}

	if (peer->bg_tile) {
		jive_tile_blit(peer->bg_tile, srf, peer->w.bounds.x, peer->w.bounds.y, peer->w.bounds.w, peer->w.bounds.h);
	}

	lua_getfield(L, 1, "isHeaderWidget");
	if (lua_toboolean(L, -1)) {
		//y offset not used for header widget, not sure why it should ever auto-apply
		y_offset = peer->y_offset;

		//adjust clip height so we don't draw below parent's bounds
		lua_getfield(L, 1, "parent");
		if (jive_getmethod(L, -1, "getBounds")) {
			lua_pushvalue(L, -2);
			lua_call(L, 1, 4);

			new_clip.h  = lua_tointeger(L, -1) - peer->w.padding.top - peer->w.padding.bottom;
			lua_pop(L, 4);
		}
		lua_pop(L, 1);
	} else {
		new_clip.h = peer->w.bounds.h - peer->w.padding.top;
	}

	lua_pop(L, 1);

	new_clip.x = peer->w.bounds.x;
	new_clip.y = peer->w.bounds.y + peer->w.padding.top;
	new_clip.w = peer->w.bounds.w;

	//Fairly ugly hack to support textarea as a menu item for multiline_text style
	//Otherwise, for the extra hidden menu item for smooth scrolling, the textarea will draw into iconbar
	lua_getfield(L, 1, "isMenuChild");
	if (lua_toboolean(L, -1)) {
		is_menu_child = true;
	}
	lua_pop(L, 1);
/*
	if (lua_toboolean(L, -1)) {
		lua_getfield(L, 1, "parent"); //group
		lua_getfield(L, -1, "parent"); //menu
		if (jive_getmethod(L, -1, "getBounds")) {
			int menu_h, menu_y;
			lua_pushvalue(L, -2);
			lua_call(L, 1, 4);
			menu_h  = lua_tointeger(L, -1);
			menu_y  = lua_tointeger(L, -3);
			lua_pop(L, 4);

			//if bottom of textarea is below bottom of bounding menu, don't draw
			if (new_clip.h + new_clip.y > menu_h + menu_y) {
				lua_pop(L, 1);
				lua_pop(L, 1);
				return 0;

			}
		}
		lua_pop(L, 1);
		lua_pop(L, 1);
	}
	lua_pop(L, 1);
*/
	jive_surface_push_clip(srf, &new_clip, &pop_clip);


	lua_getglobal(L, "tostring");
	lua_getfield(L, 1, "text");
	if (lua_isnil(L, -1) && !peer->font) {
		lua_pop(L, 2);
		return 0;
	}
	lua_call(L, 1, 1);

	text = (char *) lua_tostring(L, -1);

	y = peer->w.bounds.y + peer->w.padding.top - peer->text_offset + y_offset;

	lua_getfield(L, 1, "topLine");
	top_line = lua_tointeger(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, 1, "visibleLines");
	visible_lines = lua_tointeger(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, 1, "numLines");
	num_lines = lua_tointeger(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, 1, "pixelOffsetY");
	new_pixel_offset_y = lua_tointeger(L, -1);
	lua_pop(L, 1);

	jive_surface_get_offset(srf, &old_pixel_offset_x, &old_pixel_offset_y);
	if (!is_menu_child) {
		jive_surface_set_offset(srf, old_pixel_offset_x, new_pixel_offset_y);
	}

	bottom_line = top_line + visible_lines;

	for (i = top_line; i < bottom_line + 1 && i < num_lines ; i++) {
		JiveSurface *tsrf;
		int x;

		int line = peer->lines[i];
		int next = peer->lines[i+1];

		unsigned char b = text[(next - 1)];
		unsigned char c = text[next];
		text[next] = '\0';
		if (b == '\n') {
			text[(next - 1)] = '\0';
		}

		x = peer->w.bounds.x + peer->w.padding.left;
		switch (peer->align) {
		case JIVE_ALIGN_CENTER:
		case JIVE_ALIGN_TOP:
		case JIVE_ALIGN_BOTTOM: {
			Uint16 line_width = jive_font_width(peer->font, &text[line]);
			x = jive_widget_halign((JiveWidget *)peer, peer->align, line_width);
			break;
		}
		default:
			break;
		}

		/* shadow text */
		if (peer->is_sh) {
			tsrf = jive_font_draw_text(peer->font, peer->sh, &text[line]);
			jive_surface_blit(tsrf, srf, x + 1, y + 1);
			jive_surface_free(tsrf);
		}

		/* foreground text */
		tsrf = jive_font_draw_text(peer->font, peer->fg, &text[line]);
		jive_surface_blit(tsrf, srf, x, y);
		jive_surface_free(tsrf);

		text[next] = c;
		text[(next - 1)] = b;

		y += peer->line_height;
	}
	if (!is_menu_child) {
		jive_surface_set_offset(srf, old_pixel_offset_x, old_pixel_offset_y);
	}
	jive_surface_set_clip(srf, &pop_clip);

	/* draw scrollbar */
	if (peer->has_scrollbar && !peer->is_header_widget) {
		lua_getfield(L, 1, "scrollbar");
		if (!lua_isnil(L, -1) && jive_getmethod(L, -1, "draw")) {
			lua_pushvalue(L, -2);
			lua_pushvalue(L, 2);
			lua_pushvalue(L, 3);
			lua_call(L, 3, 0);
		}	
		lua_pop(L, 1);
	}

	return 0;
}
예제 #4
0
static int jiveL_initSDL(lua_State *L) {
	const SDL_VideoInfo *video_info;
#ifndef JIVE_NO_DISPLAY
	JiveSurface *srf, *splash;
	Uint16 splash_w, splash_h;
	bool fullscreen = false;
	char splashfile[32] = "jive/splash.png";
#endif
	/* logging */
	log_ui_draw = LOG_CATEGORY_GET("squeezeplay.ui.draw");
	log_ui = LOG_CATEGORY_GET("squeezeplay.ui");

	/* linux fbcon does not need a mouse */
	SDL_putenv("SDL_NOMOUSE=1");

#ifdef JIVE_NO_DISPLAY
#   define JIVE_SDL_FEATURES (SDL_INIT_EVENTLOOP)
#else
#   define JIVE_SDL_FEATURES (SDL_INIT_VIDEO)
#endif
	/* initialise SDL */
	if (SDL_Init(JIVE_SDL_FEATURES) < 0) {
		LOG_ERROR(log_ui_draw, "SDL_Init(V|T|A): %s\n", SDL_GetError());
		SDL_Quit();
		exit(-1);
	}

	/* report video info */
	if ((video_info = SDL_GetVideoInfo())) {
		LOG_INFO(log_ui_draw, "%d,%d %d bits/pixel %d bytes/pixel [R<<%d G<<%d B<<%d]", video_info->current_w, video_info->current_h, video_info->vfmt->BitsPerPixel, video_info->vfmt->BytesPerPixel, video_info->vfmt->Rshift, video_info->vfmt->Gshift, video_info->vfmt->Bshift);
		LOG_INFO(log_ui_draw, "Hardware acceleration %s available", video_info->hw_available?"is":"is not");
		LOG_INFO(log_ui_draw, "Window Manager %s available", video_info->wm_available?"is":"is not");
	}

	/* Register callback for additional events (used for multimedia keys)*/
	SDL_EventState(SDL_SYSWMEVENT,SDL_ENABLE);
	SDL_SetEventFilter(filter_events);

	// Secific magic for windows|linux|macos
	platform_init(L);

#ifndef JIVE_NO_DISPLAY

	/* open window */
	SDL_WM_SetCaption("SqueezePlay", "SqueezePlay");
	SDL_ShowCursor(SDL_DISABLE);
	SDL_EnableKeyRepeat (100, 100);
	SDL_EnableUNICODE(1);


#ifdef SCREEN_ROTATION_ENABLED
	screen_w = video_info->current_h;
	screen_h = video_info->current_w;
#else
	screen_w = video_info->current_w;
	screen_h = video_info->current_h;
#endif
	screen_bpp = video_info->vfmt->BitsPerPixel;

	if (video_info->wm_available) {
		/* desktop build */
		JiveSurface *icon;

		/* load the icon */
		icon = jive_surface_load_image("jive/app.png");
		if (icon) {
			jive_surface_set_wm_icon(icon);
			jive_surface_free(icon);
		}

		splash = jive_surface_load_image(splashfile);
		if (splash) {
			jive_surface_get_size(splash, &splash_w, &splash_h);

			screen_w = splash_w;
			screen_h = splash_h;
		}
	} else {
		/* product build and full screen...*/

		sprintf(splashfile, "jive/splash%dx%d.png", screen_w, screen_h);

		splash = jive_surface_load_image(splashfile);
		if(!splash) {
			sprintf(splashfile,"jive/splash.png");
			splash = jive_surface_load_image(splashfile);
		}

		if (splash) {
			jive_surface_get_size(splash, &splash_w, &splash_h);
		}

		fullscreen = true;
	}

	srf = jive_surface_set_video_mode(screen_w, screen_h, screen_bpp, fullscreen);
	if (!srf) {
		LOG_ERROR(log_ui_draw, "Video mode not supported: %dx%d\n", screen_w, screen_h);

		SDL_Quit();
		exit(-1);
	}

	if (splash) {
		jive_surface_blit(splash, srf, (screen_w - splash_w) > 0 ?((screen_w - splash_w) / 2):0, (screen_w - splash_w) > 0 ?((screen_w - splash_w) / 2):0);
		jive_surface_flip(srf);
		LOG_INFO(log_ui_draw, "Splash %s %dx%d Screen %dx%d", splashfile,splash_w,splash_h,screen_w,screen_h);
	}

	lua_getfield(L, 1, "screen");
	if (lua_isnil(L, -1)) {
		LOG_ERROR(log_ui_draw, "no screen table");

		SDL_Quit();
		exit(-1);
	}

	/* store screen surface */
	tolua_pushusertype(L, srf, "Surface");
	lua_setfield(L, -2, "surface");

	lua_getfield(L, -1, "bounds");
	lua_pushinteger(L, screen_w);
	lua_rawseti(L, -2, 3);
	lua_pushinteger(L, screen_h);
	lua_rawseti(L, -2, 4);
	lua_pop(L, 2);

	/* background image */
	jive_background = jive_tile_fill_color(0x000000FF);

	/* jive.ui.style = {} */
	lua_getglobal(L, "jive");
	lua_getfield(L, -1, "ui");
	lua_newtable(L);
	lua_setfield(L, -2, "style");
	lua_pop(L, 2);

	ui_watchdog = watchdog_get();
	watchdog_keepalive(ui_watchdog, 6); /* 60 seconds to start */

#endif /* JIVE_NO_DISPLAY */

	return 0;
}
예제 #5
0
static int jiveL_initSDL(lua_State *L) {
	const SDL_VideoInfo *video_info;
	JiveSurface *srf, *splash, *icon;
	Uint16 splash_w, splash_h;

	/* logging */
	log_ui_draw = LOG_CATEGORY_GET("jivelite.ui.draw");
	log_ui = LOG_CATEGORY_GET("jivelite.ui");

	/* linux fbcon does not need a mouse */
	SDL_putenv("SDL_NOMOUSE=1");

	/* allow the screensaver */
	SDL_putenv("SDL_VIDEO_ALLOW_SCREENSAVER=1");

	/* initialise SDL */
	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		LOG_ERROR(log_ui_draw, "SDL_Init(V|T|A): %s\n", SDL_GetError());
		SDL_Quit();
		exit(-1);
	}

	/* report video info */
	if ((video_info = SDL_GetVideoInfo())) {
		LOG_INFO(log_ui_draw, "%d,%d %d bits/pixel %d bytes/pixel [R<<%d G<<%d B<<%d]", video_info->current_w, video_info->current_h, video_info->vfmt->BitsPerPixel, video_info->vfmt->BytesPerPixel, video_info->vfmt->Rshift, video_info->vfmt->Gshift, video_info->vfmt->Bshift);
		LOG_INFO(log_ui_draw, "Hardware acceleration %s available", video_info->hw_available?"is":"is not");
		LOG_INFO(log_ui_draw, "Window manager %s available", video_info->wm_available?"is":"is not");
	}

	/* Register callback for additional events (used for multimedia keys)*/
	SDL_EventState(SDL_SYSWMEVENT,SDL_ENABLE);
	SDL_SetEventFilter(filter_events);

	platform_init(L);

	/* open window */
	SDL_WM_SetCaption("JiveLite Alpha", "JiveLite Alpha");
	SDL_ShowCursor(SDL_DISABLE);
	SDL_EnableKeyRepeat (100, 100);
	SDL_EnableUNICODE(1);

	/* load the icon */
	icon = jive_surface_load_image("jive/app.png");
	if (icon) {
		jive_surface_set_wm_icon(icon);
		jive_surface_free(icon);
	}

	screen_w = video_info->current_w;
	screen_h = video_info->current_h;

	screen_bpp = video_info->vfmt->BitsPerPixel;

	splash = jive_surface_load_image("jive/splash.png");
	if (splash) {
		jive_surface_get_size(splash, &splash_w, &splash_h);
		if (video_info->wm_available) {
			screen_w = splash_w;
			screen_h = splash_h;
		}
	}

	srf = jive_surface_set_video_mode(screen_w, screen_h, screen_bpp, video_info->wm_available ? false : true);
	if (!srf) {
		SDL_Quit();
		exit(-1);
	}

	if (splash) {
		jive_surface_blit(splash, srf, MAX(0, (screen_w - splash_w) / 2), MAX(0, (screen_h - splash_h) / 2));
		jive_surface_flip(srf);
	}

	lua_getfield(L, 1, "screen");
	if (lua_isnil(L, -1)) {
		LOG_ERROR(log_ui_draw, "no screen table");

		SDL_Quit();
		exit(-1);
	}

	/* store screen surface */
	JiveSurface **p = (JiveSurface **)lua_newuserdata(L, sizeof(JiveSurface *));
	*p = jive_surface_ref(srf);
	luaL_getmetatable(L, "JiveSurface");
	lua_setmetatable(L, -2);

	lua_setfield(L, -2, "surface");

	lua_getfield(L, -1, "bounds");
	lua_pushinteger(L, screen_w);
	lua_rawseti(L, -2, 3);
	lua_pushinteger(L, screen_h);
	lua_rawseti(L, -2, 4);
	lua_pop(L, 2);

	/* background image */
	jive_background = jive_tile_fill_color(0x000000FF);

	/* jive.ui.style = {} */
	lua_getglobal(L, "jive");
	lua_getfield(L, -1, "ui");
	lua_newtable(L);
	lua_setfield(L, -2, "style");
	lua_pop(L, 2);

	return 0;
}