mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-18 18:06:44 +00:00
add dark theme
This commit is contained in:
@@ -13,14 +13,13 @@ local Text = require((...) .. '.text')
|
||||
local IntOut = ffi.typeof 'int[1]'
|
||||
|
||||
-- create window and renderer
|
||||
sdl.setHint(sdl.HINT_VIDEO_ALLOW_SCREENSAVER, '1')
|
||||
|
||||
local window = sdl.createWindow('', 0, 0, 800, 600,
|
||||
sdl.WINDOW_SHOWN + sdl.WINDOW_RESIZABLE)
|
||||
|
||||
if window == nil then
|
||||
io.stderr:write(ffi.string(sdl.getError()))
|
||||
sdl.quit()
|
||||
os.exit(1)
|
||||
error(ffi.string(sdl.getError()))
|
||||
end
|
||||
|
||||
ffi.gc(window, sdl.destroyWindow)
|
||||
@@ -29,9 +28,7 @@ local renderer = sdl.createRenderer(window, -1,
|
||||
sdl.RENDERER_ACCELERATED + sdl.RENDERER_PRESENTVSYNC)
|
||||
|
||||
if renderer == nil then
|
||||
io.stderr:write(ffi.string(sdl.getError()))
|
||||
sdl.quit()
|
||||
os.exit(1)
|
||||
error(ffi.string(sdl.getError()))
|
||||
end
|
||||
|
||||
ffi.gc(renderer, sdl.destroyRenderer)
|
||||
@@ -151,11 +148,13 @@ end
|
||||
|
||||
local currentFont = Font()
|
||||
|
||||
local lastColor
|
||||
|
||||
-- print( text, x, y, r, sx, sy, ox, oy, kx, ky )
|
||||
Backend.print = function (text, x, y)
|
||||
if not text or text == '' then return end
|
||||
local font = currentFont.sdlFont
|
||||
local color = sdl.Color(currentFont.color or { 0, 0, 0, 255 })
|
||||
local color = sdl.Color(lastColor or { 0, 0, 0, 255 })
|
||||
local write = Font.SDL2_ttf.TTF_RenderUTF8_Blended
|
||||
|
||||
local surface = write(font, text, color)
|
||||
@@ -236,8 +235,6 @@ Backend.quit = function ()
|
||||
os.exit()
|
||||
end
|
||||
|
||||
local lastColor
|
||||
|
||||
Backend.setColor = function (color)
|
||||
lastColor = color
|
||||
sdl.setRenderDrawColor(renderer,
|
||||
|
||||
@@ -210,9 +210,7 @@ function Font:constructor (path, size)
|
||||
local font = SDL2_ttf.TTF_OpenFont(path, size)
|
||||
|
||||
if font == nil then
|
||||
io.stderr:write(ffi.string(sdl.getError()))
|
||||
sdl.quit()
|
||||
os.exit(1)
|
||||
error(ffi.string(sdl.getError()))
|
||||
end
|
||||
|
||||
fontCache[key] = font
|
||||
|
||||
@@ -17,9 +17,19 @@ function Image:constructor (renderer, path)
|
||||
self.sdlSurface = ffi.gc(
|
||||
SDL2_image.IMG_Load(path),
|
||||
sdl.freeSurface)
|
||||
|
||||
if self.sdlSurface == nil then
|
||||
error(ffi.string(sdl.getError()))
|
||||
end
|
||||
|
||||
self.sdlTexture = ffi.gc(
|
||||
sdl.createTextureFromSurface(renderer, self.sdlSurface),
|
||||
sdl.destroyTexture)
|
||||
|
||||
if self.sdlTexture == nil then
|
||||
error(ffi.string(sdl.getError()))
|
||||
end
|
||||
|
||||
self.width = self.sdlSurface.w
|
||||
self.height = self.sdlSurface.h
|
||||
end
|
||||
|
||||
@@ -60,8 +60,7 @@ sdl.atomic_t = ffi.typeof 'SDL_atomic_t'
|
||||
sdl.version = ffi.typeof 'SDL_version'
|
||||
|
||||
if sdl.init(sdl.INIT_VIDEO) ~= 0 then
|
||||
io.stderr:write(ffi.string(sdl.getError()))
|
||||
os.exit(1)
|
||||
error(ffi.string(sdl.getError()))
|
||||
end
|
||||
|
||||
return sdl
|
||||
|
||||
@@ -38,14 +38,19 @@ local function renderMulti (self, font, text, color, align, limit)
|
||||
|
||||
local r, g, b, a
|
||||
|
||||
--[[
|
||||
if sdl.BYTEORDER == sdl.BIG_ENDIAN then
|
||||
r, g, b, a = 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
|
||||
else
|
||||
r, g, b, a = 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
|
||||
end
|
||||
--]]
|
||||
|
||||
-- values from SDL_ttf.c
|
||||
r, g, b, a = 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000
|
||||
|
||||
local surface = ffi.gc(
|
||||
sdl.createRGBSurface(0, limit, height, 32, r, g, b, a),
|
||||
sdl.createRGBSurface(sdl.SWSURFACE, limit, height, 32, r, g, b, a),
|
||||
sdl.freeSurface)
|
||||
self.sdlSurface = surface
|
||||
|
||||
@@ -55,6 +60,8 @@ local function renderMulti (self, font, text, color, align, limit)
|
||||
ttf.TTF_RenderUTF8_Blended(font.sdlFont, text, color),
|
||||
sdl.freeSurface)
|
||||
if lineSurface ~= nil then
|
||||
sdl.setSurfaceBlendMode(lineSurface, sdl.BLENDMODE_NONE)
|
||||
|
||||
local w, h = lineSurface.w, lineSurface.h
|
||||
local top = (index - 1) * lineHeight
|
||||
|
||||
|
||||
Reference in New Issue
Block a user