-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,474 additions
and
22 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
|
|||
game = { | |||
graphics = { | |||
fullscreen = false, | |||
mode = { height = love.graphics.getHeight(), width = love.graphics.getWidth() } | |||
}, | |||
fonts = {}, | |||
} | |||
|
|||
function game:createFonts(offset) | |||
self.fonts = { | |||
lineHeight = (10 + offset) * 1.7, | |||
small = love.graphics.newFont(10 + offset), | |||
regular = love.graphics.newFont(14 + offset), | |||
large = love.graphics.newFont(24 + offset), | |||
very_large = love.graphics.newFont(48 + offset) | |||
} | |||
end | |||
|
|||
function game:setMode(mode) | |||
self.graphics.mode = mode | |||
love.graphics.setMode(mode.width, mode.height) | |||
if self.graphics.mode.height < 600 then | |||
self:createFonts(-2) | |||
else | |||
self:createFonts(0) | |||
end | |||
end | |||
|
|||
|
|||
function game:start() | |||
end |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
|
|||
GameState = class("GameState") | |||
function GameState:initialize(game, name) | |||
self.name = name | |||
self.game = game | |||
end | |||
|
|||
function GameState:update(dt) | |||
end | |||
|
|||
function GameState:draw() | |||
end | |||
|
|||
function GameState:keypressed(key) | |||
end |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
require 'views/start_menu_view' | |||
|
|||
StartMenu = class("Menu", GameState) | |||
|
|||
function StartMenu:initialize() | |||
self.view = StartMenuView() | |||
end | |||
|
|||
function StartMenu:update(dt) | |||
self.view:update(dt) | |||
end | |||
|
|||
function StartMenu:draw() | |||
self.view:draw() | |||
end |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,160 @@ | |||
# QUICKIE | |||
|
|||
Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial inspiration came from the article [Sol on Immediate Mode GUIs (IMGUI)][Sol]. You should check it out to understand how Quickie works. | |||
|
|||
|
|||
# Example | |||
|
|||
local gui = require "Quickie" | |||
|
|||
-- lazy font loading | |||
local fonts = setmetatable({}, {__index = function(t,k) | |||
local f = love.graphics.newFont(k) | |||
rawset(t, k, f) | |||
return f | |||
end }) | |||
|
|||
function love.load() | |||
love.graphics.setBackgroundColor(17,17,17) | |||
love.graphics.setFont(fonts[12]) | |||
|
|||
-- group defaults | |||
gui.group.default.size[1] = 150 | |||
gui.group.default.size[2] = 25 | |||
gui.group.default.spacing = 5 | |||
end | |||
|
|||
local menu_open = { | |||
main = false, | |||
right = false, | |||
foo = false, | |||
demo = false | |||
} | |||
local check1 = {checked = false, label = "Checkbox"} | |||
local check2 = {checked = false, label = "Another one"} | |||
local input = {text = ""} | |||
local slider = {value = .5} | |||
local slider2d = {value = {.5,.5}} | |||
function love.update(dt) | |||
gui.group.push{grow = "down", pos = {5,5}} | |||
if gui.Button{text = "Menu"} then | |||
menu_open.main = not menu_open.main | |||
end | |||
|
|||
if menu_open.main then | |||
gui.group.push{grow = "right"} | |||
if gui.Button{text = "Group stacking"} then | |||
menu_open.right = not menu_open.right | |||
end | |||
|
|||
if menu_open.right then | |||
gui.group.push{grow = "up"} | |||
if gui.Button{text = "Foo"} then | |||
menu_open.foo = not menu_open.foo | |||
end | |||
if menu_open.foo then | |||
gui.Button{text = "???"} | |||
end | |||
gui.group.pop{} | |||
|
|||
gui.Button{text = "Bar"} | |||
gui.Button{text = "Baz"} | |||
end | |||
gui.group.pop{} | |||
|
|||
if gui.Button{text = "Widget demo"} then | |||
menu_open.demo = not menu_open.open | |||
end | |||
|
|||
end | |||
gui.group.pop{} | |||
|
|||
if menu_open.demo then | |||
gui.group.push{grow = "down", pos = {200, 80}} | |||
|
|||
love.graphics.setFont(fonts[20]) | |||
gui.Label{text = "Widgets"} | |||
love.graphics.setFont(fonts[12]) | |||
gui.group.push{grow = "right"} | |||
gui.Button{text = "Button"} | |||
gui.Button{text = "Tight Button", size = {"tight"}} | |||
gui.Button{text = "Tight² Button", size = {"tight", "tight"}} | |||
gui.group.pop{} | |||
|
|||
gui.group.push{grow = "right"} | |||
gui.Button{text = "", size = {2}} | |||
gui.Label{text = "Tight Label", size = {"tight"}} | |||
gui.Button{text = "", size = {2}} | |||
gui.Label{text = "Center Label", align = "center"} | |||
gui.Button{text = "", size = {2}} | |||
gui.Label{text = "Another Label"} | |||
gui.Button{text = "", size = {2}} | |||
gui.group.pop{} | |||
|
|||
gui.group.push{grow = "right"} | |||
gui.Checkbox{info = check1, size = {"tight"}} | |||
gui.Checkbox{info = check2} | |||
gui.group.pop{} | |||
|
|||
gui.group.push{grow = "right"} | |||
gui.Label{text = "Input", size = {70}} | |||
gui.Input{info = input, size = {300}} | |||
gui.group.pop{} | |||
|
|||
gui.group.push{grow = "right"} | |||
gui.Label{text = "Slider", size = {70}} | |||
gui.Slider{info = slider} | |||
gui.Label{text = ("Value: %.2f"):format(slider.value), size = {70}} | |||
gui.group.pop{} | |||
|
|||
gui.Label{text = "2D Slider", pos = {nil,10}} | |||
gui.Slider2D{info = slider2d, size = {250, 250}} | |||
gui.Label{text = ("Value: %.2f, %.2f"):format(slider2d.value[1], slider2d.value[2])} | |||
|
|||
end | |||
end | |||
|
|||
function love.draw() | |||
gui.core.draw() | |||
end | |||
|
|||
function love.keypressed(key, code) | |||
gui.keyboard.pressed(key, code) | |||
end | |||
|
|||
|
|||
# Documentation | |||
|
|||
To be done... | |||
|
|||
|
|||
# License | |||
|
|||
Copyright (c) 2012 Matthias Richter | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
|
|||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
|
|||
Except as contained in this notice, the name(s) of the above copyright holders | |||
shall not be used in advertising or otherwise to promote the sale, use or | |||
other dealings in this Software without prior written authorization. | |||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. | |||
|
|||
|
|||
[LOVE]: http://love2d.org | |||
[IMGUI]: http://www.mollyrocket.com/forums/viewforum.php?f=10 | |||
[Sol]: http://sol.gfxile.net/imgui/ |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,77 @@ | |||
--[[ | |||
Copyright (c) 2012 Matthias Richter | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
Except as contained in this notice, the name(s) of the above copyright holders | |||
shall not be used in advertising or otherwise to promote the sale, use or | |||
other dealings in this Software without prior written authorization. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. | |||
]]-- | |||
local BASE = (...):match("(.-)[^%.]+$") | |||
local core = require(BASE .. 'core') | |||
local group = require(BASE .. 'group') | |||
local mouse = require(BASE .. 'mouse') | |||
local keyboard = require(BASE .. 'keyboard') | |||
|
|||
-- the widget | |||
-- {text = text, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} | |||
return function(w) | |||
assert(type(w) == "table" and w.text, "Invalid argument") | |||
|
|||
-- if tight fit requested, compute the size according to text size | |||
-- have a 2px margin around the text | |||
local tight = w.size and (w.size[1] == 'tight' or w.size[2] == 'tight') | |||
if tight then | |||
local f = assert(love.graphics.getFont()) | |||
if w.size[1] == 'tight' then | |||
w.size[1] = f:getWidth(w.text) + 4 | |||
end | |||
if w.size[2] == 'tight' then | |||
w.size[2] = f:getHeight(w.text) + 4 | |||
end | |||
end | |||
|
|||
-- Generate unique identifier for gui state update and querying. | |||
local id = core.generateID() | |||
|
|||
-- group.getRect determines the position and size of the widget according | |||
-- to the currently active group. Both arguments may be omitted. | |||
local pos, size = group.getRect(w.pos, w.size) | |||
|
|||
-- mouse.updateWidget(id, {x,y}, {w,h}, widgetHit) updates the state for this widget. | |||
-- widgetHit may be nil, in which case mouse.widgetHit will be used. | |||
-- The widget mouse-state can be: | |||
-- hot (mouse over widget), | |||
-- active (mouse pressed on widget) or | |||
-- normal (mouse not on widget and not pressed on widget). | |||
mouse.updateWidget(id, pos, size, w.widgetHit) | |||
|
|||
-- keyboard.makeCyclable makes the item focus on tab or whatever binding is | |||
-- in place (see core.keyboard.cycle). Cycle order is determied by the | |||
-- order you call the widget functions. | |||
keyboard.makeCyclable(id) | |||
|
|||
-- core.registerDraw(id, drawfunction, drawfunction-arguments...) | |||
-- shows widget when core.draw() is called. | |||
core.registerDraw(id, w.draw or core.style.Button, | |||
w.text, pos[1],pos[2], size[1],size[2]) | |||
|
|||
return mouse.releasedOn(id) or (keyboard.key == 'return' and keyboard.hasFocus(id)) | |||
end | |||
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,68 @@ | |||
--[[ | |||
Copyright (c) 2012 Matthias Richter | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
Except as contained in this notice, the name(s) of the above copyright holders | |||
shall not be used in advertising or otherwise to promote the sale, use or | |||
other dealings in this Software without prior written authorization. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. | |||
]]-- | |||
local BASE = (...):match("(.-)[^%.]+$") | |||
local core = require(BASE .. 'core') | |||
local group = require(BASE .. 'group') | |||
local mouse = require(BASE .. 'mouse') | |||
local keyboard = require(BASE .. 'keyboard') | |||
|
|||
-- {info = {checked = status, label = "", algin = "left"}, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} | |||
return function(w) | |||
assert(type(w) == "table") | |||
w.info.label = w.info.label or "" | |||
|
|||
local tight = w.size and (w.size[1] == 'tight' or w.size[2] == 'tight') | |||
if tight then | |||
local f = assert(love.graphics.getFont()) | |||
if w.size[1] == 'tight' then | |||
w.size[1] = f:getWidth(w.info.label) | |||
end | |||
if w.size[2] == 'tight' then | |||
w.size[2] = f:getHeight(w.info.label) | |||
end | |||
-- account for the checkbox | |||
local bw = math.min(w.size[1] or group.size[1], w.size[2] or group.size[2]) | |||
w.size[1] = w.size[1] + bw + 4 | |||
end | |||
|
|||
local id = core.generateID() | |||
local pos, size = group.getRect(w.pos, w.size) | |||
|
|||
mouse.updateWidget(id, pos, size, w.widgetHit) | |||
keyboard.makeCyclable(id) | |||
|
|||
local checked = w.info.checked | |||
local key = keyboard.key | |||
if mouse.releasedOn(id) or ((key == 'return' or key == ' ') and keyboard.hasFocus(id)) then | |||
w.info.checked = not w.info.checked | |||
end | |||
|
|||
core.registerDraw(id, w.draw or core.style.Checkbox, | |||
w.info.checked, w.info.label, w.info.align or 'left', pos[1], pos[2], size[1], size[2]) | |||
|
|||
return w.info.checked ~= checked | |||
end | |||
|
Oops, something went wrong.