Skip to content

Commit d0b67dc

Browse files
committed
add basic window generation
1 parent ab3ccb6 commit d0b67dc

File tree

8 files changed

+125
-1
lines changed

8 files changed

+125
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode
2+
build

CMakeLists.txt

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
# Set the project name and version
4+
project(Piano VERSION 1.0.0)
5+
6+
# Set C++ standard
7+
set(CMAKE_CXX_STANDARD 11)
8+
set(CMAKE_CXX_EXTENSIONS OFF)
9+
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
10+
11+
# Enable debug symbols by default
12+
if(NOT CMAKE_BUILD_TYPE)
13+
set(CMAKE_BUILD_TYPE Debug
14+
CACHE STRING
15+
"Choose the type of build (Debug or Release)" FORCE)
16+
endif()
17+
18+
# Export compile commands for completion engines (optional)
19+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
20+
21+
# Set option to control setting the resource path variable
22+
option(USE_INSTALL_RESOURCE_PATH "Set resource path to install location" OFF)
23+
24+
# Find SFML shared libraries
25+
find_package(SFML 2.5 COMPONENTS system window graphics audio network REQUIRED)
26+
27+
# Including custom headers
28+
include_directories(./include)
29+
30+
# Compile executable
31+
add_executable(Piano ./src/main.cpp ./src/piano.cpp)
32+
33+
# Link executable to required SFML modules
34+
target_link_libraries(Piano sfml-graphics sfml-audio)

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
# Piano
1+
# Piano
2+
3+
## Setup
4+
My setup was on Ubuntu 20.04. To download SFML, run:
5+
6+
```sh
7+
sudo apt update
8+
sudo apt upgrade
9+
sudo apt install libsfml-dev
10+
```
11+
12+
Now, in order to run the application, navigate into this directory and run the following commands:
13+
```sh
14+
chmod +x ./run.sh
15+
./run.sh
16+
```

include/config.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef CONFIG_H_INCLUDED
2+
#define CONFIG_H_INCLUDED
3+
4+
const int WINDOW_WIDTH = 1200;
5+
const int WINDOW_HEIGHT = 600;
6+
7+
#endif // CONFIG_H_INCLUDED

include/piano.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef PIANO_H_INCLUDED
2+
#define PIANO_H_INCLUDED
3+
4+
#include <SFML/Graphics.hpp>
5+
6+
#include "config.h"
7+
8+
class Piano
9+
{
10+
private:
11+
sf::RenderWindow* window;
12+
sf::Event event;
13+
14+
public:
15+
Piano();
16+
~Piano();
17+
18+
void play();
19+
void display();
20+
};
21+
22+
#endif // PIANO_H_INCLUDED

run.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /bin/bash
2+
3+
if [ ! -d "./build" ]; then
4+
mkdir build
5+
fi
6+
7+
cd build
8+
cmake ..
9+
make
10+
11+
./Piano

src/main.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "piano.h"
2+
3+
int main(int argc, char** argv){
4+
5+
Piano piano;
6+
piano.play();
7+
8+
return EXIT_SUCCESS;
9+
}

src/piano.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "piano.h"
2+
3+
Piano::Piano(){
4+
window = new sf::RenderWindow(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Piano");
5+
window->setFramerateLimit(10);
6+
}
7+
8+
Piano::~Piano(){
9+
delete window;
10+
}
11+
12+
void Piano::play(){
13+
while (window->isOpen()){
14+
window->pollEvent(event);
15+
16+
if (event.type == sf::Event::Closed)
17+
window->close();
18+
}
19+
}
20+
21+
void Piano::display(){
22+
window->clear();
23+
window->display();
24+
}

0 commit comments

Comments
 (0)