Перейти к содержанию

Рисование стрелок


MasterGH

Рекомендуемые сообщения

58d0c543bdced_.png.71e7cebedf53591acfec2

 

Скрытый текст

 

 

Скрытый текст

local arrowMap = '*00000000000000* ****00000000**** ******0000****** **************** ******0000****** ****00000000**** *00000000000000*'
arrowBitMap = nil

function GetBitMapArrows(colorArrows, colorBackGround)

	local tableStringPixels = {}
	for i in string.gmatch(arrowMap, "%S+") do table.insert(tableStringPixels, i) end
	local height = #tableStringPixels
	local width = #tableStringPixels[1]

	local bitmap = createBitmap(width, height)
    bitmap.Canvas.Brush.Color = colorBackGround
    bitmap.Canvas.fillRect(0, 0, width, height)

	for y=1,height do
		local line = tableStringPixels[y]
		for x=1,width  do
	    if(string.sub(line,x,x)=='*') then
				bitmap.Canvas.setPixel(x-1, y-1, colorArrows)
	    end
		end
	end

	return bitmap
end

function DrawArrow(targetCanvas, point1, point2, distance, minHeight, colorArrow, colorBackGround, arrowBitMap, isDot , isShowPosition)

    targetCanvas.Brush.Color = colorBackGround
	targetCanvas.Pen.Color = colorArrow
	
	if(isDot) then
		targetCanvas.Pen.Style = 'psDot'
	else
		targetCanvas.Pen.Style = 'psSolid'
	end

	if(isShowPosition) then
		targetCanvas.textOut(point1.x, point1.y, string.format('(%s,%s)',point1.x, point1.y))
		targetCanvas.textOut(point2.x, point2.y, string.format('(%s,%s)',point2.x, point2.y))
	end
	
	local height = targetCanvas.Height

	isDrawSideLine1 = true

	if(point1.y < minHeight) then
	  point1.y = minHeight  isDrawSideLine1 = false
	elseif (point1.y > height) then
	  point1.y = height isDrawSideLine1 = false end

	isDrawRow = true
	if(point2.y < minHeight) then
	  point2.y = minHeight
	  isDrawRow = false
	elseif (point2.y > height) then
	  point2.y = height isDrawRow = false
	end

	if(isDrawSideLine1) then
		targetCanvas.line(point1.x, point1.y, point2.x - distance, point1.y)
	end
	
	targetCanvas.line(point2.x - distance, point1.y, point2.x - distance, point2.y)



	if(isDrawRow) then
		targetCanvas.line(point2.x, point2.y, point2.x - distance, point2.y)
		--targetCanvas.Pen.Style = 'psSolid' --'psSolid'

		local x1 = point2.x - 5
		local x2 = point2.x
		local y2 = point2.y

		local arrowWidth = arrowBitMap.Width / 2
		local arrowHeight = arrowBitMap.Height
		local dyArrow =  arrowHeight/2 - 1

		if(point2.x - distance > point2.x) then
			targetCanvas.copyRect (
				point2.x, point2.y - dyArrow,
				point2.x + arrowWidth, point2.y + arrowHeight - dyArrow,
				arrowBitMap.Canvas,
				arrowWidth,
				0,
				arrowWidth*2,
				arrowHeight
			)
		else
			targetCanvas.copyRect(
				point2.x, point2.y - dyArrow,
				point2.x + arrowWidth, point2.y + arrowHeight - dyArrow,
				arrowBitMap.Canvas,
				0,
				0,
				arrowWidth,
				arrowHeight)
		end


	end

end

if(UDF1 == nil) then
	UDF1 = createForm(true)
	UDF1.Width = 500
	UDF1.Height = 300
end




local point1 = {x = UDF1.Width/2, y = UDF1.Height/2}
local point2 = {x = 200, y = 200}
local distance = -50
local colorArrow = 0x00000000
local colorBackGround = 0xC8D0D4
local minHeight = 10
local isDot = false
local isShowPosition = true

if(arrowBitMap == nil) then
	arrowBitMap = GetBitMapArrows(colorArrow, colorBackGround)
end


if(testTimer == nil) then
  testTimer = createTimer(UDF1)
  testTimer.Interval = 50
end

testTimer.OnTimer = function()
	point2.x, point2.y = getMousePos()
	point2.x = point2.x - UDF1.Left
	point2.y = point2.y - UDF1.Top
	
	UDF1.repaint()
	DrawArrow (UDF1.canvas, point1, point2, distance, minHeight, colorArrow, colorBackGround, arrowBitMap, isDot, isShowPosition)
end

 

 

Ссылка на комментарий
Поделиться на другие сайты

×
×
  • Создать...

Важная информация

Находясь на нашем сайте, Вы автоматически соглашаетесь соблюдать наши Условия использования.