/* generate mini maps */ void Interface::Radar::Generate(void) { const u16 world_w = world.w(); const u16 world_h = world.h(); const u8 n = world.w() == Maps::SMALL ? 4 : 2; Surface tile_surface(n, n); for(s32 index = 0; index < world_w * world_h; ++index) { const Maps::Tiles & tile = world.GetTiles(index); u32 color = COLOR_ROAD; if(tile.isRoad()) tile_surface.Fill(tile_surface.GetColorIndex(color)); else if(0 != (color = GetPaletteIndexFromGround(tile.GetGround()))) tile_surface.Fill(tile_surface.GetColorIndex(tile.GetObject() == MP2::OBJ_MOUNTS ? color + 2 : color)); else continue; float dstx = (index % world_w) * w / world_w; float dsty = (index / world_h) * h / world_w; tile_surface.Blit(static_cast<u16>(dstx), static_cast<u16>(dsty), *spriteArea); } }
mate_bg_crossfade_set_start_pixmap (MateBGCrossfade* fade, GdkPixmap *surface) #endif { g_return_val_if_fail (MATE_IS_BG_CROSSFADE (fade), FALSE); if (fade->priv->fading_surface != NULL) { cairo_surface_destroy (fade->priv->fading_surface); fade->priv->fading_surface = NULL; } fade->priv->fading_surface = tile_surface (surface, fade->priv->width, fade->priv->height); return fade->priv->fading_surface != NULL; }
/** * gnome_bg_crossfade_set_start_surface: * @fade: a #GnomeBGCrossfade * @surface: The cairo surface to fade from * * Before initiating a crossfade with gnome_bg_crossfade_start() * a start and end surface have to be set. This function sets * the surface shown at the beginning of the crossfade effect. * * Return value: %TRUE if successful, or %FALSE if the surface * could not be copied. **/ gboolean gnome_bg_crossfade_set_start_surface (GnomeBGCrossfade *fade, cairo_surface_t *surface) { g_return_val_if_fail (GNOME_IS_BG_CROSSFADE (fade), FALSE); if (fade->priv->fading_surface != NULL) { cairo_surface_destroy (fade->priv->fading_surface); fade->priv->fading_surface = NULL; } fade->priv->fading_surface = tile_surface (surface, fade->priv->width, fade->priv->height); return fade->priv->fading_surface != NULL; }
mate_bg_crossfade_set_end_pixmap (MateBGCrossfade* fade, GdkPixmap *surface) #endif { g_return_val_if_fail (MATE_IS_BG_CROSSFADE (fade), FALSE); if (fade->priv->end_surface != NULL) { cairo_surface_destroy (fade->priv->end_surface); fade->priv->end_surface = NULL; } fade->priv->end_surface = tile_surface (surface, fade->priv->width, fade->priv->height); /* Reset timer in case we're called while animating */ fade->priv->start_time = get_current_time (); return fade->priv->end_surface != NULL; }
/** * gnome_bg_crossfade_set_end_surface: * @fade: a #GnomeBGCrossfade * @surface: The cairo surface to fade to * * Before initiating a crossfade with gnome_bg_crossfade_start() * a start and end surface have to be set. This function sets * the surface shown at the end of the crossfade effect. * * Return value: %TRUE if successful, or %FALSE if the surface * could not be copied. **/ gboolean gnome_bg_crossfade_set_end_surface (GnomeBGCrossfade *fade, cairo_surface_t *surface) { g_return_val_if_fail (GNOME_IS_BG_CROSSFADE (fade), FALSE); if (fade->priv->end_surface != NULL) { cairo_surface_destroy (fade->priv->end_surface); fade->priv->end_surface = NULL; } fade->priv->end_surface = tile_surface (surface, fade->priv->width, fade->priv->height); /* Reset timer in case we're called while animating */ fade->priv->start_time = get_current_time (); return fade->priv->end_surface != NULL; }
void part_ui::prepare_background() { #ifdef SDL_GPU base_rect_.w = video_.getx(); base_rect_.h = video_.gety(); has_background_ = false; bool no_base_yet = true; BOOST_FOREACH(const background_layer& bl, p_.get_background_layers()) { sdl::timage layer; if (!bl.file().empty()) { layer = image::get_texture(bl.file()); } has_background_ = has_background_ || !layer.null(); if(layer.null() || layer.width() * layer.height() == 0) { continue; } const double xscale = 1.0 * video_.getx() / layer.base_width(); const double yscale = 1.0 * video_.gety() / layer.base_height(); const bool scalev = bl.scale_vertically(); const bool scaleh = bl.scale_horizontally(); const bool keep_ratio = bl.keep_aspect_ratio(); const bool tileh = bl.tile_horizontally(); const bool tilev = bl.tile_vertically(); double x_scale_factor = scaleh ? xscale : 1.0; double y_scale_factor = scalev ? yscale : 1.0; if (scalev && scaleh && keep_ratio) { x_scale_factor = y_scale_factor = std::min<double>(xscale, yscale); } else if (keep_ratio && scaleh) { x_scale_factor = y_scale_factor = xscale; } else if (keep_ratio && scalev) { x_scale_factor = y_scale_factor = yscale; } layer.set_smooth_scaling(true); SDL_Rect clip = sdl::create_rect(0, 0, layer.base_width(), layer.base_height()); if (tileh) { clip.x = (layer.base_width() - video_.getx())/2; clip.w = video_.getx(); layer.set_hwrap(GPU_WRAP_REPEAT); } if (tilev) { clip.y = (layer.base_height() - video_.gety())/2; clip.h = video_.gety(); layer.set_vwrap(GPU_WRAP_REPEAT); } layer.set_clip(clip); layer.set_scale(x_scale_factor, y_scale_factor); SDL_Rect base_rect = sdl::create_rect( (video_.getx() - layer.width()) / 2 , (video_.gety() - layer.height()) / 2 , layer.width() , layer.height()); background_images_.push_back(layer); background_positions_.push_back(std::pair<int, int>(base_rect.x, base_rect.y)); if (bl.is_base_layer() || no_base_yet) { x_scale_factor_ = x_scale_factor; y_scale_factor_ = y_scale_factor; base_rect_ = base_rect; no_base_yet = false; } } #else background_.assign( create_neutral_surface(video_.getx(), video_.gety()) ); base_rect_.w = video_.getx(); base_rect_.h = video_.gety(); has_background_ = false; bool no_base_yet = true; // Build background surface BOOST_FOREACH(const background_layer& bl, p_.get_background_layers()) { surface layer; if(bl.file().empty() != true) { layer.assign( image::get_image(bl.file()) ); } has_background_ = has_background_ || !layer.null(); if(layer.null() || layer->w * layer->h == 0) { continue; } layer = make_neutral_surface(layer); const double xscale = 1.0 * video_.getx() / layer->w; const double yscale = 1.0 * video_.gety() / layer->h; const bool scalev = bl.scale_vertically(); const bool scaleh = bl.scale_horizontally(); const bool keep_ratio = bl.keep_aspect_ratio(); double x_scale_factor = scaleh ? xscale : 1.0; double y_scale_factor = scalev ? yscale : 1.0; if (scalev && scaleh && keep_ratio) { x_scale_factor = y_scale_factor = std::min<double>(xscale, yscale); } else if (keep_ratio && scaleh) { x_scale_factor = y_scale_factor = xscale; } else if (keep_ratio && scalev) { x_scale_factor = y_scale_factor = yscale; } layer = scale_surface(layer, static_cast<int>(layer->w*x_scale_factor), static_cast<int>(layer->h*y_scale_factor), false); const int tilew = bl.tile_horizontally() ? video_.getx() : layer->w; const int tileh = bl.tile_vertically() ? video_.gety() : layer->h; layer = tile_surface(layer, tilew, tileh, false); SDL_Rect drect = sdl::create_rect( (background_->w - layer->w) / 2 , (background_->h - layer->h) / 2 , layer->w , layer->h); SDL_Rect srect = sdl::create_rect( 0 , 0 , layer->w , layer->h); SDL_Rect base_rect = drect; // If we can't see the whole image anyways, we'll want to display the // top-middle area. if (drect.y < 0) { drect.y = 0; base_rect.y = 0; } if (drect.x < 0) { srect.x -= drect.x; drect.x = 0; } blit_surface(layer, &srect, background_, &drect); ASSERT_LOG(layer.null() == false, "Oops: a storyscreen part background layer got NULL"); if (bl.is_base_layer() || no_base_yet) { x_scale_factor_ = x_scale_factor; y_scale_factor_ = y_scale_factor; base_rect_ = base_rect; no_base_yet = false; } } #endif }
/** * mate_bg_crossfade_start: * @fade: a #MateBGCrossfade * @window: The #GdkWindow to draw crossfade on * * This function initiates a quick crossfade between two surfaces on * the background of @window. Before initiating the crossfade both * mate_bg_crossfade_set_start_surface() and * mate_bg_crossfade_set_end_surface() need to be called. If animations * are disabled, the crossfade is skipped, and the window background is * set immediately to the end surface. **/ void mate_bg_crossfade_start (MateBGCrossfade *fade, GdkWindow *window) { GSource *source; GMainContext *context; g_return_if_fail (MATE_IS_BG_CROSSFADE (fade)); g_return_if_fail (window != NULL); g_return_if_fail (fade->priv->start_surface != NULL); g_return_if_fail (fade->priv->end_surface != NULL); g_return_if_fail (!mate_bg_crossfade_is_started (fade)); g_return_if_fail (gdk_window_get_window_type (window) != GDK_WINDOW_FOREIGN); /* If drawing is done on the root window, * it is essential to have the root pixmap. */ if (gdk_window_get_window_type (window) == GDK_WINDOW_ROOT) { GdkDisplay *display = gdk_window_get_display (window); cairo_surface_t *surface = get_root_pixmap_id_surface (display); g_return_if_fail (surface != NULL); cairo_surface_destroy (surface); } if (fade->priv->fading_surface != NULL) { cairo_surface_destroy (fade->priv->fading_surface); fade->priv->fading_surface = NULL; } fade->priv->window = window; if (gdk_window_get_window_type (fade->priv->window) != GDK_WINDOW_ROOT) { fade->priv->fading_surface = tile_surface (fade->priv->start_surface, fade->priv->width, fade->priv->height); if (fade->priv->widget != NULL) { g_signal_connect (fade->priv->widget, "draw", (GCallback) on_widget_draw, fade); } } else { cairo_t *cr; GdkDisplay *display = gdk_window_get_display (fade->priv->window); fade->priv->fading_surface = get_root_pixmap_id_surface (display); cr = cairo_create (fade->priv->fading_surface); cairo_set_source_surface (cr, fade->priv->start_surface, 0, 0); cairo_paint (cr); cairo_destroy (cr); } draw_background (fade); source = g_timeout_source_new (1000 / 60.0); g_source_set_callback (source, (GSourceFunc) on_tick, fade, (GDestroyNotify) on_finished); context = g_main_context_default (); fade->priv->timeout_id = g_source_attach (source, context); g_source_unref (source); fade->priv->is_first_frame = TRUE; fade->priv->total_duration = .75; fade->priv->start_time = get_current_time (); }