Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/src/resources.c')
-rw-r--r--source/blender/src/resources.c568
1 files changed, 3 insertions, 565 deletions
diff --git a/source/blender/src/resources.c b/source/blender/src/resources.c
index 078bcec2aaa..c206f12d01f 100644
--- a/source/blender/src/resources.c
+++ b/source/blender/src/resources.c
@@ -52,6 +52,7 @@
#include "BIF_gl.h"
#include "BIF_resources.h"
+#include "BIF_interface_icons.h"
#include "BLI_blenlib.h"
#include "blendef.h" // CLAMP
@@ -63,578 +64,15 @@ typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
static bTheme *theme_active=NULL;
static int theme_spacetype= SPACE_VIEW3D;
-typedef struct {
- /* If drawFunc is defined then it is a vector icon, otherwise use data */
- VectorDrawFunc drawFunc;
-
- int w, h;
-
- /* Data for image icons */
- unsigned char *data;
- float uv[4][2];
- GLuint texid;
-} Icon;
-
-static Icon *icon_new_vector(VectorDrawFunc drawFunc, int w, int h)
-{
- Icon *icon= MEM_callocN(sizeof(*icon), "internicon");
- icon->drawFunc = drawFunc;
- icon->w = w;
- icon->h = h;
-
- return icon;
-}
-
-static Icon *icon_from_data(unsigned char *rect, GLuint texid, int xofs, int yofs, int w, int h, int rowstride)
-{
- Icon *icon= MEM_mallocN(sizeof(*icon), "internicon");
- int y;
-
- icon->drawFunc = NULL;
- icon->texid= texid;
- icon->uv[0][0]= ((float)xofs)/512.0;
- icon->uv[0][1]= ((float)yofs)/256.0;
- icon->uv[1][0]= icon->uv[0][0] + ((float)w)/512.0;
- icon->uv[1][1]= icon->uv[0][1];
- icon->uv[2][0]= icon->uv[0][0] + ((float)w)/512.0;
- icon->uv[2][1]= icon->uv[0][1] + ((float)w)/256.0;
- icon->uv[3][0]= icon->uv[0][0];
- icon->uv[3][1]= icon->uv[0][1] + ((float)w)/256.0;
-
- icon->w= w;
- icon->h= h;
-
- icon->data= MEM_mallocN(w*h*4, "icon->data");
- for (y=0; y<h; y++)
- memcpy(&icon->data[y*w*4], &rect[y*rowstride], w*4);
-
- return icon;
-}
-
-#if 0
-static float icon_x=0.0, icon_y=0.0;
-void BIF_icon_pos(float xs, float ys)
-{
- icon_x= xs; icon_y= ys;
-}
-
-static GLuint init_icon_texture(ImBuf *bbuf)
-{
- GLuint texid;
-
- glGenTextures(1, &texid);
- glBindTexture(GL_TEXTURE_2D, texid);
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bbuf->x, bbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bbuf->rect);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
- return texid;
-}
-
-/* texture version for drawpixels */
-static void icon_draw_tex(Icon *icon)
-{
- glBindTexture(GL_TEXTURE_2D, icon->texid);
-
- /* drawing it */
- glColor3ub(255, 255, 255);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
-
- glTexCoord2fv(icon->uv[0]);
- glVertex2f(icon_x, icon_y);
- glTexCoord2fv(icon->uv[1]);
- glVertex2f(icon_x+icon->w, icon_y);
- glTexCoord2fv(icon->uv[2]);
- glVertex2f(icon_x+icon->w, icon_y+icon->h);
- glTexCoord2fv(icon->uv[3]);
- glVertex2f(icon_x, icon_y+icon->h);
-
- glEnd();
- glDisable(GL_TEXTURE_2D);
-}
-#endif
-
-
-static void icon_draw(float x, float y, Icon *icon)
-{
- if (icon->drawFunc) {
- icon->drawFunc(x, y, icon->w, icon->h, 1.0);
- } else {
- glRasterPos2f(x, y);
- glDrawPixels(icon->w, icon->h, GL_RGBA, GL_UNSIGNED_BYTE, icon->data);
- }
-}
-
-
-static void icon_draw_blended(float x, float y, Icon *icon, char *blendcol, int shade)
-{
- if (icon->drawFunc) {
- icon->drawFunc(x, y, icon->w, icon->h, shade<0?((128+shade)/128.0):1.0);
- } else {
- if(shade < 0) {
- float r= (128+shade)/128.0;
- glPixelTransferf(GL_ALPHA_SCALE, r);
- }
- glRasterPos2f(x, y);
- glDrawPixels(icon->w, icon->h, GL_RGBA, GL_UNSIGNED_BYTE, icon->data);
- glPixelTransferf(GL_ALPHA_SCALE, 1.0);
- }
-}
-
-
-static void icon_free(Icon *icon)
-{
- if (icon->data) MEM_freeN(icon->data);
- MEM_freeN(icon);
-}
-
-
-static Icon **common_icons_arr= NULL;
-
-static Icon *get_icon(BIFIconID icon)
-{
- int iconidx= icon-BIFICONID_FIRST;
- if (iconidx>=0 && iconidx<BIFNICONIDS) {
- return common_icons_arr[iconidx];
- } else {
- return common_icons_arr[ICON_ERROR-BIFICONID_FIRST];
- }
-}
-static void free_common_icons(void)
-{
- int i;
-
- for (i=0; i<BIFNICONIDS; i++) {
- icon_free(common_icons_arr[i+BIFICONID_FIRST]);
- }
-}
-
-void BIF_draw_icon(float x, float y, BIFIconID icon)
-{
- icon_draw(x, y, get_icon(icon));
-}
-
-void BIF_draw_icon_blended(float x, float y, BIFIconID icon, int colorid, int shade)
-{
- char *cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
- icon_draw_blended(x, y, get_icon(icon), cp, shade);
- // icon_draw_tex(get_icon(icon));
-}
-
-int BIF_get_icon_width(BIFIconID icon)
-{
- return get_icon(icon)->w;
-}
-
-int BIF_get_icon_height(BIFIconID icon)
-{
- return get_icon(icon)->h;
-}
-
-static void def_icon(ImBuf *bbuf, GLuint texid, BIFIconID icon, int xidx, int yidx, int w, int h, int offsx, int offsy)
-{
- int iconidx= icon-BIFICONID_FIRST;
-
- if (iconidx>=0 && iconidx<BIFNICONIDS) {
- int rowstride= bbuf->x*4;
- unsigned char *start= ((unsigned char*) bbuf->rect) + (yidx*21 + 3 + offsy)*rowstride + (xidx*20 + 3 + offsx)*4;
-
- common_icons_arr[iconidx]=
- icon_from_data(start, texid, (xidx*20 + 3 + offsx), (yidx*21 + 3 + offsy), w, h, rowstride);
-
- } else {
- printf("def_icon: Internal error, bad icon ID: %d\n", icon);
- }
-}
-
-static void def_vicon(BIFIconID icon, int w, int h, VectorDrawFunc drawFunc)
-{
- int iconidx= icon-BIFICONID_FIRST;
-
- if (iconidx>=0 && iconidx<BIFNICONIDS) {
- common_icons_arr[iconidx]= icon_new_vector(drawFunc, w, h);
- } else {
- printf("def_icon: Internal error, bad icon ID: %d\n", icon);
- }
-}
-
-/* this only works for the hardcoded buttons image, turning the grey AA pixels to alpha, and slight off-grey to half alpha */
-
-static void clear_transp_rect_soft(unsigned char *transp, unsigned char *rect, int w, int h, int rowstride)
-{
- int x, y, val;
-
- for (y=1; y<h-1; y++) {
- unsigned char *row0= &rect[(y-1)*rowstride];
- unsigned char *row= &rect[y*rowstride];
- unsigned char *row1= &rect[(y+1)*rowstride];
- for (x=1; x<w-1; x++) {
- unsigned char *pxl0= &row0[x*4];
- unsigned char *pxl= &row[x*4];
- unsigned char *pxl1= &row1[x*4];
-
- if(pxl[3]!=0) {
- val= (abs(pxl[0]-transp[0]) + abs(pxl[1]-transp[1]) + abs(pxl[2]-transp[2]))/3;
- if(val<20) {
- pxl[3]= 128;
- }
- else if(val<50) {
- // one of pixels surrounding has alpha null?
- if(pxl[3-4]==0 || pxl[3+4]==0 || pxl0[3]==0 || pxl1[3]==0) {
-
- if(pxl[0]>val) pxl[0]-= val; else pxl[0]= 0;
- if(pxl[1]>val) pxl[1]-= val; else pxl[1]= 0;
- if(pxl[2]>val) pxl[2]-= val; else pxl[2]= 0;
-
- pxl[3]= 128;
- }
- }
- }
- }
- }
-}
-
-
-static void clear_transp_rect(unsigned char *transp, unsigned char *rect, int w, int h, int rowstride)
-{
- int x,y;
- for (y=0; y<h; y++) {
- unsigned char *row= &rect[y*rowstride];
- for (x=0; x<w; x++) {
- unsigned char *pxl= &row[x*4];
- if (*((unsigned int*) pxl)==*((unsigned int*) transp)) {
- pxl[3]= 0;
- }
- }
- }
-}
-
-/* Vector Icon Drawing Routines */
-
- /* Utilities */
-
-static void viconutil_set_point(GLint pt[2], int x, int y)
-{
- pt[0] = x;
- pt[1] = y;
-}
-
-static void viconutil_draw_tri(GLint (*pts)[2])
-{
- glBegin(GL_TRIANGLES);
- glVertex2iv(pts[0]);
- glVertex2iv(pts[1]);
- glVertex2iv(pts[2]);
- glEnd();
-}
-
-#if 0
-static void viconutil_draw_quad(GLint (*pts)[2])
-{
- glBegin(GL_QUADS);
- glVertex2iv(pts[0]);
- glVertex2iv(pts[1]);
- glVertex2iv(pts[2]);
- glVertex2iv(pts[3]);
- glEnd();
-}
-#endif
-
-static void viconutil_draw_lineloop(GLint (*pts)[2], int numPoints)
-{
- int i;
-
- glBegin(GL_LINE_LOOP);
- for (i=0; i<numPoints; i++) {
- glVertex2iv(pts[i]);
- }
- glEnd();
-}
-
-static void viconutil_draw_lineloop_smooth(GLint (*pts)[2], int numPoints)
-{
- glEnable(GL_LINE_SMOOTH);
- viconutil_draw_lineloop(pts, numPoints);
- glDisable(GL_LINE_SMOOTH);
-}
-
-static void viconutil_draw_points(GLint (*pts)[2], int numPoints, int pointSize)
-{
- int i;
-
- glBegin(GL_QUADS);
- for (i=0; i<numPoints; i++) {
- int x = pts[i][0], y = pts[i][1];
-
- glVertex2i(x-pointSize,y-pointSize);
- glVertex2i(x+pointSize,y-pointSize);
- glVertex2i(x+pointSize,y+pointSize);
- glVertex2i(x-pointSize,y+pointSize);
- }
- glEnd();
-}
-
- /* Drawing functions */
-
-static void vicon_x_draw(int x, int y, int w, int h, float alpha)
-{
- x += 3;
- y += 3;
- w -= 6;
- h -= 6;
-
- glEnable( GL_LINE_SMOOTH );
-
- glLineWidth(2.5);
-
- glColor4f(0.0, 0.0, 0.0, alpha);
- glBegin(GL_LINES);
- glVertex2i(x ,y );
- glVertex2i(x+w,y+h);
- glVertex2i(x+w,y );
- glVertex2i(x ,y+h);
- glEnd();
-
- glLineWidth(1.0);
-
- glDisable( GL_LINE_SMOOTH );
-}
-
-static void vicon_view3d_draw(int x, int y, int w, int h, float alpha)
-{
- int cx = x + w/2;
- int cy = y + h/2;
- int d = MAX2(2, h/3);
-
- glColor4f(0.5, 0.5, 0.5, alpha);
- glBegin(GL_LINES);
- glVertex2i(x , cy-d);
- glVertex2i(x+w, cy-d);
- glVertex2i(x , cy+d);
- glVertex2i(x+w, cy+d);
-
- glVertex2i(cx-d, y );
- glVertex2i(cx-d, y+h);
- glVertex2i(cx+d, y );
- glVertex2i(cx+d, y+h);
- glEnd();
-
- glColor4f(0.0, 0.0, 0.0, alpha);
- glBegin(GL_LINES);
- glVertex2i(x , cy);
- glVertex2i(x+w, cy);
- glVertex2i(cx, y );
- glVertex2i(cx, y+h);
- glEnd();
-}
-
-static void vicon_edit_draw(int x, int y, int w, int h, float alpha)
-{
- GLint pts[4][2];
-
- viconutil_set_point(pts[0], x+3 , y+3 );
- viconutil_set_point(pts[1], x+w-3, y+3 );
- viconutil_set_point(pts[2], x+w-3, y+h-3);
- viconutil_set_point(pts[3], x+3 , y+h-3);
-
- glColor4f(0.0, 0.0, 0.0, alpha);
- viconutil_draw_lineloop(pts, 4);
-
- glColor3f(1, 1, 0.0);
- viconutil_draw_points(pts, 4, 1);
-}
-
-static void vicon_editmode_hlt_draw(int x, int y, int w, int h, float alpha)
-{
- GLint pts[3][2];
-
- viconutil_set_point(pts[0], x+w/2, y+h-2);
- viconutil_set_point(pts[1], x+3, y+4);
- viconutil_set_point(pts[2], x+w-3, y+4);
-
- glColor4f(0.5, 0.5, 0.5, alpha);
- viconutil_draw_tri(pts);
-
- glColor4f(0.0, 0.0, 0.0, 1);
- viconutil_draw_lineloop_smooth(pts, 3);
-
- glColor3f(1, 1, 0.0);
- viconutil_draw_points(pts, 3, 1);
-}
-
-static void vicon_editmode_dehlt_draw(int x, int y, int w, int h, float alpha)
-{
- GLint pts[3][2];
-
- viconutil_set_point(pts[0], x+w/2, y+h-2);
- viconutil_set_point(pts[1], x+3, y+4);
- viconutil_set_point(pts[2], x+w-3, y+4);
-
- glColor4f(0.0, 0.0, 0.0, 1);
- viconutil_draw_lineloop_smooth(pts, 3);
-
- glColor3f(.9, .9, .9);
- viconutil_draw_points(pts, 3, 1);
-}
-
-static void vicon_disclosure_tri_right_draw(int x, int y, int w, int h, float alpha)
-{
- GLint pts[3][2];
- int cx = x+w/2;
- int cy = y+w/2;
- int d = w/3, d2 = w/5;
-
- viconutil_set_point(pts[0], cx-d2, cy+d);
- viconutil_set_point(pts[1], cx-d2, cy-d);
- viconutil_set_point(pts[2], cx+d2, cy);
-
- glShadeModel(GL_SMOOTH);
- glBegin(GL_TRIANGLES);
- glColor4f(0.8, 0.8, 0.8, alpha);
- glVertex2iv(pts[0]);
- glVertex2iv(pts[1]);
- glColor4f(0.3, 0.3, 0.3, alpha);
- glVertex2iv(pts[2]);
- glEnd();
- glShadeModel(GL_FLAT);
-
- glColor4f(0.0, 0.0, 0.0, 1);
- viconutil_draw_lineloop_smooth(pts, 3);
-}
-
-static void vicon_disclosure_tri_down_draw(int x, int y, int w, int h, float alpha)
-{
- GLint pts[3][2];
- int cx = x+w/2;
- int cy = y+w/2;
- int d = w/3, d2 = w/5;
-
- viconutil_set_point(pts[0], cx+d, cy+d2);
- viconutil_set_point(pts[1], cx-d, cy+d2);
- viconutil_set_point(pts[2], cx, cy-d2);
-
- glShadeModel(GL_SMOOTH);
- glBegin(GL_TRIANGLES);
- glColor4f(0.8, 0.8, 0.8, alpha);
- glVertex2iv(pts[0]);
- glVertex2iv(pts[1]);
- glColor4f(0.3, 0.3, 0.3, alpha);
- glVertex2iv(pts[2]);
- glEnd();
- glShadeModel(GL_FLAT);
-
- glColor4f(0.0, 0.0, 0.0, 1);
- viconutil_draw_lineloop_smooth(pts, 3);
-}
-
-static void vicon_move_up_draw(int x, int y, int w, int h, float alpha)
-{
- int d=-2;
-
- glEnable(GL_LINE_SMOOTH);
- glLineWidth(1);
- glColor3f(0.0, 0.0, 0.0);
-
- glBegin(GL_LINE_STRIP);
- glVertex2i(x+w/2-d*2, y+h/2+d);
- glVertex2i(x+w/2, y+h/2-d + 1);
- glVertex2i(x+w/2+d*2, y+h/2+d);
- glEnd();
-
- glLineWidth(1.0);
- glDisable(GL_LINE_SMOOTH);
-}
-
-static void vicon_move_down_draw(int x, int y, int w, int h, float alpha)
-{
- int d=2;
-
- glEnable(GL_LINE_SMOOTH);
- glLineWidth(1);
- glColor3f(0.0, 0.0, 0.0);
-
- glBegin(GL_LINE_STRIP);
- glVertex2i(x+w/2-d*2, y+h/2+d);
- glVertex2i(x+w/2, y+h/2-d - 1);
- glVertex2i(x+w/2+d*2, y+h/2+d);
- glEnd();
-
- glLineWidth(1.0);
- glDisable(GL_LINE_SMOOTH);
-}
-
-/***/
void BIF_resources_init(void)
{
- ImBuf *bbuf= IMB_ibImageFromMemory((int *)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
- GLuint texid=0;
- int x, y;
-
- common_icons_arr= MEM_mallocN(sizeof(*common_icons_arr)*BIFNICONIDS, "common_icons");
-
- /* hack! */
- for (y=0; y<12; y++) {
- for (x=0; x<21; x++) {
- int rowstride= bbuf->x*4;
- unsigned char *start= ((unsigned char*) bbuf->rect) + (y*21 + 3)*rowstride + (x*20 + 3)*4;
- unsigned char transp[4];
- /* this sets backdrop of icon to zero alpha */
- transp[0]= start[0];
- transp[1]= start[1];
- transp[2]= start[2];
- transp[3]= start[3];
- clear_transp_rect(transp, start, 20, 21, rowstride);
- clear_transp_rect_soft(transp, start, 20, 21, rowstride);
-
- /* this sets outside of icon to zero alpha */
- start= ((unsigned char*) bbuf->rect) + (y*21)*rowstride + (x*20)*4;
- QUATCOPY(transp, start);
- clear_transp_rect(transp, start, 20, 21, rowstride);
-
-
- }
- }
-
- // disabled for now (ton)
- // texid= init_icon_texture(bbuf);
-
- /* hack! */
- for (y=0; y<12; y++) {
- for (x=0; x<21; x++) {
- if (x==11 && y==6) {
- def_icon(bbuf, texid, ICON_BEVELBUT_HLT, x, y, 7, 13, 4, 2);
- } else if (x==12 && y==6) {
- def_icon(bbuf, texid, ICON_BEVELBUT_DEHLT, x, y, 7, 13, 4, 2);
- } else {
- def_icon(bbuf, texid, BIFICONID_FIRST + y*21 + x, x, y, 15, 16, 0, 0);
- }
- }
- }
-
- def_vicon(VICON_VIEW3D, 16, 16, vicon_view3d_draw);
- def_vicon(VICON_EDIT, 16, 16, vicon_edit_draw);
- def_vicon(VICON_EDITMODE_DEHLT, 16, 16, vicon_editmode_dehlt_draw);
- def_vicon(VICON_EDITMODE_HLT, 16, 16, vicon_editmode_hlt_draw);
- def_vicon(VICON_DISCLOSURE_TRI_RIGHT, 16, 16, vicon_disclosure_tri_right_draw);
- def_vicon(VICON_DISCLOSURE_TRI_DOWN, 16, 16, vicon_disclosure_tri_down_draw);
- def_vicon(VICON_MOVE_UP, 16, 16, vicon_move_up_draw);
- def_vicon(VICON_MOVE_DOWN, 16, 16, vicon_move_down_draw);
- def_vicon(VICON_X, 16, 16, vicon_x_draw);
-
- IMB_freeImBuf(bbuf);
+ BIF_icons_init(BIFICONID_LAST+1);
}
void BIF_resources_free(void)
{
- free_common_icons();
-
- MEM_freeN(common_icons_arr);
-
+ BIF_icons_free();
}