Commit d401cac2 authored by Dr Jon Hays's avatar Dr Jon Hays
Browse files

FTLK_File example updated for 2016 module and CLion with CMake

parent 632b83a9
FLTK_File
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Colours.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Window.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Window.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/main.cpp" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Header Search Paths">
<CLASSES>
<root url="file://L:/GNU_FLTK_1.3.3" />
<root url="file://L:/GNU_Fortran/MinGW/include" />
<root url="file://L:/GNU_Fortran/MinGW/lib/gcc/mingw32/4.7.2/include" />
<root url="file://L:/GNU_Fortran/MinGW/lib/gcc/mingw32/4.7.2/include-fixed" />
<root url="file://L:/GNU_Fortran/MinGW/lib/gcc/mingw32/4.7.2/include/c++" />
<root url="file://L:/GNU_Fortran/MinGW/lib/gcc/mingw32/4.7.2/include/ssp" />
</CLASSES>
<SOURCES>
<root url="file://L:/GNU_FLTK_1.3.3" />
<root url="file://L:/GNU_Fortran/MinGW/include" />
<root url="file://L:/GNU_Fortran/MinGW/lib/gcc/mingw32/4.7.2/include" />
<root url="file://L:/GNU_Fortran/MinGW/lib/gcc/mingw32/4.7.2/include-fixed" />
<root url="file://L:/GNU_Fortran/MinGW/lib/gcc/mingw32/4.7.2/include/c++" />
<root url="file://L:/GNU_Fortran/MinGW/lib/gcc/mingw32/4.7.2/include/ssp" />
</SOURCES>
</library>
</orderEntry>
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="C:\Users\apw253\ClionProjects\2016\FLTK_File" />
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/FLTK_File.iml" filepath="$PROJECT_DIR$/.idea/FLTK_File.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
cmake_minimum_required(VERSION 3.3)
#
# Change this line to the name of your project
# exchange "." in the name for "_"
# so for a project called Ex2.1 you need
# project(Ex2_1)
#
project(FLTK_File)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-std=c++11")
set(SOURCE_FILES main.cpp Window.cpp Window.h Colours.h)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
set(mingw true)
if(mingw)
add_definitions(-DWIN32)
set( FLTK_PLATFORM_DEPENDENT_LIBS ole32 uuid wsock32 gdi32 comdlg32)
endif(mingw)
set(FLTK_SKIP_FLUID true)
find_package(FLTK REQUIRED)
include_directories(${FLTK_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${FLTK_BASE_LIBRARY} ${FLTK_PLATFORM_DEPENDENT_LIBS})
/*
* colors.hpp
*
* Created on: 1 Feb 2015
* Author: Jon
*/
#ifndef COLORS_HPP_
#define COLORS_HPP_
namespace SPA {
enum colors { BLACK=0, RED, GREEN, BLUE, CYAN, MAGENTA, WHITE};
// a simple function to translate an integer input into the appropriate
// FL_Color object
Fl_Color getColor(int i) {
switch(i) {
case BLACK:
return FL_BLACK;
case RED:
return FL_RED;
case GREEN:
return FL_GREEN;
case BLUE:
return FL_BLUE;
case CYAN:
return FL_CYAN;
case MAGENTA:
return FL_MAGENTA;
case WHITE:
return FL_WHITE;
default:
return FL_BLACK;
}
}
}
#endif /* COLORS_HPP_ */
/*
* Window.cpp
*
* Created on: 25 Jan 2015
* Author: Jon
*/
#include "Window.h"
namespace SPA {
Window::~Window() {;}
}
/*
* Window.hpp
*
* Created on: 25 Jan 2015
* Author: Jon
*/
#ifndef SPAWINDOW_HPP_
#define SPAWINDOW_HPP_
#include <FL/Fl.h>
#include <FL/Fl_Window.H>
#include <FL/fl_draw.h>
#include <vector>
#include <cmath>
#include <iostream>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.7182818284590452354
#endif
namespace SPA {
class Point {
public:
Point(float x = 0, float y = 0) :
x(x), y(y) {
;
}
float x;
float y;
};
class Line {
public:
Line() : color(FL_BLACK){
;
}
void addPoint(Point p) {
points.push_back(p);
}
void clear() {
points.clear();
}
void draw() {
Fl_Color oldcolor = fl_color();
fl_color(color);
fl_begin_line();
for (int i = 0, n = points.size(); i < n; ++i) {
Point & p = points[i];
fl_vertex(round(p.x), round(p.y));
}
fl_end_line();
fl_color(oldcolor);
}
void setColor(Fl_Color col) {
color = col;
}
int size() {
return points.size();
}
private:
Fl_Color color;
std::vector<Point> points;
};
class Window: public Fl_Window {
public:
Window(int w, int h, const char * l = 0) :
Fl_Window(h, w, l), currentLine(), currentPoint(0, 0),
currentColor(FL_BLACK), currentAngle(0) {
}
~Window();
void draw() {
for (int i = 0, n = lines.size(); i < n; ++i) {
Line & l = lines[i];
l.draw();
}
}
void addPoint(const Point & p) {
addPoint(p.x,p.y);
}
void addPoint(double x, double y) {
if (currentLine.size() == 0) {
// start a new line
startLine(round(x), round(y));
} else {
Point p(round(x), round(y));
currentPoint = p;
currentLine.addPoint(p);
}
}
void setColor(Fl_Color color) { currentColor = color;}
void startLine(int x, int y) {
if (currentLine.size() > 0) {
stopLine();
}
//
currentLine.clear();
currentLine.setColor(currentColor);
currentPoint.x = x;
currentPoint.y = y;
currentLine.addPoint(currentPoint);
}
void stopLine() {
lines.push_back(currentLine);
currentLine.clear();
}
void setAngle(float angle) {
currentAngle = angle * M_PI / 180.;
}
void forward(float l) {
Point p;
p.x = currentPoint.x + l * std::cos(currentAngle);
p.y = currentPoint.y + l * std::sin(currentAngle);
currentPoint = p;
currentLine.addPoint(p);
}
// a clockwise rotation
void rotateDegrees(float angle) {
float radians = angle * M_PI / 180.;
currentAngle += radians;
}
private:
std::vector<Line> lines;
Line currentLine;
Point currentPoint;
Fl_Color currentColor;
float currentAngle;
};
}
#endif /* SPAWINDOW_HPP_ */
/*
* main.cpp
*
* Created on: 18 Dec 2014
* Author: apw253
*/
#include "Window.h"
#include "Colours.h"
int main(int argc, char * argv[]) {
// create a new window of size 500 x 500 pixels
// the top left corner of the window is (0,0)
SPA::Window window(500,500,"My Test");
// Add code here to draw things
/*
* Here are some of the options
* window.startLine(float x, float y) start a new line from location (x,y)
* window.setAngle(float angle) to set the initial ang of the pen in degrees
* window.rotateDegrees(float angle) rotate the pen in degrees
* window.forward(float distance) move the pen forward
* window.stopLine() to stop the current line
* window.addPoint(float x, float y) add a point to the current line
* window.addPoint(Point p) add a point to the current line
* window.setColor(FL_Color c) set the colour for the next line
*/
// display the window
window.show(argc,argv);
// run the FLTK event loop - this allows you to move the window around etc
// and ultimately set up click events.
// program will end when you close the window
return Fl::run();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment