Skip to content

Commit 10cf056

Browse files
committed
Add missing libs/headers, fix main.c/raylua.c
1 parent b8b05e4 commit 10cf056

File tree

1,497 files changed

+755039
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,497 files changed

+755039
-4
lines changed

app/src/main/cpp/bind.c

Lines changed: 3748 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (C) 2019-2020 Teddy Astie (TSnake41)
2+
3+
Permission to use, copy, modify, and/or distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12+
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13+
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Lynx
2+
3+
Lynx is a very-lightweight work-in-progress list-based UI library. It allows to
4+
build efficient and functionnal menues with only a few lines of codes and without
5+
needing to worry about the coordinates of all menu elements.
6+
7+
It also includes a minimal C port.
8+
9+
# Installation
10+
To use Lynx, place this directory in your project, then when you need Lynx :
11+
```lua
12+
local lynx = require "lynx"
13+
-- or
14+
local lynx = require "path.to.lynx"
15+
```
16+
17+
You also need a "funcs" table which contains all platform-specific functions to draw our menu.
18+
For love2d, you can use love-lynx :
19+
```lua
20+
local lynx_funcs = lynx.love_lynx
21+
```
22+
23+
# Creation
24+
25+
To create a menu, you need a item list (which is a table containing items you can make with e.g lynx.button)
26+
and a parameter table which contains few parameters as defined in menu.lua.
27+
28+
A demo menu :
29+
```lua
30+
menu = lynx.menu({
31+
lynx.text "Sample text 1",
32+
lynx.text "Sample text 2",
33+
lynx.text "Sample text 3",
34+
lynx.button("Simple hello button", function () print "Hello World !" end, {})
35+
}, {
36+
viewport = { 0, 0, 300, 200 },
37+
offset = { 0, 50 },
38+
default_height = 20,
39+
funcs = lynx_funcs
40+
})
41+
```
42+
43+
# Usage
44+
45+
### Modifying a menu
46+
47+
You can access all parameters of few other things directly from menu.
48+
All informations of params are copied into this table, you can safely
49+
modify these parameters.
50+
menu.current must be lower than #menu.items otherwise, behavior is undefined.
51+
52+
### Updating a menu
53+
54+
```lua
55+
menu:update(dt)
56+
```
57+
Update all items with item:update(dt).
58+
59+
### Drawing a menu
60+
61+
```lua
62+
menu:draw()
63+
```
64+
Draw all items with correct coordinates at menu.viewport.
65+
66+
### Managing input
67+
68+
```lua
69+
menu:input_key(key, key_state)
70+
```
71+
Insert key event, can be a platform-specific key if funcs.simpleKey is implemented to consider them.
72+
key_state might be "pressed", "up" or "down".
73+
74+
```lua
75+
menu:input_mouse(x, y, btn)
76+
```
77+
Insert mouse event, x, y, btn must be numbers, btn can be 0 which indicate no button pressed.
78+
Some specific buttons have some defined behavior :
79+
- btn == 0 : Inserts `menu:input_key("enter", "pressed")` event.
80+
- btn == 1 : Do `menu:pop()`
81+
82+
These behavior currently cannot be customized.
83+
84+
### And then ?
85+
86+
As this project is still work-in-progress, bugs can exist, some features can be missing, some
87+
others are hard-coded.
88+
This library is designed to be very simple and lightweight with a modular architecture (following
89+
the KISS philosophy) while still being functionnal and powerful.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
local text = require "text"
2+
local button = text:extend()
3+
4+
button.event_fn = function () end
5+
6+
-- lynx.button(text, event_fn, params)
7+
-- text: string
8+
-- event_fn: function
9+
-- params: table
10+
--
11+
function button:new(_text, event_fn, params)
12+
text.new(self, _text, params)
13+
14+
if event_fn then
15+
self.event_fn = event_fn
16+
end
17+
end
18+
19+
function button:input(menu, key, state)
20+
if menu.funcs.simple_key(key) == "enter" and state == "pressed" then
21+
self:event_fn(menu)
22+
end
23+
end
24+
25+
function button:mouse(menu, x, y, btn)
26+
if btn == 1 then
27+
self:event_fn(menu)
28+
end
29+
end
30+
31+
return button
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
--
2+
-- classic
3+
--
4+
-- Copyright (c) 2014, rxi
5+
-- Copyright (c) 2020, Astie Teddy (TSnake41)
6+
--
7+
-- This module is free software; you can redistribute it and/or modify it under
8+
-- the terms of the MIT license. See LICENSE for details.
9+
--
10+
-- Lynx version, with some modifications.
11+
--
12+
13+
14+
local Object = {}
15+
Object.__index = Object
16+
17+
function Object:new()
18+
end
19+
20+
function Object:extend()
21+
local cls = {}
22+
23+
for k, v in pairs(self) do
24+
if k:find("__") == 1 then
25+
cls[k] = v
26+
end
27+
end
28+
29+
cls.__index = cls
30+
cls.super = self
31+
32+
return setmetatable(cls, self)
33+
end
34+
35+
function Object:implement(...)
36+
for _, cls in pairs { ... } do
37+
for k, v in pairs(cls) do
38+
if self[k] == nil then
39+
self[k] = v
40+
end
41+
end
42+
end
43+
end
44+
45+
function Object:is(T)
46+
local mt = getmetatable(self)
47+
while mt do
48+
if mt == T then
49+
return true
50+
end
51+
mt = getmetatable(mt)
52+
end
53+
return false
54+
end
55+
56+
function Object:__tostring()
57+
return "Object"
58+
end
59+
60+
function Object:__call(...)
61+
local obj = setmetatable({}, self)
62+
obj:new(...)
63+
return obj
64+
end
65+
66+
return Object
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
local lynx = {}
2+
local path = (...) .. "."
3+
4+
-- Backup old require to replace it with a custom local one.
5+
local _require = require
6+
7+
function require (mod)
8+
return lynx[mod] or _require(mod)
9+
end
10+
11+
-- All loaded modules, should contain all required stuff.
12+
-- Must to be ordered properly.
13+
local modules = {
14+
-- Base items
15+
"classic",
16+
"menu",
17+
"item",
18+
19+
-- Advanced items
20+
"text",
21+
"button",
22+
"slider",
23+
"observer",
24+
"list",
25+
26+
-- Other things
27+
"love_lynx",
28+
"raylua_lynx"
29+
}
30+
31+
-- Load stuff.
32+
for i=1,#modules do
33+
lynx[modules[i]] = _require(path .. modules[i])
34+
end
35+
36+
require = _require
37+
38+
return lynx
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local item = require "classic":extend()
2+
3+
function item:__tostring()
4+
return "lynx.item"
5+
end
6+
7+
return item
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
local text = require "text"
2+
local list = text:extend()
3+
4+
list.value_index = 1
5+
list.editable = true
6+
list.selectable = true
7+
list.loop = true
8+
list.format = "%s"
9+
10+
list.event_fn = function () end
11+
12+
-- lynx.observer(variable, key, format, params)
13+
-- values: table
14+
-- event_fn: function (self, value)
15+
-- params: table
16+
--
17+
function list:new(values, event_fn, params)
18+
text.new(self, nil, params)
19+
20+
if event_fn then
21+
self.event_fn = event_fn
22+
end
23+
24+
self.values = values or {}
25+
self.value = self.values[self.value_index]
26+
27+
self.selected = false
28+
29+
self.text = self:format_fn(false)
30+
end
31+
32+
function list:format_fn(locked)
33+
local str = string.format(self.format, self.value)
34+
35+
if locked then
36+
if self.value_index > 1 or self.loop then
37+
str = "< " .. str
38+
end
39+
40+
if self.value_index < #self.values or self.loop then
41+
str = str .. " >"
42+
end
43+
end
44+
45+
return str
46+
end
47+
48+
function list:input(menu, key, state)
49+
if (not self.allow_repeat and state == "down") or state == "up" then
50+
return
51+
end
52+
53+
if self.editable then
54+
if menu.funcs.simple_key(key) == "enter" and state == "pressed" then
55+
self.selected = not self.selected
56+
menu.locked = self.selected
57+
self.text = self:format_fn(self.selected)
58+
59+
elseif self.selected then
60+
if menu.funcs.simple_key(key) == "left" then
61+
self.value_index = self.value_index - 1
62+
63+
if self.value_index == 0 then
64+
self.value_index = self.loop and #self.values or 1
65+
end
66+
67+
self.value = self.values[self.value_index]
68+
69+
self:event_fn(menu, self.value)
70+
self.text = self:format_fn(self.selected)
71+
72+
elseif menu.funcs.simple_key(key) == "right" then
73+
self.value_index = self.value_index + 1
74+
75+
if self.value_index == #self.values + 1 then
76+
self.value_index = self.loop and 1 or #self.values
77+
end
78+
79+
self.value = self.values[self.value_index]
80+
81+
self:event_fn(menu, self.value)
82+
self.text = self:format_fn(self.selected)
83+
end
84+
end
85+
end
86+
end
87+
88+
function list:mouse(menu, x, y, btn)
89+
if btn == 1 then
90+
self:input(menu, "enter", "pressed")
91+
end
92+
end
93+
94+
function list:__tostring()
95+
return "lynx.list"
96+
end
97+
98+
return list
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
return {
2+
simple_key = function (k) return k end,
3+
draw_background = function (menu, x, y, w, h)
4+
local background = menu.background
5+
6+
-- Backup previous color.
7+
local r, g, b, a = love.graphics.getColor()
8+
love.graphics.setColor(background)
9+
love.graphics.rectangle("fill", x, y, w, h)
10+
love.graphics.setColor(r, g, b, a)
11+
end,
12+
draw_text = function (menu, text, color, x, y, w, align)
13+
local r, g, b, a = love.graphics.getColor()
14+
love.graphics.setColor(color)
15+
love.graphics.printf(text, x, y, w, align)
16+
love.graphics.setColor(r, g, b, a)
17+
end
18+
}

0 commit comments

Comments
 (0)