我正试着把这个放到画布上
名称:飞跃的熔岩水
像这样做..它检查玩家的名字下是否应该有一些东西,如飞行,熔岩,或水。因此,标签文本以球员的名字开头。所有的标签都会有这个。然后,如果任何像canwater这样的“额外内容”是真的,那么它将添加一个包含相关文本的新行。如下所示。
canwater := (FTherePlayers.Player[strtoint(name2)].values['water'] = 'Yes'); //checks if unit can enter water
canlava := (FTherePlayers.Player[strtoint(name2)].values['lava'] = 'Yes'); //checks if unit can enter lava
canfly := (FTherePlayers.Player[strtoint(name2)].values['Flying'] = 'Yes'); //checks if unit can fly
labeltext := FTherePlayers.Player[strtoint(name2)].values['name'];
if canfly then
labeltext := labeltext+ #13#10+ 'Flying';
if canlava then
labeltext := Labeltext+#13#10+'Lava';
if canwater then
labeltext := labeltext+#13#10+'Water';
hexmap1.AddLabelName(Labeltext,posL); //add name to placement label现在,它将为标题提供正确的信息。但是它并没有添加新的行,而是看起来像这样
name[][]flying[][]lava[][]water[][]其中[]是小方块,我用于文本输出的代码如下所示。
procedure THexmap.AddLabelName(text :string; Position :TPoint);
var
hex_id :string;
P0:tpoint;
begin
with TempMap.canvas do
begin
hex_id := text;
hex_id := text;
{font := self.font;}
p0 := convertcoords(point(Position.X,Position.Y),ptROWCOL);
textout(p0.x - (trunc(textwidth(hex_id) / 2)) ,p0.y- (textheight(hex_id)) ,hex_id);
end;
Refresh;
end;它很大程度上会将新图像或文本加载到临时映射中。hex_ID是名称/飞行/熔岩..例如PO是将其放在地图上的位置,也就是第1行,第3列。至于文本输出,我不确定它是如何工作的。但是想一想“换行符”代码#10#13在那里变得混乱了。那我怎么解决这个问题有什么建议吗?
添加了如何获得XY(tpoint)
{******************************************************************************}
{ This function will return the Row / Col pair based on a given X/Y
for a using application that calls it}
function THexMap.ConvertCoords(point:Tpoint;pointtype:Tpointtype):Tpoint;
var
temp:TPoint;
begin
case PointType of
ptXY: {Convert from x/y to Row/Col}
Begin
temp.x:= round( (point.x + (HexRadius/2) ) / (1.5 * Hexradius));
if odd(temp.x) then
temp.y := round( (point.y + rise) / (rise*2))
else
temp.y := round( point.y / (2*rise));
{ This section insures row / col is good}
if (temp.x < 1) or (temp.y < 1) then
begin
temp.x := 0;
temp.y := 0;
end
else if (temp.y > HexRows) or (temp.x > HexColumns) then
begin
temp.y := 0;
temp.x := 0;
end;
ConvertCoords := temp;
end;
ptRowCol: { Converts Row/Col to X/Y }
begin
if point.x=1 then
temp.x:= HexRadius
else
temp.x := HexRadius+(point.x-1) * (round(1.5 * hexradius));
if odd(point.x) then
if point.y=1 then
temp.y:= rise
else
temp.y := rise+(point.y-1) * (2 * rise)
else
temp.y := (point.y * (2*rise));
ConvertCoords := temp;
end;
end;
end;发布于 2012-11-19 14:48:15
TextOut只是将#13#10视为两个要绘制的字符。这就是为什么你会看到方块。它不知道您打算将文本放在不同的行上。
您必须将文本放在不同的线条上,例如,通过编写4个对TextOut的调用。
您也可以从Win32应用编程接口中使用DrawText。
发布于 2012-11-19 15:37:45
var
s:String;
r:TRect;
begin
s := 'Just'#13#10'for'#13#10'demonstration';
r.Left := 10;
r.top := 10;
r.Right := 100;
r.Bottom := 100;
// you can use this with newer Delphiversions
// Canvas.TextRect(r,s, [tfCenter,tfWordBreak]);
// with olderversions you can use this =1 =16
DrawTextEx(Canvas.Handle, PChar(s), Length(s), r, DT_CENTER or DT_WORDBREAK, nil);
end;作为如何从点获得直方图问题的答案
var
s:String;
r:TRect;
begin
s := 'Just'#13#10'for'#13#10'demonstration';
r.Left := p0.x;
r.top := p0.y;
r.Right := p0.x + 10000; // we will calculate needed rect later
r.Bottom := p0.y + 10000; // via DT_CALCRECT
// you can use this with newer Delphiversions
// Canvas.TextRect(r,s, [tfCenter,tfWordBreak,tfCalcRect]);
// with olderversions you can use this =1 =16 1024
DrawTextEx(Canvas.Handle, PChar(s), Length(s), r, DT_CENTER or DT_WORDBREAK or DT_CALCRECT, nil);
// you can use this with newer Delphiversions
// Canvas.TextRect(r,s, [tfCenter,tfWordBreak]);
// with olderversions you can use this =1 =16
DrawTextEx(Canvas.Handle, PChar(s), Length(s), r, DT_CENTER or DT_WORDBREAK, nil);
end;https://stackoverflow.com/questions/13448476
复制相似问题