ScummVM API documentation
nine_patch.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 /* This code is based on Nine Patch code by Matthew Leverton
22  taken from https://github.com/konforce/Allegro-Nine-Patch
23 
24  Copyright (C) 2011 Matthew Leverton
25 
26  Permission is hereby granted, free of charge, to any person obtaining a copy of
27  this software and associated documentation files (the "Software"), to deal in
28  the Software without restriction, including without limitation the rights to
29  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
30  of the Software, and to permit persons to whom the Software is furnished to do
31  so, subject to the following conditions:
32 
33  The above copyright notice and this permission notice shall be included in all
34  copies or substantial portions of the Software.
35 
36  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42  SOFTWARE.
43  */
44 
45 #ifndef GRAPHICS_NINE_PATCH_H
46 #define GRAPHICS_NINE_PATCH_H
47 
48 #include "common/array.h"
49 #include "common/rect.h"
50 #include "common/hashmap.h"
51 
52 namespace Graphics {
53 
54 class ManagedSurface;
55 class MacWindowManager;
56 
57 struct NinePatchMark {
58  int offset;
59  int length;
60  int dest_offset;
61  int dest_length;
62  float ratio;
63 };
64 
66 public:
68  int _fix;
69 
70  NinePatchSide() : _fix(0) { _m.clear(); }
71  ~NinePatchSide();
72 
73  bool init(Graphics::ManagedSurface *bmp, bool vertical, uint32 black, uint32 white, int titlePos = 0, int *titleIndex = nullptr);
74 
75  void calcOffsets(int len, int titleIndex = 0, int titleWidth = 0);
76 };
77 
80  NinePatchSide _h, _v;
81  Common::Rect _padding;
82  bool _destroy_bmp;
83  int _width, _height;
84  int _cached_dw, _cached_dh;
85  int _titleIndex, _titleWidth, _titlePos;
86 
87 public:
88  NinePatchBitmap(Graphics::ManagedSurface *bmp, bool owns_bitmap, int titlePos = 0);
89  ~NinePatchBitmap();
90 
91  void blit(Graphics::ManagedSurface &target, int dx, int dy, int dw, int dh, MacWindowManager *wm = NULL);
92  void modifyTitleWidth(int titleWidth);
93 
94  int getWidth() { return _width; }
95  int getHeight() { return _height; }
96  int getMinWidth() { return _h._fix; }
97  int getMinHeight() { return _v._fix; }
98  int getTitleWidth() { return _titleWidth; }
99  // always call it after you calc the offset, such as after you call blit, then you will get the right offset
100  int getTitleOffset();
101  Graphics::ManagedSurface *getSource() { return _bmp; }
102  Common::Rect &getPadding() { return _padding; }
103 
104 private:
105 
106  void drawRegions(Graphics::ManagedSurface &target, int dx, int dy, int dw, int dh);
107 };
108 
109 } // end of namespace Graphics
110 
111 #endif // GRAPHICS_NINE_PATCH_H
Definition: managed_surface.h:51
Definition: array.h:52
void clear()
Definition: array.h:320
Definition: nine_patch.h:78
Definition: rect.h:144
Definition: nine_patch.h:65
Definition: macwindowmanager.h:149
Definition: nine_patch.h:57
Definition: formatinfo.h:28