~ubuntu-branches/ubuntu/karmic/icewm/karmic

« back to all changes in this revision

Viewing changes to src/ypixmap.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2009-06-05 23:39:03 UTC
  • mfrom: (1.2.12 upstream) (3.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090605233903-an40kzzm9pdp0zue
Tags: 1.2.37+1.3.4pre2-2ubuntu1
* Merge from debian unstable, remaining changes:
 - debian/rules: call dh_icons

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "config.h"
 
2
 
 
3
#include "ypixmap.h"
 
4
#include "yxapp.h"
 
5
 
 
6
#include <stdlib.h>
 
7
 
 
8
static Pixmap createPixmap(int w, int h, int depth) {
 
9
    return XCreatePixmap(xapp->display(), desktop->handle(), w, h, depth);
 
10
}
 
11
 
 
12
static Pixmap createPixmap(int w, int h) {
 
13
    return createPixmap(w, h, xapp->depth());
 
14
}
 
15
 
 
16
static Pixmap createMask(int w, int h) {
 
17
    return XCreatePixmap(xapp->display(), desktop->handle(), w, h, 1);
 
18
}
 
19
 
 
20
void YPixmap::replicate(bool horiz, bool copyMask) {
 
21
    if (this == NULL || pixmap() == None || (fMask == None && copyMask))
 
22
        return;
 
23
 
 
24
    int dim(horiz ? width() : height());
 
25
    if (dim >= 128) return;
 
26
    dim = 128 + dim - 128 % dim;
 
27
 
 
28
    Pixmap nPixmap(horiz ? createPixmap(dim, height())
 
29
                         : createPixmap(width(), dim));
 
30
    Pixmap nMask(copyMask ? (horiz ? createMask(dim, height())
 
31
                                   : createMask(width(), dim)) : None);
 
32
 
 
33
    if (horiz)
 
34
        Graphics(nPixmap, dim, height()).repHorz(fPixmap, width(), height(), 0, 0, dim);
 
35
    else
 
36
        Graphics(nPixmap, width(), dim).repVert(fPixmap, width(), height(), 0, 0, dim);
 
37
 
 
38
    if (nMask != None)
 
39
        if (horiz)
 
40
            Graphics(nMask, dim, height()).repHorz(fMask, width(), height(), 0, 0, dim);
 
41
        else
 
42
            Graphics(nMask, width(), dim).repVert(fMask, width(), height(), 0, 0, dim);
 
43
 
 
44
    if (
 
45
#if 1
 
46
        true
 
47
#else
 
48
        fOwned
 
49
#endif
 
50
       )
 
51
    {
 
52
        if (fPixmap != None)
 
53
            XFreePixmap(xapp->display(), fPixmap);
 
54
        if (fMask != None)
 
55
            XFreePixmap(xapp->display(), fMask);
 
56
    }
 
57
 
 
58
    fPixmap = nPixmap;
 
59
    fMask = nMask;
 
60
 
 
61
    (horiz ? fWidth : fHeight) = dim;
 
62
}
 
63
 
 
64
YPixmap::~YPixmap() {
 
65
    if (fPixmap != None) {
 
66
        if (xapp != 0)
 
67
            XFreePixmap(xapp->display(), fPixmap);
 
68
        fPixmap = 0;
 
69
    }
 
70
    if (fMask != None) {
 
71
        if (xapp != 0)
 
72
            XFreePixmap(xapp->display(), fMask);
 
73
        fMask = 0;
 
74
    }
 
75
}
 
76
 
 
77
#if 0
 
78
ref<YPixmap> YPixmap::scale(ref<YPixmap> source, int const w, int const h) {
 
79
    ref<YPixmap> scaled;
 
80
    scaled = source;
 
81
    return scaled;
 
82
}
 
83
#endif
 
84
 
 
85
ref<YPixmap> YPixmap::scale(int const w, int const h) {
 
86
    ref<YPixmap> pixmap;
 
87
    pixmap.init(this);
 
88
    ref<YImage> image = YImage::createFromPixmap(pixmap);
 
89
    if (image != null) {
 
90
        image = image->scale(w, h);
 
91
        if (image != null)
 
92
            pixmap = YPixmap::createFromImage(image);
 
93
    }
 
94
    return pixmap;
 
95
}
 
96
 
 
97
ref<YPixmap> YPixmap::create(int w, int h, bool useMask) {
 
98
    ref<YPixmap> n;
 
99
 
 
100
    Pixmap pixmap = createPixmap(w, h);
 
101
    Pixmap mask = useMask ? createMask(w, h) : None;
 
102
    if (pixmap != None && (!useMask || mask != None))
 
103
 
 
104
        n.init(new YPixmap(pixmap, mask, w, h));
 
105
    return n;
 
106
}
 
107
 
 
108
ref<YPixmap> YPixmap::createFromImage(ref<YImage> image) {
 
109
    return image->renderToPixmap();
 
110
}
 
111
 
 
112
ref<YPixmap> YPixmap::createFromPixmapAndMask(Pixmap pixmap,
 
113
                                              Pixmap mask,
 
114
                                              int w, int h)
 
115
{
 
116
    abort();
 
117
}
 
118
 
 
119
ref<YPixmap> YPixmap::createFromPixmapAndMaskScaled(Pixmap pix, Pixmap mask,
 
120
                                                    int width, int height,
 
121
                                                    int nw, int nh)
 
122
{
 
123
    if (pix != None) {
 
124
        ref<YImage> image =
 
125
            YImage::createFromPixmapAndMaskScaled(pix, mask,
 
126
                                                  width, height, nw, nh);
 
127
        if (image != null) {
 
128
            ref<YPixmap> pixmap =
 
129
                YPixmap::createFromImage(image);
 
130
            return pixmap;
 
131
        }
 
132
    }
 
133
    return null;
 
134
}
 
135
 
 
136
ref<YPixmap> YPixmap::load(upath filename) {
 
137
    ref<YImage> image = YImage::load(filename);
 
138
    ref<YPixmap> pixmap;
 
139
    if (image != null) {
 
140
        pixmap = YPixmap::createFromImage(image);
 
141
    }
 
142
    return pixmap;
 
143
}