ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

nine_patch.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  */
00021 
00022 /* This code is based on Nine Patch code by Matthew Leverton
00023    taken from https://github.com/konforce/Allegro-Nine-Patch
00024 
00025    Copyright (C) 2011 Matthew Leverton
00026 
00027    Permission is hereby granted, free of charge, to any person obtaining a copy of
00028    this software and associated documentation files (the "Software"), to deal in
00029    the Software without restriction, including without limitation the rights to
00030    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
00031    of the Software, and to permit persons to whom the Software is furnished to do
00032    so, subject to the following conditions:
00033 
00034    The above copyright notice and this permission notice shall be included in all
00035    copies or substantial portions of the Software.
00036 
00037    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00038    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00039    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00040    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00041    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00042    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00043    SOFTWARE.
00044  */
00045 
00046 #ifndef GRAPHICS_NINE_PATCH_H
00047 #define GRAPHICS_NINE_PATCH_H
00048 
00049 #include "common/array.h"
00050 #include "common/rect.h"
00051 #include "common/hashmap.h"
00052 
00053 namespace Graphics {
00054 
00055 struct TransparentSurface;
00056 struct Surface;
00057 
00058 struct NinePatchMark {
00059     int offset;
00060     int length;
00061     int dest_offset;
00062     int dest_length;
00063     float ratio;
00064 };
00065 
00066 class NinePatchSide {
00067 public:
00068     Common::Array<NinePatchMark *> _m;
00069     int _fix;
00070 
00071     NinePatchSide() : _fix(0) {}
00072     ~NinePatchSide();
00073 
00074     bool init(Graphics::TransparentSurface *bmp, bool vertical);
00075     void calcOffsets(int len);
00076 };
00077 
00078 class NinePatchBitmap {
00079     Graphics::TransparentSurface *_bmp;
00080     NinePatchSide _h, _v;
00081     Common::Rect _padding;
00082     bool _destroy_bmp;
00083     int _width, _height;
00084     int _cached_dw, _cached_dh;
00085     Common::HashMap<uint32, int> _cached_colors;
00086 
00087 public:
00088     NinePatchBitmap(Graphics::TransparentSurface *bmp, bool owns_bitmap);
00089     ~NinePatchBitmap();
00090 
00091     void blit(Graphics::Surface &target, int dx, int dy, int dw, int dh, byte *palette = NULL, byte numColors = 0);
00092     void blitClip(Graphics::Surface &target, Common::Rect clip, int dx, int dy, int dw, int dh);
00093 
00094     int getWidth() { return _width; }
00095     int getHeight() { return _height; }
00096     int getMinWidth() { return _h._fix; }
00097     int getMinHeight() { return _v._fix; }
00098     Graphics::TransparentSurface *getSource() { return _bmp; }
00099     Common::Rect &getPadding() { return _padding; }
00100 
00101 private:
00102 
00103     void drawRegions(Graphics::Surface &target, int dx, int dy, int dw, int dh);
00104 
00105     // Assumes color is in the palette
00106     byte getColorIndex(uint32 target, byte *palette);
00107     uint32 grayscale(uint32 color);
00108     uint32 grayscale(byte r, byte g, byte b);
00109     byte closestGrayscale(uint32 color, byte* palette, byte paletteLength);
00110 };
00111 
00112 } // end of namespace Graphics
00113 
00114 #endif // GRAPHICS_NINE_PATCH_H


Generated on Sat May 18 2019 05:01:10 for ResidualVM by doxygen 1.7.1
curved edge   curved edge