123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- return function(BOXUI)
- local utils = BOXUI.utils
- local int = utils.int
- local clamp = utils.clamp
- local colorWhite = {1, 1, 1}
- local theme = {
- name = "theme",
-
- -- list
- itemHeight = 24, itemPadVert = 2, itemPadHori = 4,
- itemBack = {0.2, 0.7, 0.9},
- itemFore = {0.1, 0.1, 0.1}, itemForeActive = {1, 0, 0, 0.2},
- -- container
- sliderThickness = 12, sliderLengthMin = 10,
- sliderBack = {0.0, 0.2, 0.3},
- sliderFore = {0.9, 0.2, 0.4}, sliderForeActive = {0.7, 0.9, 1.0},
- borderThickness = 2,
- borderBack = {0.1, 0.1, 0.1},
- borderFore = {0.0, 0.4, 0.6},
- handleHeight = 20, handleButtonWidth = 16, handleButtonHeight = 16,
- handlePadVert = 4,
- handleBack = {0.5, 0.7, 0.8},
- handleFore = {0.2,0.2,0.2},
-
- -- panel
- panelBack = {0.1, 0.15, 0.2},
-
- -- slider
- sliderButtonWidth = 20, sliderButtonHeight = 20,
- sliderNobThickness = 4, sliderNobLength = 12,
- }
- theme.draw = {}
- -- CONTAINER
- -- active elements
- theme.draw.containerActive = function(self, x, y)
- local theme = self.theme
- -- draw active components
- local boxes = self.boxes
- local box = boxes.panel
- if box and not box.hidden and self.content.draw then
- local sx, sy, sw, sh = love.graphics.getScissor()
- love.graphics.intersectScissor(x + box.x, y + box.y, box.width, box.height)
- self.content:draw(x + box.x, y + box.y)
- if self.drawOverlay then self:drawOverlay(x, y) end
- love.graphics.setScissor(sx, sy, sw, sh)
- end
-
- box = boxes.sliderVert
- if box and not box.hidden then
- local color = self.activeArea == box and theme.sliderForeActive or theme.sliderFore
- love.graphics.setColor(color)
- love.graphics.rectangle('fill', x + box.x, y + box.y + box.pos, box.width, box.length)
- end
-
- box = boxes.sliderHori
- if box and not box.hidden then
- local color = self.activeArea == box and theme.sliderForeActive or theme.sliderFore
- love.graphics.setColor(color)
- love.graphics.rectangle('fill', x + box.x + box.pos, y + box.y, box.length, box.height)
- end
- end
- -- passive elements
- theme.draw.containerPassive = function(self, x, y)
- local oldcolor = {love.graphics.getColor()}
- local oldlinew = love.graphics.getLineWidth()
-
- local theme = self.theme
- local bt = theme.borderThickness
- local w, h = self.width, self.height
-
- love.graphics.setColor(theme.borderBack)
- love.graphics.rectangle('fill', x, y, w, h)
- love.graphics.setColor(theme.borderFore)
- love.graphics.setLineWidth(bt)
- love.graphics.rectangle('line', x + bt / 2, y + bt / 2, w - bt, h - bt)
-
- local boxes = self.boxes
- local box
- local fontheight = love.graphics.getFont():getHeight()
- love.graphics.setLineWidth(1)
-
- local bx, by, bty
-
- box = boxes.handle
- if box then
- bx, by = x + box.x, y + box.y
- bty = by + int((box.height - fontheight) / 2)
- love.graphics.setColor(theme.handleBack)
- love.graphics.rectangle('fill', bx, by, box.width, box.height)
- love.graphics.setColor(theme.handleFore)
- love.graphics.printf(self.title, bx, bty, box.width, "center")
-
- box = boxes.close
- if box then
- bx, by = x + box.x, y + box.y
- bty = by + int((box.height - fontheight) / 2)
- love.graphics.rectangle('line', bx + .5, by + .5, box.width - 1, box.height - 1)
- love.graphics.printf("X", bx, bty, box.width, "center")
- end
- box = boxes.shade
- if box and not box.hidden then
- bx, by = x + box.x, y + box.y
- bty = by + int((box.height - fontheight) / 2)
- love.graphics.rectangle('line', bx + .5, by + .5, box.width - 1, box.height - 1)
- love.graphics.printf("S", bx, bty, box.width, "center")
- end
- box = boxes.expand
- if box and not box.hidden then
- bx, by = x + box.x, y + box.y
- bty = by + int((box.height - fontheight) / 2)
- love.graphics.rectangle('line', bx + .5, by + .5, box.width - 1, box.height - 1)
- love.graphics.printf("E", bx, bty, box.width, "center")
- end
- end
- box = boxes.sliderVert
- if box and not box.hidden then
- love.graphics.setColor(theme.sliderBack)
- love.graphics.rectangle('fill', x + box.x, y + box.y, box.width, box.height)
- end
-
- box = boxes.sliderHori
- if box and not box.hidden then
- love.graphics.setColor(theme.sliderBack)
- love.graphics.rectangle('fill', x + box.x, y + box.y, box.width, box.height)
- end
-
- love.graphics.setColor(oldcolor)
- love.graphics.setLineWidth(oldlinew)
- end
- -- BUTTON
- theme.draw.button = function(self, x, y)
- x, y = x + self.x, y + self.y
- local fh = self.font:getHeight()
- local theme = self.theme
- local bt = theme.borderThickness
- love.graphics.setColor(theme.borderFore)
- love.graphics.rectangle('fill', x, y, self.width, self.height)
- love.graphics.setColor(theme.itemBack)
- love.graphics.rectangle('fill', x + bt, y + bt, self.width - 2 * bt, self.height - 2 * bt)
- love.graphics.setColor(theme.itemFore)
- local label = self.checked and "[X] button" or "[ ] button"
- love.graphics.printf(label, x, y + utils.int((self.height - fh) / 2), self.width, "center")
- end
- -- LIST
- theme.draw.listOverlay = function(self, x, y)
- local vieww, viewh, viewy = self.viewW, self.viewH, self.viewY
-
- local list = self.list
- local active, selected = list.itemActive, list.itemSelected
- if active then
- local panel = self.boxes.panel
- local x, y = x + panel.x, y + panel.y
- local vieww, viewh, viewy = self.viewW, self.viewH, self.viewY
-
- local listtheme = list.theme
- local height = listtheme.itemHeight
- local advance = height + listtheme.itemPadVert
-
- local mode, alphamode = love.graphics.getBlendMode()
- local oldcolor = {love.graphics.getColor()}
- love.graphics.setBlendMode("multiply", "premultiplied")
- --local shader = love.graphics.getShader()
- love.graphics.setColor(active == selected and {.7,0,0} or {0,.7,0})
- --love.graphics.setShader(theme.colorizeShader)
- love.graphics.rectangle("fill", x, y + (active - 1) * advance - viewy, vieww, height)
- --love.graphics.setShader()
- love.graphics.setColor(oldcolor)
- love.graphics.setBlendMode(mode, alphamode)
- end
- end
- -- LIST CONTENT
- -- y = l1: start line, y = l2: end line
- theme.draw.listContentPassive = function(self, x, y, l1, l2)
- local items = self.items
- if not items or #items == 0 then return end
-
- local theme = self.theme
- local itemh = theme.itemHeight
- local itempv = theme.itemPadVert
- local itemph = theme.itemPadHori
-
- local oldfont = love.graphics.getFont()
- local oldcolor = {love.graphics.getColor()}
-
- local advance = itemh + itempv
- local font = self.font
- local fonth = font:getHeight()
- local itemfore, itemback = theme.itemFore, theme.itemBack
- local width = self.width
-
- local text, icon, posx, posy
- love.graphics.setFont(font)
- local items, item = self.items, nil
- local start, finish = 1, #items
- if l1 and l2 then
- start = clamp(math.floor(l1 / advance) + 1, start, finish)
- finish = clamp(math.ceil(l2 / advance), start, finish)
- end
- for i = start, finish do
- item = items[i]
- posx, posy = x, y + (i - 1) * advance
- love.graphics.setColor(item.back or itemback)
- love.graphics.rectangle('fill', posx, posy, width, itemh)
- text = item.text
- icon = item.icon
- posx = posx + itemph
- if icon then
- love.graphics.setColor(item.fore or colorWhite)
- local iconw, iconh = icon:getDimensions()
- love.graphics.draw(icon, posx, posy + int((itemh - iconh) / 2))
- posx = posx + iconw + itemph
- end
- love.graphics.setColor(item.fore or (type(text) == "string" and itemfore or colorWhite))
- love.graphics.print(text, posx, posy + int((itemh - fonth) / 2))
- end
-
- love.graphics.setFont(oldfont)
- love.graphics.setColor(oldcolor)
- end
- -- SLIDER
- theme.draw.slider = function(self, x, y)
- local theme = self.theme
- x, y = x + self.x, y + self.y
- local fh = self.font:getHeight()
- love.graphics.setColor(theme.borderBack)
- love.graphics.rectangle('fill', x, y, self.width, self.height)
- love.graphics.setColor(theme.borderFore)
- love.graphics.rectangle('fill', x, int(y + self.height/2), self.width, 1)
- love.graphics.rectangle('fill', int(x + self.width/2), y, 1, self.height)
- love.graphics.setColor(1,0,0)
- love.graphics.printf(self.value, x, y + int((self.height - fh) / 2), self.width, "center")
-
- local boxes = self.boxes
- local box
-
- box = boxes.dec
- love.graphics.setColor(theme.itemBack)
- love.graphics.rectangle('fill', x + box.x, y + box.y, box.width, box.height)
- love.graphics.setColor(theme.itemFore)
- love.graphics.print("[<]", x + box.x, y + box.y + (box.height - fh) / 2)
- box = boxes.inc
- love.graphics.setColor(theme.itemBack)
- love.graphics.rectangle('fill', x + box.x, y + box.y, box.width, box.height)
- love.graphics.setColor(theme.itemFore)
- love.graphics.print("[>]", x + box.x, y + box.y + (box.height - fh) / 2)
-
- box = boxes.nob
- love.graphics.setColor(theme.borderFore)
- love.graphics.rectangle('fill', x + box.x, y + box.y, box.width, box.height)
- end
- BOXUI.add(theme)
- end
|