Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Side by Side Diff: ui/gfx/image/image_family.h

Issue 1424913007: Added ImageFamily::CreateExact, which scales the best image to size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master-plus
Patch Set: IconUtil: Rewrite comment. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/icon_util.cc ('k') | ui/gfx/image/image_family.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_GFX_IMAGE_IMAGE_FAMILY_H_ 5 #ifndef UI_GFX_IMAGE_IMAGE_FAMILY_H_
6 #define UI_GFX_IMAGE_IMAGE_FAMILY_H_ 6 #define UI_GFX_IMAGE_IMAGE_FAMILY_H_
7 7
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 // Gets the best image to use in a rectangle of |size|. 130 // Gets the best image to use in a rectangle of |size|.
131 // Gets an image at the same aspect ratio as |size.width()|:|size.height()|, 131 // Gets an image at the same aspect ratio as |size.width()|:|size.height()|,
132 // if possible, or if not, the closest aspect ratio. Among images of that 132 // if possible, or if not, the closest aspect ratio. Among images of that
133 // aspect ratio, returns the smallest image with both its width and height 133 // aspect ratio, returns the smallest image with both its width and height
134 // bigger or equal to the requested size. If none exists, returns the largest 134 // bigger or equal to the requested size. If none exists, returns the largest
135 // image of that aspect ratio. If there are no images in the family, returns 135 // image of that aspect ratio. If there are no images in the family, returns
136 // NULL. 136 // NULL.
137 const gfx::Image* GetBest(const gfx::Size& size) const; 137 const gfx::Image* GetBest(const gfx::Size& size) const;
138 138
139 // Gets an image of size |width|x|height|. If no image of that exact size
140 // exists, chooses the nearest larger image using GetBest() and scales it to
141 // the desired size. If there are no images in the family, returns an empty
142 // image.
143 gfx::Image CreateExact(int width, int height) const;
144
145 // Gets an image of size |size|. If no image of that exact size exists,
146 // chooses the nearest larger image using GetBest() and scales it to the
147 // desired size. If there are no images in the family, returns an empty image.
148 gfx::Image CreateExact(const gfx::Size& size) const;
149
139 private: 150 private:
140 // Find the closest aspect ratio in the map to |desired_aspect|. 151 // Find the closest aspect ratio in the map to |desired_aspect|.
141 // Ties are broken by the thinner aspect. 152 // Ties are broken by the thinner aspect.
142 // |map_| must not be empty. |desired_aspect| must be > 0.0. 153 // |map_| must not be empty. |desired_aspect| must be > 0.0.
143 float GetClosestAspect(float desired_aspect) const; 154 float GetClosestAspect(float desired_aspect) const;
144 155
145 // Gets an image with aspect ratio |aspect|, at the best size for |width|. 156 // Gets an image with aspect ratio |aspect|, at the best size for |width|.
146 // Returns the smallest image of aspect ratio |aspect| with its width bigger 157 // Returns the smallest image of aspect ratio |aspect| with its width bigger
147 // or equal to |width|. If none exists, returns the largest image of aspect 158 // or equal to |width|. If none exists, returns the largest image of aspect
148 // ratio |aspect|. Behavior is undefined if there is not at least one image in 159 // ratio |aspect|. Behavior is undefined if there is not at least one image in
149 // |map_| of aspect ratio |aspect|. 160 // |map_| of aspect ratio |aspect|.
150 const gfx::Image* GetWithExactAspect(float aspect, int width) const; 161 const gfx::Image* GetWithExactAspect(float aspect, int width) const;
151 162
152 // Map from (aspect ratio, width) to image. 163 // Map from (aspect ratio, width) to image.
153 std::map<MapKey, gfx::Image> map_; 164 std::map<MapKey, gfx::Image> map_;
154 }; 165 };
155 166
156 } // namespace gfx 167 } // namespace gfx
157 168
158 #endif // UI_GFX_IMAGE_IMAGE_FAMILY_H_ 169 #endif // UI_GFX_IMAGE_IMAGE_FAMILY_H_
OLDNEW
« no previous file with comments | « ui/gfx/icon_util.cc ('k') | ui/gfx/image/image_family.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698