Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --==[Libraries]==--
- local cmp = require("component")
- local m = cmp.modem
- local event = require("event")
- local serialization = require("serialization")
- local unicode=require("unicode")
- local filesystem = require("filesystem")
- local shell = require("shell")
- local term = require("term")
- local unicode=require('unicode')
- local computer = require("computer")
- local gpu = cmp.gpu
- local draw = require("draw")
- --local thread = require("thread")
- local keyboard = require("keyboard")
- a,b=gpu.getResolution()
- --==[Locals]==--
- symb=" "
- local back =0
- local fore =0xFFFFFF
- -------
- gpu.setBackground(0xffffff)
- term.clear()
- --==[Other functions]==--
- local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
- local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
- function f()
- arr={}
- for j=1,a-21 do
- for i=1,b do
- symb1,fore,back=gpu.get(j,i)
- if symb1 ~= '░' then
- arr[#arr+1]={j,i,symb1,fore,back}
- end
- end
- end
- return arr
- end
- function exit(x,y)
- gpu.setBackground(0xff0000)
- gpu.fill(a,1,1,1," ")
- gpu.setForeground(0xFFFFFF)
- gpu.set(a,1,"X")
- if x==a and y==1 then
- gpu.setBackground(0)
- arr=f()
- saveTbl(arr,picFile)
- term.clear()
- os.exit()
- end
- end
- --==[Graphics]==--
- function drawField()
- gpu.setBackground(0)
- gpu.setForeground(0)
- drawWeb()
- gpu.setBackground(0xffffff)
- gpu.fill(a-20,1,21,b," ")
- gpu.setBackground(back)
- gpu.fill(a-15,3,7,3," ")
- draw.field(a-16,b-5,12,4,' ',0x505050,0x505050)
- draw.clound('┌','┐','└','┘','│','─',a-16,b-5,12,4,0x505050,0xFFFFFF)
- draw.text(a-16,b-5,12,'Авторы:',0x505050,0xFFFFFF)
- draw.text(a-15,b-4,10,'MeXaN1cK',0x505050,0xFFFFFF)
- draw.text(a-15,b-3,10,'PandaDoddo',0x505050,0xFFFFFF)
- end
- function drawWeb()
- gpu.setForeground(0xffffff)
- gpu.setBackground(0xffffff)
- gpu.fill(1,1,a-20,b,'░')
- gpu.setForeground(0xAAAAAA)
- gpu.setBackground(0xAAAAAA)
- for j=1,b do
- for i=1,a-20 do
- if math.ceil(j/2) > math.floor(j/2) then
- if math.ceil(i/2) > math.floor(i/2) then
- gpu.set(i,j,'░')
- end
- else
- if math.ceil(i/2) == math.floor(i/2) then
- gpu.set(i,j,'░')
- end
- end
- end
- end
- end
- function pr()
- for i=1,#arr do
- gpu.setBackground(arr[i][5])
- gpu.setForeground(arr[i][4])
- gpu.set(arr[i][1],arr[i][2],arr[i][3])
- end
- end
- function drawPixel(key,x,y,mB)
- if key=="drag" or key=="drop" or key=="touch" then
- if x>0 and x<a-20 and y>0 and y<=b then
- if mB == 0 then
- gpu.set(x,y,symb)
- elseif mB ==1 then
- gpu.setForeground(0xAAAAAA)
- gpu.setBackground(0xAAAAAA)
- if math.ceil(y/2) > math.floor(y/2) then
- if math.ceil(x/2) > math.floor(x/2) then
- gpu.set(x,y,'░')
- else
- gpu.setForeground(0xffffff)
- gpu.setBackground(0xffffff)
- gpu.set(x,y,"░")
- end
- elseif math.ceil(y/2) == math.floor(y/2) then
- if math.ceil(x/2) == math.floor(x/2) then
- gpu.set(x,y,'░')
- else
- gpu.setForeground(0xffffff)
- gpu.setBackground(0xffffff)
- gpu.set(x,y,'░')
- end
- end
- end
- end
- end
- end
- function selCol(x,y)
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0)
- gpu.fill(a-15,8,7,1," ")
- gpu.set(a-15,8,"Палитра")
- if x>=a-15 and x<=a-8 and y>=8 and y<=8 then
- arr=f()
- back=draw.colorSelector("Палитра для выбора цвета")
- drawField()
- pr()
- end
- end
- function enter(x,y,w,h,color_back,color_fore)
- got=nil
- function drawTextInPass(x,y,w,h,txt,col)
- if unicode.len(txt) > w-3 then
- txt=unicode.sub(txt,unicode.len(txt)-(w-3),unicode.len(txt))
- end
- draw.field(x+1,y+1,w-2,1,' ',color_back,color_fore)
- oldB=gpu.getBackground()
- oldF=gpu.getForeground()
- gpu.setBackground(color_back)
- gpu.setForeground(col)
- gpu.set(x+1,y+1,txt)
- gpu.setBackground(oldB)
- gpu.setForeground(oldF)
- end
- draw.field(x,y,w,h,' ',color_back,color_fore)
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,0xAA0000)
- local function getKey(s)
- local key, _, x1 , code, _ = event.pull()
- if key == 'key_up' or key == 'touch' then
- return code , x1 , key
- end
- end
- local function enterPass(x,y,w,h)
- try = ""
- ex=true
- while ex do
- local err, f , x1 , key = pcall(getKey)
- if not err then
- return err, try
- end
- if f ~= nil and key == 'key_up' then --
- if keyboard.keys[f] == 'grave' then ex=false end
- if f < 60 and f > 0 then
- if keyboard.keys[f] == 'enter' then
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- return err, try , 's'
- end
- if keyboard.keys[f] == 'back' then
- if unicode.len(try) > 0 then
- try=unicode.sub(try,0,unicode.len(try)-1)
- drawTextInPass(x,y,w,h,try,color_fore)
- else
- try = nil
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- return err , try , 'f'
- end
- end
- if unicode.len(keyboard.keys[f]) == 1 then
- try = try..keyboard.keys[f]
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'space' then
- try = try..'_'
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'minus' then
- try = try..'-'
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'period' then
- try = try..'.'
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'comma' then
- try = try..','
- drawTextInPass(x,y,w,h,try,color_fore)
- elseif keyboard.keys[f] == 'slash' then
- try = try..'/'
- drawTextInPass(x,y,w,h,try,color_fore)
- end
- end
- elseif key == 'touch' and f ~= nil then
- if x1 > x-1 and x1 < x+w and f > y-1 and f < y+h then
- --
- else
- draw.clound('┌','┐','└','┘','│','─',x,y,w,h,color_back,color_fore)
- return err, try , 's'
- end
- end
- end
- end --
- while true do
- err, try , got = enterPass(x,y,w,h)
- if got == 's' then -- success
- break
- elseif got == 'f' then
- try = nil
- break
- end
- end
- return try
- end
- local function drawButtonAddMenu(arr,i)
- draw.field(arr[i][1],arr[i][2],arr[i][3],1,'▄',arr[i][4],arr[i][5])
- draw.field(arr[i][1],arr[i][2]+1,arr[i][3],1,' ',arr[i][5],arr[i][5])
- draw.field(arr[i][1],arr[i][2]+2,arr[i][3],1,'▄',arr[i][5],arr[i][4])
- end
- function drawFrame(txt)
- arrDrawFrame={
- {25,12,12,0xAAAAAA,0xBBBB00,0,'Отмена'},
- {43,12,12,0xAAAAAA,0xBBBB00,0,'Готово'}
- }
- draw.field(20,8,40,8,' ',0xAAAAAA,0xFFFFFF) -- frame
- draw.clound('┌','┐','└','┘','│','─',20,8,40,8,0xAAAAAA,0)
- draw.text(20,8,38,txt,0xAAAAAA,0) -- /frame
- draw.field(25,9,30,3,' ',0xAAAAAA,0xFFFFFF) -- nameFrame
- draw.clound('┌','┐','└','┘','│','─',25,9,30,3,0xAAAAAA,0) -- nameFrame
- for i=1,#arrDrawFrame do
- drawButtonAddMenu(arrDrawFrame,i)
- draw.text(arrDrawFrame[i][1],arrDrawFrame[i][2]+1,arrDrawFrame[i][3],arrDrawFrame[i][7],arrDrawFrame[i][5],arrDrawFrame[i][6])
- end
- while true do
- local key,_,x,y,_,_ = event.pull('touch')
- if x > 20 and x < 40 and y >8 and y < 12 then
- name=enter(25,9,30,3,0xAAAAAA,0)
- elseif x > 24 and x < 36 and y > 12 and y < 16 then
- name = nil
- os.exit()
- elseif x > 42 and x < 55 and y > 12 and y < 16 then
- if name ~= nil and unicode.len(name) > 0 and name ~= '' then
- break
- end
- end
- end
- return name
- end
- function selColText(x,y)
- gpu.setBackground(0)
- gpu.setForeground(0xFFFFFF)
- gpu.fill(a-18,12,18,1," ")
- gpu.set(a-18,12,"Палитра для текста")
- if x>=a-18 and x<=a-2 and y>=12 and y<=12 then
- arr=f()
- fore=draw.colorSelector("Палитра для выбора цвета текста")
- drawField()
- pr()
- end
- end
- function selSymb()
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0)
- gpu.fill(a-17,10,15,1," ")
- gpu.set(a-16,10,"Выбор символа")
- if x>=a-17 and x<=a-3 and y>=10 and y<=10 then
- arr=f()
- symb=drawFrame('[Выбор символа]')
- if symb == nil then symb = ' ' end
- drawField()
- pr()
- end
- end
- --==[Events]==--
- function getEvent()
- key,_,x,y,mB= event.pull()
- return key,x,y,mB
- end
- --==[Main Cycle]==--
- picFile=drawFrame('[Редактирование изображения]')
- if unicode.sub(picFile,unicode.len(picFile)-3,unicode.len(picFile)) ~= '.pic' then
- picFile=picFile..'.pic'
- elseif picFile == nil then
- os.exit()
- end
- if filesystem.exists(picFile) == true then
- arr=loadTbl(picFile)
- else
- arr={}
- end
- getEvent()
- drawField()
- selSymb()
- selCol(x,y)
- selColText(x,y)
- exit(x,y)
- pr()
- while true do
- gpu.setBackground(back)
- gpu.setForeground(fore)
- drawPixel(key,x,y,mB)
- getEvent()
- selSymb()
- selCol(x,y)
- selColText(x,y)
- exit(x,y)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement