void brush(int x1,int y1) { int x2,y2; int button=0; setcolor(c); mousecall(); mousepos(button,x2,y2); do { if(button==1) { static int v1=0,v2=0,v3=0,v4=0; hidemouse(); line(x1,y1,x2,y2); if(v1!=x1 || v2!=y1 || v3!=y2 || v4!=x2) { fout<<"line("<<x1<<','<<y1<<','<<x2<<','<<y2<<");\n"; v1=x1,v2=y1,v3=y2,v4=x2; } mousecall(); x1=x2,y1=y2; } else mousepos(button,x1,y1); mousepos(button,x2,y2); }while(x2>43 && x2<597 && y2>63 && y2<457); }
/* thoingggg!! "message for you sir!!!" */ static LRESULT CALLBACK patsy(HWND wh, UINT msg, WPARAM wp, LPARAM lp) /* "WndProc" */ { /* printf("msg %d\n", msg); */ switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_MOUSEMOVE: if (wp & (MK_LBUTTON|MK_MBUTTON|MK_RBUTTON)) { #ifdef SWITCH_CURSORS if (ws_lp_x == -1 && !display_tablet) SetCursor(cross); #endif mousepos(lp); } #ifdef SWITCH_CURSORS else if (ws_lp_x != -1 && !display_tablet) SetCursor(arrow); #endif break; /* return?? */ case WM_LBUTTONDOWN: display_lp_sw = 1; case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: #ifdef SWITCH_CURSORS if (!display_tablet) SetCursor(cross); #endif mousepos(lp); break; /* return?? */ case WM_LBUTTONUP: display_lp_sw = 0; case WM_MBUTTONUP: case WM_RBUTTONUP: #ifdef SWITCH_CURSORS if (!display_tablet) SetCursor(arrow); #endif ws_lp_x = ws_lp_y = -1; break; /* return?? */ case WM_KEYDOWN: keydown(wp); break; case WM_KEYUP: keyup(wp); break; case WM_PAINT: display_repaint(); break; /* return?? */ } return DefWindowProc(wh, msg, wp, lp); }
void fillp() { int a[2]; int x,y,button; setcolor(c); hidemouse(); rectangle(42,62,598,458); mousecall(); mousepos(button,x,y); if(button==1) { setfillstyle(cc,c); a[0]=x; a[1]=y; static int v1=0,v2=0; hidemouse(); floodfill(a[0],a[1],c); if(v1!=a[0] || v2!=a[1]) { fout<<"floodfill("<<a[0]<<','<<a[1]<<','<<c<<");\n"; v1=a[0],v2=a[1]; } mousecall(); } }
int main() { initgraph(640, 480); setfont(18, 0, "宋体"); int k = 0; // 这个循环,is_run判断窗口是否还在,delay_fps是延时 // 后面讲动画的时候会详细讲解,现不要在此纠结 for ( ; is_run(); delay_fps(60)) { char str[32]; int x, y; //获取鼠标坐标,此函数不等待。若鼠标移出了窗口,那么坐标值不会更新 //特殊情况是,你按着鼠标键不放,拖出窗口,这样坐标值会依然更新 mousepos(&x, &y); //格式化输出为字符串,用于后面输出 sprintf(str, "%4d %4d", x, y); outtextxy(0, 0, str); } closegraph(); return 0; }
int mouse(int type) { int x=0,y=0; mousepos(&x,&y); if(type==X) return x; if(type==Y) return y; return 0; }
void EditableBezier::mousePressed(ofMouseEventArgs &e) { ofPoint mousepos(e.x,e.y); if(!editable) return; if(start.distance(mousepos)<handleSize) { startDragging = true; } else if(c1.distance(mousepos)<handleSize) { c1Dragging = true; } else if(c2.distance(mousepos)<handleSize) { c2Dragging = true; } else if(end.distance(mousepos)<handleSize) { endDragging = true; } lastMousePos = mousepos; }
void EditableBezier::mouseDragged(ofMouseEventArgs &e) { ofPoint mousepos(e.x,e.y); if(!editable) return; ofPoint diff = mousepos - lastMousePos; if(startDragging) { start+=diff; } if(c1Dragging || startDragging) { c1+=diff; } if(c2Dragging || endDragging) { c2+=diff; } if(endDragging) { end+=diff; } lastMousePos = mousepos; }
void eraser() { bar(15); setfillstyle(SOLID_FILL,15); int button,x,y; mousepos(button,x,y); if(button==1 && x>48&&x<592&&y<452&&y>68) { static int v1=0,v2=0; hidemouse(); pieslice(x, y, 0, 360, 6); if(v1!=x ||v2!=y) { fout<<"pieslice("<<x<<','<<y<<','<<"0,360,6);\n"; v1=x,v2=y; } mousecall(); } }
void CSSceneNodeAnimatorFPS::animateNode(ISceneNode* node, u32 timeMs) { if (!node || node->getType() != ESNT_CAMERA) return; ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node); if (firstUpdate) { camera->updateAbsolutePosition(); if (CursorControl) { CursorControl->setPosition(m_CursorOffsetX, m_CursorOffsetY); CursorPos = CenterCursor = CursorControl->getRelativePosition(); } LastAnimationTime = timeMs; firstUpdate = false; } // If the camera isn't the active camera, and receiving input, then don't process it. if (!camera->isInputReceiverEnabled()) { firstInput = true; return; } if (firstInput) { allKeysUp(); firstInput = false; } scene::ISceneManager * smgr = camera->getSceneManager(); if (smgr && smgr->getActiveCamera() != camera) return; // get time f32 timeDiff = (f32)(timeMs - LastAnimationTime); LastAnimationTime = timeMs; // update position core::vector3df pos = camera->getPosition(); // Update rotation core::vector3df target = (camera->getTarget() - camera->getAbsolutePosition()); core::vector3df relativeRotation = target.getHorizontalAngle(); if (CursorControl) { if (CursorPos != CenterCursor) { relativeRotation.Y -= (m_CursorOffsetX - CursorPos.X) * RotateSpeed; relativeRotation.X -= (m_CursorOffsetY - CursorPos.Y) * RotateSpeed * MouseYDirection; // X < MaxVerticalAngle or X > 360-MaxVerticalAngle if (relativeRotation.X > MaxVerticalAngle * 2 && relativeRotation.X < 360.0f - MaxVerticalAngle) { relativeRotation.X = 360.0f - MaxVerticalAngle; } else if (relativeRotation.X > MaxVerticalAngle && relativeRotation.X < 360.0f - MaxVerticalAngle) { relativeRotation.X = MaxVerticalAngle; } // Do the fix as normal, special case below // reset cursor position to the centre of the window. CursorControl->setPosition(m_CursorOffsetX, m_CursorOffsetY); CenterCursor = CursorControl->getRelativePosition(); // needed to avoid problems when the event receiver is disabled CursorPos = CenterCursor; } // Special case, mouse is whipped outside of window before it can update. video::IVideoDriver* driver = smgr->getVideoDriver(); core::vector2d<u32> mousepos(u32(CursorControl->getPosition().X), u32(CursorControl->getPosition().Y)); core::rect<u32> screenRect(0, 0, driver->getScreenSize().Width, driver->getScreenSize().Height); // Only if we are moving outside quickly. bool reset = !screenRect.isPointInside(mousepos); if (reset) { // Force a reset. CursorControl->setPosition(m_CursorOffsetX, m_CursorOffsetY); CenterCursor = CursorControl->getRelativePosition(); CursorPos = CenterCursor; } } // set target target.set(0, 0, core::max_(1.f, pos.getLength())); core::vector3df movedir = target; core::matrix4 mat; mat.setRotationDegrees(core::vector3df(relativeRotation.X, relativeRotation.Y, 0)); mat.transformVect(target); if (NoVerticalMovement) { mat.setRotationDegrees(core::vector3df(0, relativeRotation.Y, 0)); mat.transformVect(movedir); } else { movedir = target; } movedir.normalize(); if (CursorKeys[EKA_MOVE_FORWARD]) pos += movedir * timeDiff * MoveSpeed; if (CursorKeys[EKA_MOVE_BACKWARD]) pos -= movedir * timeDiff * MoveSpeed; // strafing core::vector3df strafevect = target; strafevect = strafevect.crossProduct(camera->getUpVector()); if (NoVerticalMovement) strafevect.Y = 0.0f; strafevect.normalize(); if (CursorKeys[EKA_STRAFE_LEFT]) pos += strafevect * timeDiff * MoveSpeed; if (CursorKeys[EKA_STRAFE_RIGHT]) pos -= strafevect * timeDiff * MoveSpeed; // For jumping, we find the collision response animator attached to our camera // and if it's not falling, we tell it to jump. if (CursorKeys[EKA_JUMP_UP]) { const ISceneNodeAnimatorList& animators = camera->getAnimators(); ISceneNodeAnimatorList::ConstIterator it = animators.begin(); while (it != animators.end()) { if (ESNAT_COLLISION_RESPONSE == (*it)->getType()) { ISceneNodeAnimatorCollisionResponse * collisionResponse = static_cast<ISceneNodeAnimatorCollisionResponse *>(*it); if (!collisionResponse->isFalling()) collisionResponse->jump(JumpSpeed); } it++; } } // write translation camera->setPosition(pos); // write right target target += pos; camera->setTarget(target); }
void CSceneNodeAnimatorCameraFPS::animateNode(IDummyTransformationSceneNode* node, uint32_t timeMs) { if (!node || node->getType() != ESNT_CAMERA) return; ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node); if (firstUpdate) { camera->updateAbsolutePosition(); if (CursorControl ) { CursorControl->setPosition(0.5f, 0.5f); CursorPos = CenterCursor = CursorControl->getRelativePosition(); } LastAnimationTime = timeMs; firstUpdate = false; } // If the camera isn't the active camera, and receiving input, then don't process it. if(!camera->isInputReceiverEnabled()) { firstInput = true; return; } if ( firstInput ) { allKeysUp(); firstInput = false; } scene::ISceneManager * smgr = camera->getSceneManager(); if(smgr && smgr->getActiveCamera() != camera) return; // get time float timeDiff = (float) ( timeMs - LastAnimationTime ); LastAnimationTime = timeMs; // update position core::vector3df pos = camera->getPosition(); // Update rotation core::vector3df target = (camera->getTarget() - camera->getAbsolutePosition()); core::vector3df relativeRotation = target.getHorizontalAngle(); if (CursorControl) { if (CursorPos != CenterCursor) { relativeRotation.Y -= (0.5f - CursorPos.X) * RotateSpeed; relativeRotation.X -= (0.5f - CursorPos.Y) * RotateSpeed * MouseYDirection; // X < MaxVerticalAngle or X > 360-MaxVerticalAngle if (relativeRotation.X > MaxVerticalAngle*2 && relativeRotation.X < 360.0f-MaxVerticalAngle) { relativeRotation.X = 360.0f-MaxVerticalAngle; } else if (relativeRotation.X > MaxVerticalAngle && relativeRotation.X < 360.0f-MaxVerticalAngle) { relativeRotation.X = MaxVerticalAngle; } // Do the fix as normal, special case below // reset cursor position to the centre of the window. CursorControl->setPosition(0.5f, 0.5f); CenterCursor = CursorControl->getRelativePosition(); // needed to avoid problems when the event receiver is disabled CursorPos = CenterCursor; } // Special case, mouse is whipped outside of window before it can update. video::IVideoDriver* driver = smgr->getVideoDriver(); core::vector2d<uint32_t> mousepos(uint32_t(CursorControl->getPosition().X), uint32_t(CursorControl->getPosition().Y)); core::rect<uint32_t> screenRect(0, 0, driver->getScreenSize().Width, driver->getScreenSize().Height); // Only if we are moving outside quickly. bool reset = !screenRect.isPointInside(mousepos); if(reset) { // Force a reset. CursorControl->setPosition(0.5f, 0.5f); CenterCursor = CursorControl->getRelativePosition(); CursorPos = CenterCursor; } } // set target target.set(0,0, core::max_(1.f, pos.getLength())); core::vector3df movedir = target; core::matrix4x3 mat; mat.setRotationDegrees(core::vector3df(relativeRotation.X, relativeRotation.Y, 0)); mat.transformVect(&target.X); if (NoVerticalMovement) { mat.setRotationDegrees(core::vector3df(0, relativeRotation.Y, 0)); mat.transformVect(&movedir.X); } else { movedir = target; } movedir.normalize(); if (CursorKeys[EKA_MOVE_FORWARD]) pos += movedir * timeDiff * MoveSpeed; if (CursorKeys[EKA_MOVE_BACKWARD]) pos -= movedir * timeDiff * MoveSpeed; // strafing core::vector3df strafevect = target; strafevect = strafevect.crossProduct(camera->getUpVector()); if (NoVerticalMovement) strafevect.Y = 0.0f; strafevect.normalize(); if (CursorKeys[EKA_STRAFE_LEFT]) pos += strafevect * timeDiff * MoveSpeed; if (CursorKeys[EKA_STRAFE_RIGHT]) pos -= strafevect * timeDiff * MoveSpeed; // write translation camera->setPosition(pos); // write right target target += pos; camera->setTarget(target); }
void Mouse(char ch) { if(ch=='o') bar(0); else if(ch=='n') { setfillstyle(SOLID_FILL,15); hidemouse(); bar(42,62,598,458); mousecall(); setcolor(c); bar(c); } int cl,x5,y5,tool; int x1=604,y1=70,z=616,w=84; setfillstyle(cc,c); bar(12,290,27,310); //fillp show bar do { if(ch=='n') { ch='k'; if(tool==4) fout<<"setfillstyle(SOLID_FILL,"<<c<<");\n"; else if(tool==1) fout<<"setfillstyle(SOLID_FILL,15);\n"; else if(tool==6) fout<<"setfillstyle("<<cc<<','<<c<<");\n"; fout<<"setcolor("<<c<<");\n"; fout<<"rectangle(42,62,598,458);\n"; } mousecall(); x1=604,y1=70,z=616,w=84; for(int i=0;i<8;i++,y1+=25,w+=25) { mousepos(cl,x5,y5); if(x5>=x1&&x5<=z&&y5>=y1&&y5<=w) if(cl==1) { static int v=1; if(v!=c) { fout<<"setfillstyle(SOLID_FILL,"<<c<<");\n"; fout<<"setcolor("<<c<<");\n"; fout<<"rectangle(42,62,598,458);\n"; v=c; } c=i; setfillstyle(cc,c); bar(12,290,27,310); setfillstyle(SOLID_FILL,c); } } x1=621,y1=70,z=633,w=84; for( i=8;i<16;i++,y1+=25,w+=25) { mousepos(cl,x5,y5); if(x5>=x1&&x5<=z&&y5>=y1&&y5<=w) if(cl==1) { static int v=0; c=i; setfillstyle(cc,c); bar(12,290,27,310); setfillstyle(SOLID_FILL,c); if(v!=c) { fout<<"setfillstyle(SOLID_FILL,"<<c<<");\n"; fout<<"setcolor("<<c<<");\n"; fout<<"rectangle(42,62,598,458);\n"; v=c; } } } x1=605,y1=320,z=637,w=457; for(i=7;i<11;i++,y1+=25,w+=25) { mousepos(cl,x5,y5); if(x5>=x1&&x5<=z&&y5>=y1&&y5<=w) if(cl==1) { static int v=0; cc=i; setfillstyle(cc,c); bar(12,290,27,310); if(v!=cc) { fout<<"setfillstyle("<<cc<<','<<c<<");\n"; v=cc; } } } x1=5,y1=320,z=37,w=457; for(i=2;i<7;i++,y1+=25,w+=25) { mousepos(cl,x5,y5); if(x5>=x1&&x5<=z&&y5>=y1&&y5<=w) if(cl==1) { static int v=0; cc=i; setfillstyle(cc,c); bar(12,290,27,310); if(v!=cc) { fout<<"setfillstyle("<<cc<<','<<c<<");\n"; v=cc; } } } bar(c); delay(100); mousepos(cl,x5,y5); if(x5>=621&&x5<=635&&y5>=3&&y5<=16) //changes made !!! { if(cl==1) { hidemouse(); break; } } mousepos(cl,x5,y5); int gg=0; gg=help_bar(gg); while(x5>=24&&x5<=36&&y5>=70&&y5<=84) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"RECTANGLE "); gg=1; if(cl==1) { tool=0; } } gg=help_bar(gg); static int er=1; mousepos(cl,x5,y5); while(x5>=6&&x5<=18&&y5>=145&&y5<=159) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"ERASER "); gg=1; if(cl==1 && er==1) { tool=1; bar(15); fout<<"setfillstyle(SOLID_FILL,15);\n"; fout<<"setcolor(15);\n"; er=2; } } if(tool!=1) { bar(c); er=1; } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=6&&x5<=18&&y5>=70&&y5<=84) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"LINE"); gg=1; if(cl==1) { tool=2; } } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=6&&x5<=18&&y5>=90&&y5<=109) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"CIRCLE"); gg=1; if(cl==1) { tool=3; } } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=24&&x5<=36&&y5>=120&&y5<=134) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"BUCKET"); gg=1; if(cl==1) { if(cc!=1) { fout<<"setfillstyle(SOLID_FILL,"<<c<<");\n"; cc=1; } tool=4; } } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=24&&x5<=36&&y5>=90&&y5<=109) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); outtextxy(45,464,"BRUSH "); gg=1; if(cl==1) { tool=5; } } gg=help_bar(gg); mousepos(cl,x5,y5); while(x5>=6&&x5<=18&&y5>=120&&y5<=134) { mousepos(cl,x5,y5); setcolor(0); settextstyle(SMALL_FONT,0,4); gg=1; outtextxy(45,464,"FILLER"); if(cl==1) { tool=6; } } gg=help_bar(gg); mousepos(cl,x5,y5); static int v=0; if(x5>39 && x5<78 && y5>=42 && y5<=55) //save { if(cl==1) { char f[20]; hidemouse(); SBMP("temp.bmp"); if(op('b')) { strcpy(f,s); if(!strchr(f,'.')) strcat(f,".bmp"); int check; check=rename("temp.bmp",f); if(check==-1) { remove(f); rename("temp.bmp",f); } } if(v==0) { if(op('c')) { v=1; if(!strchr(s,'.')) strcat(s,".cpp"); strcpy(::f,s); } else if(bmp("temp.bmp",0,0)) {} else bmp(f,0,0); } if(bmp(f,0,0)); else bmp("temp.bmp",0,0); mousecall(); } } mousepos(cl,x5,y5); if(x5>=10 && x5<39 && y5>=42 && y5<=55) //open { if(cl==1) { hidemouse(); SBMP("temp.bmp"); if(op('o')) { if(!strchr(s,'.')) strcat(s,".bmp"); if(bmp(s,0,0)) { settextstyle(2,0,7); cleardevice(); setcolor(RED); outtextxy(200,220," SUCH FILE DOES NOT EXIST"); outtextxy(200,280,"PRESS ENTER TO CONTINUE:"); getch(); bmp("temp.bmp",0,0); } } else bmp("temp.bmp",0,0); mousecall(); } } mousepos(cl,x5,y5); if(x5>78 && x5<111 && y5>=42 && y5<=55) //new { if(cl==1) { v=0; main('n'); } } mousepos(cl,x5,y5); if(x5>111 && x5<174 && y5>=42 && y5<=55) //password change { if(cl==1) { hidemouse(); SBMP("temp.bmp"); if(op('p')) { ofstream fout("pass.txt"); char t[20]; for(int m=0;s[m]!='\0';m++) { t[m]=s[m]-27; } t[m]='\0'; fout<<t; fout.close(); } bmp("temp.bmp",0,0); mousecall(); } } mousepos(cl,x5,y5); if(x5>174 && x5<217 && y5>=42 && y5<=55) //help { if(cl==1) { hidemouse(); SBMP("temp.bmp"); help(); bmp("temp.bmp",0,0); mousecall(); } } while(x5>43 && x5<597 && y5>63 && y5<457) { mousepos(cl,x5,y5); mousecall(); if(cl==1 && x5>43 && x5<597 && y5>63 && y5<457 ) { double a,b,p,x1,y1,x2,y2; static int v1=0,v2=0,v3=0,v4=0; double r; switch(tool) { case 0://rectangle mousecall(); x1=x5; y1=y5; delay(500); restrict(43,597,63,457); mousepos(cl,x5,y5); x2=x5,y2=y5; setcolor(c); hidemouse(); rectangle(x1,y1,x2,y2); if(v1!=x1 || v2!=x2 || v3!=y1 || v4!=y2) { fout<<"rectangle("<<x1<<','<<y1<<','<<x2<<','<<y2<<");\n"; v1=x1,v2=x2,v3=y1,v4=y2; } mousecall(); restrict(0,640,0,480); break; case 1:eraser(); break; case 2://line(); mousecall(); x1=x5; y1=y5; delay(500); restrict(43,597,63,457); mousepos(cl,x5,y5); x2=x5,y2=y5; setcolor(c); hidemouse(); line(x1,y1,x2,y2); if(v1!=x1 || v2!=x2 || v3!=y1 || v4!=y2) { fout<<"line("<<x1<<','<<y1<<','<<x2<<','<<y2<<");\n"; v1=x1,v2=x2,v3=y1,v4=y2; } mousecall(); restrict(0,640,0,480); break; case 3://circle(); mousecall(); x1=x5; y1=y5; delay(500); restrict(43,597,63,457); mousepos(cl,x5,y5); x2=x5,y2=y5; a=(x1-x2)*(x1-x2),b=(y1-y2)*(y1-y2); p=a+b; r=SQRT(p); setcolor(c); int c1=x1+r,c2=x1-r,c3=y1+r,c4=y1-r; hidemouse(); circle(x1,y1,r); if(v1!=x1 || v2!=y1) { fout<<"circle("<<x1<<','<<y1<<','<<r<<");\n"; v1=x1,v2=y1; } if(c1>597 || c2<43 || c3>457 || c4<63) SCREEN(); mousecall(); restrict(0,640,0,480); break; case 4:bucket(); break; case 5:brush(x5,y5); break; case 6:fillp(); break; default:brush(x5,y5); } } } }while(1); }
void getmouse(int *x, int *y, int *key) { mousepos(x, y); *key = keystate(key_mouse_l); }
// Poll Events void Game::PollEvents() { // For every passive tool and the current tool. int toolcount = passivetools.size(); if (currentTool >= 0 && currentTool < tools.size()) toolcount++; Tool** tools = new Tool*[toolcount]; for (int i = 0; i < passivetools.size(); ++i) { tools[i] = passivetools[i]; } if (toolcount > passivetools.size()) tools[passivetools.size()] = GetToolList()[currentTool]; // Keep track of the last mouse position. static sf::Vector2i lastmousepos = sf::Mouse::getPosition(window); // Handle events sf::Event event; while (window.pollEvent(event)) { // Window closed or escape key pressed : exit if ((event.type == sf::Event::Closed) || ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))) { window.close(); break; } else if (event.type == sf::Event::Resized) { OnResize(event.size.width, event.size.height); } // Pause / Unpause physics if (event.type == sf::Event::KeyReleased) { if (event.key.code == sf::Keyboard::Space) { SetPhysicsActive(!GetPhysiscActive()); } } // Process the event with gwen. if (!gwenInput.ProcessMessage(event)) { // Make sure this message is relevant. if (event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::MouseButtonReleased) { // Figure out the position sf::Vector2i mousepos(event.mouseButton.x, event.mouseButton.y); // Convert to world coordinates. sf::Vector2f pos = window.mapPixelToCoords(mousepos); // Get entity at a position Entity* entity = GetEntityAt(pos); // Loop through each tool. for (int i = 0; i < toolcount; ++i) { // Report to the tool. if (event.type == sf::Event::MouseButtonPressed) { tools[i]->OnPress(entity, pos, event.mouseButton.button); // Add event. toolevents.push_back(ToolEvent(ToolEvent::PRESS, event.mouseButton.button, pos, currentTool)); } if (event.type == sf::Event::MouseButtonReleased) { tools[i]->OnRelease(entity, pos, event.mouseButton.button); // Add event. toolevents.push_back(ToolEvent(ToolEvent::RELEASE, event.mouseButton.button, pos, currentTool)); } } } // Detect drags if (event.type == sf::Event::MouseMoved) { for (int i = 0; i < toolcount; ++i) { // Get how much the mouse moved. sf::Vector2i delta = sf::Vector2i(event.mouseMove.x, event.mouseMove.y) - lastmousepos; sf::Vector2f deltaf(delta.x, delta.y); // Check if any mouse button is pressed. if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) { tools[i]->OnDrag(deltaf, sf::Mouse::Button::Left); // Add event. toolevents.push_back(ToolEvent(ToolEvent::DRAG, sf::Mouse::Button::Left, deltaf, currentTool)); } if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Middle)) { tools[i]->OnDrag(deltaf, sf::Mouse::Button::Middle); // Add event. toolevents.push_back(ToolEvent(ToolEvent::DRAG, sf::Mouse::Button::Middle, deltaf, currentTool)); } if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Right)) { tools[i]->OnDrag(deltaf, sf::Mouse::Button::Right); // Add event. toolevents.push_back(ToolEvent(ToolEvent::DRAG, sf::Mouse::Button::Right, deltaf, currentTool)); } } } // Detect scrolling if (event.type == sf::Event::MouseWheelMoved) { for (int i = 0; i < toolcount; ++i) { tools[i]->OnScroll(event.mouseWheel.delta); } } } } // Update the mouse pos. lastmousepos = sf::Mouse::getPosition(window); // Delete tool list delete tools; }
void EditableBezier::mouseReleased(ofMouseEventArgs &e) { ofPoint mousepos(e.x,e.y); if(!editable) return; startDragging = c1Dragging = c2Dragging = endDragging = false; }