Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- * * *
- -- GUI API (OpenComputers) (1.0)
- -- 05/04/2015 (c) computercraft.ru
- -- Created by Totoro, LeshaInc, Xom and with some magic
- -- * * *
- -- Создаем таблицу
- local API = {}
- local param= {}
- -- Подключаем системные API
- local event = require('event')
- local term = require("term")
- local component = require("component")
- local gpu = component.gpu
- -- Константы
- -- Получаем разрешение монитора
- local WIDTH, HEIGHT = gpu.getResolution() -- понятные названия - наше все =)
- -- Цвета
- local color = {}
- color.green = 0x00AA00
- color.red = 0xAA0000
- color.black = 0x000000
- color.white = 0xFFFFFF
- -- Символы из Юникода
- local LOWER_HALF_BLOCK = "▄"
- local UPPER_HALF_BLOCK = "▀"
- local LEFT_HALF_BLOCK = "▌"
- local RIGHT_HALF_BLOCK = "▐"
- local FLOWERS = "✽ ✾ ✿ ❁ ❃ ❋ ❀"
- -- Функция очистки (можно заменить на вызов term.clear()) На всякий случай
- function API.xclear()
- gpu.setBackground(Black)
- gpu.fill(1, 1, WIDTH, HEIGHT, " ")
- end
- function API.clear()
- for i = 1, HEIGHT, 1 do
- for j = 1, WIDTH, 1 do
- if gpu.get(i, j) then
- gpu.set(i, j
- end
- -- Псевдографика --
- -- Функция рисования пикселя
- function API.pixel(x,y,color)
- gpu.setBackground(color)
- gpu.set(x,y," ")
- end
- -- Линия от А до Б
- -- (Запасной вариант) LeshaInc опять ничего не понял.
- function API.xline(x1, y1, x2, y2, color, symbol)
- local deltax,deltay,stat,errors= 0,0,1
- deltax= x1-x2
- deltay= y1-y2
- errors= deltax/deltay
- if (x1 < x2)then
- stat= -1
- end
- for i=x1,x2,stat do
- end
- end
- -- Функция создания заполненной коробки
- function API.box(x,y,WIDTH,HEIGHT,color)
- gpu.setBackground(color)
- gpu.fill(x,y,WIDTH,HEIGHT," ")
- end
- -- Функция выдачи позиции курсора
- function API.getClick()
- local name, x, y, button, playerName = event.pull()
- return x, y, button, playerName
- end
- -- Функция написания текста центрированного относительно X
- function API.centerTextX(y,text,color)
- gpu.setForeground(color)
- gpu.set(w/2 - #text/2, y, text)
- end
- -- Функция написания текста центрированного относительно Y
- function API.centerTextY(x,text,color)
- gpu.setForeground(color)
- gpu.set(x,h/2-#text/2,text)
- end
- -- Функция написания текста центрированно относительно XY
- function API.centerTextXY(text,color)
- gpu.setForeground(color)
- gpu.set(x-#text/2,y-#text/2,text)
- -- Функция отображения 'пустой' коробки
- function API.emptyBox(x,y,WIDTH,HEIGHT,color_inside,color_side,strip_thickness)
- gpu.setBackground(color_side)
- gpu.fill(x,y,WIDTH,HEIGHT, " ")
- gpu.setBackground(color_inside)
- gpu.fill(x+strip_thickness,y+strip_thickness,WIDTH-strip_thickness,HEIGHT-strip_thickness, " ")
- end
- -- Ported from CC paintutils lib: LeshaInc говорит:"Это за грани моего понимания."
- function API.line(startX, startY, endX, endY, nColor)
- if type(startX) ~= "number" or type(startX) ~= "number" or
- type(endX) ~= "number" or type(endY) ~= "number" or
- (nColor ~= nil and type(nColor) ~= "number") then
- error("Expected startX, startY, endX, endY, color", 2)
- end
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- if startX == endX and startY == endY then
- API.pixel(startX, startY, nColor)
- return
- end
- local minX = math.min(startX, endX)
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- -- TODO: clip to screen rectangle?
- local xDiff = maxX - minX
- local yDiff = maxY - minY
- if xDiff > math.abs(yDiff) then
- local y = minY
- local dy = yDiff / xDiff
- for x=minX,maxX do
- API.pixel(x, math.floor(y + 0.5), nColor)
- y = y + dy
- end
- else
- local x = minX
- local dx = xDiff / yDiff
- if maxY >= minY then
- for y=minY,maxY do
- API.pixel(math.floor(x + 0.5), y, nColor)
- x = x + dx
- end
- else
- for y=minY,maxY,-1 do
- API.pixel(math.floor(x + 0.5 ), y, nColor)
- x = x - dx
- end
- end
- end
- end
- return API
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement