istereo2

changeset 6:3bccfc7d10fe

goatkit is drawing
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 23 Sep 2015 05:44:58 +0300
parents 6a39b8912752
children a3c4fcc9f8f3
files istereo.xcodeproj/project.pbxproj libs/goatkit/boolanm.cc libs/goatkit/boolanm.h libs/goatkit/button.cc libs/goatkit/button.h libs/goatkit/checkbox.cc libs/goatkit/checkbox.h libs/goatkit/event.cc libs/goatkit/event.h libs/goatkit/goatkit.h libs/goatkit/label.cc libs/goatkit/label.h libs/goatkit/screen.cc libs/goatkit/screen.h libs/goatkit/slider.cc libs/goatkit/slider.h libs/goatkit/textbox.cc libs/goatkit/textbox.h libs/goatkit/theme.cc libs/goatkit/theme.h libs/goatkit/vec.h libs/goatkit/widget.cc libs/goatkit/widget.h sdr/color.p.glsl sdr/color.v.glsl sdr/ui.p.glsl sdr/ui.v.glsl src/config.h src/ios/viewctl.m src/istereo.c src/istereo.h src/opengl.h src/sanegl.c src/sanegl.h src/ui.cc src/ui.h
diffstat 36 files changed, 2731 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/istereo.xcodeproj/project.pbxproj	Tue Sep 22 07:13:47 2015 +0300
     1.2 +++ b/istereo.xcodeproj/project.pbxproj	Wed Sep 23 05:44:58 2015 +0300
     1.3 @@ -7,6 +7,21 @@
     1.4  	objects = {
     1.5  
     1.6  /* Begin PBXBuildFile section */
     1.7 +		060ECAD41BB1A9CC00CE9B80 /* boolanm.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAC91BB1A9CC00CE9B80 /* boolanm.cc */; settings = {ASSET_TAGS = (); }; };
     1.8 +		060ECAD51BB1A9CC00CE9B80 /* button.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECACB1BB1A9CC00CE9B80 /* button.cc */; settings = {ASSET_TAGS = (); }; };
     1.9 +		060ECAD71BB1A9CC00CE9B80 /* event.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECACD1BB1A9CC00CE9B80 /* event.cc */; settings = {ASSET_TAGS = (); }; };
    1.10 +		060ECAD91BB1A9CC00CE9B80 /* screen.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECACF1BB1A9CC00CE9B80 /* screen.cc */; settings = {ASSET_TAGS = (); }; };
    1.11 +		060ECADA1BB1A9CC00CE9B80 /* slider.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAD01BB1A9CC00CE9B80 /* slider.cc */; settings = {ASSET_TAGS = (); }; };
    1.12 +		060ECADB1BB1A9CC00CE9B80 /* textbox.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAD11BB1A9CC00CE9B80 /* textbox.cc */; settings = {ASSET_TAGS = (); }; };
    1.13 +		060ECADC1BB1A9CC00CE9B80 /* theme.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAD21BB1A9CC00CE9B80 /* theme.cc */; settings = {ASSET_TAGS = (); }; };
    1.14 +		060ECADD1BB1A9CC00CE9B80 /* widget.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAD31BB1A9CC00CE9B80 /* widget.cc */; settings = {ASSET_TAGS = (); }; };
    1.15 +		060ECAEB1BB1AA5200CE9B80 /* checkbox.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECADF1BB1AA5200CE9B80 /* checkbox.cc */; settings = {ASSET_TAGS = (); }; };
    1.16 +		060ECAEC1BB1AA5200CE9B80 /* label.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAE31BB1AA5200CE9B80 /* label.cc */; settings = {ASSET_TAGS = (); }; };
    1.17 +		060ECAEF1BB22A4400CE9B80 /* ui.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAED1BB22A4400CE9B80 /* ui.cc */; settings = {ASSET_TAGS = (); }; };
    1.18 +		060ECAF11BB243B000CE9B80 /* color.v.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF01BB243B000CE9B80 /* color.v.glsl */; settings = {ASSET_TAGS = (); }; };
    1.19 +		060ECAF31BB2441600CE9B80 /* color.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF21BB2441600CE9B80 /* color.p.glsl */; settings = {ASSET_TAGS = (); }; };
    1.20 +		060ECAF61BB2496100CE9B80 /* ui.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF41BB2496100CE9B80 /* ui.p.glsl */; settings = {ASSET_TAGS = (); }; };
    1.21 +		060ECAF71BB2496100CE9B80 /* ui.v.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF51BB2496100CE9B80 /* ui.v.glsl */; settings = {ASSET_TAGS = (); }; };
    1.22  		0669D67F1BA85DDE00611CFA /* app_delegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67B1BA85DDE00611CFA /* app_delegate.m */; };
    1.23  		0669D6801BA85DDE00611CFA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67C1BA85DDE00611CFA /* main.m */; };
    1.24  		0669D6811BA85DDE00611CFA /* viewctl.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67E1BA85DDE00611CFA /* viewctl.m */; };
    1.25 @@ -118,6 +133,34 @@
    1.26  /* End PBXBuildFile section */
    1.27  
    1.28  /* Begin PBXFileReference section */
    1.29 +		060ECAC91BB1A9CC00CE9B80 /* boolanm.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = boolanm.cc; path = libs/goatkit/boolanm.cc; sourceTree = "<group>"; };
    1.30 +		060ECACA1BB1A9CC00CE9B80 /* boolanm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = boolanm.h; path = libs/goatkit/boolanm.h; sourceTree = "<group>"; };
    1.31 +		060ECACB1BB1A9CC00CE9B80 /* button.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = button.cc; path = libs/goatkit/button.cc; sourceTree = "<group>"; };
    1.32 +		060ECACD1BB1A9CC00CE9B80 /* event.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = event.cc; path = libs/goatkit/event.cc; sourceTree = "<group>"; };
    1.33 +		060ECACF1BB1A9CC00CE9B80 /* screen.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = screen.cc; path = libs/goatkit/screen.cc; sourceTree = "<group>"; };
    1.34 +		060ECAD01BB1A9CC00CE9B80 /* slider.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = slider.cc; path = libs/goatkit/slider.cc; sourceTree = "<group>"; };
    1.35 +		060ECAD11BB1A9CC00CE9B80 /* textbox.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = textbox.cc; path = libs/goatkit/textbox.cc; sourceTree = "<group>"; };
    1.36 +		060ECAD21BB1A9CC00CE9B80 /* theme.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = theme.cc; path = libs/goatkit/theme.cc; sourceTree = "<group>"; };
    1.37 +		060ECAD31BB1A9CC00CE9B80 /* widget.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = widget.cc; path = libs/goatkit/widget.cc; sourceTree = "<group>"; };
    1.38 +		060ECADE1BB1AA5200CE9B80 /* button.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = button.h; path = libs/goatkit/button.h; sourceTree = "<group>"; };
    1.39 +		060ECADF1BB1AA5200CE9B80 /* checkbox.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = checkbox.cc; path = libs/goatkit/checkbox.cc; sourceTree = "<group>"; };
    1.40 +		060ECAE01BB1AA5200CE9B80 /* checkbox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = checkbox.h; path = libs/goatkit/checkbox.h; sourceTree = "<group>"; };
    1.41 +		060ECAE11BB1AA5200CE9B80 /* event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = event.h; path = libs/goatkit/event.h; sourceTree = "<group>"; };
    1.42 +		060ECAE21BB1AA5200CE9B80 /* goatkit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = goatkit.h; path = libs/goatkit/goatkit.h; sourceTree = "<group>"; };
    1.43 +		060ECAE31BB1AA5200CE9B80 /* label.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = label.cc; path = libs/goatkit/label.cc; sourceTree = "<group>"; };
    1.44 +		060ECAE41BB1AA5200CE9B80 /* label.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = label.h; path = libs/goatkit/label.h; sourceTree = "<group>"; };
    1.45 +		060ECAE51BB1AA5200CE9B80 /* screen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = screen.h; path = libs/goatkit/screen.h; sourceTree = "<group>"; };
    1.46 +		060ECAE61BB1AA5200CE9B80 /* slider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = slider.h; path = libs/goatkit/slider.h; sourceTree = "<group>"; };
    1.47 +		060ECAE71BB1AA5200CE9B80 /* textbox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = textbox.h; path = libs/goatkit/textbox.h; sourceTree = "<group>"; };
    1.48 +		060ECAE81BB1AA5200CE9B80 /* theme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = theme.h; path = libs/goatkit/theme.h; sourceTree = "<group>"; };
    1.49 +		060ECAE91BB1AA5200CE9B80 /* vec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vec.h; path = libs/goatkit/vec.h; sourceTree = "<group>"; };
    1.50 +		060ECAEA1BB1AA5200CE9B80 /* widget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = widget.h; path = libs/goatkit/widget.h; sourceTree = "<group>"; };
    1.51 +		060ECAED1BB22A4400CE9B80 /* ui.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ui.cc; path = src/ui.cc; sourceTree = "<group>"; };
    1.52 +		060ECAEE1BB22A4400CE9B80 /* ui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ui.h; path = src/ui.h; sourceTree = "<group>"; };
    1.53 +		060ECAF01BB243B000CE9B80 /* color.v.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = color.v.glsl; path = sdr/color.v.glsl; sourceTree = "<group>"; };
    1.54 +		060ECAF21BB2441600CE9B80 /* color.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = color.p.glsl; path = sdr/color.p.glsl; sourceTree = "<group>"; };
    1.55 +		060ECAF41BB2496100CE9B80 /* ui.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ui.p.glsl; path = sdr/ui.p.glsl; sourceTree = "<group>"; };
    1.56 +		060ECAF51BB2496100CE9B80 /* ui.v.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ui.v.glsl; path = sdr/ui.v.glsl; sourceTree = "<group>"; };
    1.57  		0669D6471BA851BE00611CFA /* istereo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = istereo.app; sourceTree = BUILT_PRODUCTS_DIR; };
    1.58  		0669D6741BA858BF00611CFA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ios/Info.plist; sourceTree = "<group>"; };
    1.59  		0669D67A1BA85DDE00611CFA /* app_delegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = app_delegate.h; path = src/ios/app_delegate.h; sourceTree = "<group>"; };
    1.60 @@ -139,7 +182,6 @@
    1.61  		0669D68D1BACDF6C00611CFA /* sdr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sdr.h; path = src/sdr.h; sourceTree = "<group>"; };
    1.62  		0669D68E1BACDF6C00611CFA /* tex.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = tex.c; path = src/tex.c; sourceTree = "<group>"; };
    1.63  		0669D68F1BACDF6C00611CFA /* tex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tex.h; path = src/tex.h; sourceTree = "<group>"; };
    1.64 -		0669D6901BACDF6C00611CFA /* ui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ui.h; path = src/ui.h; sourceTree = "<group>"; };
    1.65  		0669D69D1BAD020B00611CFA /* basis_c.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = basis_c.c; path = libs/vmath/basis_c.c; sourceTree = "<group>"; };
    1.66  		0669D69E1BAD020B00611CFA /* basis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = basis.h; path = libs/vmath/basis.h; sourceTree = "<group>"; };
    1.67  		0669D69F1BAD020B00611CFA /* geom.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = geom.c; path = libs/vmath/geom.c; sourceTree = "<group>"; };
    1.68 @@ -293,6 +335,35 @@
    1.69  /* End PBXFrameworksBuildPhase section */
    1.70  
    1.71  /* Begin PBXGroup section */
    1.72 +		060ECAC81BB1A9BA00CE9B80 /* goatkit */ = {
    1.73 +			isa = PBXGroup;
    1.74 +			children = (
    1.75 +				060ECADE1BB1AA5200CE9B80 /* button.h */,
    1.76 +				060ECADF1BB1AA5200CE9B80 /* checkbox.cc */,
    1.77 +				060ECAE01BB1AA5200CE9B80 /* checkbox.h */,
    1.78 +				060ECAE11BB1AA5200CE9B80 /* event.h */,
    1.79 +				060ECAE21BB1AA5200CE9B80 /* goatkit.h */,
    1.80 +				060ECAE31BB1AA5200CE9B80 /* label.cc */,
    1.81 +				060ECAE41BB1AA5200CE9B80 /* label.h */,
    1.82 +				060ECAE51BB1AA5200CE9B80 /* screen.h */,
    1.83 +				060ECAE61BB1AA5200CE9B80 /* slider.h */,
    1.84 +				060ECAE71BB1AA5200CE9B80 /* textbox.h */,
    1.85 +				060ECAE81BB1AA5200CE9B80 /* theme.h */,
    1.86 +				060ECAE91BB1AA5200CE9B80 /* vec.h */,
    1.87 +				060ECAEA1BB1AA5200CE9B80 /* widget.h */,
    1.88 +				060ECAC91BB1A9CC00CE9B80 /* boolanm.cc */,
    1.89 +				060ECACA1BB1A9CC00CE9B80 /* boolanm.h */,
    1.90 +				060ECACB1BB1A9CC00CE9B80 /* button.cc */,
    1.91 +				060ECACD1BB1A9CC00CE9B80 /* event.cc */,
    1.92 +				060ECACF1BB1A9CC00CE9B80 /* screen.cc */,
    1.93 +				060ECAD01BB1A9CC00CE9B80 /* slider.cc */,
    1.94 +				060ECAD11BB1A9CC00CE9B80 /* textbox.cc */,
    1.95 +				060ECAD21BB1A9CC00CE9B80 /* theme.cc */,
    1.96 +				060ECAD31BB1A9CC00CE9B80 /* widget.cc */,
    1.97 +			);
    1.98 +			name = goatkit;
    1.99 +			sourceTree = "<group>";
   1.100 +		};
   1.101  		0669D63E1BA851BE00611CFA = {
   1.102  			isa = PBXGroup;
   1.103  			children = (
   1.104 @@ -317,6 +388,8 @@
   1.105  		0669D6761BA858D600611CFA /* src */ = {
   1.106  			isa = PBXGroup;
   1.107  			children = (
   1.108 +				060ECAED1BB22A4400CE9B80 /* ui.cc */,
   1.109 +				060ECAEE1BB22A4400CE9B80 /* ui.h */,
   1.110  				0669D6821BACDF6C00611CFA /* cam.c */,
   1.111  				0669D6831BACDF6C00611CFA /* cam.h */,
   1.112  				0669D6841BACDF6C00611CFA /* config.h */,
   1.113 @@ -331,7 +404,6 @@
   1.114  				0669D68D1BACDF6C00611CFA /* sdr.h */,
   1.115  				0669D68E1BACDF6C00611CFA /* tex.c */,
   1.116  				0669D68F1BACDF6C00611CFA /* tex.h */,
   1.117 -				0669D6901BACDF6C00611CFA /* ui.h */,
   1.118  				0669D6791BA85DCC00611CFA /* ios */,
   1.119  			);
   1.120  			name = src;
   1.121 @@ -352,6 +424,7 @@
   1.122  		0669D6971BAD01C200611CFA /* libs */ = {
   1.123  			isa = PBXGroup;
   1.124  			children = (
   1.125 +				060ECAC81BB1A9BA00CE9B80 /* goatkit */,
   1.126  				0669D69C1BAD01EA00611CFA /* vmath */,
   1.127  				0669D69B1BAD01E300611CFA /* imago2 */,
   1.128  				0669D69A1BAD01DD00611CFA /* jpeglib */,
   1.129 @@ -528,12 +601,16 @@
   1.130  		0669D77B1BAD028300611CFA /* sdr */ = {
   1.131  			isa = PBXGroup;
   1.132  			children = (
   1.133 +				060ECAF41BB2496100CE9B80 /* ui.p.glsl */,
   1.134 +				060ECAF51BB2496100CE9B80 /* ui.v.glsl */,
   1.135  				0669D77C1BAD02A200611CFA /* test.p.glsl */,
   1.136  				0669D77D1BAD02A200611CFA /* test.v.glsl */,
   1.137  				0669D77E1BAD02A200611CFA /* text.p.glsl */,
   1.138  				0669D77F1BAD02A200611CFA /* text.v.glsl */,
   1.139  				0669D7801BAD02A200611CFA /* tunnel.p.glsl */,
   1.140  				0669D7811BAD02A200611CFA /* tunnel.v.glsl */,
   1.141 +				060ECAF01BB243B000CE9B80 /* color.v.glsl */,
   1.142 +				060ECAF21BB2441600CE9B80 /* color.p.glsl */,
   1.143  			);
   1.144  			name = sdr;
   1.145  			sourceTree = "<group>";
   1.146 @@ -610,8 +687,12 @@
   1.147  				0669D7861BAD02A200611CFA /* tunnel.p.glsl in Resources */,
   1.148  				0669D7821BAD02A200611CFA /* test.p.glsl in Resources */,
   1.149  				0669D78D1BAD02DC00611CFA /* stonewall_normal.jpg in Resources */,
   1.150 +				060ECAF11BB243B000CE9B80 /* color.v.glsl in Resources */,
   1.151  				0669D78E1BAD02DC00611CFA /* stonewall.jpg in Resources */,
   1.152 +				060ECAF61BB2496100CE9B80 /* ui.p.glsl in Resources */,
   1.153 +				060ECAF71BB2496100CE9B80 /* ui.v.glsl in Resources */,
   1.154  				0669D7841BAD02A200611CFA /* text.p.glsl in Resources */,
   1.155 +				060ECAF31BB2441600CE9B80 /* color.p.glsl in Resources */,
   1.156  				06ED084A1BAF9A2E00C1211D /* icons.xcassets in Resources */,
   1.157  				0669D7901BAD02DC00611CFA /* tiles.jpg in Resources */,
   1.158  				0669D7871BAD02A200611CFA /* tunnel.v.glsl in Resources */,
   1.159 @@ -644,11 +725,13 @@
   1.160  				0669D6CC1BAD022C00611CFA /* modules.c in Sources */,
   1.161  				0669D7301BAD024700611CFA /* jmemmgr.c in Sources */,
   1.162  				0669D72E1BAD024700611CFA /* jidctint.c in Sources */,
   1.163 +				060ECAD41BB1A9CC00CE9B80 /* boolanm.cc in Sources */,
   1.164  				0669D6B81BAD020B00611CFA /* ray_c.c in Sources */,
   1.165  				0669D71D1BAD024700611CFA /* jddctmgr.c in Sources */,
   1.166  				0669D7571BAD025B00611CFA /* pngwtran.c in Sources */,
   1.167  				0669D7081BAD024700611CFA /* jcapistd.c in Sources */,
   1.168  				0669D72C1BAD024700611CFA /* jidctflt.c in Sources */,
   1.169 +				060ECADB1BB1A9CC00CE9B80 /* textbox.cc in Sources */,
   1.170  				0669D7511BAD025B00611CFA /* pngrutil.c in Sources */,
   1.171  				0669D6BB1BAD020B00611CFA /* vmath.c in Sources */,
   1.172  				0669D7341BAD024700611CFA /* jutils.c in Sources */,
   1.173 @@ -670,19 +753,25 @@
   1.174  				0669D7521BAD025B00611CFA /* pngset.c in Sources */,
   1.175  				0669D7561BAD025B00611CFA /* pngwrite.c in Sources */,
   1.176  				0669D7131BAD024700611CFA /* jcphuff.c in Sources */,
   1.177 +				060ECAD91BB1A9CC00CE9B80 /* screen.cc in Sources */,
   1.178  				0669D70A1BAD024700611CFA /* jccolor.c in Sources */,
   1.179 +				060ECADD1BB1A9CC00CE9B80 /* widget.cc in Sources */,
   1.180  				0669D74F1BAD025B00611CFA /* pngrio.c in Sources */,
   1.181  				0669D6C81BAD022C00611CFA /* file_png.c in Sources */,
   1.182  				0669D7231BAD024700611CFA /* jdmerge.c in Sources */,
   1.183  				0669D77A1BAD027000611CFA /* zutil.c in Sources */,
   1.184  				0669D7721BAD027000611CFA /* deflate.c in Sources */,
   1.185 +				060ECAEB1BB1AA5200CE9B80 /* checkbox.cc in Sources */,
   1.186  				0669D71F1BAD024700611CFA /* jdinput.c in Sources */,
   1.187  				0669D7581BAD025B00611CFA /* pngwutil.c in Sources */,
   1.188  				0669D7261BAD024700611CFA /* jdsample.c in Sources */,
   1.189  				0669D7701BAD027000611CFA /* compress.c in Sources */,
   1.190  				0669D7111BAD024700611CFA /* jcomapi.c in Sources */,
   1.191  				0669D71A1BAD024700611CFA /* jdatasrc.c in Sources */,
   1.192 +				060ECADC1BB1A9CC00CE9B80 /* theme.cc in Sources */,
   1.193  				0669D74B1BAD025B00611CFA /* pngget.c in Sources */,
   1.194 +				060ECAD71BB1A9CC00CE9B80 /* event.cc in Sources */,
   1.195 +				060ECAD51BB1A9CC00CE9B80 /* button.cc in Sources */,
   1.196  				0669D7211BAD024700611CFA /* jdmarker.c in Sources */,
   1.197  				0669D7251BAD024700611CFA /* jdpostct.c in Sources */,
   1.198  				0669D6811BA85DDE00611CFA /* viewctl.m in Sources */,
   1.199 @@ -702,10 +791,12 @@
   1.200  				0669D7271BAD024700611CFA /* jdtrans.c in Sources */,
   1.201  				0669D6B21BAD020B00611CFA /* basis_c.c in Sources */,
   1.202  				0669D7161BAD024700611CFA /* jctrans.c in Sources */,
   1.203 +				060ECADA1BB1A9CC00CE9B80 /* slider.cc in Sources */,
   1.204  				0669D7311BAD024700611CFA /* jmemnobs.c in Sources */,
   1.205  				0669D74E1BAD025B00611CFA /* pngread.c in Sources */,
   1.206  				0669D71E1BAD024700611CFA /* jdhuff.c in Sources */,
   1.207  				0669D74A1BAD025B00611CFA /* pnggccrd.c in Sources */,
   1.208 +				060ECAEF1BB22A4400CE9B80 /* ui.cc in Sources */,
   1.209  				0669D70E1BAD024700611CFA /* jcmainct.c in Sources */,
   1.210  				0669D7151BAD024700611CFA /* jcsample.c in Sources */,
   1.211  				0669D7141BAD024700611CFA /* jcprepct.c in Sources */,
   1.212 @@ -717,6 +808,7 @@
   1.213  				0669D7071BAD024700611CFA /* jcapimin.c in Sources */,
   1.214  				0669D6C61BAD022C00611CFA /* conv.c in Sources */,
   1.215  				0669D6B41BAD020B00611CFA /* matrix_c.c in Sources */,
   1.216 +				060ECAEC1BB1AA5200CE9B80 /* label.cc in Sources */,
   1.217  				0669D7321BAD024700611CFA /* jquant1.c in Sources */,
   1.218  				0669D6C91BAD022C00611CFA /* file_ppm.c in Sources */,
   1.219  				0669D72D1BAD024700611CFA /* jidctfst.c in Sources */,
   1.220 @@ -820,6 +912,11 @@
   1.221  				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
   1.222  				ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
   1.223  				CODE_SIGN_IDENTITY = "iPhone Developer";
   1.224 +				GCC_PREPROCESSOR_DEFINITIONS = (
   1.225 +					"DEBUG=1",
   1.226 +					HAVE_OPENGL_H,
   1.227 +				);
   1.228 +				HEADER_SEARCH_PATHS = libs;
   1.229  				INFOPLIST_FILE = "$(SRCROOT)/ios/Info.plist";
   1.230  				IPHONEOS_DEPLOYMENT_TARGET = 6.0;
   1.231  				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
   1.232 @@ -834,6 +931,8 @@
   1.233  				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
   1.234  				ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
   1.235  				CODE_SIGN_IDENTITY = "iPhone Developer";
   1.236 +				GCC_PREPROCESSOR_DEFINITIONS = HAVE_OPENGL_H;
   1.237 +				HEADER_SEARCH_PATHS = libs;
   1.238  				INFOPLIST_FILE = "$(SRCROOT)/ios/Info.plist";
   1.239  				IPHONEOS_DEPLOYMENT_TARGET = 6.0;
   1.240  				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/libs/goatkit/boolanm.cc	Wed Sep 23 05:44:58 2015 +0300
     2.3 @@ -0,0 +1,151 @@
     2.4 +/*
     2.5 +GoatKit - a themable/animated widget toolkit for games
     2.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
     2.7 +
     2.8 +This program is free software: you can redistribute it and/or modify
     2.9 +it under the terms of the GNU Lesser General Public License as published by
    2.10 +the Free Software Foundation, either version 3 of the License, or
    2.11 +(at your option) any later version.
    2.12 +
    2.13 +This program is distributed in the hope that it will be useful,
    2.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.16 +GNU Lesser General Public License for more details.
    2.17 +
    2.18 +You should have received a copy of the GNU Lesser General Public License
    2.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    2.20 +*/
    2.21 +#include "boolanm.h"
    2.22 +
    2.23 +static long default_get_msec();
    2.24 +
    2.25 +BoolAnim::BoolAnim(bool st)
    2.26 +{
    2.27 +	set(st);
    2.28 +	trans_start = 0;
    2.29 +	trans_dur = 500;
    2.30 +	get_msec = default_get_msec;
    2.31 +}
    2.32 +
    2.33 +void BoolAnim::update(long tm) const
    2.34 +{
    2.35 +	if(trans_dir == 0.0) return;
    2.36 +
    2.37 +	float dt = (tm - trans_start) / 1000.0;
    2.38 +	float t = dt / (trans_dur / 1000.0);
    2.39 +
    2.40 +	if(trans_dir > 0.0) {
    2.41 +		value = t;
    2.42 +	} else {
    2.43 +		value = 1.0 - t;
    2.44 +	}
    2.45 +
    2.46 +	if(value < 0.0) {
    2.47 +		value = 0.0;
    2.48 +		trans_dir = 0.0;
    2.49 +	} else if(value > 1.0) {
    2.50 +		value = 1.0;
    2.51 +		trans_dir = 0.0;
    2.52 +	}
    2.53 +}
    2.54 +
    2.55 +void BoolAnim::set_transition_duration(long dur)
    2.56 +{
    2.57 +	trans_dur = dur;
    2.58 +}
    2.59 +
    2.60 +void BoolAnim::set_time_callback(long (*time_func)())
    2.61 +{
    2.62 +	get_msec = time_func;
    2.63 +}
    2.64 +
    2.65 +void BoolAnim::set(bool st)
    2.66 +{
    2.67 +	value = st ? 1.0 : 0.0;
    2.68 +	trans_dir = 0.0;
    2.69 +}
    2.70 +
    2.71 +void BoolAnim::change(bool st)
    2.72 +{
    2.73 +	change(st, get_msec());
    2.74 +}
    2.75 +
    2.76 +void BoolAnim::change(bool st, long tm)
    2.77 +{
    2.78 +	trans_dir = st ? 1.0 : -1.0;
    2.79 +	trans_start = tm;
    2.80 +}
    2.81 +
    2.82 +bool BoolAnim::get_state() const
    2.83 +{
    2.84 +	return get_state(get_msec());
    2.85 +}
    2.86 +
    2.87 +bool BoolAnim::get_state(long tm) const
    2.88 +{
    2.89 +	update(tm);
    2.90 +
    2.91 +	// if we're not in transition use the value (should be 0 or 1)
    2.92 +	if(trans_dir == 0.0) {
    2.93 +		return value > 0.5;
    2.94 +	}
    2.95 +
    2.96 +	// if we're in transition base it on the direction of the transition
    2.97 +	return trans_dir > 0.0;
    2.98 +}
    2.99 +
   2.100 +float BoolAnim::get_value() const
   2.101 +{
   2.102 +	return get_value(get_msec());
   2.103 +}
   2.104 +
   2.105 +float BoolAnim::get_value(long tm) const
   2.106 +{
   2.107 +	update(tm);
   2.108 +	return value;
   2.109 +}
   2.110 +
   2.111 +float BoolAnim::get_dir() const
   2.112 +{
   2.113 +	return get_dir(get_msec());
   2.114 +}
   2.115 +
   2.116 +float BoolAnim::get_dir(long tm) const
   2.117 +{
   2.118 +	update(tm);
   2.119 +	return trans_dir;
   2.120 +}
   2.121 +
   2.122 +BoolAnim::operator bool() const
   2.123 +{
   2.124 +	return get_state();
   2.125 +}
   2.126 +
   2.127 +BoolAnim::operator float() const
   2.128 +{
   2.129 +	return get_value();
   2.130 +}
   2.131 +
   2.132 +#ifdef WIN32
   2.133 +#include <windows.h>
   2.134 +
   2.135 +static long default_get_msec()
   2.136 +{
   2.137 +	return GetTickCount();
   2.138 +}
   2.139 +#else
   2.140 +#include <sys/time.h>
   2.141 +
   2.142 +static long default_get_msec()
   2.143 +{
   2.144 +	static struct timeval tv0;
   2.145 +	struct timeval tv;
   2.146 +
   2.147 +	gettimeofday(&tv, 0);
   2.148 +	if(tv0.tv_sec == 0 && tv0.tv_usec == 0) {
   2.149 +		tv0 = tv;
   2.150 +		return 0;
   2.151 +	}
   2.152 +	return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
   2.153 +}
   2.154 +#endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/libs/goatkit/boolanm.h	Wed Sep 23 05:44:58 2015 +0300
     3.3 @@ -0,0 +1,57 @@
     3.4 +/*
     3.5 +GoatKit - a themable/animated widget toolkit for games
     3.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
     3.7 +
     3.8 +This program is free software: you can redistribute it and/or modify
     3.9 +it under the terms of the GNU Lesser General Public License as published by
    3.10 +the Free Software Foundation, either version 3 of the License, or
    3.11 +(at your option) any later version.
    3.12 +
    3.13 +This program is distributed in the hope that it will be useful,
    3.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.16 +GNU Lesser General Public License for more details.
    3.17 +
    3.18 +You should have received a copy of the GNU Lesser General Public License
    3.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    3.20 +*/
    3.21 +#ifndef BOOLANIM_H_
    3.22 +#define BOOLANIM_H_
    3.23 +
    3.24 +class BoolAnim {
    3.25 +private:
    3.26 +	mutable float value;
    3.27 +	mutable float trans_dir;	// transition direction (sign)
    3.28 +	long trans_start;	// transition start time
    3.29 +	long trans_dur;
    3.30 +
    3.31 +	long (*get_msec)();
    3.32 +
    3.33 +	void update(long tm) const;
    3.34 +
    3.35 +public:
    3.36 +	BoolAnim(bool st = false);
    3.37 +
    3.38 +	void set_transition_duration(long dur);
    3.39 +	void set_time_callback(long (*time_func)());
    3.40 +
    3.41 +	void set(bool st);
    3.42 +
    3.43 +	void change(bool st);
    3.44 +	void change(bool st, long trans_start);
    3.45 +
    3.46 +	bool get_state() const;
    3.47 +	bool get_state(long tm) const;
    3.48 +
    3.49 +	float get_value() const;
    3.50 +	float get_value(long tm) const;
    3.51 +
    3.52 +	// transition direction (-1, 0, 1)
    3.53 +	float get_dir() const;
    3.54 +	float get_dir(long tm) const;
    3.55 +
    3.56 +	operator bool() const;	// equivalent to get_state
    3.57 +	operator float() const;	// equivalent to get_value
    3.58 +};
    3.59 +
    3.60 +#endif	// BOOLANIM_H_
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/libs/goatkit/button.cc	Wed Sep 23 05:44:58 2015 +0300
     4.3 @@ -0,0 +1,40 @@
     4.4 +/*
     4.5 +GoatKit - a themable/animated widget toolkit for games
     4.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
     4.7 +
     4.8 +This program is free software: you can redistribute it and/or modify
     4.9 +it under the terms of the GNU Lesser General Public License as published by
    4.10 +the Free Software Foundation, either version 3 of the License, or
    4.11 +(at your option) any later version.
    4.12 +
    4.13 +This program is distributed in the hope that it will be useful,
    4.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.16 +GNU Lesser General Public License for more details.
    4.17 +
    4.18 +You should have received a copy of the GNU Lesser General Public License
    4.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    4.20 +*/
    4.21 +#include "button.h"
    4.22 +
    4.23 +namespace goatkit {
    4.24 +
    4.25 +struct ButtonImpl {
    4.26 +};
    4.27 +
    4.28 +Button::Button()
    4.29 +{
    4.30 +	button = new ButtonImpl;
    4.31 +}
    4.32 +
    4.33 +Button::~Button()
    4.34 +{
    4.35 +	delete button;
    4.36 +}
    4.37 +
    4.38 +const char *Button::get_type_name() const
    4.39 +{
    4.40 +	return "button";
    4.41 +}
    4.42 +
    4.43 +}	// namespace goatkit
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/libs/goatkit/button.h	Wed Sep 23 05:44:58 2015 +0300
     5.3 @@ -0,0 +1,40 @@
     5.4 +/*
     5.5 +GoatKit - a themable/animated widget toolkit for games
     5.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
     5.7 +
     5.8 +This program is free software: you can redistribute it and/or modify
     5.9 +it under the terms of the GNU Lesser General Public License as published by
    5.10 +the Free Software Foundation, either version 3 of the License, or
    5.11 +(at your option) any later version.
    5.12 +
    5.13 +This program is distributed in the hope that it will be useful,
    5.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.16 +GNU Lesser General Public License for more details.
    5.17 +
    5.18 +You should have received a copy of the GNU Lesser General Public License
    5.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    5.20 +*/
    5.21 +#ifndef GOATKIT_BUTTON_H_
    5.22 +#define GOATKIT_BUTTON_H_
    5.23 +
    5.24 +#include "widget.h"
    5.25 +
    5.26 +namespace goatkit {
    5.27 +
    5.28 +struct ButtonImpl;
    5.29 +
    5.30 +class Button : public Widget {
    5.31 +private:
    5.32 +	ButtonImpl *button;
    5.33 +
    5.34 +public:
    5.35 +	Button();
    5.36 +	virtual ~Button();
    5.37 +
    5.38 +	virtual const char *get_type_name() const;
    5.39 +};
    5.40 +
    5.41 +}	// namespace goatkit
    5.42 +
    5.43 +#endif	// GOATKIT_BUTTON_H_
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/libs/goatkit/checkbox.cc	Wed Sep 23 05:44:58 2015 +0300
     6.3 @@ -0,0 +1,83 @@
     6.4 +/*
     6.5 +GoatKit - a themable/animated widget toolkit for games
     6.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
     6.7 +
     6.8 +This program is free software: you can redistribute it and/or modify
     6.9 +it under the terms of the GNU Lesser General Public License as published by
    6.10 +the Free Software Foundation, either version 3 of the License, or
    6.11 +(at your option) any later version.
    6.12 +
    6.13 +This program is distributed in the hope that it will be useful,
    6.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.16 +GNU Lesser General Public License for more details.
    6.17 +
    6.18 +You should have received a copy of the GNU Lesser General Public License
    6.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    6.20 +*/
    6.21 +#include "checkbox.h"
    6.22 +#include "boolanm.h"
    6.23 +
    6.24 +namespace goatkit {
    6.25 +
    6.26 +struct CheckBoxImpl {
    6.27 +	BoolAnim checked;
    6.28 +};
    6.29 +
    6.30 +CheckBox::CheckBox()
    6.31 +{
    6.32 +	cbox = new CheckBoxImpl;
    6.33 +	cbox->checked = false;
    6.34 +	cbox->checked.set_transition_duration(60);
    6.35 +}
    6.36 +
    6.37 +CheckBox::~CheckBox()
    6.38 +{
    6.39 +	delete cbox;
    6.40 +}
    6.41 +
    6.42 +const char *CheckBox::get_type_name() const
    6.43 +{
    6.44 +	return "checkbox";
    6.45 +}
    6.46 +
    6.47 +
    6.48 +void CheckBox::check()
    6.49 +{
    6.50 +	cbox->checked.change(true);
    6.51 +}
    6.52 +
    6.53 +void CheckBox::uncheck()
    6.54 +{
    6.55 +	cbox->checked.change(false);
    6.56 +}
    6.57 +
    6.58 +float CheckBox::get_checked() const
    6.59 +{
    6.60 +	return cbox->checked.get_value();
    6.61 +}
    6.62 +
    6.63 +bool CheckBox::is_checked() const
    6.64 +{
    6.65 +	return cbox->checked.get_state();
    6.66 +}
    6.67 +
    6.68 +void CheckBox::toggle()
    6.69 +{
    6.70 +	if(is_checked()) {
    6.71 +		uncheck();
    6.72 +	} else {
    6.73 +		check();
    6.74 +	}
    6.75 +}
    6.76 +
    6.77 +void CheckBox::on_click()
    6.78 +{
    6.79 +	toggle();
    6.80 +
    6.81 +	Event ev;
    6.82 +	ev.type = EV_CHANGE;
    6.83 +	handle_event(ev);
    6.84 +}
    6.85 +
    6.86 +}	// namespace goatkit
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/libs/goatkit/checkbox.h	Wed Sep 23 05:44:58 2015 +0300
     7.3 @@ -0,0 +1,48 @@
     7.4 +/*
     7.5 +GoatKit - a themable/animated widget toolkit for games
     7.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
     7.7 +
     7.8 +This program is free software: you can redistribute it and/or modify
     7.9 +it under the terms of the GNU Lesser General Public License as published by
    7.10 +the Free Software Foundation, either version 3 of the License, or
    7.11 +(at your option) any later version.
    7.12 +
    7.13 +This program is distributed in the hope that it will be useful,
    7.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.16 +GNU Lesser General Public License for more details.
    7.17 +
    7.18 +You should have received a copy of the GNU Lesser General Public License
    7.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    7.20 +*/
    7.21 +#ifndef CHECKBOX_H_
    7.22 +#define CHECKBOX_H_
    7.23 +
    7.24 +#include "widget.h"
    7.25 +
    7.26 +namespace goatkit {
    7.27 +
    7.28 +struct CheckBoxImpl;
    7.29 +
    7.30 +class CheckBox : public Widget {
    7.31 +private:
    7.32 +	CheckBoxImpl *cbox;
    7.33 +
    7.34 +public:
    7.35 +	CheckBox();
    7.36 +	virtual ~CheckBox();
    7.37 +
    7.38 +	virtual const char *get_type_name() const;
    7.39 +
    7.40 +	virtual void check();
    7.41 +	virtual void uncheck();
    7.42 +	virtual float get_checked() const;
    7.43 +	virtual bool is_checked() const;
    7.44 +	virtual void toggle();
    7.45 +
    7.46 +	virtual void on_click();
    7.47 +};
    7.48 +
    7.49 +}	// namespace goatkit
    7.50 +
    7.51 +#endif	// CHECKBOX_H_
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/libs/goatkit/event.cc	Wed Sep 23 05:44:58 2015 +0300
     8.3 @@ -0,0 +1,35 @@
     8.4 +/*
     8.5 +GoatKit - a themable/animated widget toolkit for games
     8.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
     8.7 +
     8.8 +This program is free software: you can redistribute it and/or modify
     8.9 +it under the terms of the GNU Lesser General Public License as published by
    8.10 +the Free Software Foundation, either version 3 of the License, or
    8.11 +(at your option) any later version.
    8.12 +
    8.13 +This program is distributed in the hope that it will be useful,
    8.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.16 +GNU Lesser General Public License for more details.
    8.17 +
    8.18 +You should have received a copy of the GNU Lesser General Public License
    8.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    8.20 +*/
    8.21 +#include "event.h"
    8.22 +
    8.23 +
    8.24 +const char *goatkit::event_type_name(EventType type)
    8.25 +{
    8.26 +	// XXX keep this array synchronized with enum EventType
    8.27 +	static const char *names[NUM_EVENTS] = {
    8.28 +		"mouse button",
    8.29 +		"mouse motion",
    8.30 +		"focus",
    8.31 +		"keyboard",
    8.32 +		"click",
    8.33 +		"double click",
    8.34 +		"change"
    8.35 +	};
    8.36 +
    8.37 +	return names[type];
    8.38 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/libs/goatkit/event.h	Wed Sep 23 05:44:58 2015 +0300
     9.3 @@ -0,0 +1,83 @@
     9.4 +/*
     9.5 +GoatKit - a themable/animated widget toolkit for games
     9.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
     9.7 +
     9.8 +This program is free software: you can redistribute it and/or modify
     9.9 +it under the terms of the GNU Lesser General Public License as published by
    9.10 +the Free Software Foundation, either version 3 of the License, or
    9.11 +(at your option) any later version.
    9.12 +
    9.13 +This program is distributed in the hope that it will be useful,
    9.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.16 +GNU Lesser General Public License for more details.
    9.17 +
    9.18 +You should have received a copy of the GNU Lesser General Public License
    9.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    9.20 +*/
    9.21 +#ifndef EVENT_H_
    9.22 +#define EVENT_H_
    9.23 +
    9.24 +#include "vec.h"
    9.25 +
    9.26 +namespace goatkit {
    9.27 +
    9.28 +enum EventType {
    9.29 +	// primary events
    9.30 +	EV_MOUSE_BUTTON,
    9.31 +	EV_MOUSE_MOTION,
    9.32 +	EV_MOUSE_FOCUS,
    9.33 +	EV_KEY,
    9.34 +
    9.35 +	// derived events
    9.36 +	EV_CLICK,
    9.37 +	EV_DOUBLE_CLICK,
    9.38 +	EV_CHANGE,
    9.39 +
    9.40 +	NUM_EVENTS
    9.41 +};
    9.42 +
    9.43 +enum SpecialKeys {
    9.44 +	KEY_ESCAPE = 27,
    9.45 +	KEY_DELETE = 127,
    9.46 +
    9.47 +	KEY_F1 = 256, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6,
    9.48 +	KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12,
    9.49 +	KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN,
    9.50 +	KEY_HOME, KEY_END, KEY_PGUP, KEY_PGDOWN,
    9.51 +	KEY_INSERT
    9.52 +};
    9.53 +
    9.54 +struct ButtonEvent {
    9.55 +	Vec2 pos;
    9.56 +	int button;
    9.57 +	bool press;
    9.58 +};
    9.59 +
    9.60 +struct MotionEvent {
    9.61 +	Vec2 pos;
    9.62 +};
    9.63 +
    9.64 +struct FocusEvent {
    9.65 +	bool enter;
    9.66 +};
    9.67 +
    9.68 +struct KeyEvent {
    9.69 +	int key;
    9.70 +	bool press;
    9.71 +};
    9.72 +
    9.73 +struct Event {
    9.74 +	EventType type;
    9.75 +
    9.76 +	ButtonEvent button;
    9.77 +	MotionEvent motion;
    9.78 +	FocusEvent focus;
    9.79 +	KeyEvent key;
    9.80 +};
    9.81 +
    9.82 +const char *event_type_name(EventType type);
    9.83 +
    9.84 +}	// namespace goatkit
    9.85 +
    9.86 +#endif	// EVENT_H_
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/libs/goatkit/goatkit.h	Wed Sep 23 05:44:58 2015 +0300
    10.3 @@ -0,0 +1,31 @@
    10.4 +/*
    10.5 +GoatKit - a themable/animated widget toolkit for games
    10.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    10.7 +
    10.8 +This program is free software: you can redistribute it and/or modify
    10.9 +it under the terms of the GNU Lesser General Public License as published by
   10.10 +the Free Software Foundation, either version 3 of the License, or
   10.11 +(at your option) any later version.
   10.12 +
   10.13 +This program is distributed in the hope that it will be useful,
   10.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.16 +GNU Lesser General Public License for more details.
   10.17 +
   10.18 +You should have received a copy of the GNU Lesser General Public License
   10.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   10.20 +*/
   10.21 +#ifndef GOATKIT_H_
   10.22 +#define GOATKIT_H_
   10.23 +
   10.24 +#include "screen.h"
   10.25 +#include "widget.h"
   10.26 +#include "button.h"
   10.27 +#include "checkbox.h"
   10.28 +#include "label.h"
   10.29 +#include "textbox.h"
   10.30 +#include "slider.h"
   10.31 +#include "event.h"
   10.32 +#include "theme.h"
   10.33 +
   10.34 +#endif	// GOATKIT_H_
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/libs/goatkit/label.cc	Wed Sep 23 05:44:58 2015 +0300
    11.3 @@ -0,0 +1,40 @@
    11.4 +/*
    11.5 +GoatKit - a themable/animated widget toolkit for games
    11.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    11.7 +
    11.8 +This program is free software: you can redistribute it and/or modify
    11.9 +it under the terms of the GNU Lesser General Public License as published by
   11.10 +the Free Software Foundation, either version 3 of the License, or
   11.11 +(at your option) any later version.
   11.12 +
   11.13 +This program is distributed in the hope that it will be useful,
   11.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.16 +GNU Lesser General Public License for more details.
   11.17 +
   11.18 +You should have received a copy of the GNU Lesser General Public License
   11.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   11.20 +*/
   11.21 +#include "label.h"
   11.22 +
   11.23 +namespace goatkit {
   11.24 +
   11.25 +struct LabelImpl {
   11.26 +};
   11.27 +
   11.28 +Label::Label()
   11.29 +{
   11.30 +	label = new LabelImpl;
   11.31 +}
   11.32 +
   11.33 +Label::~Label()
   11.34 +{
   11.35 +	delete label;
   11.36 +}
   11.37 +
   11.38 +const char *Label::get_type_name() const
   11.39 +{
   11.40 +	return "label";
   11.41 +}
   11.42 +
   11.43 +}	// namespace goatkit
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/libs/goatkit/label.h	Wed Sep 23 05:44:58 2015 +0300
    12.3 @@ -0,0 +1,40 @@
    12.4 +/*
    12.5 +GoatKit - a themable/animated widget toolkit for games
    12.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    12.7 +
    12.8 +This program is free software: you can redistribute it and/or modify
    12.9 +it under the terms of the GNU Lesser General Public License as published by
   12.10 +the Free Software Foundation, either version 3 of the License, or
   12.11 +(at your option) any later version.
   12.12 +
   12.13 +This program is distributed in the hope that it will be useful,
   12.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.16 +GNU Lesser General Public License for more details.
   12.17 +
   12.18 +You should have received a copy of the GNU Lesser General Public License
   12.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   12.20 +*/
   12.21 +#ifndef GOATKIT_LABEL_H_
   12.22 +#define GOATKIT_LABEL_H_
   12.23 +
   12.24 +#include "widget.h"
   12.25 +
   12.26 +namespace goatkit {
   12.27 +
   12.28 +struct LabelImpl;
   12.29 +
   12.30 +class Label : public Widget {
   12.31 +private:
   12.32 +	LabelImpl *label;
   12.33 +
   12.34 +public:
   12.35 +	Label();
   12.36 +	virtual ~Label();
   12.37 +
   12.38 +	virtual const char *get_type_name() const;
   12.39 +};
   12.40 +
   12.41 +}	// namespace goatkit
   12.42 +
   12.43 +#endif	// GOATKIT_LABEL_H_
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/libs/goatkit/screen.cc	Wed Sep 23 05:44:58 2015 +0300
    13.3 @@ -0,0 +1,299 @@
    13.4 +/*
    13.5 +GoatKit - a themable/animated widget toolkit for games
    13.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    13.7 +
    13.8 +This program is free software: you can redistribute it and/or modify
    13.9 +it under the terms of the GNU Lesser General Public License as published by
   13.10 +the Free Software Foundation, either version 3 of the License, or
   13.11 +(at your option) any later version.
   13.12 +
   13.13 +This program is distributed in the hope that it will be useful,
   13.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.16 +GNU Lesser General Public License for more details.
   13.17 +
   13.18 +You should have received a copy of the GNU Lesser General Public License
   13.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   13.20 +*/
   13.21 +#include <stdio.h>
   13.22 +#include <stdlib.h>
   13.23 +#include <string.h>
   13.24 +#include <vector>
   13.25 +#include "screen.h"
   13.26 +#include "widget.h"
   13.27 +
   13.28 +#define MAX_BUTTONS		16
   13.29 +
   13.30 +namespace goatkit {
   13.31 +
   13.32 +struct ScreenImpl {
   13.33 +	bool visible;
   13.34 +	std::vector<Widget*> widgets;
   13.35 +	BBox box;
   13.36 +
   13.37 +	Widget *inp_focused, *over, *pressed[MAX_BUTTONS];
   13.38 +	Widget *mgrab;
   13.39 +};
   13.40 +
   13.41 +static Vec2 world_to_scr(const ScreenImpl *scr, const Vec2 &v);
   13.42 +//static Vec2 scr_to_world(const ScreenImpl *scr, const Vec2 &v)
   13.43 +
   13.44 +Screen::Screen()
   13.45 +{
   13.46 +	scr = new ScreenImpl;
   13.47 +
   13.48 +	scr->box.bmin = Vec2(0, 0);
   13.49 +	scr->box.bmax = Vec2(1, 1);
   13.50 +
   13.51 +	scr->inp_focused = scr->over = 0;
   13.52 +	for(int i=0; i<MAX_BUTTONS; i++) {
   13.53 +		scr->pressed[i] = 0;
   13.54 +	}
   13.55 +
   13.56 +	scr->visible = true;
   13.57 +	scr->mgrab = 0;
   13.58 +}
   13.59 +
   13.60 +Screen::~Screen()
   13.61 +{
   13.62 +	delete scr;
   13.63 +}
   13.64 +
   13.65 +void Screen::set_position(float x, float y)
   13.66 +{
   13.67 +	set_position(Vec2(x, y));
   13.68 +}
   13.69 +
   13.70 +void Screen::set_position(const Vec2 &pos)
   13.71 +{
   13.72 +	Vec2 sz = get_size();
   13.73 +
   13.74 +	scr->box.bmin = pos;
   13.75 +	scr->box.bmax.x = pos.x + sz.x;
   13.76 +	scr->box.bmax.y = pos.y + sz.y;
   13.77 +}
   13.78 +
   13.79 +const Vec2 &Screen::get_position() const
   13.80 +{
   13.81 +	return scr->box.bmin;
   13.82 +}
   13.83 +
   13.84 +void Screen::set_size(float x, float y)
   13.85 +{
   13.86 +	set_size(Vec2(x, y));
   13.87 +}
   13.88 +
   13.89 +void Screen::set_size(const Vec2 &sz)
   13.90 +{
   13.91 +	scr->box.bmax.x = scr->box.bmin.x + sz.x;
   13.92 +	scr->box.bmax.y = scr->box.bmin.y + sz.y;
   13.93 +}
   13.94 +
   13.95 +const Vec2 Screen::get_size() const
   13.96 +{
   13.97 +	return Vec2(scr->box.bmax.x - scr->box.bmin.x,
   13.98 +			scr->box.bmax.y - scr->box.bmin.y);
   13.99 +}
  13.100 +
  13.101 +const BBox &Screen::get_box() const
  13.102 +{
  13.103 +	return scr->box;
  13.104 +}
  13.105 +
  13.106 +void Screen::add_widget(Widget *w)
  13.107 +{
  13.108 +	scr->widgets.push_back(w);
  13.109 +	if(scr->visible) {
  13.110 +		w->show();
  13.111 +	} else {
  13.112 +		w->hide();
  13.113 +	}
  13.114 +
  13.115 +	w->set_screen(this);
  13.116 +}
  13.117 +
  13.118 +int Screen::get_widget_count() const
  13.119 +{
  13.120 +	return (int)scr->widgets.size();
  13.121 +}
  13.122 +
  13.123 +Widget *Screen::get_widget(int idx) const
  13.124 +{
  13.125 +	if(idx < 0 || idx >= (int)scr->widgets.size()) {
  13.126 +		return 0;
  13.127 +	}
  13.128 +	return scr->widgets[idx];
  13.129 +}
  13.130 +
  13.131 +Widget *Screen::get_widget(const char *name) const
  13.132 +{
  13.133 +	for(size_t i=0; i<scr->widgets.size(); i++) {
  13.134 +		if(strcmp(scr->widgets[i]->get_name(), name) == 0) {
  13.135 +			return scr->widgets[i];
  13.136 +		}
  13.137 +	}
  13.138 +	return 0;
  13.139 +}
  13.140 +
  13.141 +void Screen::show()
  13.142 +{
  13.143 +	scr->visible = true;
  13.144 +
  13.145 +	for(size_t i=0; i<scr->widgets.size(); i++) {
  13.146 +		scr->widgets[i]->show();
  13.147 +	}
  13.148 +}
  13.149 +
  13.150 +void Screen::hide()
  13.151 +{
  13.152 +	scr->visible = false;
  13.153 +
  13.154 +	for(size_t i=0; i<scr->widgets.size(); i++) {
  13.155 +		scr->widgets[i]->hide();
  13.156 +	}
  13.157 +}
  13.158 +
  13.159 +bool Screen::is_visible() const
  13.160 +{
  13.161 +	return scr->visible;
  13.162 +}
  13.163 +
  13.164 +bool Screen::grab_mouse(Widget *w)
  13.165 +{
  13.166 +	if(!scr->mgrab || !w) {
  13.167 +		scr->mgrab = w;
  13.168 +		return true;
  13.169 +	}
  13.170 +	return false;
  13.171 +}
  13.172 +
  13.173 +void Screen::draw() const
  13.174 +{
  13.175 +	for(size_t i=0; i<scr->widgets.size(); i++) {
  13.176 +		scr->widgets[i]->draw();
  13.177 +	}
  13.178 +}
  13.179 +
  13.180 +static Widget *find_widget_at(const ScreenImpl *scr, const Vec2 &pt)
  13.181 +{
  13.182 +	for(size_t i=0; i<scr->widgets.size(); i++) {
  13.183 +		Widget *w = scr->widgets[i];
  13.184 +
  13.185 +		if(w->hit_test(pt)) {
  13.186 +			return w;
  13.187 +		}
  13.188 +	}
  13.189 +	return 0;
  13.190 +}
  13.191 +
  13.192 +void Screen::sysev_keyboard(int key, bool press)
  13.193 +{
  13.194 +	Event ev;
  13.195 +
  13.196 +	if(scr->inp_focused) {
  13.197 +		ev.type = EV_KEY;
  13.198 +		ev.key.key = key;
  13.199 +		ev.key.press = press;
  13.200 +		scr->inp_focused->handle_event(ev);
  13.201 +	}
  13.202 +}
  13.203 +
  13.204 +void Screen::sysev_mouse_button(int bn, bool press, float x, float y)
  13.205 +{
  13.206 +	Event ev;
  13.207 +	Vec2 pt = world_to_scr(scr, Vec2(x, y));
  13.208 +	Widget *new_over = scr->mgrab ? scr->mgrab : find_widget_at(scr, pt);
  13.209 +
  13.210 +	ev.type = EV_MOUSE_BUTTON;
  13.211 +	ev.button.button = bn;
  13.212 +	ev.button.pos = pt;
  13.213 +	ev.button.press = press;
  13.214 +
  13.215 +	if(press) {
  13.216 +		if(bn == 0) {
  13.217 +			// left click gives input focus
  13.218 +			// TODO: add input focus event in widget
  13.219 +			if(new_over && new_over != scr->inp_focused && new_over->can_focus()) {
  13.220 +				printf("input focus %p -> %p\n", (void*)scr->inp_focused, (void*)new_over);
  13.221 +				new_over->focusin();
  13.222 +
  13.223 +				if(scr->inp_focused) {
  13.224 +					scr->inp_focused->focusout();
  13.225 +				}
  13.226 +				scr->inp_focused = new_over;
  13.227 +			}
  13.228 +		}
  13.229 +
  13.230 +		scr->pressed[bn] = new_over;
  13.231 +		scr->over = new_over;
  13.232 +
  13.233 +		if(new_over) {
  13.234 +			new_over->handle_event(ev);
  13.235 +		}
  13.236 +
  13.237 +	} else {
  13.238 +		// send the mouse release event to the widget that got the matching press
  13.239 +		if(scr->pressed[bn]) {
  13.240 +			scr->pressed[bn]->handle_event(ev);
  13.241 +			scr->pressed[bn] = 0;
  13.242 +		}
  13.243 +	}
  13.244 +
  13.245 +	// if we're not over the same widget any more send the leave/enter events
  13.246 +	// TODO also add drag/drop events
  13.247 +	if(scr->over != new_over) {
  13.248 +		ev.type = EV_MOUSE_FOCUS;
  13.249 +		if(scr->over) {
  13.250 +			ev.focus.enter = false;
  13.251 +			scr->over->handle_event(ev);
  13.252 +		}
  13.253 +		if(new_over) {
  13.254 +			ev.focus.enter = true;
  13.255 +			new_over->handle_event(ev);
  13.256 +		}
  13.257 +		scr->over = new_over;
  13.258 +	}
  13.259 +}
  13.260 +
  13.261 +void Screen::sysev_mouse_motion(float x, float y)
  13.262 +{
  13.263 +	Event ev;
  13.264 +	Vec2 pt = world_to_scr(scr, Vec2(x, y));
  13.265 +	Widget *new_over = scr->mgrab ? scr->mgrab : find_widget_at(scr, pt);
  13.266 +
  13.267 +	// if we're not over the same widget any more send the leave/enter events
  13.268 +	if(scr->over != new_over) {
  13.269 +		ev.type = EV_MOUSE_FOCUS;
  13.270 +		if(scr->over) {
  13.271 +			ev.focus.enter = false;
  13.272 +			scr->over->handle_event(ev);
  13.273 +		}
  13.274 +		if(new_over) {
  13.275 +			ev.focus.enter = true;
  13.276 +			new_over->handle_event(ev);
  13.277 +		}
  13.278 +		scr->over = new_over;
  13.279 +	}
  13.280 +
  13.281 +	if(new_over) {
  13.282 +		// send motion event
  13.283 +		ev.type = EV_MOUSE_MOTION;
  13.284 +		ev.motion.pos = pt;
  13.285 +		new_over->handle_event(ev);
  13.286 +	}
  13.287 +}
  13.288 +
  13.289 +static Vec2 world_to_scr(const ScreenImpl *scr, const Vec2 &v)
  13.290 +{
  13.291 +	return Vec2(v.x - scr->box.bmin.x, v.y - scr->box.bmin.y);
  13.292 +}
  13.293 +
  13.294 +/*
  13.295 +static Vec2 scr_to_world(const ScreenImpl *scr, const Vec2 &v)
  13.296 +{
  13.297 +	return Vec2(v.x + scr->box.bmin.x, v.y + scr->box.bmin.y);
  13.298 +}
  13.299 +*/
  13.300 +
  13.301 +
  13.302 +} // namespace goatkit
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/libs/goatkit/screen.h	Wed Sep 23 05:44:58 2015 +0300
    14.3 @@ -0,0 +1,66 @@
    14.4 +/*
    14.5 +GoatKit - a themable/animated widget toolkit for games
    14.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    14.7 +
    14.8 +This program is free software: you can redistribute it and/or modify
    14.9 +it under the terms of the GNU Lesser General Public License as published by
   14.10 +the Free Software Foundation, either version 3 of the License, or
   14.11 +(at your option) any later version.
   14.12 +
   14.13 +This program is distributed in the hope that it will be useful,
   14.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.16 +GNU Lesser General Public License for more details.
   14.17 +
   14.18 +You should have received a copy of the GNU Lesser General Public License
   14.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   14.20 +*/
   14.21 +#ifndef SCREEN_H_
   14.22 +#define SCREEN_H_
   14.23 +
   14.24 +#include "vec.h"
   14.25 +#include "widget.h"
   14.26 +
   14.27 +namespace goatkit {
   14.28 +
   14.29 +class ScreenImpl;
   14.30 +
   14.31 +class Screen {
   14.32 +private:
   14.33 +	ScreenImpl *scr;
   14.34 +
   14.35 +public:
   14.36 +	Screen();
   14.37 +	~Screen();
   14.38 +
   14.39 +	void set_position(float x, float y);
   14.40 +	void set_position(const Vec2 &pos);
   14.41 +	const Vec2 &get_position() const;
   14.42 +	void set_size(float x, float y);
   14.43 +	void set_size(const Vec2 &sz);
   14.44 +	const Vec2 get_size() const;
   14.45 +	const BBox &get_box() const;
   14.46 +
   14.47 +	void add_widget(Widget *w);
   14.48 +	int get_widget_count() const;
   14.49 +	Widget *get_widget(int idx) const;
   14.50 +	Widget *get_widget(const char *name) const;
   14.51 +
   14.52 +	void show();
   14.53 +	void hide();
   14.54 +	bool is_visible() const;
   14.55 +
   14.56 +	bool grab_mouse(Widget *w);
   14.57 +
   14.58 +	void draw() const;
   14.59 +
   14.60 +	// window system events used to generate widget events (see event.h)
   14.61 +	void sysev_keyboard(int key, bool press);
   14.62 +	// mouse position as reported by the window system. might fall outside
   14.63 +	void sysev_mouse_button(int bn, bool press, float x, float y);
   14.64 +	void sysev_mouse_motion(float x, float y);
   14.65 +};
   14.66 +
   14.67 +}	// namespace goatkit
   14.68 +
   14.69 +#endif /* SCREEN_H_ */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/libs/goatkit/slider.cc	Wed Sep 23 05:44:58 2015 +0300
    15.3 @@ -0,0 +1,196 @@
    15.4 +/*
    15.5 +GoatKit - a themable/animated widget toolkit for games
    15.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    15.7 +
    15.8 +This program is free software: you can redistribute it and/or modify
    15.9 +it under the terms of the GNU Lesser General Public License as published by
   15.10 +the Free Software Foundation, either version 3 of the License, or
   15.11 +(at your option) any later version.
   15.12 +
   15.13 +This program is distributed in the hope that it will be useful,
   15.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.16 +GNU Lesser General Public License for more details.
   15.17 +
   15.18 +You should have received a copy of the GNU Lesser General Public License
   15.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   15.20 +*/
   15.21 +#include <stdio.h>
   15.22 +#include <math.h>
   15.23 +#include "slider.h"
   15.24 +#include "screen.h"
   15.25 +
   15.26 +namespace goatkit {
   15.27 +
   15.28 +struct SliderImpl {
   15.29 +	float value, prev_value;
   15.30 +	float range_min, range_max;
   15.31 +	float padding;
   15.32 +	float step;
   15.33 +	bool dragging;
   15.34 +	bool cont_change;
   15.35 +};
   15.36 +
   15.37 +static float remap(float val, float inlow, float inhigh, float outlow, float outhigh);
   15.38 +
   15.39 +Slider::Slider()
   15.40 +{
   15.41 +	slider = new SliderImpl;
   15.42 +	slider->value = slider->prev_value = 0.0f;
   15.43 +	slider->dragging = false;
   15.44 +	slider->cont_change = true;
   15.45 +
   15.46 +	slider->range_min = 0.0;
   15.47 +	slider->range_max = 1.0;
   15.48 +	slider->step = 0.0;
   15.49 +
   15.50 +	slider->padding = -1.0;
   15.51 +}
   15.52 +
   15.53 +Slider::~Slider()
   15.54 +{
   15.55 +	delete slider;
   15.56 +}
   15.57 +
   15.58 +const char *Slider::get_type_name() const
   15.59 +{
   15.60 +	return "slider";
   15.61 +}
   15.62 +
   15.63 +void Slider::set_value(float val)
   15.64 +{
   15.65 +	slider->value = remap(val, slider->range_min, slider->range_max, 0, 1);
   15.66 +}
   15.67 +
   15.68 +float Slider::get_value() const
   15.69 +{
   15.70 +	return remap(slider->value, 0, 1, slider->range_min, slider->range_max);
   15.71 +}
   15.72 +
   15.73 +void Slider::set_value_norm(float val)
   15.74 +{
   15.75 +	slider->value = val < 0.0 ? 0.0 : (val > 1.0 ? 1.0 : val);
   15.76 +}
   15.77 +
   15.78 +float Slider::get_value_norm() const
   15.79 +{
   15.80 +	return slider->value;
   15.81 +}
   15.82 +
   15.83 +void Slider::set_padding(float pad)
   15.84 +{
   15.85 +	slider->padding = pad;
   15.86 +}
   15.87 +
   15.88 +float Slider::get_padding() const
   15.89 +{
   15.90 +	if(slider->padding < 0.0) {
   15.91 +		BBox box = get_box();
   15.92 +		return (box.bmax.y - box.bmin.y) * 0.25;
   15.93 +	}
   15.94 +	return slider->padding;
   15.95 +}
   15.96 +
   15.97 +void Slider::set_continuous_change(bool cont)
   15.98 +{
   15.99 +	slider->cont_change = cont;
  15.100 +}
  15.101 +
  15.102 +bool Slider::get_continuous_change() const
  15.103 +{
  15.104 +	return slider->cont_change;
  15.105 +}
  15.106 +
  15.107 +void Slider::set_range(float min, float max)
  15.108 +{
  15.109 +	slider->range_min = min;
  15.110 +	slider->range_max = max;
  15.111 +}
  15.112 +
  15.113 +float Slider::get_range_min() const
  15.114 +{
  15.115 +	return slider->range_min;
  15.116 +}
  15.117 +
  15.118 +float Slider::get_range_max() const
  15.119 +{
  15.120 +	return slider->range_max;
  15.121 +}
  15.122 +
  15.123 +void Slider::set_step(float step)
  15.124 +{
  15.125 +	slider->step = step;
  15.126 +}
  15.127 +
  15.128 +float Slider::get_step() const
  15.129 +{
  15.130 +	return slider->step;
  15.131 +}
  15.132 +
  15.133 +void Slider::on_mouse_button(const ButtonEvent &ev)
  15.134 +{
  15.135 +	if(ev.button == 0) {
  15.136 +		Screen *scr = get_screen();
  15.137 +
  15.138 +		slider->dragging = ev.press;
  15.139 +		if(ev.press) {
  15.140 +			if(scr) scr->grab_mouse(this);
  15.141 +		} else {
  15.142 +			if(scr) scr->grab_mouse(0);
  15.143 +
  15.144 +			// on release, if the value has changed send the appropriate event
  15.145 +			if(slider->prev_value != slider->value) {
  15.146 +				Event ev;
  15.147 +				ev.type = EV_CHANGE;
  15.148 +				handle_event(ev);
  15.149 +				slider->prev_value = slider->value;
  15.150 +			}
  15.151 +		}
  15.152 +	}
  15.153 +}
  15.154 +
  15.155 +#define ROUND(x)	floor((x) + 0.5)
  15.156 +
  15.157 +void Slider::on_mouse_motion(const MotionEvent &ev)
  15.158 +{
  15.159 +	if(!slider->dragging) {
  15.160 +		return;
  15.161 +	}
  15.162 +
  15.163 +	BBox box = get_box();
  15.164 +
  15.165 +	float padding = get_padding();
  15.166 +	float start = box.bmin.x + padding;
  15.167 +	float end = box.bmax.x - padding;
  15.168 +	float new_val = (ev.pos.x - start) / (end - start);
  15.169 +
  15.170 +	// if we have a non-zero step, snap to the nearest value
  15.171 +	if(slider->step > 0.0) {
  15.172 +		float range = slider->range_max - slider->range_min;
  15.173 +		float st = slider->step / range;
  15.174 +
  15.175 +		new_val = ROUND(new_val / st) * st;
  15.176 +	}
  15.177 +
  15.178 +	if(new_val < 0.0) new_val = 0.0;
  15.179 +	if(new_val > 1.0) new_val = 1.0;
  15.180 +
  15.181 +	if(new_val != slider->value) {
  15.182 +		slider->value = new_val;
  15.183 +		if(slider->cont_change) {
  15.184 +			Event cev;
  15.185 +			cev.type = EV_CHANGE;
  15.186 +			handle_event(cev);
  15.187 +		}
  15.188 +	}
  15.189 +}
  15.190 +
  15.191 +static float remap(float val, float inlow, float inhigh, float outlow, float outhigh)
  15.192 +{
  15.193 +	float t = (val - inlow) / (inhigh - inlow);
  15.194 +	if(t < 0.0) t = 0.0;
  15.195 +	if(t > 1.0) t = 1.0;
  15.196 +	return t * (outhigh - outlow) + outlow;
  15.197 +}
  15.198 +
  15.199 +}	// namespace goatkit
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/libs/goatkit/slider.h	Wed Sep 23 05:44:58 2015 +0300
    16.3 @@ -0,0 +1,62 @@
    16.4 +/*
    16.5 +GoatKit - a themable/animated widget toolkit for games
    16.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    16.7 +
    16.8 +This program is free software: you can redistribute it and/or modify
    16.9 +it under the terms of the GNU Lesser General Public License as published by
   16.10 +the Free Software Foundation, either version 3 of the License, or
   16.11 +(at your option) any later version.
   16.12 +
   16.13 +This program is distributed in the hope that it will be useful,
   16.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.16 +GNU Lesser General Public License for more details.
   16.17 +
   16.18 +You should have received a copy of the GNU Lesser General Public License
   16.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   16.20 +*/
   16.21 +#ifndef SLIDER_H_
   16.22 +#define SLIDER_H_
   16.23 +
   16.24 +#include "widget.h"
   16.25 +
   16.26 +namespace goatkit {
   16.27 +
   16.28 +struct SliderImpl;
   16.29 +
   16.30 +class Slider : public Widget {
   16.31 +private:
   16.32 +	SliderImpl *slider;
   16.33 +
   16.34 +public:
   16.35 +	Slider();
   16.36 +	virtual ~Slider();
   16.37 +
   16.38 +	virtual const char *get_type_name() const;
   16.39 +
   16.40 +	virtual void set_value(float val);
   16.41 +	virtual float get_value() const;
   16.42 +
   16.43 +	virtual void set_value_norm(float val);
   16.44 +	virtual float get_value_norm() const;
   16.45 +
   16.46 +	virtual void set_padding(float pad);
   16.47 +	virtual float get_padding() const;
   16.48 +
   16.49 +	virtual void set_continuous_change(bool cont);
   16.50 +	virtual bool get_continuous_change() const;
   16.51 +
   16.52 +	virtual void set_range(float min, float max);
   16.53 +	virtual float get_range_min() const;
   16.54 +	virtual float get_range_max() const;
   16.55 +
   16.56 +	virtual void set_step(float step);
   16.57 +	virtual float get_step() const;
   16.58 +
   16.59 +	virtual void on_mouse_button(const ButtonEvent &ev);
   16.60 +	virtual void on_mouse_motion(const MotionEvent &ev);
   16.61 +};
   16.62 +
   16.63 +}	// namespace goatkit
   16.64 +
   16.65 +#endif	// SLIDER_H_
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/libs/goatkit/textbox.cc	Wed Sep 23 05:44:58 2015 +0300
    17.3 @@ -0,0 +1,168 @@
    17.4 +/*
    17.5 +GoatKit - a themable/animated widget toolkit for games
    17.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    17.7 +
    17.8 +This program is free software: you can redistribute it and/or modify
    17.9 +it under the terms of the GNU Lesser General Public License as published by
   17.10 +the Free Software Foundation, either version 3 of the License, or
   17.11 +(at your option) any later version.
   17.12 +
   17.13 +This program is distributed in the hope that it will be useful,
   17.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.16 +GNU Lesser General Public License for more details.
   17.17 +
   17.18 +You should have received a copy of the GNU Lesser General Public License
   17.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17.20 +*/
   17.21 +#include <ctype.h>
   17.22 +#include <limits.h>
   17.23 +#include <string>
   17.24 +#include "textbox.h"
   17.25 +
   17.26 +namespace goatkit {
   17.27 +
   17.28 +struct TextBoxImpl {
   17.29 +	std::string text;
   17.30 +	int cursor;
   17.31 +};
   17.32 +
   17.33 +TextBox::TextBox()
   17.34 +{
   17.35 +	tbox = new TextBoxImpl;
   17.36 +	tbox->cursor = 0;
   17.37 +}
   17.38 +
   17.39 +TextBox::~TextBox()
   17.40 +{
   17.41 +	delete tbox;
   17.42 +}
   17.43 +
   17.44 +const char *TextBox::get_type_name() const
   17.45 +{
   17.46 +	return "textbox";
   17.47 +}
   17.48 +
   17.49 +bool TextBox::can_focus() const
   17.50 +{
   17.51 +	return true;
   17.52 +}
   17.53 +
   17.54 +void TextBox::clear()
   17.55 +{
   17.56 +	tbox->text.clear();
   17.57 +}
   17.58 +
   17.59 +void TextBox::set_text(const char *t)
   17.60 +{
   17.61 +	tbox->text = std::string(t);
   17.62 +}
   17.63 +
   17.64 +const char *TextBox::get_text() const
   17.65 +{
   17.66 +	return tbox->text.c_str();
   17.67 +}
   17.68 +
   17.69 +int TextBox::set_cursor(int idx)
   17.70 +{
   17.71 +	int len = tbox->text.size();
   17.72 +
   17.73 +	if(idx < 0) {
   17.74 +		tbox->cursor = 0;
   17.75 +	} else if(idx > len) {
   17.76 +		tbox->cursor = len;
   17.77 +	} else {
   17.78 +		tbox->cursor = idx;
   17.79 +	}
   17.80 +	return tbox->cursor;
   17.81 +}
   17.82 +
   17.83 +int TextBox::get_cursor() const
   17.84 +{
   17.85 +	return tbox->cursor;
   17.86 +}
   17.87 +
   17.88 +int TextBox::cursor_begin()
   17.89 +{
   17.90 +	return tbox->cursor = 0;
   17.91 +}
   17.92 +
   17.93 +int TextBox::cursor_end()
   17.94 +{
   17.95 +	return set_cursor(INT_MAX);
   17.96 +}
   17.97 +
   17.98 +int TextBox::cursor_prev()
   17.99 +{
  17.100 +	return set_cursor(tbox->cursor - 1);
  17.101 +}
  17.102 +
  17.103 +int TextBox::cursor_next()
  17.104 +{
  17.105 +	return set_cursor(tbox->cursor + 1);
  17.106 +}
  17.107 +
  17.108 +void TextBox::insert(char c)
  17.109 +{
  17.110 +	int len = tbox->text.size();
  17.111 +	if(tbox->cursor >= len) {
  17.112 +		tbox->text.push_back(c);
  17.113 +		tbox->cursor++;
  17.114 +	} else {
  17.115 +		tbox->text.insert(tbox->cursor++, 1, c);
  17.116 +	}
  17.117 +}
  17.118 +
  17.119 +void TextBox::on_key(const KeyEvent &ev)
  17.120 +{
  17.121 +	if(!ev.press) return;	// ignore key release events
  17.122 +
  17.123 +	switch(ev.key) {
  17.124 +	case KEY_LEFT:
  17.125 +		cursor_prev();
  17.126 +		break;
  17.127 +
  17.128 +	case KEY_RIGHT:
  17.129 +		cursor_next();
  17.130 +		break;
  17.131 +
  17.132 +	case KEY_HOME:
  17.133 +		cursor_begin();
  17.134 +		break;
  17.135 +
  17.136 +	case KEY_END:
  17.137 +		cursor_end();
  17.138 +		break;
  17.139 +
  17.140 +	case KEY_DELETE:
  17.141 +		tbox->text.erase(tbox->cursor, 1);
  17.142 +		break;
  17.143 +
  17.144 +	case '\b':
  17.145 +		if(tbox->cursor > 0) {
  17.146 +			tbox->text.erase(--tbox->cursor, 1);
  17.147 +		}
  17.148 +		break;
  17.149 +
  17.150 +	case '\n':
  17.151 +	case '\t':
  17.152 +		{
  17.153 +			Event ev;
  17.154 +			ev.type = EV_CHANGE;
  17.155 +			handle_event(ev);
  17.156 +		}
  17.157 +		break;
  17.158 +
  17.159 +	default:
  17.160 +		if(isprint(ev.key)) {
  17.161 +			insert(ev.key);
  17.162 +		}
  17.163 +	}
  17.164 +}
  17.165 +
  17.166 +void TextBox::on_click()
  17.167 +{
  17.168 +	// TODO place cursor
  17.169 +}
  17.170 +
  17.171 +}	// namespace goatkit
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/libs/goatkit/textbox.h	Wed Sep 23 05:44:58 2015 +0300
    18.3 @@ -0,0 +1,59 @@
    18.4 +/*
    18.5 +GoatKit - a themable/animated widget toolkit for games
    18.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    18.7 +
    18.8 +This program is free software: you can redistribute it and/or modify
    18.9 +it under the terms of the GNU Lesser General Public License as published by
   18.10 +the Free Software Foundation, either version 3 of the License, or
   18.11 +(at your option) any later version.
   18.12 +
   18.13 +This program is distributed in the hope that it will be useful,
   18.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.16 +GNU Lesser General Public License for more details.
   18.17 +
   18.18 +You should have received a copy of the GNU Lesser General Public License
   18.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   18.20 +*/
   18.21 +#ifndef TEXTBOX_H_
   18.22 +#define TEXTBOX_H_
   18.23 +
   18.24 +#include "widget.h"
   18.25 +
   18.26 +namespace goatkit {
   18.27 +
   18.28 +struct TextBoxImpl;
   18.29 +
   18.30 +class TextBox : public Widget {
   18.31 +private:
   18.32 +	TextBoxImpl *tbox;
   18.33 +
   18.34 +public:
   18.35 +	TextBox();
   18.36 +	virtual ~TextBox();
   18.37 +
   18.38 +	virtual const char *get_type_name() const;
   18.39 +	virtual bool can_focus() const;
   18.40 +
   18.41 +	virtual void clear();
   18.42 +
   18.43 +	virtual void set_text(const char *t);
   18.44 +	virtual const char *get_text() const;
   18.45 +
   18.46 +	virtual int set_cursor(int idx);
   18.47 +	virtual int get_cursor() const;
   18.48 +
   18.49 +	virtual int cursor_begin();
   18.50 +	virtual int cursor_end();
   18.51 +	virtual int cursor_prev();
   18.52 +	virtual int cursor_next();
   18.53 +
   18.54 +	virtual void insert(char c);
   18.55 +
   18.56 +	virtual void on_key(const KeyEvent &ev);
   18.57 +	virtual void on_click();
   18.58 +};
   18.59 +
   18.60 +}	// namespace goatkit
   18.61 +
   18.62 +#endif	// TEXTBOX_H_
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/libs/goatkit/theme.cc	Wed Sep 23 05:44:58 2015 +0300
    19.3 @@ -0,0 +1,253 @@
    19.4 +/*
    19.5 +GoatKit - a themable/animated widget toolkit for games
    19.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    19.7 +
    19.8 +This program is free software: you can redistribute it and/or modify
    19.9 +it under the terms of the GNU Lesser General Public License as published by
   19.10 +the Free Software Foundation, either version 3 of the License, or
   19.11 +(at your option) any later version.
   19.12 +
   19.13 +This program is distributed in the hope that it will be useful,
   19.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.16 +GNU Lesser General Public License for more details.
   19.17 +
   19.18 +You should have received a copy of the GNU Lesser General Public License
   19.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   19.20 +*/
   19.21 +#include "config.h"
   19.22 +#include <stdio.h>
   19.23 +#include <vector>
   19.24 +#include <string>
   19.25 +#include <map>
   19.26 +#include <algorithm>
   19.27 +#include "theme.h"
   19.28 +#include "widget.h"
   19.29 +
   19.30 +#ifdef WIN32
   19.31 +#include <windows.h>
   19.32 +
   19.33 +static void *dlopen(const char *name, int flags);
   19.34 +static void dlclose(void *so);
   19.35 +static void *dlsym(void *so, const char *symbol);
   19.36 +#else
   19.37 +#include <unistd.h>
   19.38 +#include <dlfcn.h>
   19.39 +#endif
   19.40 +
   19.41 +#ifdef HAVE_OPENGL_H
   19.42 +#include "opengl.h"
   19.43 +
   19.44 +#else
   19.45 +
   19.46 +#ifdef __APPLE__
   19.47 +#include <OpenGL/gl.h>
   19.48 +#else
   19.49 +#include <GL/gl.h>
   19.50 +#endif
   19.51 +
   19.52 +#endif	/* HAVE_OPENGL_H_ */
   19.53 +
   19.54 +#ifndef PREFIX
   19.55 +#define PREFIX	"/usr/local"
   19.56 +#endif
   19.57 +
   19.58 +namespace goatkit {
   19.59 +
   19.60 +struct ThemeImpl {
   19.61 +	void *so;
   19.62 +	WidgetDrawFunc (*lookup_theme_draw_func)(const char*);
   19.63 +	mutable std::map<std::string, WidgetDrawFunc> func_cache;
   19.64 +};
   19.65 +
   19.66 +Theme *theme;
   19.67 +static std::vector<std::string> search_paths;
   19.68 +static const char *fallback_paths[] = {
   19.69 +	PREFIX "/share/goatkit",
   19.70 +	0
   19.71 +};
   19.72 +
   19.73 +void add_theme_path(const char *path)
   19.74 +{
   19.75 +	if(!path || !*path) return;
   19.76 +
   19.77 +	std::string s = path;
   19.78 +	int last = s.length() - 1;
   19.79 +	if(s[last] == '/' || s[last] == '\\') {
   19.80 +		s.erase(last);
   19.81 +	}
   19.82 +
   19.83 +	if(std::find(search_paths.begin(), search_paths.end(), s) != search_paths.end()) {
   19.84 +		return;
   19.85 +	}
   19.86 +
   19.87 +	search_paths.push_back(s);
   19.88 +}
   19.89 +
   19.90 +Theme::Theme()
   19.91 +{
   19.92 +	impl = new ThemeImpl;
   19.93 +	impl->so = 0;
   19.94 +	impl->lookup_theme_draw_func = 0;
   19.95 +}
   19.96 +
   19.97 +Theme::~Theme()
   19.98 +{
   19.99 +	unload();
  19.100 +	delete impl;
  19.101 +}
  19.102 +
  19.103 +typedef WidgetDrawFunc (*LookupFunc)(const char*);
  19.104 +
  19.105 +bool Theme::load(const char *name)
  19.106 +{
  19.107 +	unload();
  19.108 +
  19.109 +	std::string fname = std::string(name) + ".gtheme";
  19.110 +	if(!(impl->so = dlopen(fname.c_str(), RTLD_LAZY))) {
  19.111 +		for(size_t i=0; i<search_paths.size(); i++) {
  19.112 +			std::string path = search_paths[i] + "/" + fname;
  19.113 +
  19.114 +			if((impl->so = dlopen(path.c_str(), RTLD_LAZY))) {
  19.115 +				break;
  19.116 +			}
  19.117 +		}
  19.118 +
  19.119 +		// try the fallback paths
  19.120 +		if(!impl->so) {
  19.121 +			for(int i=0; fallback_paths[i]; i++) {
  19.122 +				std::string path = std::string(fallback_paths[i]) + "/" + fname;
  19.123 +
  19.124 +				if((impl->so = dlopen(path.c_str(), RTLD_LAZY))) {
  19.125 +					break;
  19.126 +				}
  19.127 +			}
  19.128 +		}
  19.129 +
  19.130 +		if(!impl->so) {
  19.131 +			fprintf(stderr, "%s: failed to load theme plugin: %s\n", __func__, name);
  19.132 +			return false;
  19.133 +		}
  19.134 +	}
  19.135 +
  19.136 +	// loaded the shared object, now get the lookup function
  19.137 +	impl->lookup_theme_draw_func = (LookupFunc)dlsym(impl->so, "get_widget_func");
  19.138 +	if(!impl->lookup_theme_draw_func) {
  19.139 +		fprintf(stderr, "%s: invalid theme plugin %s\n", __func__, name);
  19.140 +		unload();
  19.141 +		return false;
  19.142 +	}
  19.143 +
  19.144 +	return true;
  19.145 +}
  19.146 +
  19.147 +void Theme::unload()
  19.148 +{
  19.149 +	if(impl->so) {
  19.150 +		dlclose(impl->so);
  19.151 +		impl->so = 0;
  19.152 +	}
  19.153 +	impl->func_cache.clear();
  19.154 +}
  19.155 +
  19.156 +WidgetDrawFunc Theme::get_draw_func(const char *type) const
  19.157 +{
  19.158 +	std::map<std::string, WidgetDrawFunc>::const_iterator it = impl->func_cache.find(type);
  19.159 +	if(it == impl->func_cache.end()) {
  19.160 +		// don't have it cached, try to look it up
  19.161 +		WidgetDrawFunc func;
  19.162 +		if(impl->lookup_theme_draw_func && (func = impl->lookup_theme_draw_func(type))) {
  19.163 +			impl->func_cache[type] = func;
  19.164 +			return func;
  19.165 +		}
  19.166 +
  19.167 +		// can't look it up, return the default
  19.168 +		return default_draw_func;
  19.169 +	}
  19.170 +	return it->second;
  19.171 +}
  19.172 +
  19.173 +#define LERP(a, b, t)	((a) + ((b) - (a)) * t)
  19.174 +#define DEF_TEX_SZ	32
  19.175 +void default_draw_func(const Widget *w)
  19.176 +{
  19.177 +	static unsigned int tex;
  19.178 +
  19.179 +	if(!tex) {
  19.180 +		unsigned char *pixels = new unsigned char[DEF_TEX_SZ * DEF_TEX_SZ * 3];
  19.181 +		unsigned char *ptr = pixels;
  19.182 +		for(int i=0; i<DEF_TEX_SZ; i++) {
  19.183 +			for(int j=0; j<DEF_TEX_SZ; j++) {
  19.184 +				bool stripe = (((j + i) / 8) & 1) == 1;
  19.185 +				ptr[0] = ptr[1] = ptr[2] = stripe ? 255 : 0;
  19.186 +				ptr += 3;
  19.187 +			}
  19.188 +		}
  19.189 +
  19.190 +		glGenTextures(1, &tex);
  19.191 +		glBindTexture(GL_TEXTURE_2D, tex);
  19.192 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  19.193 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  19.194 +		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, DEF_TEX_SZ, DEF_TEX_SZ, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
  19.195 +		delete [] pixels;
  19.196 +	}
  19.197 +
  19.198 +	Vec2 pos = w->get_position();
  19.199 +	Vec2 sz = w->get_size();
  19.200 +	float aspect = sz.x / sz.y;
  19.201 +
  19.202 +#if !defined(GL_ES_VERSION_2_0)
  19.203 +	glPushAttrib(GL_ENABLE_BIT);
  19.204 +	glEnable(GL_TEXTURE_2D);
  19.205 +#endif
  19.206 +	glBindTexture(GL_TEXTURE_2D, tex);
  19.207 +
  19.208 +	float offs = w->get_pressed() * 0.1 * sz.y;
  19.209 +	glMatrixMode(GL_MODELVIEW);
  19.210 +	glPushMatrix();
  19.211 +	glTranslatef(offs, -offs, 0);
  19.212 +
  19.213 +	float active = w->get_active();
  19.214 +	float hover = w->get_under_mouse();
  19.215 +
  19.216 +	float rg = LERP(0.4, 1.0, hover);
  19.217 +	float b = LERP(rg, 0, active);
  19.218 +	glColor3f(rg, rg, b);
  19.219 +
  19.220 +	glBegin(GL_QUADS);
  19.221 +	glTexCoord2f(0, 1);
  19.222 +	glVertex2f(pos.x, pos.y);
  19.223 +	glTexCoord2f(aspect, 1);
  19.224 +	glVertex2f(pos.x + sz.x, pos.y);
  19.225 +	glTexCoord2f(aspect, 0);
  19.226 +	glVertex2f(pos.x + sz.x, pos.y + sz.y);
  19.227 +	glTexCoord2f(0, 0);
  19.228 +	glVertex2f(pos.x, pos.y + sz.y);
  19.229 +	glEnd();
  19.230 +
  19.231 +	glPopMatrix();
  19.232 +
  19.233 +#ifndef GL_ES_VERSION_2_0
  19.234 +	glPopAttrib();
  19.235 +#endif
  19.236 +}
  19.237 +
  19.238 +}	// namespace goatkit
  19.239 +
  19.240 +#ifdef WIN32
  19.241 +// XXX untested
  19.242 +static void *dlopen(const char *name, int flags)
  19.243 +{
  19.244 +	return LoadLibrary(name);
  19.245 +}
  19.246 +
  19.247 +static void dlclose(void *so)
  19.248 +{
  19.249 +	FreeLibrary(so);
  19.250 +}
  19.251 +
  19.252 +static void *dlsym(void *so, const char *symbol)
  19.253 +{
  19.254 +	return (void*)GetProcAddress(so, symbol);
  19.255 +}
  19.256 +#endif
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/libs/goatkit/theme.h	Wed Sep 23 05:44:58 2015 +0300
    20.3 @@ -0,0 +1,50 @@
    20.4 +/*
    20.5 +GoatKit - a themable/animated widget toolkit for games
    20.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    20.7 +
    20.8 +This program is free software: you can redistribute it and/or modify
    20.9 +it under the terms of the GNU Lesser General Public License as published by
   20.10 +the Free Software Foundation, either version 3 of the License, or
   20.11 +(at your option) any later version.
   20.12 +
   20.13 +This program is distributed in the hope that it will be useful,
   20.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20.16 +GNU Lesser General Public License for more details.
   20.17 +
   20.18 +You should have received a copy of the GNU Lesser General Public License
   20.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   20.20 +*/
   20.21 +#ifndef THEME_H_
   20.22 +#define THEME_H_
   20.23 +
   20.24 +namespace goatkit {
   20.25 +
   20.26 +class Widget;
   20.27 +
   20.28 +typedef void (*WidgetDrawFunc)(const Widget*);
   20.29 +
   20.30 +void add_theme_path(const char *path);
   20.31 +void default_draw_func(const Widget *w);
   20.32 +
   20.33 +struct ThemeImpl;
   20.34 +
   20.35 +class Theme {
   20.36 +private:
   20.37 +	ThemeImpl *impl;
   20.38 +
   20.39 +public:
   20.40 +	Theme();
   20.41 +	~Theme();
   20.42 +
   20.43 +	bool load(const char *name);
   20.44 +	void unload();
   20.45 +
   20.46 +	WidgetDrawFunc get_draw_func(const char *type) const;
   20.47 +};
   20.48 +
   20.49 +extern Theme *theme;	// the current theme
   20.50 +
   20.51 +}	// namespace goatkit
   20.52 +
   20.53 +#endif	// THEME_H_
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/libs/goatkit/vec.h	Wed Sep 23 05:44:58 2015 +0300
    21.3 @@ -0,0 +1,33 @@
    21.4 +/*
    21.5 +GoatKit - a themable/animated widget toolkit for games
    21.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    21.7 +
    21.8 +This program is free software: you can redistribute it and/or modify
    21.9 +it under the terms of the GNU Lesser General Public License as published by
   21.10 +the Free Software Foundation, either version 3 of the License, or
   21.11 +(at your option) any later version.
   21.12 +
   21.13 +This program is distributed in the hope that it will be useful,
   21.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21.16 +GNU Lesser General Public License for more details.
   21.17 +
   21.18 +You should have received a copy of the GNU Lesser General Public License
   21.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   21.20 +*/
   21.21 +#ifndef VEC_H_
   21.22 +#define VEC_H_
   21.23 +
   21.24 +namespace goatkit {
   21.25 +
   21.26 +class Vec2 {
   21.27 +public:
   21.28 +	float x, y;
   21.29 +
   21.30 +	Vec2() : x(0), y(0) {}
   21.31 +	Vec2(float xx, float yy) : x(xx), y(yy) {}
   21.32 +};
   21.33 +
   21.34 +}	// namespace goatkit
   21.35 +
   21.36 +#endif	// VEC_H_
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/libs/goatkit/widget.cc	Wed Sep 23 05:44:58 2015 +0300
    22.3 @@ -0,0 +1,379 @@
    22.4 +/*
    22.5 +GoatKit - a themable/animated widget toolkit for games
    22.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    22.7 +
    22.8 +This program is free software: you can redistribute it and/or modify
    22.9 +it under the terms of the GNU Lesser General Public License as published by
   22.10 +the Free Software Foundation, either version 3 of the License, or
   22.11 +(at your option) any later version.
   22.12 +
   22.13 +This program is distributed in the hope that it will be useful,
   22.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22.16 +GNU Lesser General Public License for more details.
   22.17 +
   22.18 +You should have received a copy of the GNU Lesser General Public License
   22.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   22.20 +*/
   22.21 +#include <stdio.h>
   22.22 +#include <string.h>
   22.23 +#include <math.h>
   22.24 +#include <string>
   22.25 +#include <sstream>
   22.26 +#include "widget.h"
   22.27 +#include "boolanm.h"
   22.28 +#include "theme.h"
   22.29 +#include "screen.h"
   22.30 +
   22.31 +namespace goatkit {
   22.32 +
   22.33 +struct WidgetImpl {
   22.34 +	Screen *scr;
   22.35 +	std::string name, text;
   22.36 +	BBox box;
   22.37 +
   22.38 +	BoolAnim visible, active, press, hover, focus;
   22.39 +
   22.40 +	struct {
   22.41 +		EventCallback func;
   22.42 +		void *cls;
   22.43 +	} cb[NUM_EVENTS];
   22.44 +};
   22.45 +
   22.46 +
   22.47 +Widget::Widget()
   22.48 +{
   22.49 +	static int widget_count;
   22.50 +
   22.51 +	widget = new WidgetImpl;
   22.52 +	widget->scr = 0;
   22.53 +
   22.54 +	std::stringstream sstr;
   22.55 +	sstr << get_type_name() << widget_count++;
   22.56 +	widget->name = sstr.str();
   22.57 +
   22.58 +	widget->box.bmin = Vec2(0, 0);
   22.59 +	widget->box.bmax = Vec2(1, 1);
   22.60 +
   22.61 +	widget->visible.set(true);
   22.62 +	widget->active.set(true);
   22.63 +
   22.64 +	widget->hover.set_transition_duration(250);
   22.65 +	widget->press.set_transition_duration(50);
   22.66 +
   22.67 +	memset(widget->cb, 0, sizeof widget->cb);
   22.68 +}
   22.69 +
   22.70 +Widget::~Widget()
   22.71 +{
   22.72 +	delete widget;
   22.73 +}
   22.74 +
   22.75 +void Widget::set_screen(Screen *scr)
   22.76 +{
   22.77 +	widget->scr = scr;
   22.78 +}
   22.79 +
   22.80 +Screen *Widget::get_screen() const
   22.81 +{
   22.82 +	return widget->scr;
   22.83 +}
   22.84 +
   22.85 +const char *Widget::get_type_name() const
   22.86 +{
   22.87 +	return "widget";
   22.88 +}
   22.89 +
   22.90 +void Widget::set_name(const char *name)
   22.91 +{
   22.92 +	widget->name = std::string(name);
   22.93 +}
   22.94 +
   22.95 +const char *Widget::get_name() const
   22.96 +{
   22.97 +	return widget->name.c_str();
   22.98 +}
   22.99 +
  22.100 +void Widget::set_text(const char *text)
  22.101 +{
  22.102 +	widget->text = std::string(text);
  22.103 +}
  22.104 +
  22.105 +const char *Widget::get_text() const
  22.106 +{
  22.107 +	return widget->text.c_str();
  22.108 +}
  22.109 +
  22.110 +void Widget::show()
  22.111 +{
  22.112 +	widget->visible.change(true);
  22.113 +}
  22.114 +
  22.115 +void Widget::hide()
  22.116 +{
  22.117 +	widget->visible.change(false);
  22.118 +}
  22.119 +
  22.120 +float Widget::get_visibility() const
  22.121 +{
  22.122 +	return widget->visible.get_value();
  22.123 +}
  22.124 +
  22.125 +bool Widget::is_visible() const
  22.126 +{
  22.127 +	return widget->visible.get_state();
  22.128 +}
  22.129 +
  22.130 +void Widget::activate()
  22.131 +{
  22.132 +	widget->active.change(true);
  22.133 +}
  22.134 +
  22.135 +void Widget::deactivate()
  22.136 +{
  22.137 +	widget->active.change(false);
  22.138 +}
  22.139 +
  22.140 +float Widget::get_active() const
  22.141 +{
  22.142 +	return widget->active.get_value();
  22.143 +}
  22.144 +
  22.145 +bool Widget::is_active() const
  22.146 +{
  22.147 +	return widget->active.get_state();
  22.148 +}
  22.149 +
  22.150 +void Widget::press()
  22.151 +{
  22.152 +	widget->press.change(true);
  22.153 +}
  22.154 +
  22.155 +void Widget::release()
  22.156 +{
  22.157 +	widget->press.change(false);
  22.158 +}
  22.159 +
  22.160 +float Widget::get_pressed() const
  22.161 +{
  22.162 +	return widget->press.get_value();
  22.163 +}
  22.164 +
  22.165 +bool Widget::is_pressed() const
  22.166 +{
  22.167 +	return widget->press.get_state();
  22.168 +}
  22.169 +
  22.170 +void Widget::mousein()
  22.171 +{
  22.172 +	widget->hover.change(true);
  22.173 +}
  22.174 +
  22.175 +void Widget::mouseout()
  22.176 +{
  22.177 +	widget->hover.change(false);
  22.178 +	if(widget->press) {
  22.179 +		widget->press.change(false);
  22.180 +	}
  22.181 +}
  22.182 +
  22.183 +float Widget::get_under_mouse() const
  22.184 +{
  22.185 +	return widget->hover.get_value();
  22.186 +}
  22.187 +
  22.188 +bool Widget::is_under_mouse() const
  22.189 +{
  22.190 +	return widget->hover.get_state();
  22.191 +}
  22.192 +
  22.193 +bool Widget::can_focus() const
  22.194 +{
  22.195 +	return false;
  22.196 +}
  22.197 +
  22.198 +void Widget::focusin()
  22.199 +{
  22.200 +	widget->focus.change(true);
  22.201 +}
  22.202 +
  22.203 +void Widget::focusout()
  22.204 +{
  22.205 +	widget->focus.change(false);
  22.206 +}
  22.207 +
  22.208 +float Widget::get_focus() const
  22.209 +{
  22.210 +	return widget->focus.get_value();
  22.211 +}
  22.212 +
  22.213 +bool Widget::is_focused() const
  22.214 +{
  22.215 +	return widget->focus.get_state();
  22.216 +}
  22.217 +
  22.218 +void Widget::set_position(float x, float y)
  22.219 +{
  22.220 +	set_position(Vec2(x, y));
  22.221 +}
  22.222 +
  22.223 +void Widget::set_position(const Vec2 &pos)
  22.224 +{
  22.225 +	Vec2 sz = get_size();
  22.226 +
  22.227 +	widget->box.bmin = pos;
  22.228 +	widget->box.bmax.x = pos.x + sz.x;
  22.229 +	widget->box.bmax.y = pos.y + sz.y;
  22.230 +}
  22.231 +
  22.232 +const Vec2 &Widget::get_position() const
  22.233 +{
  22.234 +	return widget->box.bmin;
  22.235 +}
  22.236 +
  22.237 +void Widget::set_size(float x, float y)
  22.238 +{
  22.239 +	set_size(Vec2(x, y));
  22.240 +}
  22.241 +
  22.242 +void Widget::set_size(const Vec2 &sz)
  22.243 +{
  22.244 +	widget->box.bmax.x = widget->box.bmin.x + sz.x;
  22.245 +	widget->box.bmax.y = widget->box.bmin.y + sz.y;
  22.246 +}
  22.247 +
  22.248 +const Vec2 Widget::get_size() const
  22.249 +{
  22.250 +	return Vec2(widget->box.bmax.x - widget->box.bmin.x,
  22.251 +			widget->box.bmax.y - widget->box.bmin.y);
  22.252 +}
  22.253 +
  22.254 +
  22.255 +const BBox &Widget::get_box() const
  22.256 +{
  22.257 +	return widget->box;
  22.258 +}
  22.259 +
  22.260 +bool Widget::hit_test(const Vec2 &pt) const
  22.261 +{
  22.262 +	return pt.x >= widget->box.bmin.x && pt.x < widget->box.bmax.x &&
  22.263 +		pt.y >= widget->box.bmin.y && pt.y < widget->box.bmax.y;
  22.264 +}
  22.265 +
  22.266 +void Widget::draw() const
  22.267 +{
  22.268 +	WidgetDrawFunc draw_func = default_draw_func;
  22.269 +
  22.270 +	if(theme) {
  22.271 +		draw_func = theme->get_draw_func(get_type_name());
  22.272 +	}
  22.273 +
  22.274 +	draw_func(this);
  22.275 +}
  22.276 +
  22.277 +// dummy event handlers
  22.278 +void Widget::on_mouse_button(const ButtonEvent &ev)
  22.279 +{
  22.280 +}
  22.281 +
  22.282 +void Widget::on_mouse_motion(const MotionEvent &ev)
  22.283 +{
  22.284 +}
  22.285 +
  22.286 +void Widget::on_mouse_focus(const FocusEvent &ev)
  22.287 +{
  22.288 +}
  22.289 +
  22.290 +void Widget::on_key(const KeyEvent &ev)
  22.291 +{
  22.292 +}
  22.293 +
  22.294 +void Widget::on_click()
  22.295 +{
  22.296 +}
  22.297 +
  22.298 +void Widget::on_double_click()
  22.299 +{
  22.300 +}
  22.301 +
  22.302 +void Widget::on_change()
  22.303 +{
  22.304 +}
  22.305 +
  22.306 +
  22.307 +#define CALL_CB(w, ev) \
  22.308 +	do { \
  22.309 +		if((w)->widget->cb[ev.type].func) { \
  22.310 +			(w)->widget->cb[ev.type].func((w), ev, (w)->widget->cb[ev.type].cls); \
  22.311 +		} \
  22.312 +	} while(0)
  22.313 +
  22.314 +#define CALL_CB_TYPE(w, t) \
  22.315 +	do { \
  22.316 +		Event ev; \
  22.317 +		ev.type = (t); \
  22.318 +		CALL_CB(w, ev); \
  22.319 +	} while(0)
  22.320 +
  22.321 +/* the event dispatcher generates high-level events (click, etc)
  22.322 + * and calls the on_whatever() functions for both low and high-level
  22.323 + * events.
  22.324 + * The on_whatever functions are called *after* any other actions performed
  22.325 + * here, to give subclasses the opportunity to override them easily, by
  22.326 + * overriding the on_ functions, without having to override handle_event itself
  22.327 + */
  22.328 +// TODO also call callbacks here I guess...
  22.329 +void Widget::handle_event(const Event &ev)
  22.330 +{
  22.331 +	switch(ev.type) {
  22.332 +	case EV_MOUSE_BUTTON:
  22.333 +		if(ev.button.press) {
  22.334 +			press();
  22.335 +		} else {
  22.336 +			if(is_pressed()) {
  22.337 +				CALL_CB_TYPE(this, EV_CLICK);
  22.338 +				on_click();
  22.339 +			}
  22.340 +			release();
  22.341 +		}
  22.342 +
  22.343 +		on_mouse_button(ev.button);
  22.344 +		break;
  22.345 +
  22.346 +	case EV_MOUSE_MOTION:
  22.347 +		on_mouse_motion(ev.motion);
  22.348 +		break;
  22.349 +
  22.350 +	case EV_MOUSE_FOCUS:
  22.351 +		if(ev.focus.enter) {
  22.352 +			mousein();
  22.353 +		} else {
  22.354 +			mouseout();
  22.355 +		}
  22.356 +		on_mouse_focus(ev.focus);
  22.357 +		break;
  22.358 +
  22.359 +	case EV_KEY:
  22.360 +		on_key(ev.key);
  22.361 +		break;
  22.362 +
  22.363 +	case EV_CHANGE:
  22.364 +		on_change();
  22.365 +		break;
  22.366 +
  22.367 +	default:
  22.368 +		break;
  22.369 +	}
  22.370 +
  22.371 +	CALL_CB(this, ev);
  22.372 +}
  22.373 +
  22.374 +
  22.375 +void Widget::set_callback(EventType evtype, EventCallback func, void *cls)
  22.376 +{
  22.377 +	widget->cb[evtype].func = func;
  22.378 +	widget->cb[evtype].cls = cls;
  22.379 +}
  22.380 +
  22.381 +
  22.382 +}	// namespace goatkit
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/libs/goatkit/widget.h	Wed Sep 23 05:44:58 2015 +0300
    23.3 @@ -0,0 +1,120 @@
    23.4 +/*
    23.5 +GoatKit - a themable/animated widget toolkit for games
    23.6 +Copyright (C) 2014  John Tsiombikas <nuclear@member.fsf.org>
    23.7 +
    23.8 +This program is free software: you can redistribute it and/or modify
    23.9 +it under the terms of the GNU Lesser General Public License as published by
   23.10 +the Free Software Foundation, either version 3 of the License, or
   23.11 +(at your option) any later version.
   23.12 +
   23.13 +This program is distributed in the hope that it will be useful,
   23.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   23.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23.16 +GNU Lesser General Public License for more details.
   23.17 +
   23.18 +You should have received a copy of the GNU Lesser General Public License
   23.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   23.20 +*/
   23.21 +#ifndef GOATKIT_WIDGET_H_
   23.22 +#define GOATKIT_WIDGET_H_
   23.23 +
   23.24 +#include "vec.h"
   23.25 +#include "event.h"
   23.26 +
   23.27 +namespace goatkit {
   23.28 +
   23.29 +struct BBox {
   23.30 +	Vec2 bmin, bmax;
   23.31 +};
   23.32 +
   23.33 +class Screen;
   23.34 +class Widget;
   23.35 +struct WidgetImpl;
   23.36 +
   23.37 +typedef void (*EventCallback)(Widget*, const Event &ev, void *cls);
   23.38 +
   23.39 +class Widget {
   23.40 +protected:
   23.41 +	WidgetImpl *widget;
   23.42 +
   23.43 +	virtual void set_screen(Screen *scr);
   23.44 +	Screen *get_screen() const;
   23.45 +
   23.46 +public:
   23.47 +	Widget();
   23.48 +	virtual ~Widget();
   23.49 +
   23.50 +	virtual const char *get_type_name() const;
   23.51 +
   23.52 +	virtual void set_name(const char *name);
   23.53 +	virtual const char *get_name() const;
   23.54 +
   23.55 +	virtual void set_text(const char *text);
   23.56 +	virtual const char *get_text() const;
   23.57 +
   23.58 +	virtual void show();
   23.59 +	virtual void hide();
   23.60 +	virtual float get_visibility() const;
   23.61 +	virtual bool is_visible() const;
   23.62 +
   23.63 +	virtual void activate();
   23.64 +	virtual void deactivate();
   23.65 +	virtual float get_active() const;
   23.66 +	virtual bool is_active() const;
   23.67 +
   23.68 +	virtual void press();
   23.69 +	virtual void release();
   23.70 +	virtual float get_pressed() const;
   23.71 +	virtual bool is_pressed() const;
   23.72 +
   23.73 +	virtual void mousein();
   23.74 +	virtual void mouseout();
   23.75 +	virtual float get_under_mouse() const;
   23.76 +	virtual bool is_under_mouse() const;
   23.77 +
   23.78 +	// input focus, managed by the screen
   23.79 +	virtual bool can_focus() const;
   23.80 +	virtual void focusin();
   23.81 +	virtual void focusout();
   23.82 +	virtual float get_focus() const;
   23.83 +	virtual bool is_focused() const;
   23.84 +
   23.85 +	virtual void set_position(float x, float y);
   23.86 +	virtual void set_position(const Vec2 &pos);
   23.87 +	virtual const Vec2 &get_position() const;
   23.88 +
   23.89 +	virtual void set_size(float x, float y);
   23.90 +	virtual void set_size(const Vec2 &size);
   23.91 +	virtual const Vec2 get_size() const;
   23.92 +
   23.93 +	virtual const BBox &get_box() const;
   23.94 +
   23.95 +	virtual bool hit_test(const Vec2 &pt) const;
   23.96 +
   23.97 +	virtual void draw() const;
   23.98 +
   23.99 +	// low level events
  23.100 +	virtual void on_mouse_button(const ButtonEvent &ev);
  23.101 +	virtual void on_mouse_motion(const MotionEvent &ev);
  23.102 +	virtual void on_mouse_focus(const FocusEvent &ev);
  23.103 +	virtual void on_key(const KeyEvent &ev);
  23.104 +
  23.105 +	// high level events
  23.106 +	virtual void on_click();
  23.107 +	virtual void on_double_click();
  23.108 +	virtual void on_change();
  23.109 +	//virtual void on_drag_move(int bn, const Vec2 &pt);
  23.110 +	//virtual void on_drag_release(int bn, const Vec2 &pt);
  23.111 +
  23.112 +	// event dispatcher
  23.113 +	virtual void handle_event(const Event &ev);
  23.114 +
  23.115 +	// external callback setting
  23.116 +	virtual void set_callback(EventType evtype, EventCallback func, void *cls = 0);
  23.117 +
  23.118 +	friend class Screen;
  23.119 +};
  23.120 +
  23.121 +}
  23.122 +
  23.123 +#endif	// GOATKIT_WIDGET_H_
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/sdr/color.p.glsl	Wed Sep 23 05:44:58 2015 +0300
    24.3 @@ -0,0 +1,10 @@
    24.4 +#ifdef GL_ES
    24.5 +precision mediump float;
    24.6 +#endif
    24.7 +
    24.8 +varying vec4 vcolor;
    24.9 +
   24.10 +void main()
   24.11 +{
   24.12 +	gl_FragColor = vcolor;
   24.13 +}
   24.14 \ No newline at end of file
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/sdr/color.v.glsl	Wed Sep 23 05:44:58 2015 +0300
    25.3 @@ -0,0 +1,12 @@
    25.4 +attribute vec4 attr_vertex, attr_color;
    25.5 +
    25.6 +uniform mat4 matrix_modelview, matrix_projection;
    25.7 +
    25.8 +varying vec4 vcolor;
    25.9 +
   25.10 +void main()
   25.11 +{
   25.12 +	mat4 mvp = matrix_projection * matrix_modelview;
   25.13 +	gl_Position = mvp * attr_vertex;
   25.14 +	vcolor = attr_color;
   25.15 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/sdr/ui.p.glsl	Wed Sep 23 05:44:58 2015 +0300
    26.3 @@ -0,0 +1,14 @@
    26.4 +#ifdef GL_ES
    26.5 +precision mediump float;
    26.6 +#endif
    26.7 +
    26.8 +uniform sampler2D tex;
    26.9 +
   26.10 +varying vec4 vcolor;
   26.11 +varying vec2 vtexcoord;
   26.12 +
   26.13 +void main()
   26.14 +{
   26.15 +	vec4 texel = texture2D(tex, vtexcoord);
   26.16 +	gl_FragColor = vcolor * texel;
   26.17 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/sdr/ui.v.glsl	Wed Sep 23 05:44:58 2015 +0300
    27.3 @@ -0,0 +1,15 @@
    27.4 +attribute vec4 attr_vertex, attr_color;
    27.5 +attribute vec2 attr_texcoord;
    27.6 +
    27.7 +uniform mat4 matrix_modelview, matrix_projection;
    27.8 +
    27.9 +varying vec4 vcolor;
   27.10 +varying vec2 vtexcoord;
   27.11 +
   27.12 +void main()
   27.13 +{
   27.14 +	mat4 mvp = matrix_projection * matrix_modelview;
   27.15 +	gl_Position = mvp * attr_vertex;
   27.16 +	vcolor = attr_color;
   27.17 +	vtexcoord = attr_texcoord;
   27.18 +}
    28.1 --- a/src/config.h	Tue Sep 22 07:13:47 2015 +0300
    28.2 +++ b/src/config.h	Wed Sep 23 05:44:58 2015 +0300
    28.3 @@ -1,10 +1,13 @@
    28.4  #ifndef CONFIG_H_
    28.5  #define CONFIG_H_
    28.6  
    28.7 -#if defined(__IPHONE_3_0) || defined(__IPHONE_3_2) || defined(__IPHONE_4_0)
    28.8 +#ifdef __APPLE__
    28.9 +#include <TargetConditionals.h>
   28.10 +
   28.11 +#if defined(TARGET_IPHONE_SIMULATOR) || defined(TARGET_OS_IPHONE)
   28.12  #define IPHONE
   28.13 -
   28.14 -#define glClearDepth	glClearDepthf
   28.15  #endif
   28.16  
   28.17 +#endif	/* __APPLE__ */
   28.18 +
   28.19  #endif	/* CONFIG_H_ */
    29.1 --- a/src/ios/viewctl.m	Tue Sep 22 07:13:47 2015 +0300
    29.2 +++ b/src/ios/viewctl.m	Wed Sep 23 05:44:58 2015 +0300
    29.3 @@ -152,6 +152,34 @@
    29.4  	printf("viewport %dx%d (scale: %g)\n", xsz, ysz, pixel_scale);
    29.5  }
    29.6  
    29.7 +- (void)touchesBegan: (NSSet<UITouch*>*)touches withEvent: (UIEvent*)event
    29.8 +{
    29.9 +	UITouch *touch = [touches anyObject];
   29.10 +	CGPoint pt = [touch locationInView: nil];
   29.11 +	mouse_button(0, 1, pt.x, pt.y);
   29.12 +}
   29.13 +
   29.14 +- (void)touchesMoved: (NSSet<UITouch*>*)touches withEvent: (UIEvent*)event
   29.15 +{
   29.16 +	UITouch *touch = [touches anyObject];
   29.17 +	CGPoint pt = [touch locationInView: nil];
   29.18 +	mouse_motion(pt.x, pt.y);
   29.19 +}
   29.20 +
   29.21 +- (void)touchesEnded: (NSSet<UITouch*>*)touches withEvent: (UIEvent*)event
   29.22 +{
   29.23 +	UITouch *touch = [touches anyObject];
   29.24 +	CGPoint pt = [touch locationInView: nil];
   29.25 +	mouse_button(0, 0, pt.x, pt.y);
   29.26 +}
   29.27 +
   29.28 +- (void)touchesCancelled: (NSSet<UITouch*>*)touches withEvent: (UIEvent*)event
   29.29 +{
   29.30 +	UITouch *touch = [touches anyObject];
   29.31 +	CGPoint pt = [touch locationInView: nil];
   29.32 +	mouse_button(0, 0, pt.x, pt.y);
   29.33 +}
   29.34 +
   29.35  // ADBannerDelegate functions
   29.36  
   29.37  - (void)bannerViewDidLoadAd: (ADBannerView*)banner
    30.1 --- a/src/istereo.c	Tue Sep 22 07:13:47 2015 +0300
    30.2 +++ b/src/istereo.c	Wed Sep 23 05:44:58 2015 +0300
    30.3 @@ -1,6 +1,6 @@
    30.4  /*
    30.5  Stereoscopic tunnel for iOS.
    30.6 -Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
    30.7 +Copyright (C) 2011-2015  John Tsiombikas <nuclear@member.fsf.org>
    30.8  
    30.9  This program is free software: you can redistribute it and/or modify
   30.10  it under the terms of the GNU General Public License as published by
   30.11 @@ -30,6 +30,7 @@
   30.12  #include "cam.h"
   30.13  #include "vmath.h"
   30.14  #include "config.h"
   30.15 +#include "ui.h"
   30.16  
   30.17  static void render(float t);
   30.18  static void draw_tunnel(float t);
   30.19 @@ -40,13 +41,14 @@
   30.20  static unsigned int get_shader_program(const char *vfile, const char *pfile);
   30.21  static float get_sec(void);
   30.22  
   30.23 -unsigned int prog, prog_simple, prog_tunnel, prog_text;
   30.24 +unsigned int prog, prog_simple, prog_tunnel, prog_text, prog_color, prog_ui;
   30.25  unsigned int tex, tex_stones, tex_normal, tex_text;
   30.26  
   30.27  int view_xsz, view_ysz;
   30.28  
   30.29  int stereo = 0;
   30.30  int use_bump = 0;
   30.31 +int show_opt = 1;
   30.32  
   30.33  /* construction parameters */
   30.34  int sides = 24;
   30.35 @@ -72,6 +74,12 @@
   30.36  	if(!(prog_text = get_shader_program("text.v.glsl", "text.p.glsl"))) {
   30.37  		return -1;
   30.38  	}
   30.39 +	if(!(prog_color = get_shader_program("color.v.glsl", "color.p.glsl"))) {
   30.40 +		return -1;
   30.41 +	}
   30.42 +	if(!(prog_ui = get_shader_program("ui.v.glsl", "ui.p.glsl"))) {
   30.43 +		return -1;
   30.44 +	}
   30.45  
   30.46  	if(!(tex = load_texture(find_resource("tiles.jpg", 0, 0)))) {
   30.47  		return -1;
   30.48 @@ -89,6 +97,10 @@
   30.49  	glEnable(GL_DEPTH_TEST);
   30.50  	glEnable(GL_CULL_FACE);
   30.51  
   30.52 +	if(ui_init() == -1) {
   30.53 +		return -1;
   30.54 +	}
   30.55 +
   30.56  	cam_fov(42.5);
   30.57  	cam_clip(0.5, 250.0);
   30.58  
   30.59 @@ -97,7 +109,11 @@
   30.60  
   30.61  void cleanup(void)
   30.62  {
   30.63 -	free_program(prog);
   30.64 +	ui_shutdown();
   30.65 +	free_program(prog_simple);
   30.66 +	free_program(prog_tunnel);
   30.67 +	free_program(prog_color);
   30.68 +	free_program(prog_ui);
   30.69  }
   30.70  
   30.71  void redraw(void)
   30.72 @@ -187,6 +203,10 @@
   30.73  		}
   30.74  		glDepthMask(1);
   30.75  	}
   30.76 +
   30.77 +	if(show_opt) {
   30.78 +		ui_draw();
   30.79 +	}
   30.80  }
   30.81  
   30.82  static void draw_tunnel(float t)
   30.83 @@ -360,6 +380,22 @@
   30.84  
   30.85  	view_xsz = x;
   30.86  	view_ysz = y;
   30.87 +
   30.88 +	ui_reshape(x, y);
   30.89 +}
   30.90 +
   30.91 +void mouse_button(int bn, int press, int x, int y)
   30.92 +{
   30.93 +	if(show_opt) {
   30.94 +		ui_button(bn, press, x, y);
   30.95 +	}
   30.96 +}
   30.97 +
   30.98 +void mouse_motion(int x, int y)
   30.99 +{
  30.100 +	if(show_opt) {
  30.101 +		ui_motion(x, y);
  30.102 +	}
  30.103  }
  30.104  
  30.105  static unsigned int get_shader_program(const char *vfile, const char *pfile)
    31.1 --- a/src/istereo.h	Tue Sep 22 07:13:47 2015 +0300
    31.2 +++ b/src/istereo.h	Wed Sep 23 05:44:58 2015 +0300
    31.3 @@ -24,5 +24,7 @@
    31.4  void cleanup(void);
    31.5  void redraw(void);
    31.6  void reshape(int x, int y);
    31.7 +void mouse_button(int bn, int press, int x, int y);
    31.8 +void mouse_motion(int x, int y);
    31.9  
   31.10  #endif	/* ISTEREO_H_ */
    32.1 --- a/src/opengl.h	Tue Sep 22 07:13:47 2015 +0300
    32.2 +++ b/src/opengl.h	Wed Sep 23 05:44:58 2015 +0300
    32.3 @@ -22,8 +22,12 @@
    32.4  
    32.5  #include "config.h"
    32.6  
    32.7 -#ifdef IPHONE
    32.8 +#if defined(IPHONE) || defined(__IPHONE__)
    32.9  #include <OpenGLES/ES2/gl.h>
   32.10 +
   32.11 +#define glClearDepth	glClearDepthf
   32.12 +#define GLDEF
   32.13 +#include "sanegl.h"
   32.14  #else
   32.15  
   32.16  #include <GL/glew.h>
    33.1 --- a/src/sanegl.c	Tue Sep 22 07:13:47 2015 +0300
    33.2 +++ b/src/sanegl.c	Wed Sep 23 05:44:58 2015 +0300
    33.3 @@ -21,6 +21,12 @@
    33.4  #include <string.h>
    33.5  #include <math.h>
    33.6  #include <assert.h>
    33.7 +
    33.8 +#include "opengl.h"
    33.9 +
   33.10 +#ifdef GLDEF
   33.11 +#undef GLDEF
   33.12 +#endif
   33.13  #include "sanegl.h"
   33.14  
   33.15  #define MMODE_IDX(x)	((x) - GL_MODELVIEW)
    34.1 --- a/src/sanegl.h	Tue Sep 22 07:13:47 2015 +0300
    34.2 +++ b/src/sanegl.h	Wed Sep 23 05:44:58 2015 +0300
    34.3 @@ -74,6 +74,10 @@
    34.4  #define glVertexAttrib4f	gl_vertex_attrib4f
    34.5  #endif
    34.6  
    34.7 +#ifdef __cplusplus
    34.8 +extern "C" {
    34.9 +#endif
   34.10 +
   34.11  /* matrix stuff */
   34.12  void gl_matrix_mode(int mmode);
   34.13  void gl_push_matrix(void);
   34.14 @@ -111,4 +115,8 @@
   34.15  void gl_vertex_attrib3f(int loc, float x, float y, float z);
   34.16  void gl_vertex_attrib4f(int loc, float x, float y, float z, float w);
   34.17  
   34.18 +#ifdef __cplusplus
   34.19 +}
   34.20 +#endif
   34.21 +
   34.22  #endif	/* SANEGL_H_ */
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/src/ui.cc	Wed Sep 23 05:44:58 2015 +0300
    35.3 @@ -0,0 +1,131 @@
    35.4 +#include "ui.h"
    35.5 +#include "goatkit/goatkit.h"
    35.6 +#include "opengl.h"
    35.7 +#include "sdr.h"
    35.8 +
    35.9 +static goatkit::Screen scr;
   35.10 +static int width, height;
   35.11 +
   35.12 +extern unsigned int prog_color, prog_ui;
   35.13 +
   35.14 +int ui_init(void)
   35.15 +{
   35.16 +	float ypos = 0;
   35.17 +	float vsep = 0.1;
   35.18 +
   35.19 +	goatkit::Label *label = new goatkit::Label;
   35.20 +	label->set_position(0.5, ypos += vsep);
   35.21 +	label->set_size(0.1, 0.1);
   35.22 +	label->set_text("Stereoscopic rendering");
   35.23 +	scr.add_widget(label);
   35.24 +
   35.25 +	/*
   35.26 +	goatkit::Button *button = new goatkit::Button;
   35.27 +	button->set_position(300, ypos += vsep);
   35.28 +	button->set_size(200, 40);
   35.29 +	button->set_text("a button!");
   35.30 +	button->set_callback(goatkit::EV_CLICK, callback);
   35.31 +	scr.add_widget(button);
   35.32 +
   35.33 +	goatkit::TextBox *text = new goatkit::TextBox;
   35.34 +	text->set_position(300, ypos += vsep);
   35.35 +	text->set_size(200, 30);
   35.36 +	text->set_text("foo");
   35.37 +	text->set_callback(goatkit::EV_CHANGE, callback);
   35.38 +	scr.add_widget(text);
   35.39 +
   35.40 +	goatkit::CheckBox *cbox = new goatkit::CheckBox;
   35.41 +	cbox->set_position(300, ypos += vsep);
   35.42 +	cbox->set_size(200, 20);
   35.43 +	cbox->set_text("a checkbox!");
   35.44 +	cbox->set_callback(goatkit::EV_CHANGE, callback);
   35.45 +	scr.add_widget(cbox);
   35.46 +
   35.47 +	goatkit::Slider *slider = new goatkit::Slider;
   35.48 +	slider->set_position(300, ypos += vsep);
   35.49 +	slider->set_size(200, 40);
   35.50 +	slider->set_callback(goatkit::EV_CHANGE, callback);
   35.51 +	slider->set_continuous_change(false);
   35.52 +	slider->set_range(0, 100.0);
   35.53 +	scr.add_widget(slider);
   35.54 +
   35.55 +	goatkit::Slider *intslider = new goatkit::Slider;
   35.56 +	intslider->set_position(300, ypos += vsep);
   35.57 +	intslider->set_size(200, 40);
   35.58 +	intslider->set_callback(goatkit::EV_CHANGE, callback);
   35.59 +	intslider->set_continuous_change(false);
   35.60 +	intslider->set_range(0, 100.0);
   35.61 +	intslider->set_step(10);
   35.62 +	scr.add_widget(intslider);
   35.63 +	 */
   35.64 +
   35.65 +	scr.show();
   35.66 +
   35.67 +	// load the theme
   35.68 +	//goatkit::add_theme_path("themes/simple");
   35.69 +
   35.70 +	//goatkit::theme = new goatkit::Theme;
   35.71 +	//goatkit::theme->load("simple");
   35.72 +
   35.73 +	return 0;
   35.74 +}
   35.75 +
   35.76 +void ui_shutdown(void)
   35.77 +{
   35.78 +}
   35.79 +
   35.80 +void ui_reshape(int x, int y)
   35.81 +{
   35.82 +	width = x;
   35.83 +	height = y;
   35.84 +}
   35.85 +
   35.86 +void ui_draw(void)
   35.87 +{
   35.88 +	float aspect = (float)width / (float)height;
   35.89 +
   35.90 +	bind_program(prog_ui);
   35.91 +
   35.92 +	gl_matrix_mode(GL_PROJECTION);
   35.93 +	gl_push_matrix();
   35.94 +	gl_load_identity();
   35.95 +	gl_scalef(2.0 / aspect, 2.0, 1);
   35.96 +	gl_translatef(-1, -1, 0);
   35.97 +	gl_scalef(1, -1, 1);
   35.98 +	gl_matrix_mode(GL_MODELVIEW);
   35.99 +	gl_push_matrix();
  35.100 +	gl_load_identity();
  35.101 +
  35.102 +	glDisable(GL_CULL_FACE);
  35.103 +	glDisable(GL_DEPTH_TEST);
  35.104 +
  35.105 +	/*gl_begin(GL_QUADS);
  35.106 +	gl_color3f(1, 0, 0);
  35.107 +	gl_vertex3f(0, 0, 0);
  35.108 +	gl_vertex3f(0, 0.5, 0);
  35.109 +	gl_vertex3f(0.5 * aspect, 0.5, 0);
  35.110 +	gl_vertex3f(0.5 * aspect, 0, 0);
  35.111 +	gl_end();
  35.112 +	*/
  35.113 +
  35.114 +	scr.draw();
  35.115 +
  35.116 +	glEnable(GL_CULL_FACE);
  35.117 +	glEnable(GL_DEPTH_TEST);
  35.118 +
  35.119 +
  35.120 +	gl_matrix_mode(GL_PROJECTION);
  35.121 +	gl_pop_matrix();
  35.122 +	gl_matrix_mode(GL_MODELVIEW);
  35.123 +	gl_pop_matrix();
  35.124 +}
  35.125 +
  35.126 +void ui_button(int bn, int press, int x, int y)
  35.127 +{
  35.128 +	scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, 1.0 - (float)y / (float)height);
  35.129 +}
  35.130 +
  35.131 +void ui_motion(int x, int y)
  35.132 +{
  35.133 +	scr.sysev_mouse_motion((float)x / (float)width, 1.0 - (float)y / (float)height);
  35.134 +}
  35.135 \ No newline at end of file
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/src/ui.h	Wed Sep 23 05:44:58 2015 +0300
    36.3 @@ -0,0 +1,21 @@
    36.4 +#ifndef UI_H_
    36.5 +#define UI_H_
    36.6 +
    36.7 +#ifdef __cplusplus
    36.8 +extern "C" {
    36.9 +#endif
   36.10 +
   36.11 +int ui_init(void);
   36.12 +void ui_shutdown(void);
   36.13 +
   36.14 +void ui_reshape(int x, int y);
   36.15 +void ui_draw(void);
   36.16 +
   36.17 +void ui_button(int bn, int press, int x, int y);
   36.18 +void ui_motion(int x, int y);
   36.19 +
   36.20 +#ifdef __cplusplus
   36.21 +}
   36.22 +#endif
   36.23 +
   36.24 +#endif	/* UI_H_ */