hu xiaohua
|
The event of KD_QNX_WINDOWPROPERTY_POSITION handled
|
hu xiaohua
07/30/2009 2:56 AM
post34875
|
The event of KD_QNX_WINDOWPROPERTY_POSITION handled
I read this code but can't understand something.
gles1-kd-hmi.c
/**
** gles1-kd-hmi
** Windowed HMI example that uses OpenGL ES 1.X for rendering API.
**
*/
#include <ctype.h> /* Header file for isdigit */
#include <stdio.h> /* Header file for fprintf */
#include <stdlib.h> /* Header file for EXIT_FAILURE, EXIT_SUCCESS, atoi */
#include <string.h> /* Header file for strncmp */
#include <EGL/egl.h> /* Header file for EGL */
#include <KD/kd.h> /* Header file for OpenKODE */
#include <GLES/gl.h> /* Header file for OpenGL ES 1.X */
#include "error.h"
/* dynamically allocated array where we keep information on windows */
KDint32 *windows = NULL;
/* the value of nwin is the number of entries in the windows array */
unsigned nwin = 0;
/* dynamically allocated array where vertices are kept */
GLshort *points = NULL;
/* number of entries in points used; the size of points is nwin * 16 */
GLint nvtx = 0;
static void add_window(KDWindow *kd_hmi_win, KDWindow *kd_win)
{
kdSetWindowPropertyiv(kd_win,
KD_QNX_WINDOWPROPERTY_DELEGATE, (KDint32 *)kd_hmi_win);
}
static void set_border(int wid, KDWindow *kd_win, KDint32 kd_size[2])
{
GLshort *new_points;
KDint32 *new_windows;
KDint32 kd_dst_rect[4];
KDint32 kd_rect[4];
KDint32 vid;
KDint32 rc;
unsigned i;
rc = kdGetWindowPropertyiv(kd_win,
KD_QNX_WINDOWPROPERTY_POSITION, kd_dst_rect);
rc |= kdGetWindowPropertyiv(kd_win,
KD_WINDOWPROPERTY_SIZE, kd_dst_rect+2);
if (rc || kd_dst_rect[2] == 0 || kd_dst_rect[3] == 0) {
return;
}
if (wid == 0) {
for (i = 0; i < nwin; i++) {
if (windows[i] == -1) {
wid = i+1;
break;
}
}
}
if (wid == 0) {
new_windows = realloc(windows, (nwin + 1) * sizeof(*windows));
if (new_windows == NULL) {
return;
}
windows = new_windows;
windows[nwin] = -1;
wid = ++nwin;
}
kdSetWindowPropertyiv(kd_win,
KD_QNX_WINDOWPROPERTY_DELEGATE_POINTER, &wid);
wid--;
if (windows[wid] == -1) {
new_points = realloc(points, (nwin + 1) * 16 * sizeof(*points));
if (new_points == NULL) {
return;
}
/* We will use one vertex array for all of our rendering */
points = new_points;
glVertexPointer(2, GL_SHORT, 0, (const GLvoid *)points);
glEnableClientState(GL_VERTEX_ARRAY);
windows[wid] = nvtx;
nvtx += 16;
}
kd_rect[0] = kd_dst_rect[0] + 1;
kd_rect[1] = kd_dst_rect[1] + 1;
kd_rect[2] = kd_dst_rect[0] + kd_dst_rect[2];
kd_rect[3] = kd_dst_rect[1] + kd_dst_rect[3];
vid = windows[wid];
points[vid++] = kd_rect[0];
points[vid++] = kd_size[1] - kd_rect[3];
points[vid++] = kd_rect[0];
points[vid++] = kd_size[1] - kd_rect[1];
points[vid++] = kd_rect[0];
points[vid++] = kd_size[1] - kd_rect[1];
points[vid++] = kd_rect[2];
points[vid++] = kd_size[1] - kd_rect[1];
points[vid++] = kd_rect[2];
points[vid++] = kd_size[1] - kd_rect[1];
points[vid++] = kd_rect[2];
points[vid++] = kd_size[1] - kd_rect[3];
points[vid++] = kd_rect[2];
points[vid++] = kd_size[1] - kd_rect[3];
points[vid++] = kd_rect[0];
points[vid++] = kd_size[1] - kd_rect[3];
}
static void remove_border(int wid)
{
unsigned i; /* loop counter */
if (wid == 0) {
return;
}
wid--;
for (i = 0; i < nwin; i++) {
if (windows[i] > windows[wid]) {
/* 4 lines, 8 vertices, 16 elements */
windows[i] -= 16;
}
}
/* Decrease the...
View Full Message
|
|
|