2 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "flash/display/BitmapData_as.h"
21 #include "GnashImage.h"
22 #include "FillStyle.h"
23 #include "DynamicShape.h"
27 #include "movie_root.h"
28 #include "RunResources.h"
29 #include "Transform.h"
33 Bitmap::Bitmap(movie_root
& mr
, as_object
* object
, BitmapData_as
* bd
,
34 DisplayObject
* parent
)
36 DisplayObject(mr
, object
, parent
),
38 _width(_bitmapData
->width()),
39 _height(_bitmapData
->height())
41 _shape
.setBounds(SWFRect(0, 0,
42 pixelsToTwips(_width
), pixelsToTwips(_height
)));
44 assert(!bd
->disposed());
47 Bitmap::Bitmap(movie_root
& mr
, as_object
* object
,
48 const BitmapMovieDefinition
* def
, DisplayObject
* parent
)
50 DisplayObject(mr
, object
, parent
),
53 _width(def
->get_width_pixels()),
54 _height(def
->get_height_pixels())
56 _shape
.setBounds(def
->get_frame_size());
64 Bitmap::bitmap() const
66 if (_def
) return _def
->bitmap();
67 if (_bitmapData
) return _bitmapData
->bitmapInfo();
72 Bitmap::construct(as_object
* /*init*/)
74 if (_bitmapData
) _bitmapData
->attach(this);
76 if (!_def
&& !_bitmapData
) return;
78 // Width and height are a maximum of 2880, so there is no risk of
80 const int w
= pixelsToTwips(_width
);
81 const int h
= pixelsToTwips(_height
);
84 mat
.set_scale(1.0 / 20, 1.0 / 20);
86 // Can this be tiled? And smoothing?
87 FillStyle fill
= BitmapFill(BitmapFill::CLIPPED
, bitmap(), mat
,
88 BitmapFill::SMOOTHING_UNSPECIFIED
);
90 const size_t fillLeft
= _shape
.addFillStyle(fill
);
92 Path
bmpath(w
, h
, fillLeft
, 0, 0, false);
93 bmpath
.drawLineTo(w
, 0);
94 bmpath
.drawLineTo(0, 0);
95 bmpath
.drawLineTo(0, h
);
96 bmpath
.drawLineTo(w
, h
);
98 _shape
.add_path(bmpath
);
105 Bitmap::pointInShape(boost::int32_t x
, boost::int32_t y
) const
107 return pointInBounds(x
, y
);
111 Bitmap::display(Renderer
& renderer
, const Transform
& base
)
113 /// Don't display cleared Bitmaps.
114 if (!_def
&& !_bitmapData
) return;
116 const Transform xform
= base
* transform();
118 _shape
.display(renderer
, xform
);
123 Bitmap::add_invalidated_bounds(InvalidatedRanges
& ranges
, bool force
)
125 if (!force
&& !invalidated()) return;
127 ranges
.add(m_old_invalidated_ranges
);
130 bounds
.expand_to_transformed_rect(getWorldMatrix(*this), getBounds());
131 ranges
.add(bounds
.getRange());
136 Bitmap::getBounds() const
138 return _shape
.getBounds();
144 /// Nothing to do for disposed bitmaps.
145 if (!_bitmapData
) return;
149 if (_bitmapData
->disposed()) {