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:
authorTon Roosendaal <ton@blender.org>2005-12-28 18:42:51 +0300
committerTon Roosendaal <ton@blender.org>2005-12-28 18:42:51 +0300
commit9df1460777cceed839721ea99fd9623aedbb26f5 (patch)
treef4ad7ebfb6294be13c01a3dba67e55354973818e /source/blender/src/interface_icons.c
parent7837866b1e226925b2a50041e3f0f56ac9e82021 (diff)
Christmas coding work!
********* Node editor work: - To enable Nodes for Materials, you have to set the "Use Nodes" button, in the new Material buttons "Nodes" Panel or in header of the Node editor. Doing this will disable Material-Layers. - Nodes now execute materials ("shaders"), but still only using the previewrender code. - Nodes have (optional) previews for rendered images. - Node headers allow to hide buttons and/or preview image - Nodes can be dragged larger/smaller (right-bottom corner) - Nodes can be hidden (minimized) with hotkey H - CTRL+click on an Input Socket gives a popup with default values. - Changing Material/Texture or Mix node will adjust Node title. - Click-drag outside of a Node changes cursor to "Knife' and allows to draw a rect where to cut Links. - Added new node types RGBtoBW, Texture, In/Output, ColorRamp - Material Nodes have options to ouput diffuse or specular, or to use a negative normal. The input socket 'Normal' will force the material to use that normal, otherwise it uses the normal from the Material that has the node tree. - When drawing a link between two not-matching sockets, Blender inserts a converting node (now only for value/rgb combos) - When drawing a link to an input socket that's already in use, the old link will either disappear or flip to another unused socket. - A click on a Material Node will activate it, and show all its settings in the Material Buttons. Active Material Nodes draw the material icon in red. - A click on any node will show its options in the Node Panel in the Material buttons. - Multiple Output Nodes can be used, to sample contents of a tree, but only one Output is the real one, which is indicated in a different color and red material icon. - Added ThemeColors for node types - ALT+C will convert existing Material-Layers to Node... this currently only adds the material/mix nodes and connects them. Dunno if this is worth a lot of coding work to make perfect? - Press C to call another "Solve order", which will show all possible cyclic conflicts (if there are). - Technical: nodes now use "Type" structs which define the structure of nodes and in/output sockets. The Type structs store all fixed info, callbacks, and allow to reconstruct saved Nodes to match what is required by Blender. - Defining (new) nodes now is as simple as filling in a fixed Type struct, plus code some callbacks. A doc will be made! - Node preview images are by default float ********* Icon drawing: - Cleanup of how old icons were implemented in new system, making them 16x16 too, correctly centered *and* scaled. - Made drawing Icons use float coordinates - Moved BIF_calcpreview_image() into interface_icons.c, renamed it icon_from_image(). Removed a lot of unneeded Imbuf magic here! :) - Skipped scaling and imbuf copying when icons are OK size ********* Preview render: - Huge cleanup of code.... - renaming BIF_xxx calls that only were used internally - BIF_previewrender() now accepts an argument for rendering method, so it supports icons, buttonwindow previewrender and node editor - Only a single BIF_preview_changed() call now exists, supporting all signals as needed for buttos and node editor ********* More stuff: - glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format argument for GL_FLOAT rects - Made the ColorBand become a built-in button for interface.c Was a load of cleanup work in buttons_shading.c... - removed a load of unneeded glBlendFunc() calls - Fixed bug in calculating text length for buttons (ancient!)
Diffstat (limited to 'source/blender/src/interface_icons.c')
-rw-r--r--source/blender/src/interface_icons.c120
1 files changed, 78 insertions, 42 deletions
diff --git a/source/blender/src/interface_icons.c b/source/blender/src/interface_icons.c
index 84ed6f8f29e..686c70295c8 100644
--- a/source/blender/src/interface_icons.c
+++ b/source/blender/src/interface_icons.c
@@ -470,13 +470,18 @@ static void clear_transp_rect(unsigned char *transp, unsigned char *rect, int w,
static void prepare_internal_icons(ImBuf* bbuf)
{
int x, y;
-
+ int rowstride= bbuf->x*4;
+ char *back= (char *)bbuf->rect;
+ unsigned char transp[4];
+
+ /* this sets blueish outside of icon to zero alpha */
+ QUATCOPY(transp, back);
+ clear_transp_rect(transp, back, bbuf->x, bbuf->y, rowstride);
+
/* 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];
@@ -485,10 +490,6 @@ static void prepare_internal_icons(ImBuf* bbuf)
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);
}
}
}
@@ -503,13 +504,7 @@ static void init_internal_icons()
for (y=0; y<12; y++) {
for (x=0; x<21; x++) {
- if (x==11 && y==6) {
- def_internal_icon(bbuf, ICON_BEVELBUT_HLT, (x*20 + 3 + 4), (y*21 + 3 + 2), 7, 13);
- } else if (x==12 && y==6) {
- def_internal_icon(bbuf, ICON_BEVELBUT_DEHLT, (x*20 + 3 + 4), (y*21 + 3 + 2), 7, 13);
- } else {
- def_internal_icon(bbuf, BIFICONID_FIRST + y*21 + x, x*20+3, y*21+3, 15, 16);
- }
+ def_internal_icon(bbuf, BIFICONID_FIRST + y*21 + x, x*20+3, y*21+3, 16, 16);
}
}
@@ -617,6 +612,51 @@ void BIF_icons_init(int first_dyn_id)
init_internal_icons();
}
+/* create single icon from jpg, png etc. */
+static void icon_from_image(Image* img, RenderInfo* ri, unsigned int w, unsigned int h)
+{
+ struct ImBuf *ima;
+ float scaledx, scaledy;
+ int pr_size = w*h*sizeof(unsigned int);
+ short ex, ey, dx, dy;
+
+ if (!img)
+ return;
+
+ if (!ri->rect) {
+ ri->rect= MEM_callocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "butsrect");
+ memset(ri->rect, 0xFF, w*h*sizeof(unsigned int));
+ }
+
+ if(img->ibuf==NULL) {
+ load_image(img, IB_rect, G.sce, G.scene->r.cfra);
+ }
+ ima = IMB_dupImBuf(img->ibuf);
+
+ if (!ima)
+ return;
+
+ if (ima->x > ima->y) {
+ scaledx = (float)w;
+ scaledy = ( (float)ima->y/(float)ima->x )*(float)w;
+ }
+ else {
+ scaledx = ( (float)ima->x/(float)ima->y )*(float)h;
+ scaledy = (float)h;
+ }
+
+ ex = (short)scaledx;
+ ey = (short)scaledy;
+
+ dx = (w - ex) / 2;
+ dy = (h - ey) / 2;
+
+ IMB_scaleImBuf(ima, ex, ey);
+ memcpy(ri->rect, ima->rect, pr_size);
+ IMB_freeImBuf(ima);
+}
+
+
/* only called when icon has changed */
/* only call with valid pointer from BIF_icon_draw */
static void icon_set_image(ID* id, DrawInfo* di)
@@ -636,16 +676,9 @@ static void icon_set_image(ID* id, DrawInfo* di)
/* no drawing (see last parameter doDraw, just calculate preview image
- hopefully small enough to be fast */
if (GS(id->name) == ID_IM)
- BIF_calcpreview_image((struct Image*)id, &ri, ri.pr_rectx, ri.pr_recty);
+ icon_from_image((struct Image*)id, &ri, ri.pr_rectx, ri.pr_recty);
else {
- BIF_previewrender(id, &ri, NULL, 0);
-
- /* need to correct alpha */
- /*
- for( it = 0; it < ri.pr_rectx*ri.pr_recty; ++it) {
- ri.rect[it] |= 0xFF000000;
- }
- */
+ BIF_previewrender(id, &ri, NULL, PR_ICON_RENDER);
}
/* and copy the image into the icon */
@@ -657,13 +690,11 @@ static void icon_set_image(ID* id, DrawInfo* di)
}
-void BIF_icon_draw( int x, int y, int icon_id)
+void BIF_icon_draw(float x, float y, int icon_id)
{
Icon* icon = 0;
DrawInfo* di = 0;
- ImBuf *ima;
-
icon = BKE_icon_get(icon_id);
if (!icon) {
@@ -694,24 +725,28 @@ void BIF_icon_draw( int x, int y, int icon_id)
if (!di->rect) return; /* something has gone wrong! */
- /* di->rect contains image in 'rendersize' */
-
- /* first allocate imbuf for scaling and copy preview into it */
- ima = IMB_allocImBuf(di->rw, di->rh, 32, IB_rect, 0);
- memcpy(ima->rect, di->rect,di->rw*di->rh*sizeof(unsigned int));
-
- /* scale it */
- IMB_scaleImBuf(ima, di->w, di->h);
-
glRasterPos2f(x, y);
- glDrawPixels(di->w, di->h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect);
-
- IMB_freeImBuf(ima);
+
+ /* di->rect contains image in 'rendersize', we only scale if needed */
+ if(di->rw!=di->w && di->rh!=di->h) {
+ ImBuf *ima;
+ /* first allocate imbuf for scaling and copy preview into it */
+ ima = IMB_allocImBuf(di->rw, di->rh, 32, IB_rect, 0);
+ memcpy(ima->rect, di->rect, di->rw*di->rh*sizeof(unsigned int));
+
+ /* scale it */
+ IMB_scaleImBuf(ima, di->w, di->h);
+ glDrawPixels(di->w, di->h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect);
+
+ IMB_freeImBuf(ima);
+ }
+ else
+ glDrawPixels(di->w, di->h, GL_RGBA, GL_UNSIGNED_BYTE, di->rect);
}
}
-void BIF_icon_draw_blended(int x, int y, int icon_id, int colorid, int shade)
+void BIF_icon_draw_blended(float x, float y, int icon_id, int colorid, int shade)
{
if(shade < 0) {
@@ -724,7 +759,8 @@ void BIF_icon_draw_blended(int x, int y, int icon_id, int colorid, int shade)
glPixelTransferf(GL_ALPHA_SCALE, 1.0);
}
-void BIF_icon_set_aspect(int icon_id, float aspect) {
+void BIF_icon_set_aspect(int icon_id, float aspect)
+{
Icon* icon = 0;
DrawInfo* di = 0;
@@ -746,8 +782,8 @@ void BIF_icon_set_aspect(int icon_id, float aspect) {
}
di->aspect = aspect;
/* scale width and height according to aspect */
- di->w = 16.0 / di->aspect;
- di->h = 16.0 / di->aspect;
+ di->w = (int)(16.0f/di->aspect + 0.5f);
+ di->h = (int)(16.0f/di->aspect + 0.5f);
}