forked from love2d-community/LOVE-Example-Browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented wheel scrolling and changed colors.
The colors were changed to look more like common editors, like Notepad+
- Loading branch information
1 parent
b38c83b
commit 77384f7
Showing
1 changed file
with
27 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,48 @@ | ||
local lexer = require("lexer") | ||
local filename = (...) | ||
|
||
function love.load() | ||
love.graphics.setFont(love.graphics.newFont(11)) | ||
parsed = {} | ||
fontheight = love.graphics.getFont():getHeight() | ||
|
||
local colors = {keyword = {250,175,200}, string = {255,255,100}, comment = {175,175,175}, | ||
number = {50,50,255} , iden = {255,255,255}, default = {250,175,200}} | ||
local colors = {keyword = {0,0,255}, string = {128,128,128}, comment = {0,128,0}, | ||
number = {255,128,0} , iden = {0,0,0}, default = {0,0,128}, line={255,0,0}} | ||
|
||
local contents = love.filesystem.read(filename, 4096) | ||
if not contents then | ||
contents = "error loading file" .. filename | ||
return | ||
end | ||
|
||
|
||
maxheight=0 --this should help us in the scrolling thingy | ||
for t in contents:gfind("\n") do | ||
maxheight=maxheight+fontheight | ||
end | ||
|
||
contents = contents:gsub("\r", "") | ||
for t,v in lexer.lua(contents, {}, {}) do | ||
if colors[t] ~= nil then table.insert(parsed, colors[t]) table.insert(parsed, v) | ||
else table.insert(parsed, colors["default"]) table.insert(parsed, v) | ||
--table.insert(parsed, t..":"..v..", ") | ||
end | ||
table.insert(parsed, colors[t] or colors["default"]) | ||
table.insert(parsed, v) | ||
end | ||
|
||
end | ||
|
||
offy=0 | ||
function love.draw() | ||
love.graphics.setBackgroundColor({72, 131, 168}) | ||
love.graphics.translate(0,offy) | ||
love.graphics.setBackgroundColor({255, 255, 255}) | ||
love.graphics.print(parsed, 10, 20) | ||
end | ||
|
||
function love.wheelmoved(_,y) | ||
y=y*15 | ||
height=love.graphics.getHeight() | ||
if maxheight > height then --scrolling up | ||
if y>0 and offy<0 then | ||
offy=offy+y | ||
elseif y<0 and height - offy - 40< maxheight then --scrolling down | ||
offy=offy+y | ||
end | ||
if -offy > maxheight then offy=-maxheight end | ||
if offy > 0 then offy=0 end | ||
end | ||
end |