rectangles and lines done both evas and imlbi2 ends

SVN revision: 3055
This commit is contained in:
Carsten Haitzler 2000-08-07 03:11:05 +00:00
parent 4ccd9a636f
commit a3456bfe2e
5 changed files with 323 additions and 17 deletions

View File

@ -308,6 +308,7 @@ __evas_gl_image_set_context_for_dest(Evas_GL_Image *im, Display *disp, Window w,
glDisable(GL_BLEND);
}
glEnable(GL_DITHER);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
@ -1360,6 +1361,157 @@ __evas_gl_text_get_size(Evas_GL_Font *fn, char *text, int *w, int *h)
/*****************************************************************************/
/* rectangle externals *******************************************************/
/*****************************************************************************/
void __evas_gl_rectangle_draw(Display *disp, Window win,
int win_w, int win_h,
int x, int y, int w, int h,
int r, int g, int b, int a)
{
float rr, gg, bb, aa;
static int dest_w = 0, dest_h = 0;
if ((__evas_current_win != win) || (__evas_current_disp != disp))
{
glXMakeCurrent(disp, win, __evas_gl_cx);
__evas_current_disp = disp;
__evas_current_win = win;
}
rr = (float)r / 255;
gg = (float)g / 255;
bb = (float)b / 255;
aa = (float)a / 255;
glColor4f(rr, gg, bb, aa);
if ((win_w != dest_w) || (win_h != dest_h))
{
glViewport(0, 0, win_w, win_h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, win_w, 0, win_h, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(1, -1, 1);
glTranslatef(0, -win_h, 0);
dest_w = win_w;
dest_h = win_h;
}
if (a < 255)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else
glDisable(GL_BLEND);
glEnable(GL_DITHER);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glBegin(GL_QUADS);
glVertex2i(x, y);
glVertex2i(x + w, y);
glVertex2i(x + w, y + h);
glVertex2i(x, y + h);
glEnd();
glEnable(GL_TEXTURE_2D);
}
/*****************************************************************************/
/* line externals ************************************************************/
/*****************************************************************************/
void __evas_gl_line_draw(Display *disp, Window win,
int win_w, int win_h,
int x1, int y1, int x2, int y2,
int r, int g, int b, int a)
{
float rr, gg, bb, aa;
static int dest_w = 0, dest_h = 0;
if ((__evas_current_win != win) || (__evas_current_disp != disp))
{
glXMakeCurrent(disp, win, __evas_gl_cx);
__evas_current_disp = disp;
__evas_current_win = win;
}
rr = (float)r / 255;
gg = (float)g / 255;
bb = (float)b / 255;
aa = (float)a / 255;
glColor4f(rr, gg, bb, aa);
if ((win_w != dest_w) || (win_h != dest_h))
{
glViewport(0, 0, win_w, win_h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, win_w, 0, win_h, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(1, -1, 1);
glTranslatef(0, -win_h, 0);
dest_w = win_w;
dest_h = win_h;
}
if (a < 255)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else
glDisable(GL_BLEND);
glEnable(GL_DITHER);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
/* glEnable(GL_LINE_SMOOTH);*/
glBegin(GL_LINES);
glVertex2i(x1, y1);
glVertex2i(x2, y2);
glEnd();
glEnable(GL_TEXTURE_2D);
}
@ -1451,11 +1603,5 @@ __evas_gl_draw_add_rect(Display *disp, Window win,
int x, int y, int w, int h)
{
return;
disp = NULL;
win = 0;
x = 0;
y = 0;
w = 0;
h = 0;
}

View File

@ -127,14 +127,17 @@ void __evas_gl_text_cache_empty(Display *disp);
void __evas_gl_text_cache_set_size(Display *disp, int size);
int __evas_gl_text_cache_get_size(Display *disp);
void __evas_gl_text_draw(Evas_GL_Font *fn, Display *disp, Window win, int win_w, int win_h, int x, int y, char *text, int r, int g, int b, int a);
void __evas_gl_text_get_size(Evas_GL_Font *fn, char *text, int *w, int *h);
/**************/
/* rectangles */
/**************/
void __evas_gl_rectangle_draw(Display *disp, Window win, int win_w, int win_h, int x, int y, int w, int h, int r, int g, int b, int a);
/*********/
/* lines */
/*********/
void __evas_gl_line_draw(Display *disp, Window win, int win_w, int win_h, int x1, int y1, int x2, int y2, int r, int g, int b, int a);
/*************/
/* gradients */

View File

@ -5,12 +5,23 @@
#define RECTS_INTERSECT(x, y, w, h, xx, yy, ww, hh) \
((SPANS_COMMON((x), (w), (xx), (ww))) && (SPANS_COMMON((y), (h), (yy), (hh))))
static void __evas_imlib_image_cache_flush(Display *disp);
static Evas_List drawable_list = NULL;
/*****************************************************************************/
/* image internals ***********************************************************/
/*****************************************************************************/
static void
__evas_imlib_image_cache_flush(Display *disp)
{
int size;
size = imlib_get_cache_size();
imlib_set_cache_size(0);
imlib_set_cache_size(size);
}
/*****************************************************************************/
/* image externals ***********************************************************/
/*****************************************************************************/
@ -28,16 +39,6 @@ __evas_imlib_image_free(Evas_Imlib_Image *im)
imlib_free_image();
}
void
__evas_imlib_image_cache_flush(Display *disp)
{
int size;
size = imlib_get_cache_size();
imlib_set_cache_size(0);
imlib_set_cache_size(size);
}
void
__evas_imlib_image_cache_empty(Display *disp)
{
@ -252,7 +253,7 @@ __evas_imlib_text_draw(Evas_Imlib_Font *fn, Display *disp, Window win,
if (!up->image)
up->image = imlib_create_image(up->w, up->h);
imlib_context_set_image(up->image);
imlib_text_draw(x, y, text);
imlib_text_draw(x - up->x, y - up->y, text);
}
}
}
@ -290,6 +291,140 @@ __evas_imlib_text_get_size(Evas_Imlib_Font *fn, char *text, int *w, int *h)
/*****************************************************************************/
/* rectangle externals *******************************************************/
/*****************************************************************************/
void __evas_imlib_rectangle_draw(Display *disp, Window win,
int win_w, int win_h,
int x, int y, int w, int h,
int r, int g, int b, int a)
{
Evas_List l;
imlib_context_set_color(r, g, b, a);
imlib_context_set_angle(0.0);
imlib_context_set_operation(IMLIB_OP_COPY);
imlib_context_set_color_modifier(NULL);
imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT);
imlib_context_set_anti_alias(1);
for(l = drawable_list; l; l = l->next)
{
Evas_Imlib_Drawable *dr;
dr = l->data;
if ((dr->win == win) && (dr->disp == disp))
{
Evas_List ll;
for (ll = dr->tmp_images; ll; ll = ll->next)
{
Evas_Imlib_Update *up;
up = ll->data;
/* if image intersects image update - render */
if (RECTS_INTERSECT(up->x, up->y, up->w, up->h,
x, y, w, h))
{
if (!up->image)
up->image = imlib_create_image(up->w, up->h);
imlib_context_set_image(up->image);
imlib_image_draw_rectangle(x - up->x, y - up->y, w, h);
}
}
}
}
}
/*****************************************************************************/
/* rectangle externals *******************************************************/
/*****************************************************************************/
void __evas_imlib_line_draw(Display *disp, Window win,
int win_w, int win_h,
int x1, int y1, int x2, int y2,
int r, int g, int b, int a)
{
Evas_List l;
int x, y, w, h;
imlib_context_set_color(r, g, b, a);
imlib_context_set_angle(0.0);
imlib_context_set_operation(IMLIB_OP_COPY);
imlib_context_set_color_modifier(NULL);
imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT);
imlib_context_set_anti_alias(1);
w = x2 - x1;
if (w < 0) w = -w;
h = y2 - y1;
if (h < 0) h = -h;
if (x1 < x2) x = x1;
else x = x2;
if (y1 < y2) y = y1;
else y = y2;
for(l = drawable_list; l; l = l->next)
{
Evas_Imlib_Drawable *dr;
dr = l->data;
if ((dr->win == win) && (dr->disp == disp))
{
Evas_List ll;
for (ll = dr->tmp_images; ll; ll = ll->next)
{
Evas_Imlib_Update *up;
up = ll->data;
/* if image intersects image update - render */
if (RECTS_INTERSECT(up->x, up->y, up->w, up->h,
x, y, w, h))
{
if (!up->image)
up->image = imlib_create_image(up->w, up->h);
imlib_context_set_image(up->image);
imlib_image_draw_line(x1 - up->x, y - up->x, x2 - up->x, y2 - up->y, 0);
}
}
}
}
}

View File

@ -65,10 +65,14 @@ void __evas_imlib_text_get_size(Evas_Imlib_Font *fn, char *text, in
/* rectangles */
/**************/
void __evas_imlib_rectangle_draw(Display *disp, Window win, int win_w, int win_h, int x, int y, int w, int h, int r, int g, int b, int a);
/*********/
/* lines */
/*********/
void __evas_imlib_line_draw(Display *disp, Window win, int win_w, int win_h, int x1, int y1, int x2, int y2, int r, int g, int b, int a);
/*************/
/* gradients */
/*************/

View File

@ -114,6 +114,24 @@ main(int argc, char **argv)
__evas_gl_text_draw(fn[3], d, win, win_w, win_h, 30, 200,
"With Lots of colors & transparency too!",
50, 200, 100, 100);
__evas_gl_rectangle_draw(d, win, win_w, win_h,
80, 100, 100, 30,
200, 40, 100, 100);
__evas_gl_rectangle_draw(d, win, win_w, win_h,
150, 110, 25, 25,
200, 40, 100, 255);
__evas_gl_rectangle_draw(d, win, win_w, win_h,
170, 160, 200, 180,
30, 40, 200, 160);
__evas_gl_line_draw(d, win, win_w, win_h,
10, 20, 100, 160,
255, 255, 255, 255);
__evas_gl_line_draw(d, win, win_w, win_h,
10, 20, 100, 20,
0, 0, 0, 255);
__evas_gl_line_draw(d, win, win_w, win_h,
10, 20, 10, 200,
255, 255, 0, 100);
__evas_gl_flush_draw(d, win);
a++;
if (a == (win_w * 4))