⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iagaloled.pas

📁 delphi 3d led component It provides 3d led component with source codes. you can make leds with
💻 PAS
📖 第 1 页 / 共 4 页
字号:
                if N>255 then N:=255;
                if N<0 then N:=0;
                pByte1[j*3]:=(pB^ *k div 2)* N div 255;
                pByte1[j*3+1]:=(pG^ *k div 2)* N div 255;
                pByte1[j*3+2]:=(pR^ *k div 2)* N div 255;
              end;
        end;

    end else
    begin
      if FLedPlasticSubsMode = iasmTile then
        begin
          for i:=0 to FPaintbitmap.Width div FLedPlasticSubstance.width do
            for j:=0 to FPaintbitmap.height div FLedPlasticSubstance.height do
              FPaintBitmap.Canvas.Draw(i*FPaintbitmap.Width div FLedPlasticSubstance.width,
                                       j*FPaintbitmap.height div FLedPlasticSubstance.height,
                                       FLedPlasticSubstance);
        end else
        begin
          FPaintBitmap.Canvas.StretchDraw(rect(0,0,FPaintbitmap.Width,FPaintbitmap.height),FLedPlasticSubstance);
        end;
      for i:=0 to FPaintBitmap.height-1 do
        begin
          pByte1:=FPaintBitmap.ScanLine[i];

            for j:=0 to FPaintBitmap.Width-1 do
              begin
                try
                  dd:=(FLedPlasticDepth/20)*min(FPaintBitmap.width/2-dx,FPaintBitmap.height/2-dx);
                  x:=j-dx-dd;y:=i-dx-dd;
                  w:=FPaintBitmap.width/2-dx-dd;
                  h:=FPaintBitmap.height/2-dx-dd;
                  N:=round(255-127*(abs(y-h)+abs(x-w))/(w+h));
                except
                  N:=0;
                end;
                  N:=N+(15-random(3*FLedPlasticDepth));

                if N>255 then N:=255;
                if N<0 then N:=0;
                pByte1[j*3]:=(pByte1[j*3] *k div 2)* N div 255;
                pByte1[j*3+1]:=(pByte1[j*3+1] *k div 2)* N div 255;
                pByte1[j*3+2]:=(pByte1[j*3+2] *k div 2)* N div 255;
              end;
        end;  
    end;

  if FGap<>0 then
    begin
      GapRGN:=CreaterectRGN(0,0,0,0);
      for i:=0 to length(FLedPoints)-1 do
        begin
          if i<>(length(FLedPoints)-1) then
            begin
              ar1[0].x:=FLedPoints[i].x;ar1[0].y:=FLedPoints[i].y;
              ar1[1].x:=FGapPoints[i].x;ar1[1].y:=FGapPoints[i].y;
              ar1[2].x:=FGapPoints[i+1].x;ar1[2].y:=FGapPoints[i+1].y;
              ar1[3].x:=FLedPoints[i+1].x;ar1[3].y:=FLedPoints[i+1].y;
            end else
            begin
              ar1[0].x:=FLedPoints[i].x;ar1[0].y:=FLedPoints[i].y;
              ar1[1].x:=FGapPoints[i].x;ar1[1].y:=FGapPoints[i].y;
              ar1[2].x:=FGapPoints[0].x;ar1[2].y:=FGapPoints[0].y;
              ar1[3].x:=FLedPoints[0].x;ar1[3].y:=FLedPoints[0].y;
            end;
          R1:=CreatePolygonRGN(ar1[0],4,Alternate);
          Combinergn(GapRGN,GapRGN,R1,RGN_OR);
          deleteobject(R1);
        end;


      if (FBorderSubstance=nil) or (FBorderSubstance.height=0) then
        begin
          FPaintBitmap.canvas.brush.color:=FGapColor;
          fillRGN(FPaintBitmap.canvas.handle,GapRGN,FPaintBitmap.canvas.brush.handle);
        end else
        begin
          selectClipRGN(FPaintBitmap.canvas.handle,GapRGN);
          if FBorderSubsMode = iasmTile then
            begin
              for i:=0 to FPaintbitmap.Width div FBorderSubstance.width do
                for j:=0 to FPaintbitmap.height div FBorderSubstance.height do
                  FPaintBitmap.Canvas.Draw(i*FBorderSubstance.width,
                                           j*FBorderSubstance.height,
                                           FBorderSubstance);
            end else
            begin
              FPaintBitmap.Canvas.StretchDraw(rect(0,0,FPaintbitmap.Width,FPaintbitmap.height),FBorderSubstance);
            end;
          selectClipRGN(FPaintBitmap.canvas.handle,0);
        end;
      deleteobject(GapRGN);
    end;
    // define the rgn of light and dark....
  //Outer Border...
  if OuterBorderStyle<>iablsNone then
    begin
      DR:=CreaterectRGN(0,0,0,0);
      LR:=CreaterectRGN(0,0,0,0);
      for i:=0 to length(FLedPoints)-1 do
        begin
          if i<>(length(FLedPoints)-1) then
            begin
              ar1[0].x:=FInnerPoints[i].x;ar1[0].y:=FInnerPoints[i].y;
              ar1[1].x:=FOuterPoints[i].x;ar1[1].y:=FOuterPoints[i].y;
              ar1[2].x:=FOuterPoints[i+1].x;ar1[2].y:=FOuterPoints[i+1].y;
              ar1[3].x:=FInnerPoints[i+1].x;ar1[3].y:=FInnerPoints[i+1].y;
            end else
            begin
              ar1[0].x:=FInnerPoints[i].x;ar1[0].y:=FInnerPoints[i].y;
              ar1[1].x:=FOuterPoints[i].x;ar1[1].y:=FOuterPoints[i].y;
              ar1[2].x:=FOuterPoints[0].x;ar1[2].y:=FOuterPoints[0].y;
              ar1[3].x:=FInnerPoints[0].x;ar1[3].y:=FInnerPoints[0].y;
            end;
          TryAngle:=0;
          if  OuterBorderStyle=iablsDown then inc(TryAngle,1800);
          ddx:=ar1[2].x-ar1[1].x;ddy:=ar1[1].y-ar1[2].y;
          if (abs(round(ddx))+abs(round(ddy)))<>0 then
            begin
              if round(ddx)=0 then
                begin
                  if ddy>0 then inc(TryAngle,900) else dec(TryAngle,900);
                end else
                begin
                  TryAngle:=Tryangle+round(1800*Arctan2(ddy/(abs(ddx)+abs(ddy)),ddx/(abs(ddx)+abs(ddy)))/pi);
                end;
            end;
          R1:=CreatePolygonRGN(ar1[0],4,Alternate);      
          if Angleisdark(TryAngle)      then
            Combinergn(DR,DR,R1,RGN_OR) else
            Combinergn(LR,LR,R1,RGN_OR);
          deleteobject(R1);  
        end;
      if (FBorderSubstance=nil) or (FBorderL.height=0) or (FBorderD.height=0) then
        begin
          FPaintBitmap.canvas.brush.color:=GetLColor(FBorderColor);
          fillRGN(FPaintBitmap.canvas.handle,LR,FPaintBitmap.canvas.brush.handle);
          FPaintBitmap.canvas.brush.color:=GetDColor(FBorderColor);
          fillRGN(FPaintBitmap.canvas.handle,DR,FPaintBitmap.canvas.brush.handle);
        end else
        begin
          selectClipRGN(FPaintBitmap.canvas.handle,LR);
          if FBorderSubsMode = iasmTile then
            begin
              for i:=0 to FPaintbitmap.Width div FBorderL.width do
                for j:=0 to FPaintbitmap.height div FBorderL.height do
                  FPaintBitmap.Canvas.Draw(i*FBorderL.width,
                                           j*FBorderL.height,
                                           FBorderL);
            end else
            begin
              FPaintBitmap.Canvas.StretchDraw(rect(0,0,FPaintbitmap.Width,FPaintbitmap.height),FBorderL);
            end;
          selectClipRGN(FPaintBitmap.canvas.handle,DR);
          if FLedPlasticSubsMode = iasmTile then
            begin
              for i:=0 to FPaintbitmap.Width div FBorderD.width do
                for j:=0 to FPaintbitmap.height div FBorderD.height do
                  FPaintBitmap.Canvas.Draw(i*FBorderD.width,
                                           j*FBorderD.height,
                                           FBorderD);
            end else
            begin
              FPaintBitmap.Canvas.StretchDraw(rect(0,0,FPaintbitmap.Width,FPaintbitmap.height),FBorderD);
            end;
          selectClipRGN(FPaintBitmap.canvas.handle,0);

        end;  
      deleteobject(LR);
      deleteobject(DR);
    end;
  //Inner Border...
  if InnerBorderStyle<>iablsNone then
    begin
      DR:=CreaterectRGN(0,0,0,0);
      LR:=CreaterectRGN(0,0,0,0);
      for i:=0 to length(FLedPoints)-1 do
        begin
          if i<>(length(FLedPoints)-1) then
            begin
              ar1[0].x:=FGapPoints[i].x;ar1[0].y:=FGapPoints[i].y;
              ar1[1].x:=FInnerPoints[i].x;ar1[1].y:=FInnerPoints[i].y;
              ar1[2].x:=FInnerPoints[i+1].x;ar1[2].y:=FInnerPoints[i+1].y;
              ar1[3].x:=FGapPoints[i+1].x;ar1[3].y:=FGapPoints[i+1].y;
            end else
            begin
              ar1[0].x:=FGapPoints[i].x;ar1[0].y:=FGapPoints[i].y;
              ar1[1].x:=FInnerPoints[i].x;ar1[1].y:=FInnerPoints[i].y;
              ar1[2].x:=FInnerPoints[0].x;ar1[2].y:=FInnerPoints[0].y;
              ar1[3].x:=FGapPoints[0].x;ar1[3].y:=FGapPoints[0].y;
            end;
          TryAngle:=0;
          if  InnerBorderStyle=iablsDown then inc(TryAngle,1800);
          ddx:=ar1[2].x-ar1[1].x;ddy:=ar1[1].y-ar1[2].y;
          if (abs(round(ddx))+abs(round(ddy)))<>0 then
            begin
              if round(ddx)=0 then
                begin
                  if ddy>0 then inc(TryAngle,900) else dec(TryAngle,900);
                end else
                begin
                  TryAngle:=Tryangle+round(1800*Arctan2(ddy/(abs(ddx)+abs(ddy)),ddx/(abs(ddx)+abs(ddy)))/pi);
                end;
            end;
          R1:=CreatePolygonRGN(ar1[0],4,Alternate);      
          if Angleisdark(TryAngle)      then
            Combinergn(DR,DR,R1,RGN_OR) else
            Combinergn(LR,LR,R1,RGN_OR);
          deleteobject(R1);  
        end;
      if (FBorderSubstance=nil) or (FBorderL.height=0)  or (FBorderD.height=0) then
        begin
          FPaintBitmap.canvas.brush.color:=GetLColor(FBorderColor);
          fillRGN(FPaintBitmap.canvas.handle,LR,FPaintBitmap.canvas.brush.handle);
          FPaintBitmap.canvas.brush.color:=GetDColor(FBorderColor);
          fillRGN(FPaintBitmap.canvas.handle,DR,FPaintBitmap.canvas.brush.handle);
        end else
        begin
          selectClipRGN(FPaintBitmap.canvas.handle,LR);
          if FBorderSubsMode = iasmTile then
            begin
              for i:=0 to FPaintbitmap.Width div FBorderL.width do
                for j:=0 to FPaintbitmap.height div FBorderL.height do
                  FPaintBitmap.Canvas.Draw(i*FBorderL.width,
                                           j*FBorderL.height,
                                           FBorderL);
            end else
            begin
              FPaintBitmap.Canvas.StretchDraw(rect(0,0,FPaintbitmap.Width,FPaintbitmap.height),FBorderL);
            end;
          selectClipRGN(FPaintBitmap.canvas.handle,DR);
          if FLedPlasticSubsMode = iasmTile then
            begin
              for i:=0 to FPaintbitmap.Width div FBorderD.width do
                for j:=0 to FPaintbitmap.height div FBorderD.height do
                  FPaintBitmap.Canvas.Draw(i*FBorderD.width,
                                           j*FBorderD.height,
                                           FBorderD);
            end else
            begin
              FPaintBitmap.Canvas.StretchDraw(rect(0,0,FPaintbitmap.Width,FPaintbitmap.height),FBorderD);
            end;
          selectClipRGN(FPaintBitmap.canvas.handle,0);
        end;  
      deleteobject(LR);
      deleteobject(DR);
    end;
end;

function TIAgaloLED.GetWidth: integer;
begin
  result:=inherited width;
end;

procedure TIAgaloLED.Loaded;
begin
  inherited Loaded;
  if (FBorderSubstance<>nil) and (FBorderSubstance.height<>0) then
    begin
      FBorderL.Width:=FBorderSubstance.Width;
      FBorderL.Height:=FBorderSubstance.Height;
      FBorderL.PixelFormat:=pf24bit;
      FBorderL.Canvas.Draw(0,0,FBorderSubstance);
      FBorderD.Width:=FBorderSubstance.Width;
      FBorderD.Height:=FBorderSubstance.Height;
      FBorderD.PixelFormat:=pf24bit;
      FBorderD.Canvas.Draw(0,0,FBorderSubstance);
      Light24Bitmap(FBorderL,64);
      Dark24Bitmap(FBorderD,64);
    end;  
end;


procedure TIAgaloLED.Paint;
var
  Gbmp : TBitmap;
  Gpoint : TPoint;
  H1 : HWND;
  DC : HDC;
  i,j,N : integer;
  pByte1 : pbytearray;
  C1 : Tcolor;
  pR,pG,pB : pbyte;
  rx,ry : double;
  RR : HRGN;
begin
      inherited paint;
      if assigned(parent) and (fGaloOn or FGaloOnwas) then
        begin
          RR:=CreateEllipticRGN(left-FGaloSize,top-FGalosize,left+width+FGalosize,top+height+FGalosize);
          RedrawWindow(self.parent.handle,nil,RR,RDW_INVALIDATE or RDW_UPDATENOW or RDW_NOCHILDREN);
          deleteobject(rr);
          if FGaloOnwas then FGaloOnwas:=false;
        end;
      self.Canvas.Draw(0,0,FPaintBitmap);
      if FLedon and FGaloOn and (FGaloSize>0) then
        begin
          GPoint:=self.GetClientOrigin;
          GBmp:=TBitmap.Create;
          GBmp.PixelFormat:=pf24bit;
          GBmp.Width:=width+2*FGaloSize;
          GBmp.Height:=height+2*FGalosize;
          H1:=getdesktopwindow;
          DC:=GetWindowDC(H1);
          bitblt(Gbmp.Canvas.handle,0,0,GBmp.Width,Gbmp.Height,DC,GPoint.x-FGalosize,GPoint.y-FGaloSize,SRCCOPY);
          C1:=ColortoRGB(FLedplasticcolor);
          pR:=@C1;
          pG:=pbyte(integer(pr)+1);
          pB:=pbyte(integer(pG)+1);
          for i:=0 to GBmp.height-1 do
            begin
              pByte1:=GBmp.ScanLine[i];
                for j:=0 to GBmp.Width-1 do
                  begin
                    try
                      ry:=2*i/Gbmp.Height-1;rx:=2*j/Gbmp.Width-1;
                      N:=round((FGaloIntensity /10)*(255-255*sqrt(sqr(rx)+sqr(ry))));
                    except
                      N:=0;
                    end;
                    if N>255 then N:=255;
                    if N<0 then N:=0;
                    pByte1[j*3]:=min(255,pByte1[j*3]+N*pB^ div 255);
                    pByte1[j*3+1]:=min(255,pByte1[j*3+1]+N*pG^ div 255);
                    pByte1[j*3+2]:=min(255,pByte1[j*3+2]+N*pR^ div 255);
                  end;
            end;

          bitblt(DC,GPoint.x-FGalosize,GPoint.y-FGaloSize,GBmp.Width,Gbmp.Height,Gbmp.Canvas.handle,0,0,SRCCOPY);
          releaseDC(H1,DC);
          GBmp.free;
        end;
end;

procedure TIAgaloLED.reinsertpoints;
var i : integer;
begin
  setlength(FLedPoints,length(FLedPointsxy));
  setlength(FGapPoints,length(FGapPointsxy));
  setlength(FInnerPoints,length(FInnerPointsxy));
  setlength(FOuterPoints,length(FOuterPointsxy));
  for i:=0 to length(FLedPointsxy)-1 do
    begin
      FLedpoints[i].x:=round(FLedpointsxy[i].x);
      FLedpoints[i].y:=round(FLedpointsxy[i].y);
    end;
  for i:=0 to length(FGapPointsxy)-1 do
    begin
      FGapPoints[i].x:=round(FGapPointsxy[i].x);
      FGapPoints[i].y:=round(FGapPointsxy[i].y);
    end;
  for i:=0 to length(FInnerPointsxy)-1 do
    begin
      FInnerPoints[i].x:=round(FInnerPointsxy[i].x);
      FInnerPoints[i].y:=round(FInnerPointsxy[i].y);
    end;
  for i:=0 to length(FOuterPointsxy)-1 do
    begin
      FOuterPoints[i].x:=round(FOuterPointsxy[i].x);
      FOuterPoints[i].y:=round(FOuterPointsxy[i].y);
    end;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -