public
Last active

  • Download Gist
gistfile1.dart
Dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
import 'dart:html';
 
class Window {
DivElement baseWindowDiv;
DivElement baseWindowTitleDiv;
num windowX;
num windowY;
num deltaX;
num deltaY;
void init() {
 
baseWindowDiv = new DivElement();
baseWindowDiv.$dom_className = "base-window";
baseWindowTitleDiv = new DivElement();
baseWindowTitleDiv.$dom_className = "base-window-title";
baseWindowTitleDiv.text = "Привет Мое окошео";
baseWindowDiv.append(baseWindowTitleDiv);
baseWindowTitleDiv.on.mouseDown.add((MouseEvent event) => saveWindowXY(event));
baseWindowTitleDiv.on.mouseUp.add((MouseEvent event) => stopMoveEvent(event));
DivElement baseWindowBodyDiv = new DivElement();
baseWindowBodyDiv.$dom_className = "base-window-body";
baseWindowBodyDiv.text = "Привет Body окошка";
baseWindowDiv.append(baseWindowBodyDiv);
DivElement baseWindowResizeDiv = new DivElement();
baseWindowResizeDiv.$dom_className = "base-window-resize-div";
baseWindowDiv.append(baseWindowResizeDiv);
}
void saveWindowXY(MouseEvent event) {
num mouseX = event.pageX;
num mouseY = event.pageY;
windowX = baseWindowDiv.offsetLeft;
windowY = baseWindowDiv.offsetTop;
deltaX = windowX - mouseX;
deltaY = windowY - mouseY;
document.on.mouseMove.add((MouseEvent event) => runMoveEvent(event));
}
void stopMoveEvent(MouseEvent event) {
print('stopMoveEvent call');
document.on.mouseMove.remove((MouseEvent event) => runMoveEvent(event));//does not work!
}
void runMoveEvent(MouseEvent event) {
num x = event.pageX;
num y = event.pageY;
num newX = deltaX + x;
num newY = deltaY + y;
 
StringBuffer bufferStrX = new StringBuffer();
bufferStrX.add(newX.toString());
bufferStrX.add("px");
StringBuffer bufferStrY = new StringBuffer();
bufferStrY.add(newY.toString());
bufferStrY.add("px");
baseWindowDiv.style.left = bufferStrX.toString();
baseWindowDiv.style.top = bufferStrY.toString();
}
void show() {
document.body.elements.add(baseWindowDiv);
}
}
 
void main() {
Window w = new Window();
w.init();
w.show();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.