Changeset 198
- Timestamp:
- 07/24/10 01:04:23 (2 years ago)
- Files:
-
- trunk/res/gui/font/Juras Medium Ascii.ttf (deleted)
- trunk/res/gui/skin/clear1.png (deleted)
- trunk/res/gui/skin/clear2.png (deleted)
- trunk/res/gui/skin/clear3.png (deleted)
- trunk/res/gui/skin/panel1.png (modified) (previous)
- trunk/res/gui/skin/panel2.png (modified) (previous)
- trunk/res/gui/skin/panel3.png (deleted)
- trunk/res/gui/skin/panel4.png (deleted)
- trunk/res/gui/skin/panel5.png (deleted)
- trunk/res/gui/skin/panel6.png (deleted)
- trunk/res/gui/skin/panel7.png (deleted)
- trunk/res/gui/skin/panel8.png (deleted)
- trunk/src/demo1/main.d (modified) (2 diffs)
- trunk/src/demo2/main.d (modified) (7 diffs)
- trunk/src/yage/gui/surface.d (modified) (5 diffs)
- trunk/src/yage/gui/textblock.d (modified) (14 diffs)
- trunk/src/yage/system/input.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/demo1/main.d
r197 r198 180 180 // Make a draggable window to show some useful info. 181 181 auto info = view.addChild(new Surface()); 182 info.style.set("top: 5px; right: 5px; width: 130px; height: 100px; color: black; padding: 3px; " ~183 "border-width: 5px; border-image: url('gui/skin/clear2.png'); font-size: 12px");182 info.style.set("top: 5px; right: 12px; width: 110px; height: 100px; color: white; padding: -6px; " ~ 183 "border-width: 12px; border-image: url('gui/skin/panel1.png'); font-size: 12px"); 184 184 185 185 //window.style.backgroundImage = scene.camera.getTexture(); … … 199 199 }; 200 200 info.onMouseOver = delegate bool(Surface self, byte buttons, Vec2i coordinates) { 201 self.style.set("border-image: url('gui/skin/ clear3.png')");201 self.style.set("border-image: url('gui/skin/panel2.png')"); 202 202 return false; 203 203 }; 204 204 info.onMouseOut = delegate bool(Surface self, byte buttons, Vec2i coordinates) { 205 self.style.set("border-image: url('gui/skin/ clear2.png')");205 self.style.set("border-image: url('gui/skin/panel1.png')"); 206 206 return false; 207 207 }; trunk/src/demo2/main.d
r197 r198 11 11 12 12 import tango.text.convert.Format; 13 import tango. io.Stdout;13 import tango.math.Math; 14 14 import tango.io.device.File; 15 15 import derelict.sdl.sdl; … … 32 32 Scene scene = new Scene(); 33 33 scene.play(); 34 scene.backgroundColor = "gr een";34 scene.backgroundColor = "gray"; 35 35 36 36 // Ship … … 64 64 // For Testing 65 65 auto info = view.addChild(new Surface()); 66 info.style.set("top: 40px; left: 40px; width: 500px; height: 260px; padding: 3px; color: brown; " ~67 "border-width: 5px; border-image: url('gui/skin/clear2.png'); " ~68 "font-family: url('Vera.ttf'); text-align: right; opacity: .8; overflow: hidden");66 info.style.set("top: 40px; left: 40px; width: 500px; height: 260px; padding: 3px; color: #ff8800; " ~ 67 "border-width: 12px; border-image: url('gui/skin/panel1.png'); " ~ 68 "font-family: url('Vera.ttf'); text-align: center; opacity: .8; overflow: hidden"); 69 69 info.style.overflowX = Style.Overflow.HIDDEN; 70 70 info.style.overflowY = Style.Overflow.HIDDEN; … … 85 85 }; 86 86 info.onMouseOver = delegate bool(Surface self, byte buttons, Vec2i coordinates) { 87 self.style.set("border-image: url('gui/skin/clear3.png')");87 //self.style.set("border-image: url('gui/skin/panel2.png')"); 88 88 return false; 89 89 }; 90 90 info.onMouseOut = delegate bool(Surface self, byte buttons, Vec2i coordinates) { 91 self.style.set("border-image: url('gui/skin/clear2.png')");91 //self.style.set("border-image: url('gui/skin/panel1.png')"); 92 92 return false; 93 93 }; … … 108 108 // Rendering / Input Loop 109 109 int fps = 0; 110 Timer total = new Timer(true); 110 111 Timer frame = new Timer(true); 111 112 while(!System.isAborted()) … … 119 120 // Print framerate 120 121 fps++; 121 //info.style.transform = info.style.transform.move(Vec3f(-40, -40, 0)); 122 //info.style.transform *= Matrix().rotate(Vec3f(0, 0.0005, 0.0005)); 123 //info.style.transform = info.style.transform.move(Vec3f(40, 40, 0)); 122 info.style.transform = Matrix(); 123 info.style.transform = info.style.transform.move(Vec3f(-300, -20, 0)); 124 info.style.transform *= Matrix().rotate(Vec3f(0, sin(total.tell()/2)/2, sin(total.tell()/2)/5)); 125 info.style.transform = info.style.transform.move(Vec3f(300, 20, 0)); 124 126 125 127 126 if (frame.tell()>=.25f )128 if (frame.tell()>=.25f && !(Surface.getFocusSurface() is info)) 127 129 { 128 130 info.innerHtml = `In a <s>traditional</s> <span style="color: green; text-decoration: overline; font-size:40px">`~ … … 137 139 `Some metal type required in type-setting, such as varying sizes of inter-word spacing pieces and `~ 138 140 `line-width spacers, were not part of a specific font in pre-digital usage, but were separate, `~ 139 `generic pieces.[1] `~ Format.convert(` {} fps<br/>`, fps/frame.tell());141 `generic pieces.[1] `~ Format.convert(` {} fps<br/>`, fps/frame.tell()); 140 142 141 143 frame.seek(0); trunk/src/yage/gui/surface.d
r197 r198 34 34 Style style; 35 35 36 protected char[] text; /// This html text will be rendered inside the surface.36 //protected char[] text; /// This html text will be rendered inside the surface. 37 37 bool editable = false; /// The text of this surface is editable. 38 38 bool mouseChildren = true; /// Allow the mouse to interact with this Surface's children. … … 263 263 /// 264 264 public char[] innerHtml() 265 { return text ;265 { return textBlock.getHtml(); 266 266 } 267 267 /// ditto 268 268 public void innerHtml(char[] html) 269 { this.text = html;269 { //this.text = html; 270 270 textDirty = true; 271 Style cs = getComputedStyle(); 272 textBlock.update(html, cs, cast(int)width(), cast(int)height()); 271 273 } 272 274 … … 373 375 374 376 // Text 375 if ( text.length && (resizeDirty || textDirty))377 if (resizeDirty || textDirty) 376 378 { 377 379 int width = cast(int)width(); 378 380 int height = cast(int)height(); 379 381 380 textBlock.update(text, cs, width, height); 382 //textBlock.update(text, cs, width, height); 383 //textBlock.update(text, cs, width, height); 384 textBlock.update(textBlock.getHtml(), cs, width, height); 381 385 Image textImage = textBlock.render(cs, true, editable && focusSurface is this ? &textCursor : null); // TODO: Change true to Probe.NextPow2 382 assert(textImage !is null);383 386 384 if (!textTexture) // create texture on first go 385 textTexture = new Texture(textImage, Texture.Format.AUTO, false, "Surface Text", true); 386 else 387 textTexture.setImage(textImage); 388 textTexture.padding = Vec2i(nextPow2(width)-width, -(nextPow2(height)-height)); 387 if (textImage) 388 { if (!textTexture) // create texture on first go 389 textTexture = new Texture(textImage, Texture.Format.AUTO, false, "Surface Text", true); 390 else 391 textTexture.setImage(textImage); 392 textTexture.padding = Vec2i(nextPow2(width)-width, -(nextPow2(height)-height)); 393 } else 394 textTexture = null; 389 395 390 396 textDirty = false; 391 397 } 392 398 393 if (!text.length)394 textTexture = null;399 //if (!text.length) 400 // textTexture = null; 395 401 396 402 geometry.setColors(style.backgroundColor, style.borderColor, style.opacity); … … 480 486 * unicode = unicode value of pressed key. */ 481 487 void keyPress(int key, int mod=ModifierKey.NONE, dchar unicode=0) 482 { bool propagate = true; 488 { 489 bool propagate = true; 483 490 if(onKeyPress) 484 491 propagate = onKeyPress(this, key, mod); … … 487 494 { 488 495 textBlock.input(key, mod, unicode, textCursor, getComputedStyle()); 489 text = textBlock.toString(); // TODO: Do this lazily?490 496 textDirty = true; 491 497 } trunk/src/yage/gui/textblock.d
r197 r198 53 53 private ubyte[] imageLookaside; // TODO: Have the lookaside passed into Render 54 54 55 private char[] text;55 private char[] html; 56 56 package InlineStyle style; // base style of entire text block 57 57 private int width; … … 74 74 Vec2i result; 75 75 int line = cursorToLine(position); 76 //Log.trace(line, " ", position); 76 77 for (int i=0; i<line; i++) 77 78 result.y += lines[i].height; … … 102 103 * position = Character position from the beginning of the TextBlock 103 104 * After the function executes, this will be the position on the line returned. 104 * Returns: The line number. If position is after the last line, then the number of the last line +1is returned.*/105 * Returns: The line number. If position is after the last line, then the number of the last line is returned.*/ 105 106 int cursorToLine(inout int position) 106 107 { foreach (i, line; lines.data) 107 { if (position < line.letters.length)108 { if (position <= line.letters.length) 108 109 return i; 109 110 position -= line.letters.length; 110 111 } 111 return lines.length ;112 return lines.length-1; 112 113 } 113 114 … … 124 125 return position; 125 126 } 126 /* 127 // Get the x position in pixels of a character on a line. TODO: Also y. 128 int positionToX(int line, int position) 129 { assert (line < lines.length); 130 int x; 131 int last = min(lines[line].letters.length, position); 132 for (int i=0; i<last; i++) 133 x+= lines[line].letters[i].advanceX; 134 return x; 135 } 136 137 // Get the nearest character position on a line from an x poxition in pixels 138 int xToPosition(int line, int x) 139 { 140 for (int i=0; i<lines[line].letters.length; i++) 141 { x-= lines[line].letters[i].advanceX; 142 if (x<0) // TODO: More accurate rounding 143 return i; 144 } 145 } 146 */ 127 } 128 129 char[] getHtml() 130 { return html; 147 131 } 148 132 … … 158 142 { 159 143 style = InlineStyle(computedStyle); 144 //Log.trace(cursor.position, " " , letters.length); 160 145 assert(cursor.position <= letters.length); 161 146 … … 198 183 break; 199 184 case SDLK_DELETE: 200 if (cursor.position < letters.length) // doesn't work185 if (cursor.position < letters.length) 201 186 letters.splice(cursor.position, 1); 202 187 break; 203 188 // New letters 204 default: 189 default: 205 190 if (unicode) 206 191 { 192 if (unicode=='\r') 193 unicode='\n'; 194 //Log.trace(cast(int)unicode); 195 207 196 // Get the style to use for a new letter 208 197 InlineStyle *style; … … 219 208 cursor.position++; 220 209 } 221 break; 222 // TODO: selection, ctrl+a, z, x, c, v223 }224 225 210 break; 211 212 213 // TODO: click to position cursor, selection, ctrl+a, z, x, c, v 214 } 226 215 227 216 lines = lettersToLines(letters.data, width, lines); 228 229 //return toString(); 217 //Log.trace(lines.length); 230 218 } 231 219 … … 247 235 Image result; 248 236 249 if ( text.length)237 if (html.length || cursor) 250 238 { 251 239 // Get total height of all lines … … 272 260 273 261 foreach (letter; line.letters) 274 { InlineStyle* istyle = (cast(InlineStyle*)letter.extra); 262 { 263 if (letter.letter < 32) 264 continue; // skip non-printable letters. 265 266 InlineStyle* istyle = (cast(InlineStyle*)letter.extra); 275 267 276 268 // Calculate local coordinates … … 307 299 break; 308 300 } 309 }310 311 // Draw cursor312 if (cursor)313 { Vec2i xy = cursorToXy(cursor.position);314 int lineHeight = cast(int)style.lineHeight.toPx(0);315 if (letters.length)316 { //xy.x += letters[cursor.position].advanceX;317 int position = cursor.position; // copy318 int line = min(cursorToLine(position), lines.length-1);319 lineHeight = lines[line].height;320 }321 int hmin = max(0, xy.y), hmax = min(lineHeight+xy.y, height);322 int wmin = max(0, xy.x), wmax = min(xy.x+2, width);323 for (int h=hmin; h<hmax; h++)324 for (int w=wmin; w<wmax; w++)325 result[w, h] = style.color.ub;301 302 // Draw cursor 303 if (cursor) 304 { Vec2i xy = cursorToXy(cursor.position); 305 int lineHeight = cast(int)style.lineHeight.toPx(0); 306 if (letters.length) 307 { //xy.x += letters[cursor.position].advanceX; 308 int position = cursor.position; // copy 309 int line = min(cursorToLine(position), lines.length-1); 310 lineHeight = lines[line].height; 311 } 312 int hmin = max(0, xy.y), hmax = min(lineHeight+xy.y, height); 313 int wmin = max(0, xy.x), wmax = min(xy.x+2, width); 314 for (int h=hmin; h<hmax; h++) 315 for (int w=wmin; w<wmax; w++) 316 result[w, h] = style.color.ub; 317 } 326 318 } 327 319 … … 394 386 * Returns: True if the text will need to be re-rendered, false otherwise. 395 387 * TODO: Should this be a constructor to maintain RAII? */ 396 bool update(char[] text, Style style, int width, int height)388 bool update(char[] html, Style style, int width, int height) 397 389 { 398 390 InlineStyle istyle = InlineStyle(style); … … 400 392 // If text has changed 401 393 //bool newLetters = text != (*this).text || istyle != (*this).style; 402 bool newLetters = text != this.text|| istyle != this.style;394 bool newLetters = html != this.html || istyle != this.style; 403 395 if (newLetters) 404 396 { … … 406 398 letters.length = 0; 407 399 styles.length = 0; 408 HtmlParser.htmlToLetters( text, style, letters, styles);409 410 this. text = text;400 HtmlParser.htmlToLetters(html, style, letters, styles); 401 402 this.html = html; 411 403 this.style = istyle; 412 404 } … … 494 486 //line.xOffsets.resize(lineEnd); 495 487 496 if (line.letters[$-1].letter == '\n')497 line.letters.length = line.letters.length-1;488 //if (line.letters[$-1].letter == '\n') 489 // line.letters.length = line.letters.length-1; 498 490 499 491 // Calculate line.width trunk/src/yage/system/input.d
r195 r198 16 16 17 17 /** 18 * A class to handle keyboard, mouse, and eventually joystick input.18 * A static class to handle keyboard, mouse, and eventually joystick input. 19 19 * This polls SDL for input and passes it to the current surface. 20 20 * 21 21 * TODO: Ditch SDL! SDL requires input processing to be in the same thread as the renderer. 22 22 */ 23 class Input23 abstract class Input 24 24 { 25 25 public static int KEY_DELAY = 500; /// milliseconds before repeating a call to keyPress after holding a key down. … … 30 30 31 31 protected static SDL_keysym lastKeyDown; // Used for manual key-repeat. 32 protected static uint lastKeyDownTime ;32 protected static uint lastKeyDownTime = uint.max; 33 33 34 34 /** … … 60 60 if(focus) 61 61 focus.keyUp(event.key.keysym.sym, event.key.keysym.mod); 62 //focus.keyUp(event.key.keysym.unicode, event.key.keysym.mod);63 62 lastKeyDownTime = uint.max; 64 63 break; 64 65 65 // Mouse 66 66 case SDL_MOUSEBUTTONDOWN:
