Changeset 43
- Timestamp:
- 07/10/07 22:57:32 (1 year ago)
- Files:
-
- trunk/bin/yage3d.exe (modified) (previous)
- trunk/src/demo1/main.d (modified) (2 diffs)
- trunk/src/demo2 (added)
- trunk/src/demo2/gameobj.d (added)
- trunk/src/demo2/main.d (added)
- trunk/src/demo2/ship.d (added)
- trunk/src/yage/core/array.d (modified) (3 diffs)
- trunk/src/yage/gui/style.d (modified) (3 diffs)
- trunk/src/yage/gui/surface.d (modified) (3 diffs)
- trunk/src/yage/system/device.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/demo1/main.d
r42 r43 62 62 disp.bottomRight = Vec2f(1, 1); 63 63 disp.setVisibility(true); 64 65 Surface first = new Surface(disp); 66 first.texture = camera.getTexture(); 67 first.topLeft = Vec2f(0,0); 68 first.bottomRight = Vec2f(.75, .75); 69 first.setVisibility(true); 70 71 Surface second = new Surface(disp); 72 second.texture = camera.getTexture(); 73 second.topLeft = Vec2f(.25,.25); 74 second.bottomRight = Vec2f(1,1); 75 second.setVisibility(true); 64 disp.texture = camera.getTexture(); 65 76 66 77 67 void onMousedown(Surface self, byte buttons, Vec2i coordinates){ 78 self.raise();79 68 Input.button[1].up = false; 80 69 Input.setGrabMouse(!Input.getGrabMouse()); … … 86 75 } 87 76 88 first.onMousedown = &onMousedown; 89 second.onMousedown = &onMousedown; 90 first.onResize = &onResize; 77 disp.onMousedown = &onMousedown; 78 disp.onResize = &onResize; 91 79 92 80 // Music trunk/src/yage/core/array.d
r32 r43 19 19 import std.stdio; 20 20 21 /** 22 * 23 */ 21 /// Return the maximum value of an array. 22 T amax(T)(T[] array) 23 { T m = array[0]; 24 foreach (T a; array) 25 if (a>m) 26 m=a; 27 return m; 28 } 29 30 /// Return the minimum value of an array. 31 T amin(T)(T[] array) 32 { T m = array[0]; 33 foreach (T a; array) 34 if (a<m) 35 m=a; 36 return m; 37 } 38 39 /** 40 * Is the array ordered? 41 * Params: 42 * increasing = Check for ordering by small to big. 43 * getKey = a function to get a key. 44 * Example: 45 * -------------------------------- 46 * Timer[] array; 47 * // ... fill array with new Timer() ... 48 * array.ordered(true, (Timer a) { return a.get(); }); // should return true 49 * -------------------------------- 50 */ 51 bool ordered(T)(T[] array, bool increasing=true) 52 { return ordered(array, increasing, (T a) { return a; }); 53 } 54 55 /// Ditto 56 bool ordered(T, K)(T[] array, bool increasing=true, K delegate(T elem) getKey=null) 57 { if (array.length <= 1) 58 return true; 59 60 if (increasing) 61 { for (int i=0; i<array.length-1; i++) 62 if (getKey(array[i]) > getKey(array[i+1])) 63 return false; 64 } else 65 { for (int i=0; i<array.length-1; i++) 66 if (getKey(array[i]) < getKey(array[i+1])) 67 return false; 68 } 69 return true; 70 } 71 unittest 72 { assert(ordered([-1, 0, 1, 2, 2, 5]) == true); 73 assert(ordered([-1, 0, 1, 2, 1, 5]) == false); 74 assert(ordered([5, 3, 3, 3, 2, -1], false) == true); 75 } 24 76 25 77 /** … … 64 116 * // ... fill array with new Timer() ... 65 117 * array.radixSort((Timer a) { return a.get(); }); 66 * -------------------------------- */ 118 * -------------------------------- 119 */ 67 120 void radixSort(T)(inout T[] array) 68 121 { radixSort(array, (T a) { return a; }); … … 97 150 { elem[i].key2 = getKey(array[i]); 98 151 elem[i].data = array[i]; 152 writefln(elem[i].key2); 99 153 } 100 154 trunk/src/yage/gui/style.d
r38 r43 15 15 struct Style 16 16 { 17 enum Unit s{PX, PERCENT};17 enum Unit {PX, PERCENT}; 18 18 19 19 Material backgroundMaterial; … … 21 21 22 22 float[4] borderWidth; 23 byte[4] borderWidthUnits; 24 float[4] borderRadius; // used for rounded corners. 25 byte[4] borderRadiusUnits; 26 Vec4f[4] borderColor; 23 Unit[4] borderWidthUnits; 24 float[4] borderRadius; // used for rounded corners. 25 Unit[4] borderRadiusUnits; 26 Vec4f[4] borderColor; 27 Material borderMaterial; // Overrides radius and color if set 28 bool[4] borderMaterialStretch; // top, right, bottom, left 27 29 28 30 Material cursor; 29 b yte display; // block, none, anything else?31 bool visible = false;; 30 32 byte position; 31 byte visibility;32 33 33 34 //Font fontFamily; … … 36 37 float fontWeight; 37 38 38 float[4] margin Width;39 byte[4] marginUnits;39 float[4] margin; 40 Unit[4] marginUnits; 40 41 41 float[4] padding Width;42 byte[4] paddingUnits;42 float[4] padding; 43 Unit[4] paddingUnits; 43 44 44 Vec4f dimension;// top, right, bottom, left45 float[4] dimension; // top, right, bottom, left 45 46 byte[4] dimensinUnits; 46 byte overflow; 47 float height; 48 Unit heightUnits; 49 float width; 50 Unit widthUnits; 47 51 int zIndex; 48 float height;49 byte heightUnits;50 float width;51 byte widthUnits;52 52 53 53 Vec4f color; trunk/src/yage/gui/surface.d
r40 r43 1 /** 2 * Copyright: (c) 2005-2007 Eric Poggel 3 * Authors: Joe Pusderis (deformative0@gmail.com) 4 * License: <a href="lgpl.txt">LGPL</a> 5 */ 6 1 7 module yage.gui.surface; 2 8 3 import yage.resource.texture; 4 import yage.core.vector; 5 import yage.system.device; 9 import std.stdio; 6 10 import derelict.opengl.gl; 7 11 import derelict.sdl.sdl; 12 import yage.core.all; 13 import yage.system.device; 14 import yage.system.constant; 15 import yage.resource.texture; 8 16 import yage.gui.style; 9 import yage.system.constant; 10 11 import std.stdio; 12 17 18 19 /** 20 * A surface will be similar to an HTML DOM element, including having text inside it, 21 * margin, padding, a border, and a background texture, including textures from a camera. 22 * Surfaces will exist in a hierarchical structure, with each having a parent and an array of children. 23 * The children will be positioned relative to the borders of their parent. */ 13 24 class Surface{ 25 static final Style defaultStyle; 26 Style style; 27 14 28 //Style style; //move style into a higher level clas, perhaps make a geometry struct isntead 15 29 GPUTexture texture; //Change from GPUTexture to Texture or Material … … 33 47 34 48 bool visible; 49 35 50 36 51 //add root position and stuff … … 167 182 glEnd(); 168 183 } 169 foreach(sub; subs)sub.draw(); 184 185 // Sort subs 186 if (!subs.ordered(true, (Surface s){return s.style.zIndex;} )) 187 subs.radixSort((Surface s){return s.style.zIndex;} ); 188 189 foreach(sub; subs) 190 sub.draw(); 170 191 } 171 192 } trunk/src/yage/system/device.d
r40 r43 8 8 9 9 import std.stdio; 10 11 10 import std.string; 12 11 import derelict.openal.al;
