source: golgotha/src/i4/gui/gradiant.cc @ 608

Last change on this file since 608 was 80, checked in by Sam Hocevar, 15 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.8 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "image/image.hh"
10#include "palette/pal.hh"
11#include "image/context.hh"
12
13void i4_gradiant_bar(i4_image_class *im, int x1, int y1, int x2, int y2,
14                     i4_color start_color, i4_color end_color,
15                     i4_draw_context_class &context)
16{
17  context.add_both_dirty(x1,y1,x2,y2);
18
19  float sr=(start_color>>16)&0xff, sg=(start_color>>8)&0xff, sb=(start_color)&0xff;
20  float er=(end_color>>16)&0xff, eg=(end_color>>8)&0xff, eb=(end_color)&0xff;
21 
22  im->add_dirty(x1,y1,x2,y2, context);
23
24  float t=1.0/(x2-x1+1);
25  float r_step=(er-sr)*t;
26  float g_step=(eg-sg)*t;
27  float b_step=(eb-sb)*t;
28
29
30  int w=(x2-x1+1);
31  int h=(y2-y1+1);
32  if (w*h*4<32*1024)  // do it fast if it's small than 32k
33  {       
34    i4_image_class *fast=i4_create_image(w,h, i4_pal_man.default_no_alpha_32());
35   
36    for (int x=0; x<w; x++)
37    {
38      w32 c=(((int)sr)<<16) | (((int)sg)<<8) | (((int)sb));
39
40      w32 *sl=((w32 *)fast->data)+x;
41      for (int y=0; y<h; y++)
42      {
43        *sl=c;
44        sl+=w;
45      }
46
47      sr+=r_step;  sg+=g_step;  sb+=b_step;
48    }
49
50    fast->put_image(im, x1,y1, context);
51    delete fast;
52  }
53  else
54  {
55    for (int x=x1; x<=x2; x++)
56    {
57      w32 c=(((int)sr)<<16) | (((int)sg)<<8) | (((int)sb));
58      im->bar(x,y1,x,y2, c, context);
59
60      sr+=r_step;  sg+=g_step;  sb+=b_step;
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.