Changeset 369
- Timestamp:
- 06/26/08 06:20:50 (5 months ago)
- Files:
-
- trunk/qd/SDL_ttf.d (modified) (1 diff)
- trunk/qd/dsss.conf (modified) (1 diff)
- trunk/qd/qd.d (modified) (7 diffs)
- trunk/qd/snake.d (added)
- trunk/qd/test2.d (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/qd/SDL_ttf.d
r350 r369 101 101 } body { 102 102 auto surfs = new Area[strings.length]; 103 scope(exit) foreach (surf; surfs) SDL_FreeSurface(surf.surface);103 scope(exit) foreach (surf; surfs) if (surf) SDL_FreeSurface(surf.surface); 104 104 int width, height; 105 105 foreach (i, str; strings) { trunk/qd/dsss.conf
r358 r369 31 31 # [test13.d] 32 32 # buildflags=-L-lSDL -L-lSDL_ttf -O -release -inline 33 [snake.d] 34 buildflags=-L-lSDL trunk/qd/qd.d
r358 r369 73 73 Escape = 27, 74 74 LCtrl = 306, 75 Up = 273, Down = 274, Right = 275, Left = 276 75 76 } 76 77 enum SDLMod { … … 112 113 void SDL_QuitSubSystem(uint flags); 113 114 const uint SDL_INIT_VIDEO = 0x00000020; 114 } 115 int SDL_Init(uint flags); 116 } 117 static this() { SDL_Init(SDL_INIT_VIDEO); } 115 118 116 119 import std.string: toStringz; … … 486 489 void circle(T...)(T t) { 487 490 static assert(T.length!<3, "Circle: Needs x, y and radius"); 488 int cx=cast(int)t[0], cy=cast(int)t[1] , radius=cast(int)t[2];491 int cx=cast(int)t[0], cy=cast(int)t[1]; float radius=cast(float)t[2]; 489 492 SDL_LockSurface(display.surface); 490 493 scope(exit) { SDL_UnlockSurface(display.surface); if (doFlip) flip; } … … 606 609 607 610 void updateMouse(int x, int y, ubyte button, int pushed) { 611 auto b = cast(Button) button; 608 612 mouse.pos = pt(x, y); 609 613 if (pushed == 1) { 610 mouse.pressed = true; 611 if (button == 1) mouse._leftclicked = true; 612 if (button == 3) mouse._rightclicked = true; 613 } 614 if (pushed == -1) mouse.pressed = false; 615 } 614 logln("pushed ", b); 615 mouse._pressed[b] = true; 616 } 617 if (pushed == -1) mouse._pressed[b] = false; 618 } 619 620 enum Button : ubyte { Left=1, Middle, Right, Extra1, Extra2 } 616 621 617 622 struct _mouse { 618 623 pt pos; 619 int x() { return pos.x; } int y() { return pos.y; } 620 bool _leftclicked, _rightclicked; 621 bool pressed; 622 bool clicked() { if (!_leftclicked) return false; _leftclicked = false; return true; } 623 bool rightclicked() { if (!_rightclicked) return false; _rightclicked = false; return true; } 624 int x() { return pos.x; } 625 int y() { return pos.y; } 626 bool pressed() { return pressed(Button.Left); } 627 bool pressed(Button b) { return _pressed[b]; } 628 bool[256] _pressed; 629 bool[256] was_pressed; 630 bool clicked() { return clicked(Button.Left); } 631 bool clicked(Button which) { if (!was_pressed[which]) return false; was_pressed[which] = false; return true; } 632 void down(Button b) { _pressed[b] = true; was_pressed[b] = true; } 633 void up(Button b) { _pressed[b] = false; } 624 634 } 625 635 … … 627 637 628 638 bool[int] keystate; 639 640 struct _key { 641 bool[int] key_pressed; 642 bool pressed(SDLKey which) { 643 int i = cast(int) which; 644 if (auto kp = i in key_pressed) { 645 auto res = *kp; 646 *kp = false; 647 return res; 648 } else return false; 649 } 650 } 651 652 _key key; 629 653 630 654 void delegate() onResize; … … 656 680 case SDL_EventType.KeyDown: 657 681 keystate[evt.key.keysym.sym] = true; 682 .key.key_pressed[evt.key.keysym.sym] = true; 658 683 if (key) key(evt.key.keysym.sym, true); 659 684 break; … … 746 771 bool opIn_r(T)(T vt) { return (vt.x>=tl.x && vt.x<=(tl.x+size.x)) && (vt.y>=tl.y && vt.y<=(tl.y+size.y)); } 747 772 Area select(int x, int y, int w=int.max, int h=int.max) { 748 if (w==int.max) w=size.x ;749 if (h==int.max) h=size.y ;773 if (w==int.max) w=size.x - x; 774 if (h==int.max) h=size.y - x; 750 775 return Area(tl+pt(x, y), pt(w, h), surface); 751 776 } trunk/qd/test2.d
r354 r369 57 57 bool runsMe() { foreach (thread; threads) if (thread.runsMe) return true; return false; } 58 58 } 59 60 StackThreadSched mouse_sched; 61 static this() { New(mouse_sched); } 59 62 60 63 import std.thread, tools.threads; … … 87 90 pt start, end; 88 91 void delegate(ref State)[State] tf=[ 89 State.inside: (ref State s) { if (mouse. button) start=mouse.pos; },90 State.drag_zoomin: (ref State s) { if (!mouse. button) end=mouse.pos; },91 State.drag_zoomout: (ref State s) { if (!mouse. button) end=mouse.pos; },92 State.inside: (ref State s) { if (mouse.pressed) start=mouse.pos; }, 93 State.drag_zoomin: (ref State s) { if (!mouse.pressed) end=mouse.pos; }, 94 State.drag_zoomout: (ref State s) { if (!mouse.pressed) end=mouse.pos; }, 92 95 State.doZoomin: (ref State s) { 93 96 T nfrom=myArea.locate(start, from, to), nto=myArea.locate(end, from, to); … … 109 112 } 110 113 ]; 111 tf.addBidirectionalEdge({ return (mouse in area) && !mouse. button; }, { return !(mouse in area); }, State.start, State.inside);114 tf.addBidirectionalEdge({ return (mouse in area) && !mouse.pressed; }, { return !(mouse in area); }, State.start, State.inside); 112 115 tf.addEdges( 113 { return mouse. button && mouse.which==1; }, State.inside, State.drag_zoomin,114 { return mouse. button && mouse.which==3; }, State.inside, State.drag_zoomout,115 { return !mouse. button; }, State.drag_zoomin, State.doZoomin,116 { return !mouse. button; }, State.drag_zoomout, State.doZoomout116 { return mouse.pressed(Button.Left); }, State.inside, State.drag_zoomin, 117 { return mouse.pressed(Button.Right); }, State.inside, State.drag_zoomout, 118 { return !mouse.pressed; }, State.drag_zoomin, State.doZoomin, 119 { return !mouse.pressed; }, State.drag_zoomout, State.doZoomout 117 120 ); 118 121 tf.runState(yield); … … 441 444 442 445 list!(Window) windows; 446 <<<<<<< .mine 447 this() { mouse_sched~=stackthread=&mousethr; } 448 ======= 443 449 // this() { mouse.sched~=stackthread=&mousethr; } 450 >>>>>>> .r368 444 451 void draw() { windows.each((Window w) { w.draw(); }); } 452 <<<<<<< .mine 453 void mousethr(proc yield) { 454 assert(mouse_sched.runsMe); 455 ======= 445 456 /*void mousethr(proc yield) { 446 457 // assert(mouse.sched.runsMe); 458 >>>>>>> .r368 447 459 enum State { start, title_inside, title_dragging, resize_inside, resize_dragging } 448 460 pt lastpos; … … 454 466 windows.each_reverse((size_t id, ref Window w, proc brk) { 455 467 if (mouse.pos in w.area) { 456 if (mouse. button) {468 if (mouse.pressed) { 457 469 newActive=id; // make current 458 470 if (s==State.start && (w is windows.top)) w.motion(); … … 478 490 ]; 479 491 transitions.addBidirectionalEdges( 480 { return mouseInTitle && !mouse. button; }, { return !mouseInTitle; }, State.start, State.title_inside,481 { return mouseInBox && !mouse. button; }, { return !mouseInBox; }, State.start, State.resize_inside,482 { return mouse. button; }, State.title_inside, State.title_dragging,483 { return mouse. button; }, State.resize_inside, State.resize_dragging492 { return mouseInTitle && !mouse.pressed; }, { return !mouseInTitle; }, State.start, State.title_inside, 493 { return mouseInBox && !mouse.pressed; }, { return !mouseInBox; }, State.start, State.resize_inside, 494 { return mouse.pressed; }, State.title_inside, State.title_dragging, 495 { return mouse.pressed; }, State.resize_inside, State.resize_dragging 484 496 ); 485 497 transitions.runState(yield); … … 568 580 events; 569 581 countFPS(); 570 } 571 } 582 mouse_sched (); 583 } 584 }
