alpha triangle

Diposting oleh Source Code Program | 08.13 | | 0 komentar »

procedure Alpha_Triangle(p1,p2,p3: tpoint;r,g,b,ratio: byte; bit1: tbitmap);
{
p1,p2,p3 = the 3 vertices or points at the corners of the triangle
r,g,b = the red, green, and blue values being averaged with the colours behind
ratio = a value from 0 to 255 that determines how opaque the fill of the triangle will be
-> 0 for transparent, 255 for completely opaque, however,
in either of these extremes, it doesn't make sence to use this procedure
bit1 = the bitmap having the triangle drawn on
}
// this function draws a filled triangle
// by dividing it in half and stepping through
// each line
var
x,y: integer;
height: integer; // looping variables
dx_right,dx_left: real;
// the dx/dy ratio of the right and left edges of the line
xs, xe: real; // // the starting and ending points of the edges
temp_x, temp_y: integer;
right_x,left_x: integer;
pb: pbytearray;
w: integer; // (width of bitmap) * (# of bytes per pixel)
x2: integer; // x*(# of bytes per pixel)
miny,maxy,minx,maxx: integer;
nratio: byte;
begin
if (p1.x<0)and(p2.x<0)and(p3.x<0) then
exit;
if (p1.y<0)and(p2.y<0)and(p3.y<0) then
exit;
maxx:=bit1.width-1;
if (p1.x>maxx)and(p2.x>maxx)and(p3.x>maxx) then
exit;
maxy:=bit1.height-1;
if (p1.y>maxy)and(p2.y>maxy)and(p3.y>maxy) then
exit;
// exit if none of the triangle will be shown anyway
nratio:=255-ratio;
bit1.PixelFormat:=pf24bit;
w:=bit1.width*3;
// make sure points are in order
if (p2.y < p1.y) then
begin
temp_y := p1.y;
temp_x := p1.x;
p1.y := p2.y;
p1.x := p2.x;
p2.y := temp_y;
p2.x := temp_x;
end;
if (p3.y < p1.y) then
begin
temp_y := p1.y;
temp_x := p1.x;
p1.y := p3.y;
p1.x := p3.x;
p3.y := temp_y;
p3.x := temp_x;
end;
if (p3.y < p2.y) then
begin
temp_y := p3.y;
temp_x := p3.x;
p3.y := p2.y;
p3.x := p2.x;
p2.y := temp_y;
p2.x := temp_x;
end;
left_x := p2.x;
if p3.y=p1.y then
right_x := 10000
else
right_x := round(p1.x + (p2.y-p1.y)*(p3.x-p1.x)/(p3.y-p1.y));
if (right_x < left_x)then // messes up if right is on left
begin
temp_x := right_x;
right_x := left_x;
left_x := temp_x;
end;
/////!!DRAW TOP!!///////
//draw the triangle top
if (p1.y <> p2.y) then
begin
// compute height of subtriangle
height := p2.y - p1.y;
// set starting points
xs := p1.x;
xe := p1.x;
// compute edge ratios
dx_left := (left_x - p1.x) / height;
dx_right := (right_x - p1.x) / height;
///DRAW IT ALREADY!!!!
miny:=max(0,p1.y);
maxy:=min(bit1.height-1,p2.y);
for y := miny to maxy do
begin
pb:=bit1.ScanLine[y];
minx:=max(0,trunc(xs));
maxx:=min(bit1.width-1,trunc(xe));
for x := minx to maxx do
begin
x2:=x*3;
pb[x2]:=(pb[x2]*nratio+b*ratio) shr 8;
pb[x2+1]:=(pb[x2+1]*nratio+g*ratio) shr 8;
pb[x2+2]:=(pb[x2+2]*nratio+r*ratio) shr 8;
end;
//adjust starting and ending point
xs :=xs+ dx_left;
xe :=xe+ dx_right;
end;
end;
if (p2.y <> p3.y) then
begin
//now recompute slope of shorter edge to finish triangle bottom
// recompute slopes
height := p3.y - p2.y;
dx_right := (p3.x - right_x) / (height);
dx_left := (p3.x - left_x) / (height);
xs := left_x;
xe := right_x;
if p3.y>= bit1.height then
p3.y:=bit1.height-1; // prevent an access violation error
// draw the rest of the triangle
miny:=max(0,p2.y+1);
maxy:=min(bit1.height-1,p3.y);
for y := miny to maxy do
begin
pb:=bit1.ScanLine[y];
minx:=max(0,trunc(xs));
maxx:=min(bit1.width-1,trunc(xe));
for x := minx to maxx do
begin
x2:=x*3;
pb[x2]:=(pb[x2]*nratio+b*ratio) shr 8;
pb[x2+1]:=(pb[x2+1]*nratio+g*ratio) shr 8;
pb[x2+2]:=(pb[x2+2]*nratio+r*ratio) shr 8;
end;
//adjust starting and ending point
xs :=xs+ dx_left;
xe :=xe+ dx_right;
end; //end for
end;
end;

info : Planetsourcecode.com

Add Dates to treeview

Diposting oleh Source Code Program | 08.02 | | 0 komentar »

procedure TfrmMainHair.FillTreeViewWithDates(Tree : TTreeview; Format : String; NumberOfYears : Integer);

var
h, i, j, z : Integer;

sDate : String;

Year, Month, Day : Word;

YearNode, MonthNode, DayNode : TTreeNode;

Const

MonthsInYear : Array [0..11] of String = ('January', 'February', 'March', 'April', 'May',

'June', 'July', 'August', 'September', 'October', 'November', 'December');

DaysInMonth : Array [0..11] of Integer = (31,28,31,30,31,30,31,31,30,31,30,31);

begin

YearNode := Nil;

DecodeDate(Date, Year, Month, Day);

{set default integers}

z := 0;

Tree.Items.BeginUpdate;

{years will be a variable that the user can configure, make sure user does not select years > 9999}

for h := 0 to NumberOfYears - 1 do

begin

if NumberOfYears > 1 then

begin

YearNode := Tree.Items.Add(Nil,IntToStr(Year));// Child(Tree.TopItem, IntToStr(Year));

YearNode.ImageIndex := 0;

YearNode.SelectedIndex := 0;

end;

{loop for how ever many months}

for i := 0 to high(MonthsInYear) - (high(MonthsInYear) - 2) do

begin

{add a new month each pass}

if NumberOfYears > 1 then

MonthNode := Tree.Items.AddChild(YearNode, MonthsInYear[Month - 1] + ' ' + IntToStr(Year))

Restrict Delete characters from a text box string

Diposting oleh Source Code Program | 07.53 | | 0 komentar »

Name : Restrict Delete characters from a text box string
Description :The user can set a character that the user wants to not allow in an text box entry field. This performs the check for all text boxes on a form.
By: Duane Warsham Assumes:The user can set a character that the user wants to not allow in an text box entry field. Change the Comma declaration to the numeric code of the key you want to exclude. I have added a simple alert function to message you the codes as you type them to simplify getting the correct key code. simply remove it when you have your keycode. Dont forget to put the script tags around this code,uploading would not allow the tags in the code.

document.onkeydown = keyHit;
Comma = 188;
function keyHit(evt)


{
thiskey = window.event.keyCode;
if (thiskey == Comma)
{window.event.keyCode = 46};
alert(thiskey); // remove this line when u have the keyCode number you want to exclude
}