You are not logged in.
Just a small func to draw Gradient rectangles
extern void GRRLIB_GradientRectangle(f32 x, f32 y, f32 width, f32 height, u32 color1, u32 color2, u32 color3, u32 color4, u8 filled);
inline void GRRLIB_GradientRectangle(f32 x, f32 y, f32 width, f32 height, u32 color1, u32 color2, u32 color3, u32 color4, u8 filled) { f32 x2 = x+width; f32 y2 = y+height; Vector v[] = {{x,y,0.0f}, {x2,y,0.0f}, {x2,y2,0.0f}, {x,y2,0.0f}, {x,y,0.0f}}; u32 ncolor[]= {color1,color2,color3,color4,color1}; if (!filled) { GRRLIB_NGone(v, ncolor, 5); } else { GRRLIB_NGoneFilled(v, ncolor, 4); } }
Offline
Need to pass an array of the colours - that should allow a gradient of !=4 colours
for the colour count, you can either pass in the cnt, or define a colour (such as 0xABCDEF00 <- alpha 0) to mean "end of list"
Offline
How about that one?
#define GRRLIB_GRAD_DIR_TOPBOTTOM 1 //default #define GRRLIB_GRAD_DIR_BOTTOMTOP 2 #define GRRLIB_GRAD_DIR_LEFTRIGHT 3 #define GRRLIB_GRAD_DIR_RIGHTLEFT 4 void GRRLIB_RectangleGradient(f32 x, f32 y, f32 width, f32 height, u32 color1, u32 color2, u8 direction) { guVector poly[4]={{x,y,0},{x+width,y,0},{x+width,y+height,0},{x,y+height,0}}; u32 cpoly[4]={color1,color1,color2,color2}; //deafult GRRLIB_GRAD_DIR_TOPBOTTOM switch (direction) { case GRRLIB_GRAD_DIR_BOTTOMTOP: cpoly[0]=color2; cpoly[1]=color2; cpoly[3]=color1; cpoly[2]=color1; break; case GRRLIB_GRAD_DIR_LEFTRIGHT: cpoly[0]=color1; cpoly[2]=color2; cpoly[3]=color1; cpoly[2]=color1; break; case GRRLIB_GRAD_DIR_RIGHTLEFT: cpoly[2]=color2; cpoly[1]=color2; cpoly[2]=color1; cpoly[1]=color1; break; default: break; } GRRLIB_NGoneFilled(poly,cpoly,4); }
and more modes can be added...
Offline
Thanks for the code, but I have a question.
In some places you affect two times some variables:
cpoly[2]=color2; cpoly[1]=color2; cpoly[2]=color1; cpoly[1]=color1;
The first line is useless because it's getting overwritten by the second one?
Offline
Crayon wrote:
Thanks for the code, but I have a question.
In some places you affect two times some variables:Code:
cpoly[2]=color2; cpoly[1]=color2; cpoly[2]=color1; cpoly[1]=color1;The first line is useless because it's getting overwritten by the second one?
you are right, that can be avoided, and by being so, optimized.
Offline
Aside of the (cut'n'paste?) errors the switch statement is lacking a case and a default and the type really should be enumerated to allow the compiler to check things are OK. Any chance of uploading an image with an example of all 4 shades?
Offline
BlueChip, the default values are set before entering the switch with:
u32 cpoly[4]={color1,color1,color2,color2}; //deafult GRRLIB_GRAD_DIR_TOPBOTTOM
It's an unusual way to proceed, but it works...
But I agree with you, it would be easier to understand with this:
case default: // GRRLIB_GRAD_DIR_TOPBOTTOM cpoly[0]=color1; cpoly[1]=color1; cpoly[2]=color2; cpoly[3]=color2;
Offline
Aside of making the code easier to read, it will also a) remove four indexed memory writes and b) stop the compiler warning that the switch may fail.
Offline
...and in case you'd like to have some fun ...you may find that
register ui32 *dp = cpoly; *dp++ = colour1; *dp++ = colour2; *dp++ = colour3; *dp = colour4;
produces code which is both smaller AND faster and at no memory cost.
Offline