Skip to content

Instantly share code, notes, and snippets.

View dacap's full-sized avatar
🎨
Programming

David Capello dacap

🎨
Programming
View GitHub Profile
@dacap
dacap / crash.cpp
Created August 11, 2016 00:38
C++ crash
#include <iostream>
#include <string>
struct Person {
std::string name;
};
int main() {
Person* p = nullptr;
std::cout << (p ? p->name: nullptr) << "\n";
@dacap
dacap / new_sprite.xml
Created August 17, 2016 15:54
Aseprite pixel aspect ratio hack
<check id="advanced_check" text="Advanced Options" />
<vbox id="advanced">
<grid columns="2">
<label text="Pixel Ratio:" />
<combobox id="pixel_ratio" cell_align="horizontal">
<listitem text="Square Pixels (1:1)" value="1:1" />
<listitem text="Double-wide Pixels (2:1)" value="2:1" />
<listitem text="Double-high Pixels (1:2)" value="1:2" />
<listitem text="NES/SNES (8:7)" value="8:7" />
</combobox>
@dacap
dacap / extra-zoom-levels.aseprite-keys
Created December 29, 2016 21:26
Aseprite file with an extra zoom level (600%) in number keys 1,2,3,4,5,6,7
<?xml version="1.0" encoding="utf-8" ?>
<keyboard version="1">
<commands>
<key command="Zoom" shortcut="1"><param name="percentage" value="100" /></key>
<key command="Zoom" shortcut="2"><param name="percentage" value="200" /></key>
<key command="Zoom" shortcut="3"><param name="percentage" value="400" /></key>
<key command="Zoom" shortcut="4"><param name="percentage" value="600" /></key>
<key command="Zoom" shortcut="5"><param name="percentage" value="800" /></key>
<key command="Zoom" shortcut="6"><param name="percentage" value="1600" /></key>
<key command="Zoom" shortcut="7"><param name="percentage" value="3200" /></key>
@dacap
dacap / cache.cpp
Created February 24, 2017 13:48
Simple generic function to cache other functions
#include <cassert>
#include <functional>
#include <iostream>
#include <vector>
template<typename Container>
std::function<void(Container&)>
cache_function(void (*func)(Container&)) {
return [func](Container& result) {
static Container cache;
@dacap
dacap / theme.xml
Created April 24, 2017 18:34
Sunken mini check boxes
...
<style id="mini_check_box" extends="check_box" font="mini">
<newlayer />
<text color="face" align="left middle" x="14" y="1" />
<text color="face" align="left middle" x="14" y="1" state="disabled" />
<newlayer />
<text color="text" align="left middle" x="14" />
<text color="disabled" align="left middle" x="14" state="disabled" />
</style>
...
@dacap
dacap / new_sprite.xml
Created May 15, 2017 19:54
Aseprite UI example
<gui>
<window id="new_sprite" text="@.title">
<box vertical="true">
<separator text="@.size" left="true" horizontal="true" />
<grid columns="2">
<label text="@.width" />
<entry id="width" maxsize="8" magnet="true" cell_align="horizontal" suffix="px" />
<label text="@.height" />
<entry id="height" maxsize="8" cell_align="horizontal" suffix="px" />
JS Console output for mousedown left, right, middle, x1, x2 mouse buttons:
VM35:1 mousedown MouseEvent {isTrusted: true, screenX: 139, screenY: 248, clientX: 139, clientY: 128…}altKey: falsebubbles: truebutton: 0buttons: 1cancelBubble: falsecancelable: trueclientX: 139clientY: 128composed: truectrlKey: falsecurrentTarget: nulldefaultPrevented: falsedetail: 1eventPhase: 0fromElement: nullisTrusted: truelayerX: 139layerY: 128metaKey: falsemovementX: 0movementY: 0offsetX: 7offsetY: 54pageX: 139pageY: 128path: Array(9)relatedTarget: nullreturnValue: truescreenX: 139screenY: 248shiftKey: falsesourceCapabilities: InputDeviceCapabilitiessrcElement: div.news.column.two-thirdstarget: div.news.column.two-thirdstimeStamp: 227380.14500000002toElement: div.news.column.two-thirdstype: "mousedown"view: Windowwhich: 1x: 139y: 128__proto__: MouseEvent
VM35:1 mousedown MouseEvent {isTrusted: true, screenX: 139, screenY: 248, clientX: 139, clientY: 128…}altKey: falsebubbles: truebutton: 2buttons: 2cancelBubble: falsecancelable
@dacap
dacap / new_sprite.xml.h
Created August 26, 2017 13:23
Generated new_sprite.xml.h file
// Don't modify, generated file from /Users/david/Dropbox/ASEPRITE/aseprite/data/widgets/new_sprite.xml
#ifndef GENERATED_NEW_SPRITE_H_INCLUDED
#define GENERATED_NEW_SPRITE_H_INCLUDED
#pragma once
#include "app/find_widget.h"
#include "app/load_widget.h"
#include "ui/ui.h"
@dacap
dacap / test19.cpp
Created September 19, 2017 13:31
Testing -Wall on VS2017
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <string>
#include <vector>
int main() {
}
<?xml version="1.0" encoding="utf-8" ?>
<keyboard version="1">
<commands>
<key command="SaveFile" shortcut="Ctrl+S" />
<key command="SaveFile" shortcut="5" />
<key command="AdvancedMode" shortcut="F" removed="true" />
<key command="Undo" shortcut="Ctrl+Z" removed="true" />
<key command="Undo" shortcut="D" />
<key command="Redo" shortcut="Ctrl+Y" removed="true" />
<key command="Redo" shortcut="Ctrl+Shift+Z" removed="true" />