File: glcompimage.c

package info (click to toggle)
graphviz 2.26.3-5%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 63,044 kB
  • ctags: 25,930
  • sloc: ansic: 212,134; sh: 20,316; cpp: 7,239; makefile: 4,211; yacc: 3,335; xml: 2,450; tcl: 1,900; cs: 1,890; objc: 1,149; perl: 829; lex: 364; awk: 171; python: 41; ruby: 35; php: 26
file content (173 lines) | stat: -rw-r--r-- 5,249 bytes parent folder | download | duplicates (3)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* $Id: glcompimage.c,v 1.4 2009/12/04 21:08:05 arif Exp $Revision: */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2007 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/

#include "glcompimage.h"
#include "glcompfont.h"
#include "glcompset.h"
#include "glutils.h"
#include "glcomptexture.h"
#include "memory.h"

glCompImage *glCompImageNew(glCompObj * par, GLfloat x, GLfloat y)
{
    glCompImage *p;
    p = NEW(glCompImage);
    glCompInitCommon((glCompObj *) p, par, x, y);
    p->objType = glImageObj;
    //typedef enum {glPanelObj,glbuttonObj,glLabelObj,glImageObj}glObjType;

    p->objType = glImageObj;
    p->stretch = 0;
    p->pngFile = (char *) 0;
    p->texture = NULL;
    p->common.functions.draw = glCompImageDraw;
    return p;
}

void glCompImageDelete(glCompImage * p)
{
    glCompEmptyCommon(&p->common);
    if (p->pngFile)
	free(p->pngFile);
    if (p->texture)
	glCompDeleteTexture(p->texture);
    free(p);
}
extern unsigned char *load_png(char *file_name, int *imageWidth,
			       int *imageHeight);
int glCompImageLoad(glCompImage * i, unsigned char *data, int width,
		    int height)
{
    if (data != NULL) {		/*valid image data */
	glCompDeleteTexture(i->texture);
	i->texture =
	    glCompSetAddNewTexImage(i->common.compset, width, height, data,
				    1);
	if (i->texture) {
	    i->common.width = width;
	    i->common.height = height;
	    return 1;
	}

    }
    return 0;
}



int glCompImageLoadPng(glCompImage * i, char *pngFile)
{
    int imageWidth, imageHeight;
    unsigned char *data;
    data = load_png(pngFile, &imageWidth, &imageHeight);
    return glCompImageLoad(i, data, imageWidth, imageHeight);
}
int glCompImageLoadRaw(glCompSet * s, glCompImage * i, char *rawFile)
{
    int imageWidth, imageHeight;
    unsigned char *data;
    data = load_png(rawFile, &imageWidth, &imageHeight);
    return glCompImageLoad(i, data, imageWidth, imageHeight);
}

void glCompImageDraw(void *obj)
{
    glCompImage *p;
    static glCompCommon ref;
//      static GLfloat w,h,d;
    p = (glCompImage *) obj;
    ref = p->common;
    glCompCalcWidget((glCompCommon *) p->common.parent, &p->common, &ref);
    if (!p->common.visible)
	return;
    if (!p->texture)
	return;

    glRasterPos2f(ref.pos.x, ref.pos.y);
//    glPixelZoom(2,2);
    glDrawPixels(p->texture->width, p->texture->height, GL_RGBA,
		 GL_UNSIGNED_BYTE, p->texture->data);

/*	w=ref.width;
	h=ref.height;
	d=(GLfloat)p->common.layer* (GLfloat)GLCOMPSET_BEVEL_DIFF;
    glDisable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);
	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
	glBindTexture(GL_TEXTURE_2D,p->texture->id);
	glBegin(GL_QUADS);
		glTexCoord2d(0.0f, 1.0f);glVertex3d(ref.pos.x,ref.pos.y,d);
		glTexCoord2d(1.0f, 1.0f);glVertex3d(ref.pos.x+w,ref.pos.y,d);
		glTexCoord2d(1.0f, 0.0f);glVertex3d(ref.pos.x+w,ref.pos.y+h,d);
		glTexCoord2d(0.0f, 0.0f);glVertex3d(ref.pos.x,ref.pos.y+h,d);
	glEnd();

	glDisable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);*/

}

void glCompImageClick(glCompObj * o, GLfloat x, GLfloat y,
		      glMouseButtonType t)
{
    if (o->common.callbacks.click)
	o->common.callbacks.click(o, x, y, t);
}

void glCompImageDoubleClick(glCompObj * obj, GLfloat x, GLfloat y,
			    glMouseButtonType t)
{
    /*Put your internal code here */
    if (((glCompImage *) obj)->common.callbacks.doubleclick)
	((glCompImage *) obj)->common.callbacks.doubleclick(obj, x, y, t);
}

void glCompImageMouseDown(glCompObj * obj, GLfloat x, GLfloat y,
			  glMouseButtonType t)
{
    /*Put your internal code here */
    if (((glCompImage *) obj)->common.callbacks.mousedown)
	((glCompImage *) obj)->common.callbacks.mousedown(obj, x, y, t);
}

void glCompImageMouseIn(glCompObj * obj, GLfloat x, GLfloat y)
{
    /*Put your internal code here */
    if (((glCompImage *) obj)->common.callbacks.mousein)
	((glCompImage *) obj)->common.callbacks.mousein(obj, x, y);
}

void glCompImageMouseOut(glCompObj * obj, GLfloat x, GLfloat y)
{
    /*Put your internal code here */
    if (((glCompImage *) obj)->common.callbacks.mouseout)
	((glCompImage *) obj)->common.callbacks.mouseout(obj, x, y);
}

void glCompImageMouseOver(glCompObj * obj, GLfloat x, GLfloat y)
{
    /*Put your internal code here */
    if (((glCompImage *) obj)->common.callbacks.mouseover)
	((glCompImage *) obj)->common.callbacks.mouseover(obj, x, y);
}

void glCompImageMouseUp(glCompObj * obj, GLfloat x, GLfloat y,
			glMouseButtonType t)
{
    /*Put your internal code here */
    if (((glCompImage *) obj)->common.callbacks.mouseup)
	((glCompImage *) obj)->common.callbacks.mouseup(obj, x, y, t);
}