TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
guiimage.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 file : guiimage.cpp
4 created : Wed May 1 10:29:28 CEST 2002
5 copyright : (C) 2001-2026 by Eric EspiƩ, Bernhard Wymann
6 email : berniw@bluewin.ch
7
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
23
24#include <stdlib.h>
25#ifdef WIN32
26#include <windows.h>
27#endif
28#include <tgfclient.h>
29#include "gui.h"
30
31
48int GfuiStaticImageCreate(void *scr, int x, int y, int w, int h, char *name)
49{
50 tGfuiImage *image;
51 tGfuiObject *object;
52 tGfuiScreen *screen = (tGfuiScreen*)scr;
53
54 if (!screen) {
55 return -1;
56 }
57
58 object = (tGfuiObject*)calloc(1, sizeof(tGfuiObject));
59 if (!object) {
60 return -1;
61 }
62 object->widget = GFUI_IMAGE;
63 object->focusMode = GFUI_FOCUS_NONE;
64 object->visible = 1;
65 object->id = screen->curId++;
66
67 image = &(object->u.image);
68 image->texture = name ? GfImgReadTex(name) : 0;
69
70 object->xmin = x;
71 object->xmax = x + w;
72 object->ymin = y;
73 object->ymax = y + h;
74
75 gfuiAddObject(screen, object);
76
77 return object->id;
78}
79
90void GfuiStaticImageSet(void *scr, int id, char *name)
91{
92 tGfuiObject *curObject;
93 tGfuiScreen *screen = (tGfuiScreen*)scr;
94 tGfuiImage *image;
95
96 curObject = screen->objects;
97 if (curObject != NULL) {
98 do {
99 curObject = curObject->next;
100 if (curObject->id == id) {
101 if (curObject->widget == GFUI_IMAGE) {
102 image = &(curObject->u.image);
103 GfImgFreeTex(image->texture);
104 image->texture = name ? GfImgReadTex(name) : 0;
105 }
106 return;
107 }
108 } while (curObject != screen->objects);
109 }
110}
111
112void
114{
115 tGfuiImage *image;
116
117 image = &(obj->u.image);
118 GfImgFreeTex(image->texture);
119 free(obj);
120}
121
122void
124{
125 tGfuiImage *image;
126
127 image = &(obj->u.image);
128 if (!image->texture) {
129 return;
130 }
131
132 glEnable(GL_TEXTURE_2D);
133 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
134 glBindTexture(GL_TEXTURE_2D, image->texture);
135
136 glBegin(GL_TRIANGLE_STRIP);
137 {
138 glColor4f(1.0, 1.0, 1.0, 0.0);
139 glTexCoord2f(0.0, 0.0); glVertex2f(obj->xmin, obj->ymin);
140 glTexCoord2f(0.0, 1.0); glVertex2f(obj->xmin, obj->ymax);
141 glTexCoord2f(1.0, 0.0); glVertex2f(obj->xmax, obj->ymin);
142 glTexCoord2f(1.0, 1.0); glVertex2f(obj->xmax, obj->ymax);
143 }
144 glEnd();
145 glBindTexture(GL_TEXTURE_2D, 0);
146 glDisable(GL_TEXTURE_2D);
147}
static Vector y[4]
Definition Convex.cpp:56
void GfuiStaticImageSet(void *scr, int id, char *name)
Replace an image by another one.
Definition guiimage.cpp:90
int GfuiStaticImageCreate(void *scr, int x, int y, int w, int h, char *name)
Create a new static image.
Definition guiimage.cpp:48
void GfImgFreeTex(GLuint tex)
Free the texture.
Definition img.cpp:302
GLuint GfImgReadTex(char *filename)
Read a png image into a texture.
Definition img.cpp:315
#define GFUI_FOCUS_NONE
Definition gui.h:128
#define GFUI_IMAGE
Definition gui.h:48
void gfuiAddObject(tGfuiScreen *screen, tGfuiObject *object)
struct GfuiObject tGfuiObject
void gfuiDrawImage(tGfuiObject *obj)
Definition guiimage.cpp:123
void gfuiReleaseImage(tGfuiObject *obj)
Definition guiimage.cpp:113
tGfuiImage image
Definition gui.h:209
int ymin
Definition gui.h:199
int xmin
Definition gui.h:199
int xmax
Definition gui.h:200
int ymax
Definition gui.h:200
int id
Definition gui.h:194
union GfuiObject::@107216344126174123112226307372375007210201317144 u
int widget
Definition gui.h:193
struct GfuiObject * next
Definition gui.h:211
GLuint texture
Definition gui.h:188
tGfuiObject * objects
Definition gui.h:236
int curId
Definition gui.h:238
The Gaming Framework API (client part).