Skip to content

Instantly share code, notes, and snippets.

-- note: https://raw.githubusercontent.com/alexander-yakushev/awesompd/master/utf8.lua
print = function(...)
local str = ""
local num = select("#", ...)
for i = 1, num do
str = str .. tostring(select(i, ...))
if i < num then
local len = utf8.len(str) + 1
local tab = 8

Creating a new Screen

Defining metrics

Screens need to be defined in a theme's metrics file to be available. At a minimum you must define a screen's name, class, next and previous screen. Different screen classes need different things to work, here is a basic ScreenAttract:

; Screen name
@shakesoda
shakesoda / textinput-polyfill.lua
Last active August 29, 2015 14:20
Love 0.10 setTextInput polyfill for 0.9.2
local ffi = require "ffi"
ffi.cdef [[
typedef struct SDL_Rect
{
int x, y;
int w, h;
} SDL_Rect;
void SDL_SetTextInputRect(SDL_Rect *rect);
]]
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <cstdio>
#ifdef _MSC_VER
// I really don't give a shit about your deprecation warnings, MSVC.
#pragma warning(disable: 4996)
#define usleep _sleep
#else
#include <unistd.h>
@shakesoda
shakesoda / color-correct.glsl
Created October 26, 2014 23:57
color correction shader (gutted out of a larger post processing shader)
// For textureSize2D, etc.
#extension GL_EXT_gpu_shader4 : enable
uniform int u_color_correct = 0;
// Sort of a hack: LOVE doesn't expose 3D textures, so we have to sample them
// as 2D and interpolate the samples ourselves.
uniform sampler2D u_lut_primary;
uniform sampler2D u_lut_secondary;
uniform float u_factor = 0.0;
@shakesoda
shakesoda / save-the-world.diff
Last active August 29, 2015 14:08
add line drawing mode (really useful for debugging) and fix crash on non-OS X in love-experiments vertex buffer branch
diff -r 125cff058bd5 src/modules/graphics/opengl/Mesh.cpp
--- a/src/modules/graphics/opengl/Mesh.cpp Mon Jun 02 00:22:41 2014 -0300
+++ b/src/modules/graphics/opengl/Mesh.cpp Sat Oct 25 10:12:35 2014 -0700
@@ -581,6 +581,8 @@
{
case DRAW_MODE_FAN:
return GL_TRIANGLE_FAN;
+ case DRAW_MODE_LINES:
+ return GL_LINES;
case DRAW_MODE_STRIP:
@shakesoda
shakesoda / utf8.lua
Last active August 29, 2015 14:08 — forked from markandgo/utf8.lua
-- $Id: utf8.lua 179 2009-04-03 18:10:03Z pasta $
--
-- Provides UTF-8 aware string functions implemented in pure lua:
-- * string.utf8len(s)
-- * string.utf8sub(s, i, j)
-- * string.utf8reverse(s)
-- * string.utf8char(unicode)
-- * string.utf8unicode(s, i, j)
-- * string.utf8gensub(s, sub_len)
--
@shakesoda
shakesoda / gist:c8d1d108101776f461d9
Created October 22, 2014 12:27
don't even worry about it
// Generate vertices
const int size = 256;
verts.reserve(size*size);
faces.reserve(size*size);
for (int j = 0; j < size; j++)
{
for (int i = 0; i < size; i++)
{
@shakesoda
shakesoda / demo.lua
Last active August 29, 2015 14:07 — forked from LPGhatguy/demo.lua
local glfw = require("glfw3") --Let's say we have a magic GLFW3 binding there!
local openGL = require("opengl")
openGL.loader = glfw.GetProcAddress
openGL:import()
--and somewhere else
local vbo = ffi.new("GLuint[1]")
gl.GenBuffers(1, vbo)
gl.BindBuffer(GL.ARRAY_BUFFER, vbo[0])
gl.BufferData(GL.ARRAY_BUFFER, ffi.sizeof(vertices), vertices, GL.STATIC_DRAW)
@shakesoda
shakesoda / chord.lua
Created September 11, 2014 04:18
axis + face button -> letters. the guts of a controller keyboard.
function gate(axis, num)
local function wrap(x)
return math.fmod(x, math.pi * 2)
end
if math.abs(axis.x) < 0.1 and math.abs(axis.y) < 0.1 then
return num + 1
end
local angle = math.atan2(axis.y, axis.x) -- in radians