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

📄 myedit.~pas

📁 delphi LED 显示屏用,带串口发送,内容编辑,演示功能
💻 ~PAS
📖 第 1 页 / 共 5 页
字号:
begin
    if Value <> Fscale then
    begin
        Fscale:=Value;
        width:=8*Ftpbyte*Fscale;
        height:=16*Ftprownum*Fscale;
    end;
end;

procedure Tmyedit.setspace(Value: integer);
begin
    if Value <> Fspace then
    begin
        Fspace:=Value;
    end;
end;

procedure Tmyedit.setplay(Value: Boolean);
begin
    if Value <> Fplay then
    begin
        Fplay:=Value;
        Invalidate;
    end;
end;

procedure Tmyedit.setaddflag(Value: Boolean);
begin
    if Value <> Faddflag then
    begin
        Faddflag:=Value;
        Invalidate;
    end;
end;

procedure Tmyedit.setdataflag(Value: Boolean);
begin
    if Value <> Fdataflag then
    begin
        Fdataflag:=Value;
        writestr;
        paint;
    end;
end;

procedure Tmyedit.Setselectbmpno(Value: integer);
begin
    if (Value <> Fselectbmpno) and (Value<getimagecount) and (Fplay=false) then
    begin
        Fselectbmpno:=Value;
        Invalidate;
    end;
end;

procedure Tmyedit.change;
begin
    if (Ftpcount=0) and (Ftxt<>'') then Ftpcount:=1;
    paint;
end;

procedure Tmyedit.settxt(value:ansistring);
begin
     if  Ftxt<>Value then
     begin
        Ftxt:=value;
     end;
end;

procedure Tmyedit.writestr;
var
   linewidth,lineheight,lineno,kw,kh:integer;
   i,j,klen,kk,k:longint;
   str1,str2:ansistring;
begin
     for i:=0 to 5000 do tpstr[i].no:=0;
     str1:=ftxt;
     klen:=length(str1);
     i:=0;
     kk:=0;
     lineno:=0;
     linewidth:=0;
     lineheight:=0;
     Canvas.Font:=font;
     while i<klen do
     begin
          kh:=(4*tpdata[i].fontsize+1) div 3;
          if str1[i+1]=#13 then
          begin
               if lineheight<kh then lineheight:=kh;
               lineheight:=lineheight;
               tpstr[lineno].lineheight:=lineheight+Fspace;
               tpstr[lineno].linebyte:=i-kk+2;
               lineno:=lineno+1;
               linewidth:=0;
               lineheight:=0;
               i:=i+2;
               kk:=i;
          end
          else
          begin
               str2:=str1[i+1];
               k:=1;
               if str1[i+1]>#$80 then
               begin
                    k:=2;
                    str2:=str2+str1[i+2];
               end;
               kw:=k*kh div 2;
               linewidth:=linewidth+kw;
               if linewidth>8*Ftpbyte then
               begin
                    tpstr[lineno].linebyte:=i-kk;
                    tpstr[lineno].lineheight:=lineheight+Fspace;
                    lineno:=lineno+1;
                    kk:=i;
                    linewidth:=kw;
                    lineheight:=kh;
               end
               else
               begin
                    if lineheight<kh then  lineheight:=kh;
               end;
               i:=i+k;
          end;
     end;
     if  linewidth<>0 then
     begin
          tpstr[lineno].linebyte:=klen-kk;
          tpstr[lineno].lineheight:=lineheight+Fspace;
          lineno:=lineno+1;
     end;
     totalline:=lineno;
     j:=0;
     tptotal:=0;
     for i:=0  to lineno-1 do
     begin
          j:=j+tpstr[i].lineheight;
          if j>16*Ftprownum then
          begin
               tptotal:=tptotal+1;
               j:=tpstr[i].lineheight;
          end;
          tpstr[i].no:=tptotal+1;
     end;
     if (j>0) then tptotal:=tptotal+1;
end;

procedure Tmyedit.settppos(Value: longint);
var
    i:integer;
    kk,klen:longint;
begin
    if Value <> Ftppos then
    begin
          Ftppos:=Value;
          if Ftxt='' then Ftpcount:=0
          else
          begin
               kk:=0;
               i:=0;
               klen:=Ftppos;
               while (kk+tpstr[i].linebyte<=klen) and (i<totalline) do
               begin
                    if kk+tpstr[i].linebyte<=klen then
                    begin
                         kk:=kk+tpstr[i].linebyte;
                         if kk<=klen then i:=i+1;
                    end;
               end;
               if i>=totalline then i:=totalline-1;
               Ftpcount:=tpstr[i].no;
          end;
     end;
end;

procedure Tmyedit.settpcount(Value: integer);
var
    i,j:integer;
    kk:longint;
begin
    if Value <> Ftpcount then
    begin
        Ftpcount:=Value;
        if Ftpcount<2 then Ftppos:=0
        else
        begin
            kk:=0;
            j:=0;
            for i:=0 to Ftpcount-2 do
            begin
                while (tpstr[j].no=i+1) and (j<totalline) do
                begin
                    kk:=kk+tpstr[j].linebyte;
                    j:=j+1;
                end;
            end;
            Ftppos:=kk;
        end;
     //   Invalidate;
    end;
end;

procedure Tmyedit.Paint;
begin
    calpaint;
    Canvas.Draw(0,0,bmp);
end;

procedure Tmyedit.calpaint;
var
    str1:string;
    i,j,k,x,y,k1,kh,kw,yoff,yy:integer;
    kx,ky:integer;
    kk,kct:longint;
    pic:Tpicture;
begin
    bmp.Width:=width;
    bmp.Height:=height;
    bmp.Canvas.Brush.Color:=color;
    bmp.Canvas.FillRect(rect(0,0,bmp.Width,bmp.Height));
    bmp.Canvas.Font:=Font;
    bmp.Canvas.CopyMode:=cmSrcPaint;
    kk:=0;
    if Ftpcount>0 then
    begin
        i:=0;
        while (tpstr[i].no<Ftpcount) and (i<totalline) do
        begin
            kk:=kk+tpstr[i].linebyte;
            i:=i+1;
        end;
        y:=0;
        j:=i;
        x:=1;
        while (tpstr[j].no=Ftpcount) and (j<totalline) do
        begin
               y:=y+tpstr[j].lineheight;
               j:=j+1;
               x:=x+1;
        end;
        yy:=(height-y*Fscale) div x;
        y:=yy;
        while (tpstr[i].no=Ftpcount) and (i<totalline) do
        begin
            j:=0;
            x:=0;
            while(j<tpstr[i].linebyte) do
            begin
                str1:=Ftxt[kk+1];
                k:=1;
                if str1[1]>#$80 then
                begin
                    str1:=str1+Ftxt[kk+2];
                    k:=2;
                end;
                kh:=((4*tpdata[kk].fontsize+1) div 3);
                kw:=k*kh div 2;
                k1:=tpdata[kk].extra div $10;
                if (k1=0) or (k1>6) then
                begin
                    myfont.lfHeight:=kh;
                    myfont.lfWidth:=kh;
                end
                else if (k1=6) or (k1=5) then
                begin
                    myfont.lfHeight:=kh-2;
                    myfont.lfWidth:=kh-2;
                end
                else if (k1=1) or (k1=2) then
                begin
                    myfont.lfWidth:=kh;
                    myfont.lfHeight:=kh-1;
                end
                else  if (k1=3) or (k1=4) then
                begin
                    myfont.lfWidth:=kh-1;
                    myfont.lfHeight:=kh;
                end;
                if (tpdata[kk].fontstyle and $80)=0 then myfont.lfWeight:=400
                else  myfont.lfWeight:=700;
                if (tpdata[kk].fontstyle and $40)=0 then myfont.lfItalic:=0
                else myfont.lfItalic:=1;
                if (tpdata[kk].fontstyle and $20)=0 then myfont.lfUnderline:=0
                else myfont.lfUnderline:=1;
                if (tpdata[kk].fontstyle and $10)=0 then  myfont.lfStrikeOut:=0
                else myfont.lfStrikeOut:=1;
                sysfont.Handle:=CreateFontIndirect(myfont);
                bmp.Canvas.font.Assign(SYSfont);

                if tpdata[kk].fontname<=0 then tpdata[kk].fontname:=fontname.Count-1;
                bmp.Canvas.Font.Name:=fontname.Strings[tpdata[kk].fontname];
                if (tpdata[kk].color<0) or (tpdata[kk].color>2)  then  tpdata[kk].color:=0;
               // bmp.Canvas.Font.Color:=SCREENCOLOR[tpdata[kk].color];
                if str1[1]>=#$20 then
                begin
                    yoff:=((tpstr[i].lineheight-kh)) div 2;
                    if yoff<0 then yoff:=0;
                    if (kw>0) and (kh>0) then
                    begin
                      bmptemp.Width:=2*kw;
                      bmptemp.Height:=kh;
                      bmptemp.Canvas.Brush.Color:=color;
                      bmptemp.Canvas.FillRect(Rect(0,0,bmptemp.Width,bmptemp.Height));
                      bmptemp.Canvas.Font:=bmp.Canvas.Font;

                      if (k1=6) then
                      begin
                        bmp.Canvas.CopyMode:=cmSrcPaint;
                        bmptemp.Canvas.Font.Color:=SCREENCOLOR[tpdata[kk].color];
                        bmptemp.canvas.TextOut(1,0,str1);
                        bmp.Canvas.Draw(x,y+yoff,bmptemp);
                        bmptemp.Canvas.Brush.Color:=color;
                        bmptemp.Canvas.FillRect(Rect(0,0,bmptemp.Width,bmptemp.Height));
                        bmptemp.canvas.TextOut(1,2,str1);
                        bmp.Canvas.Draw(x,y+yoff,bmptemp);
                        bmptemp.Canvas.FillRect(Rect(0,0,bmptemp.Width,bmptemp.Height));
                        bmptemp.canvas.TextOut(0,1,str1);
                        bmp.Canvas.Draw(x,y+yoff,bmptemp);
                        bmptemp.Canvas.FillRect(Rect(0,0,bmptemp.Width,bmptemp.Height));
                        bmptemp.canvas.TextOut(2,1,str1);
                        bmp.Canvas.Draw(x,y+yoff,bmptemp);
                        bmptemp.Canvas.Brush.Color:=$ffffff;
                        bmptemp.Canvas.FillRect(Rect(0,0,bmptemp.Width,bmptemp.Height));
                        bmp.Canvas.CopyMode:=cmSrcAnd;
                        bmptemp.Canvas.Font.Color:=0;
                        bmptemp.canvas.TextOut(1,1,str1);
                        bmp.Canvas.Draw(x,y+yoff,bmptemp);
                      end
                      else if k1=1 then
                      begin
                        bmp.Canvas.CopyMode:=cmSrcPaint;
                        bmptemp.Canvas.Font.Color:=$ff*(tpdata[kk].extra and 1)+$ff00*(tpdata[kk].extra div 2 and 1);
                        bmptemp.canvas.TextOut(0,0,str1);
                        bmp.Canvas.Draw(x,y+yoff,bmptemp);
                        bmptemp.Canvas.Brush.Color:=$fffff;
                        bmptemp.Canvas.FillRect(Rect(0,0,bmptemp.Width,bmptemp.Height));
                        bmp.Canvas.CopyMode:=cmSrcAnd;
                        bmptemp.Canvas.Font.Color:=0;
                        bmptemp.canvas.TextOut(0,1,str1);
                        bmp.Canvas.Draw(x,y+yoff,bmptemp);
                        bmptemp.Canvas.Brush.Color:=0;
                        bmptemp.Canvas.FillRect(Rect(0,0,bmptemp.Width,bmptemp.Height));
                        bmp.Canvas.CopyMode:=cmSrcPaint;
                        bmptemp.Canvas.Font.Color:=SCREENCOLOR[tpdata[kk].color];
                        bmptemp.canvas.TextOut(0,1,str1);
                        bmp.Canvas.Draw(x,y+yoff,bmptemp);
                      end
                      else if k1=2 then

⌨️ 快捷键说明

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