浏览代码

selecting windows works now

naelstrof 7 年前
父节点
当前提交
bdd433c1f7
共有 3 个文件被更改,包括 17 次插入3 次删除
  1. 1
    0
      src/slop.cpp
  2. 12
    3
      src/slopstates.cpp
  3. 4
    0
      src/slopstates.hpp

+ 1
- 0
src/slop.cpp 查看文件

@@ -29,6 +29,7 @@ SlopMemory::SlopMemory( SlopOptions* options ) {
29 29
     state = (SlopState*)new SlopStart();
30 30
     nextState = NULL;
31 31
     rectangle = new Rectangle(glm::vec2(0,0), glm::vec2(0,0), options->borderSize, options->padding, glm::vec4( options->r, options->g, options->b, options->a ), options->highlight);
32
+    state->onEnter( *this );
32 33
 }
33 34
 
34 35
 SlopMemory::~SlopMemory() {

+ 12
- 3
src/slopstates.cpp 查看文件

@@ -11,15 +11,24 @@ void SlopState::update( SlopMemory& memory, double dt ) {
11 11
 void SlopState::draw( SlopMemory& memory, glm::mat4 matrix ) {
12 12
 }
13 13
 
14
-// Start
14
+void SlopStart::onEnter( SlopMemory& memory ) {
15
+    setStartPos = false;
16
+}
15 17
 void SlopStart::update( SlopMemory& memory, double dt ) {
16
-    if ( mouse->getButton( 1 ) ) {
17
-        memory.setState( (SlopState*)new SlopStartDrag( mouse->getMousePos() ) );
18
+    if ( mouse->getButton( 1 ) && !setStartPos ) {
19
+        startPos = mouse->getMousePos();
20
+        setStartPos = true;
21
+    }
22
+    if ( setStartPos && glm::distance( startPos, mouse->getMousePos() ) > 4 ) {
23
+        memory.setState( (SlopState*)new SlopStartDrag( startPos ) );
18 24
     }
19 25
     if ( mouse->hoverWindow != None ) {
20 26
         glm::vec4 rect = getWindowGeometry( mouse->hoverWindow, true );
21 27
         memory.rectangle->setPoints( glm::vec2( (float)rect.x, (float)rect.y ), glm::vec2( (float)rect.x+rect.z, (float)rect.y+rect.w ) );
22 28
     }
29
+    if ( setStartPos && !mouse->getButton( 1 ) ) {
30
+        memory.setState( (SlopState*)new SlopEndDrag() );
31
+    }
23 32
 }
24 33
 
25 34
 void SlopStart::draw( SlopMemory& memory, glm::mat4 matrix ) {

+ 4
- 0
src/slopstates.hpp 查看文件

@@ -38,7 +38,11 @@ public:
38 38
 };
39 39
 
40 40
 class SlopStart : SlopState {
41
+private:
42
+    bool setStartPos;
43
+    glm::vec2 startPos;
41 44
 public:
45
+    virtual void onEnter( SlopMemory& memory );
42 46
     virtual void update( SlopMemory& memory, double dt );
43 47
     virtual void draw( SlopMemory& memory, glm::mat4 matrix );
44 48
 };