MCPcopy Create free account
hub / github.com/EasyRPG/Player / Draw

Method Draw

src/plane.cpp:32–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32void Plane::Draw(Bitmap& dst) {
33 if (!bitmap) return;
34
35 if (needs_refresh) {
36 needs_refresh = false;
37
38 if (!tone_bitmap ||
39 bitmap->GetWidth() != tone_bitmap->GetWidth() ||
40 bitmap->GetHeight() != tone_bitmap->GetHeight()) {
41 tone_bitmap = Bitmap::Create(bitmap->GetWidth(), bitmap->GetHeight());
42 }
43 tone_bitmap->Clear();
44 tone_bitmap->ToneBlit(0, 0, *bitmap, bitmap->GetRect(), tone_effect, Opacity::Opaque());
45 }
46
47 BitmapRef source = tone_effect == Tone() ? bitmap : tone_bitmap;
48
49 Rect dst_rect = dst.GetRect();
50 int src_x = -ox - GetRenderOx();
51 int src_y = -oy - GetRenderOy();
52
53 // Apply screen shaking
54 const int shake_x = Main_Data::game_screen->GetShakeOffsetX();
55 const int shake_y = Main_Data::game_screen->GetShakeOffsetY();
56 if (Game_Map::LoopHorizontal()) {
57 src_x += shake_x;
58 } else {
59 // The panorama occupies the same rectangle as the whole map.
60 // Using coordinates where the top-left of the screen is the origin...
61 // Minimal width is a 20 tile wide map by default, smaller maps are hacked
62 int bg_x = -Game_Map::GetDisplayX() / TILE_SIZE + shake_x;
63 int bg_width = std::max(Game_Map::GetTilesX() * TILE_SIZE, Player::screen_width);
64
65 // Clip the panorama to the screen
66 if (bg_x < 0) {
67 bg_width += bg_x;
68 bg_x = 0;
69 }
70 if (dst_rect.width < bg_x + bg_width) {
71 bg_width = dst_rect.width - bg_x;
72 }
73
74 bool off_screen =
75 bg_x >= dst_rect.width ||
76 bg_x + bg_width <= 0;
77 if (off_screen) {
78 // This probably won't happen...
79 return;
80 }
81
82 dst_rect.x = bg_x;
83 dst_rect.width = bg_width;
84
85 // Correct the offset if the top-left corner moved.
86 src_x += shake_x + bg_x;
87 }
88 src_y += shake_y;
89

Callers

nothing calls this directly

Calls 10

maxFunction · 0.85
ToneBlitMethod · 0.80
GetRectMethod · 0.80
GetShakeOffsetXMethod · 0.80
GetShakeOffsetYMethod · 0.80
TiledBlitMethod · 0.80
ToneClass · 0.70
GetWidthMethod · 0.45
GetHeightMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected