summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-11-26 15:50:46 (GMT)
committerfluxgen <fluxgen>2002-11-26 15:50:46 (GMT)
commitfe2e6b32e7fd285a32d5210220e18da9abb7732f (patch)
treed3361a8c7188ca8a66d0d96db32a50216b04a9cf /src
parente980fe82969013db45daa0cc0bce90b3df180f62 (diff)
downloadfluxbox_lack-fe2e6b32e7fd285a32d5210220e18da9abb7732f.zip
fluxbox_lack-fe2e6b32e7fd285a32d5210220e18da9abb7732f.tar.bz2
alignment function
Diffstat (limited to 'src')
-rw-r--r--src/DrawUtil.cc50
-rw-r--r--src/DrawUtil.hh5
2 files changed, 38 insertions, 17 deletions
diff --git a/src/DrawUtil.cc b/src/DrawUtil.cc
index 868e4fa..f83c1ca 100644
--- a/src/DrawUtil.cc
+++ b/src/DrawUtil.cc
@@ -13,31 +13,49 @@
13// 13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 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, 15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 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 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 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 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: DrawUtil.cc,v 1.9 2002/11/25 14:00:20 fluxgen Exp $ 22// $Id: DrawUtil.cc,v 1.10 2002/11/26 15:50:46 fluxgen Exp $
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif //HAVE_CONFIG_H
27 23
28#include "DrawUtil.hh" 24#include "DrawUtil.hh"
29#include "StringUtil.hh"
30#include "i18n.hh"
31
32#include <cstdlib>
33#include <cassert>
34#include <cstdio>
35#include <iostream>
36#include <X11/Xutil.h>
37
38using namespace std;
39 25
40namespace DrawUtil { 26namespace DrawUtil {
41 27
28int doAlignment(int max_width, int bevel, Font::FontJustify justify,
29 const FbTk::Font &font, const char * const text, size_t textlen, size_t &newlen) {
30
31 if (text == 0 || textlen == 0)
32 return 0;
33
34 int l = font.textWidth(text, textlen) + bevel;
35 size_t dlen = textlen;
36 int dx = bevel;
37 if (l > max_width) {
38 for (; dlen > 0; dlen--) {
39 l = font.textWidth(text, dlen) + bevel;
40 if (l<=max_width)
41 break;
42 }
43 }
44
45 newlen = dlen;
46
47 switch (justify) {
48 case DrawUtil::Font::RIGHT:
49 dx = max_width - l - bevel;
50 break;
51 case DrawUtil::Font::CENTER:
52 dx = (max_width - l)/2;
53 break;
54 case DrawUtil::Font::LEFT:
55 break;
56 }
57
58 return dx;
59}
42 60
43}; //end namespace DrawUtil 61}; //end namespace DrawUtil
diff --git a/src/DrawUtil.hh b/src/DrawUtil.hh
index 48caeec..f3710ae 100644
--- a/src/DrawUtil.hh
+++ b/src/DrawUtil.hh
@@ -19,12 +19,13 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: DrawUtil.hh,v 1.8 2002/11/25 14:00:20 fluxgen Exp $ 22// $Id: DrawUtil.hh,v 1.9 2002/11/26 15:45:48 fluxgen Exp $
23 23
24#ifndef DRAWUTIL_HH 24#ifndef DRAWUTIL_HH
25#define DRAWUTIL_HH 25#define DRAWUTIL_HH
26 26
27#include <X11/Xlib.h> 27#include <X11/Xlib.h>
28#include "Font.hh"
28 29
29namespace DrawUtil { 30namespace DrawUtil {
30 // note: obsolete! 31 // note: obsolete!
@@ -37,6 +38,8 @@ namespace DrawUtil {
37 FontJustify justify; 38 FontJustify justify;
38 }; 39 };
39 40
41 int doAlignment(int max_width, int bevel, Font::FontJustify justify,
42 const FbTk::Font &font, const char * const text, size_t textlen, size_t &newlen);
40}; //end namespace DrawUtil 43}; //end namespace DrawUtil
41 44
42#endif //DRAWUTIL_HH 45#endif //DRAWUTIL_HH