Question: Create a C++ file using the template below that does the following: Pressing the number keys 1 through 8 allows you to draw in a
Create a C++ file using the template below that does the following:
- Pressing the number keys 1 through 8 allows you to draw in a different color.
- Use the Static Public Attributes of the sf::Color class so that:
- 1 = Black
- 2 = White
- 3 = Red
- 4 = Green
- 5 = Blue
- 6 = Yellow
- 7 = Magenta
- 8 = Cyan
- Pressing the space key will clear the canvas to the last color you have seleted.
- When a the mouse is pressed and a user left-clicks (i.e. on the pressed event, not released) a pixel color will change wherever the mouse is located. I should be able to drag and draw over the canvas like a pencil on paper.
---------------------------------------------------------------------- #include #include #include #include #include
int main(){ sf::RenderWindow window(sf::VideoMode(600,400), "Mini-Paint alpha version",sf::Style::Titlebar); window.setVerticalSyncEnabled(true); sf::Image image; image.create(600,400, sf::Color::White); sf::Texture texture; texture.loadFromImage(image); sf::Sprite sprite; sprite.setTexture(texture);
while(window.isOpen()){ sf::Event event; while(window.pollEvent(event)){ if(event.type == sf::Event::Closed){ window.close(); exit(EXIT_SUCCESS); }
if(event.type == sf::Event::KeyReleased){ std::cout << "Key Pressed" << std::endl; if(event.key.code == sf::Keyboard::Escape){ std::cout << "escape Pressed" << std::endl; window.close(); exit(EXIT_SUCCESS); } if(event.key.code == sf::Keyboard::1){ std::cout << "1 = Black" << std::endl; (sf::Color::Black);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
