Exemplo n.º 1
0
surface map_palette(surface s, int palette)
{
    if(palette < 0 || palette >= palettes.size() || palettes[palette].mapping.empty()) {
        return s;
    }

    surface result(SDL_CreateRGBSurface(SDL_SWSURFACE, s->w, s->h, 32, SURFACE_MASK));

    s = surface(SDL_ConvertSurface(s.get(), result->format, 0));

    ASSERT_LOG(s->format->BytesPerPixel == 4, "SURFACE NOT IN 32bpp PIXEL FORMAT");

    std::cerr << "mapping palette " << palette << "\n";


    uint32_t* dst = reinterpret_cast<uint32_t*>(result->pixels);
    const uint32_t* src = reinterpret_cast<const uint32_t*>(s->pixels);

    const std::map<uint32_t,uint32_t>& mapping = palettes[palette].mapping;

    for(int n = 0; n != s->w*s->h; ++n) {
        std::map<uint32_t,uint32_t>::const_iterator i = mapping.find(*src);
        if(i != mapping.end()) {
            *dst = i->second;
        } else {
            *dst = *src;
        }

        ++src;
        ++dst;
    }
    return result;
}
Exemplo n.º 2
0
void textbox::append_text(const std::string& text, bool auto_scroll, const SDL_Color& color)
{
	if(text_image_.get() == NULL) {
		set_text(text, color);
		return;
	}

	//disallow adding multi-line text to a single-line text box
	if(wrap_ == false && std::find_if(text.begin(),text.end(),utils::isnewline) != text.end()) {
		return;
	}
	const bool is_at_bottom = get_position() == get_max_position();
	const wide_string& wtext = utils::string_to_wstring(text);

	const surface new_text = add_text_line(wtext, color);
	const surface new_surface = create_compatible_surface(text_image_,std::max<size_t>(text_image_->w,new_text->w),text_image_->h+new_text->h);

	SDL_SetAlpha(new_text.get(),0,0);
	SDL_SetAlpha(text_image_.get(),0,0);

	SDL_BlitSurface(text_image_,NULL,new_surface,NULL);

	SDL_Rect target = {0,text_image_->h,new_text->w,new_text->h};
	SDL_BlitSurface(new_text,NULL,new_surface,&target);
	text_image_.assign(new_surface);

	text_.resize(text_.size() + wtext.size());
	std::copy(wtext.begin(),wtext.end(),text_.end()-wtext.size());

	set_dirty(true);
	update_text_cache(false);
	if(auto_scroll && is_at_bottom) scroll_to_bottom();
	handle_text_changed(text_);
}
Exemplo n.º 3
0
void run_formula(surface surf, const std::string& algo)
{
	const hi_res_timer timer("run_formula");

	const int ticks = SDL_GetTicks();
	surface_formula_symbol_table table(surf);
	game_logic::formula f(algo, &table);
	bool locked = false;
	if(SDL_MUSTLOCK(surf.get())) {
		const int res = SDL_LockSurface(surf.get());
		if(res == 0) {
			locked = true;
		}
	}

	std::map<Uint32, Uint32> pixel_map;

	Uint32* pixels = reinterpret_cast<Uint32*>(surf->pixels);
	Uint32* end_pixels = pixels + surf->w*surf->h;

	Uint32 AlphaPixel = SDL_MapRGBA(surf->format, 0x6f, 0x6d, 0x51, 0x0);

	int skip = 0;
	while(pixels != end_pixels) {
		if(((*pixels)&(~surf->format->Amask)) == AlphaPixel) {
			++pixels;
			continue;
		}
		std::map<Uint32, Uint32>::const_iterator itor = pixel_map.find(*pixels);
		if(itor == pixel_map.end()) {
			pixel_callable p(surf, *pixels);
			Uint32 result = f.execute(p).as_int();
			pixel_map[*pixels] = result;
			*pixels = result;
		} else {
			*pixels = itor->second;
		}
		++pixels;
	}

	if(locked) {
		SDL_UnlockSurface(surf.get());
	}
}
Exemplo n.º 4
0
static SDL_Cursor* get_cursor(cursor::CURSOR_TYPE type)
{
	bool is_color = use_color_cursors();
	if(cache[type] == NULL || indeterminate(cache_color[type]) || cache_color[type] != is_color) {
		const std::string prefix = is_color ? "cursors/" : "cursors-bw/";
		const surface surf(image::get_image(prefix + (is_color ? color_images : bw_images)[type]));
		if (is_color) {
			cache[type] = SDL_CreateColorCursor(surf.get(), shift_x[type], shift_y[type]);
		} else {
			cache[type] = create_cursor(surf);
		}
		cache_color[type] = is_color;
	}

	return cache[type];
}
Exemplo n.º 5
0
	void assign(const surface& s)
	{
		assign_surface_internal(s.get());
	}
Exemplo n.º 6
0
	surface(const surface& s) : surface_(s.get())
	{
		add_surface_ref(surface_);
	}
Exemplo n.º 7
0
bool operator<(const surface& a, const surface& b)
{
	return a.get() < b.get();
}