From 8a147717ab063f34e0e41330979758cdf191f3d6 Mon Sep 17 00:00:00 2001 From: Igor Date: Sat, 19 Mar 2016 00:48:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=BE=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20"Viewer"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications.txt | 23 +++ Applications/Viewer/About.txt | 1 + Applications/Viewer/Icon.pic | Bin 0 -> 245 bytes Applications/Viewer/Viewer.lua | 225 +++++++++++++++++++++++++++++ Applications/Viewer/arrowLeft.pic | Bin 0 -> 155 bytes Applications/Viewer/arrowRight.pic | Bin 0 -> 155 bytes Applications/Viewer/play.pic | Bin 0 -> 161 bytes lib/ECSAPI.lua | 5 +- 8 files changed, 250 insertions(+), 4 deletions(-) create mode 100644 Applications/Viewer/About.txt create mode 100644 Applications/Viewer/Icon.pic create mode 100644 Applications/Viewer/Viewer.lua create mode 100644 Applications/Viewer/arrowLeft.pic create mode 100644 Applications/Viewer/arrowRight.pic create mode 100644 Applications/Viewer/play.pic diff --git a/Applications.txt b/Applications.txt index 7d805f4b..67768c18 100644 --- a/Applications.txt +++ b/Applications.txt @@ -774,4 +774,27 @@ }, }, }, + { + ["name"]="MineOS/Applications/Viewer", + ["url"]="IgorTimofeev/OpenComputers/master/Applications/Viewer/Viewer.lua", + ["about"]="IgorTimofeev/OpenComputers/master/Applications/Viewer/About.txt", + ["type"]="Application", + ["icon"]="IgorTimofeev/OpenComputers/master/Applications/Viewer/Icon.pic", + ["createShortcut"] = "desktop", + ["version"]=1.0, + ["resources"]={ + { + ["name"]="arrowLeft.pic", + ["url"]="IgorTimofeev/OpenComputers/master/Applications/Viewer/arrowLeft.pic", + }, + { + ["name"]="arrowRight.pic", + ["url"]="IgorTimofeev/OpenComputers/master/Applications/Viewer/arrowRight.pic", + }, + { + ["name"]="play.pic", + ["url"]="IgorTimofeev/OpenComputers/master/Applications/Viewer/play.pic", + }, + }, + }, } \ No newline at end of file diff --git a/Applications/Viewer/About.txt b/Applications/Viewer/About.txt new file mode 100644 index 00000000..72244292 --- /dev/null +++ b/Applications/Viewer/About.txt @@ -0,0 +1 @@ +Программа для просмотра изображений в нашем формате .pic, имеется возможность проигрывания картинок в режиме слайдшоу. \ No newline at end of file diff --git a/Applications/Viewer/Icon.pic b/Applications/Viewer/Icon.pic new file mode 100644 index 0000000000000000000000000000000000000000..e61626d780a656e99dedb2346d2d8a7f73fb1465 GIT binary patch literal 245 zcmYMsu?@m76a-M;`6u=mStUfWL`C5$+fXn7RU|4pD%L@wPR$5Na3&6^p1$ti9fp0f zXg$2kn5Sb3Zs+hE0m`>Dd6q#s3Hg#<4ziUu*<^J8Hfx);O|@CtaU>C!3DybL32I`V rP6-d?Zj2uE*0dq^uuq9D3HM(FTVI#kjJ^$--P(m=`;Dc0-ER8=coHkv literal 0 HcmV?d00001 diff --git a/Applications/Viewer/Viewer.lua b/Applications/Viewer/Viewer.lua new file mode 100644 index 00000000..a30c25e8 --- /dev/null +++ b/Applications/Viewer/Viewer.lua @@ -0,0 +1,225 @@ + +local ecs = require("ECSAPI") +local image = require("image") +local fs = require("filesystem") +local buffer = require("doubleBuffering") +local unicode = require("unicode") +local event = require("event") + + +local pathToApplicationResources = "MineOS/Applications/Viewer.app/Resources/" +local currentPath = "MineOS/Pictures/" +local imageList = {} +local currentImage = 1 +local showGUI = true +local slideShowInterval = 5 +local enableSlideShow = true +local currentLoadedImage + +local arrowLeftImage = image.load(pathToApplicationResources .. "arrowLeft.pic") +local arrowRightImage = image.load(pathToApplicationResources .. "arrowRight.pic") +local playImage = image.load(pathToApplicationResources .. "play.pic") +local wallpaperImage = image.load("MineOS/System/OS/Icons/Computer.pic") + +local obj = {} + +buffer.start() + +local function loadImageList() + local fileList = fs.list(currentPath) + imageList = {} + for file in fileList do + if ecs.getFileFormat(file) == ".pic" then + table.insert(imageList, currentPath .. file) + end + end +end + +local function loadCurrentImage() + if #imageList > 0 then + currentLoadedImage = image.load(imageList[currentImage]) + end +end + +local function drawImage() + if #imageList > 0 then + local xImage, yImage = 1, 1 + if currentLoadedImage.width < buffer.screen.width then xImage = math.floor(buffer.screen.width / 2 - currentLoadedImage.width / 2) end + if currentLoadedImage.height < buffer.screen.height then yImage = math.floor(buffer.screen.height / 2 - currentLoadedImage.height / 2) end + + buffer.image(xImage, yImage, currentLoadedImage) + else + local text = "Изображения в директории \"" .. currentPath .. "\" не найдены" + buffer.text(math.floor(buffer.screen.width / 2 - unicode.len(text) / 2), math.floor(buffer.screen.height / 2), 0x000000, text) + end +end + +local function multipleButtons(x, y, widthOfButton, heightOfButton, spaceBetweenButtons, ...) + local buttons = {...} + local objectsToReturn = {} + for i = 1, #buttons do + buffer.button(x, y, widthOfButton, heightOfButton, buttons[i][1], buttons[i][2], buttons[i][3]) + table.insert(objectsToReturn, {x, y, x + widthOfButton - 1, y + heightOfButton - 1}) + x = x + widthOfButton + spaceBetweenButtons + end + return objectsToReturn +end + +local function drawBottomButtons() + local y = buffer.screen.height - 4 + local x = math.floor(buffer.screen.width / 2 - 21) + + obj.arrowLeft = {x, y, x + 7, y + 3} + buffer.image(x, y, arrowLeftImage); x = x + 10 + obj.play = {x, y, x + 7, y + 3} + buffer.image(x, y, playImage); x = x + 10 + obj.arrowRight = {x, y, x + 7, y + 3} + buffer.image(x, y, arrowRightImage); x = x + 12 + obj.wallpaper = {x, y, x + 7, y + 3} + buffer.image(x, y, wallpaperImage) +end + +local function drawGUI() + if showGUI then + --Верхний бар + buffer.square(1, 1, buffer.screen.width, 1, 0xFFFFFF, 0xFFFFFF, " ", 30) + local text = #imageList > 0 and fs.name(imageList[currentImage]) or "Viewer" + buffer.text(math.floor(buffer.screen.width / 2 - unicode.len(text) / 2), 1, 0x000000, text) + buffer.text(2, 1, ecs.colors.red, "⬤") + buffer.text(5, 1, ecs.colors.orange, "⬤") + buffer.text(8, 1, ecs.colors.green, "⬤") + + --Нижний бар + local height = 6 + local transparency = 40 + local y = buffer.screen.height - height + 1 + buffer.square(1, y, buffer.screen.width, height, 0x000000, 0xFFFFFF, " ", transparency) + -- multipleButtons(math.floor(buffer.screen.width / 2 - 16), y, 7, 3, 2, {0xEEEEEE, 0x262626, "←"}, {0xEEEEEE, 0x262626, "►"}, {0xEEEEEE, 0x262626, "→"}, {0xEEEEEE, 0x262626, "♥"}) + drawBottomButtons() + end +end + +local function drawAll(force) + buffer.clear(0xFFFFFF) + + drawImage() + drawGUI() + + buffer.draw(force) +end + +local function prevImage() + currentImage = currentImage - 1 + if currentImage < 1 then currentImage = #imageList end + loadCurrentImage() + drawAll() +end + +local function nextImage() + currentImage = currentImage + 1 + if currentImage > #imageList then currentImage = 1 end + loadCurrentImage() + drawAll() +end + +local function slideShowDro4er() + nextImage() +end + +local function enableSlideShowDro4er() + enableSlideShow = true + _G.imageViewerSlideShowTimer = event.timer(slideShowInterval, slideShowDro4er, math.huge) +end + +local function clicked(x, y, obj) + if obj and ecs.clickedAtArea(x, y, obj[1], obj[2], obj[3], obj[4]) and #imageList > 0 then + return true + end + return false +end + +local function press(x, y) + buffer.square(x, y, 10, 6, 0x000000, 0xFFFFFF, " ", 60) + drawBottomButtons() + buffer.draw() + os.sleep(0.2) + drawAll() +end + +------------------------------------------------------------------------------------------------------------------------------------------------ + +local args = {...} + +if args[1] == "open" then + if args[2] then + currentPath = fs.path(args[2]) + loadImageList() + for i = 1, #imageList do + if args[2] == imageList[i] then currentImage = i; break end + end + else + ecs.error("Invalid arguments!") + return + end +else + loadImageList() +end + +loadCurrentImage() +drawAll() + +while true do + local e = {event.pull()} + if e[1] == "touch" then + + if enableSlideShow then + showGUI = true + enableSlideShow = false + event.cancel(_G.imageViewerSlideShowTimer) + drawAll() + end + + if clicked(e[3], e[4], obj.arrowLeft) then + press(obj.arrowLeft[1] - 1, obj.arrowLeft[2] - 1) + prevImage() + elseif clicked(e[3], e[4], obj.play) then + press(obj.play[1] - 1, obj.play[2] - 1) + showGUI = false + obj = {} + enableSlideShowDro4er() + drawAll() + elseif clicked(e[3], e[4], obj.arrowRight) then + press(obj.arrowRight[1] - 1, obj.arrowRight[2] - 1) + nextImage() + elseif clicked(e[3], e[4], obj.wallpaper) then + press(obj.wallpaper[1] - 1, obj.wallpaper[2] - 1) + buffer.clear(0x262626) + buffer.draw() + ecs.createShortCut("MineOS/System/OS/Wallpaper.lnk", imageList[currentImage]) + computer.pushSignal("OSWallpaperChanged") + return + elseif (e[3] >= 2 and e[3] <= 3 and e[4] == 1) then + buffer.text(2, 1, ecs.colors.blue, "⬤") + buffer.draw() + os.sleep(0.2) + buffer.clear(0x262626) + buffer.draw() + return + end + end +end + + + + + + + + + + + + + + + diff --git a/Applications/Viewer/arrowLeft.pic b/Applications/Viewer/arrowLeft.pic new file mode 100644 index 0000000000000000000000000000000000000000..b4c6dbeeb4e250a5d2001aab3c9d4eed67f15275 GIT binary patch literal 155 zcmX|)!3~2j5Cm`c)`2o;1tM9>D-XY}8;~d=N^AUSgxHqI?`E{S_kO;zM$Jf9!TDV? zj>Tw^oar%)0jc?|dsu*I{Q0wY-tQiuNbKFhDZ>`4EeGg#MCi+ds%zH_SV7IU&qt81 Gpu2vmz#BCH literal 0 HcmV?d00001 diff --git a/Applications/Viewer/arrowRight.pic b/Applications/Viewer/arrowRight.pic new file mode 100644 index 0000000000000000000000000000000000000000..dd08f52a0252f848be35ab9250e27e854537ec83 GIT binary patch literal 155 zcmX|)yA8uI3p?|WHt9$BoPJJ9q;fC+?KU!(Fyiz_?;rcZJ)X=x_`Eq7U H&SL2grp_BR literal 0 HcmV?d00001 diff --git a/Applications/Viewer/play.pic b/Applications/Viewer/play.pic new file mode 100644 index 0000000000000000000000000000000000000000..56a7ec21b81db570b7b3e130c52060d4f02ec480 GIT binary patch literal 161 zcmX|)!3~2z3{K0Mbdk^0=3~2@)klDKI6_0NnY(Yc;c8`Mqw%CY#|`#sBvy zI2WM=)B~p7?di}QhtA)JHTifp(01dMuL4=5EeJ4MlW>?1;}k})hh~fhrk??+Xv_Zp J3{owqYB$qD9IF5T literal 0 HcmV?d00001 diff --git a/lib/ECSAPI.lua b/lib/ECSAPI.lua index c77e710b..8a88f16a 100644 --- a/lib/ECSAPI.lua +++ b/lib/ECSAPI.lua @@ -1781,13 +1781,10 @@ function ECSAPI.launchIcon(path, arguments) end --Если это фоточка elseif fileFormat == ".pic" then - shell.execute("MineOS/Applications/Photoshop.app/Photoshop.lua open " .. path) + shell.execute("MineOS/Applications/Viewer.app/Viewer.lua open " .. path) --Если это 3D-модель elseif fileFormat == ".3dm" then shell.execute("MineOS/Applications/3DPrint.app/3DPrint.lua open " .. path) - --Если это фоточка - elseif fileFormat == ".raw" then - shell.execute("MineOS/Applications/Photoshop.app/Photoshop.lua open " .. path) --Если это текст или конфиг или языковой elseif fileFormat == ".txt" or fileFormat == ".cfg" or fileFormat == ".lang" then ECSAPI.prepareToExit()