From d250973ea658c579e5535365eecb7f6490afbf6a Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Tue, 13 Mar 2018 08:26:00 +0800 Subject: [PATCH] Add libgui --- libgui.lua | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 libgui.lua diff --git a/libgui.lua b/libgui.lua new file mode 100644 index 0000000..eb900bd --- /dev/null +++ b/libgui.lua @@ -0,0 +1,67 @@ +-- LibGUI - A library for developing software with GUI +-- Author: Github/Kiritow + +require("class") +require("libevent") +require("libgpu") + +Button=class("Button") + +function Button:ctor() + self.x=1 + self.y=1 + self.w=10 + self.h=2 + self.hide=false + + self.bordered=false + self.bcolor=0x0 + self.fcolor=0xFFFFFF + self.text="" +end + +function Button:update(gpu) + for i=self.y,self.y+self.h,1 do + for j=self.x,self.x+self.w,1 do + gpu:set(i,j," ") + end + end +end + + +ProgressBar=class("ProgressBar") + +function ProgressBar:ctor() + self.x=1 + self.y=1 + self.w=10 + self.h=2 + self.hide=false + + self.val=30 + self.maxval=100 + self.fcolor=0x00FF00 + self.bcolor=0x0 +end + +function ProgressBar:update(gpu) + local persent=self.val/self.maxval + local colp=persent*self.w + + gpu:pushbg(self.fcolor) + for j=self.x,self.x+colp-1,1 do + for i=self.y,self.y+self.h,1 do + gpu:set(i,j," ") + end + end + + gpu:pushbg(self.bcolor) + for j=self.x+colp,self.x+self.w,1 do + for i=self.y,self.y+self.h,1 do + gpu:set(i,j," ") + end + end + + gpu:popbg() + gpu:popbg() +end \ No newline at end of file