File: pic.c

package info (click to toggle)
treetool 2.0.2-1
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 3,460 kB
  • ctags: 2,692
  • sloc: ansic: 26,504; makefile: 212
file content (115 lines) | stat: -rw-r--r-- 1,768 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdio.h>

#include <xview/xview.h>
#include <xview/svrimage.h>

#include "generic.h"

typedef struct {
	ltgenericd g;
	Server_image p;
	int width, height;
	} ltpicd, *ltpic;

tpic tpic_new(bits, w, h)
char bits[];
int w, h;
{
    ltpic tmp;

    if(bits==NULL || w==0 || h==0)
		return(NULL);
    
    tmp=(ltpic)titem_new(NULL, lt_pic, sizeof(ltpicd));
    if(tmp==NULL)
		return(NULL);

    tmp->p=(Server_image)xv_create(NULL, SERVER_IMAGE,
		XV_WIDTH, w,
		XV_HEIGHT, h, 
		SERVER_IMAGE_X_BITS, bits,
		SERVER_IMAGE_DEPTH, 1,
		NULL);
    
    if(tmp->p==NULL)
    {
		titem_free(tmp);
		return(NULL);
    }
	tmp->width=w;
	tmp->height=h;
    return(tmp);
}

Server_image tpic_xview(p)
ltpic p;
{
    if(p==NULL)
		return(NULL);
    if(titem_type(p)!=lt_pic)
		return(NULL);
    
    return(p->p);
}

int tpic_free(p)
ltpic p;
{
    if(p==NULL)
		return(0);
    if(titem_type(p)!=lt_pic)
		return(0);
    
    xv_destroy_safe(p->p);
    titem_free(p);
    return(1);
}

Icon tpic_icon(p, s)
ltpic p;
char *s;
{
	Icon i;
	Xv_opaque xi;
	int makelabel;
	Rect ir, lr;

    if(p==NULL)
		return(NULL);
    if(titem_type(p)!=lt_pic)
		return(NULL);
	
	if(s==NULL)
		makelabel=0;
	else if(*s=='\0')
		makelabel=0;
	else
		makelabel=1;
    
	if(p->g.parent!=NULL)
		xi=(Xv_opaque)titem_xview_window(p->g.parent);
	else
		xi=NULL;
	if(makelabel)
	{
		rect_construct(&ir, 0, 0, p->width, p->height);
		rect_construct(&lr, 0, p->height, 0, 20);
		i=(Icon)xv_create(xi, ICON,
			ICON_IMAGE, p->p,
			XV_WIDTH, p->width,
			XV_HEIGHT, p->height+20,
			XV_LABEL, s,
			ICON_LABEL_RECT, &lr,
			ICON_IMAGE_RECT, &ir,
			NULL);
	}
	else
	{
		i=(Icon)xv_create(xi, ICON,
			ICON_IMAGE, p->p,
			XV_WIDTH, p->width,
			XV_HEIGHT, p->height,
			NULL);
	}
    return(i);
}