diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2008-01-15 07:45:57 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2008-01-15 07:45:57 (GMT) |
commit | f6c292a406f183a12b2e327716aad5de4c0abcca (patch) | |
tree | a90b80a7a1ec95ce7ab0b66447b7528f64e03eae /src/FbTk/TextUtils.hh | |
parent | e1db89e2d7d56afca5335550ee1c9ff87fd54ba4 (diff) | |
download | fluxbox-f6c292a406f183a12b2e327716aad5de4c0abcca.zip fluxbox-f6c292a406f183a12b2e327716aad5de4c0abcca.tar.bz2 |
split Text.hh into Orientation.hh and TextUtils.{cc,hh}
Diffstat (limited to 'src/FbTk/TextUtils.hh')
-rw-r--r-- | src/FbTk/TextUtils.hh | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/src/FbTk/TextUtils.hh b/src/FbTk/TextUtils.hh new file mode 100644 index 0000000..efb6020 --- /dev/null +++ b/src/FbTk/TextUtils.hh | |||
@@ -0,0 +1,133 @@ | |||
1 | // TextUtils.hh for FbTk - text utils | ||
2 | // Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at fluxbox dot org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | #ifndef FBTK_TEXTUTILS_HH | ||
23 | #define FBTK_TEXTUTILS_HH | ||
24 | |||
25 | #include "Orientation.hh" | ||
26 | |||
27 | namespace FbTk { | ||
28 | |||
29 | class Font; | ||
30 | |||
31 | /** | ||
32 | Aligns the text after max width and bevel | ||
33 | */ | ||
34 | int doAlignment(int max_width, int bevel, FbTk::Justify justify, | ||
35 | const FbTk::Font &font, const char * const text, | ||
36 | unsigned int textlen, unsigned int &newlen); | ||
37 | |||
38 | /** | ||
39 | There are 3 interesting translations: | ||
40 | 1) Coords = simple rotation of coordinates | ||
41 | 2) Position = adjusting (x,y) coordinates to use to position a box with X coords | ||
42 | 3) Size = swapping of width and height if necessary | ||
43 | */ | ||
44 | |||
45 | |||
46 | // translate coordinates from ROT0 into different orientations | ||
47 | // coords are relative to rot0 0,0 position | ||
48 | // Need width and height of the area being rotated (in ROT0 coords) | ||
49 | |||
50 | inline void translateCoords(Orientation orient, int &x, int &y, unsigned int w, unsigned int h) { | ||
51 | |||
52 | int orig_x = x; | ||
53 | int orig_y = y; | ||
54 | |||
55 | switch(orient) { | ||
56 | case ROT0: | ||
57 | break; | ||
58 | case ROT90: | ||
59 | x = h - orig_y; | ||
60 | y = orig_x; | ||
61 | break; | ||
62 | case ROT180: | ||
63 | x = w - orig_x; | ||
64 | y = h - orig_y; | ||
65 | break; | ||
66 | case ROT270: | ||
67 | x = orig_y; | ||
68 | y = w - orig_x; | ||
69 | break; | ||
70 | } | ||
71 | |||
72 | } | ||
73 | |||
74 | // still require w and h in ROT0 coords | ||
75 | inline void untranslateCoords(Orientation orient, int orig_x, int orig_y, unsigned int w, unsigned int h) { | ||
76 | |||
77 | int x = orig_x; | ||
78 | int y = orig_y; | ||
79 | |||
80 | switch(orient) { | ||
81 | case ROT0: | ||
82 | break; | ||
83 | case ROT90: | ||
84 | orig_y = h - x; | ||
85 | orig_x = y; | ||
86 | break; | ||
87 | case ROT180: | ||
88 | orig_x = w - x; | ||
89 | orig_y = h - y; | ||
90 | break; | ||
91 | case ROT270: | ||
92 | orig_y = x; | ||
93 | orig_x = w - y; | ||
94 | break; | ||
95 | } | ||
96 | |||
97 | } | ||
98 | |||
99 | // When positioning an X11 box inside another area, we need to | ||
100 | // relocate the x,y coordinates | ||
101 | inline void translatePosition(Orientation orient, int x, int y, unsigned int w, unsigned int h, unsigned int bw) { | ||
102 | |||
103 | switch(orient) { | ||
104 | case ROT0: | ||
105 | break; | ||
106 | case ROT90: | ||
107 | x -= h + 2*bw; | ||
108 | break; | ||
109 | case ROT180: | ||
110 | x -= w + 2*bw; | ||
111 | y -= h + 2*bw; | ||
112 | break; | ||
113 | case ROT270: | ||
114 | y -= w + 2*bw; | ||
115 | break; | ||
116 | } | ||
117 | |||
118 | } | ||
119 | |||
120 | inline void translateSize(Orientation orient, unsigned int w, unsigned int h) { | ||
121 | if (orient == ROT0 || orient == ROT180) | ||
122 | return; | ||
123 | |||
124 | unsigned int tmp; | ||
125 | tmp = w; | ||
126 | w = h; | ||
127 | h = tmp; | ||
128 | |||
129 | } | ||
130 | |||
131 | } // end namespace FbTk | ||
132 | |||
133 | #endif // FBTK_TEXTUTILS_HH | ||