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
|
//aim:
//----------------------header files---------------------------------------------
#include <iostream>
#include <cstdlib>
#include <SFML/Graphics.hpp>
//----------------------namespaces-----------------------------------------------
using namespace std;
//------------globals/functions'n'classes-prototypes-----------------------------
//-------------------------code--------------------------------------------------
int main()
{
sf::RenderWindow winMainWindow;
sf::Shape mwCircle1;
winMainWindow.Create(sf::VideoMode(800,600,32),"Prog 5 - Main Window");
while(winMainWindow.IsOpened())
{
static sf::Event eventMainWindow;
static const sf::Input& inputMainWindow=winMainWindow.GetInput();
static bool bIsDrawing=false;
static int circle1X, circle1Y, circle1Radius, circle1Temp;
while(winMainWindow.GetEvent(eventMainWindow))
{
if(eventMainWindow.Type==sf::Event::Closed)
{
winMainWindow.Close();
}
if(eventMainWindow.Type==sf::Event::MouseButtonPressed &&
eventMainWindow.MouseButton.Button==sf::Mouse::Left && !bIsDrawing)
{
bIsDrawing=true;
circle1X=eventMainWindow.MouseButton.X;
circle1Y=eventMainWindow.MouseButton.Y;
circle1Temp=circle1X;
circle1Radius=0;
}
if(bIsDrawing)
{
circle1X=inputMainWindow.GetMouseX();
circle1Radius=(circle1X-circle1Temp);
mwCircle1.Circle(circle1X,circle1Y,circle1Radius,sf::Color(255,0,255));
winMainWindow.Clear();
winMainWindow.Draw(mwCircle1);
}
if(eventMainWindow.Type==sf::Event::MouseButtonReleased &&
eventMainWindow.MouseButton.Button==sf::Mouse::Left)
{
bIsDrawing=false;
}
}
mwCircle1.Circle(100,100,100,sf::Color(255,0,255)); //this is just to test the function but it still doesn't work?!?
winMainWindow.Draw(mwCircle1);
winMainWindow.Display();
}
return 0;
}
|