# 基于C++实现一个支持简单交互绘图小程序
# 一、概要设计
## 1.1 开发环境
IDE:Visual Studio 2019 Commity
运行环境:window10 专业版配置要求:
内存 4g
显卡 无要求
CPU 无要求
## 目的
调试编译通过图形应用编码、熟悉flk
## 1.2 结构化模块设计图
![](https://www.writebug.com/myres/static/uploads/2022/9/12/49c641f045bc686448cbdefc67f08256.writebug)
UML类图
![](https://www.writebug.com/myres/static/uploads/2022/9/12/dee8ba14d16fcd81e6d64ef163a456f2.writebug)
## 1.3 主要模块功能接口描述
Graph.cpp
```c++
void Shape::add(Point p) // 向图形中添加点
void Shape::draw_lines() // 绘制线条
void Shape::draw() // 根据选定的线条样式、颜色等绘制图像
void Shape::move(int dx, int dy) // 图像移动 dx和dy是图像横坐标和纵坐标移动的截距
void Lines::add(Point p1, Point p2) // 添加线
void Lines::draw_lines() const // 根据里面的点绘制线条
inline pair<double,double> line_intersect(Point p1, Point p2, Point p3, Point
p4, bool& parallel) // 线条之间的相交
void Polygon::add(Point p) // 多边形的添加点
void Polygon::draw_lines() // 画线
void draw_mark(Point xy, char c) // 绘制标记
void Rectangle::draw_lines() const // 矩形线条绘制
Point Circle::center() // 圆心
void Circle::draw_lines() // 绘制圆的线条
void Ellipse::draw_lines() const // 椭圆画线
void Axis::draw_lines() const // 坐标轴画线
void Axis::set_color(Color c) // 设置颜色
void Axis::move(int dx, int dy) //axis移动
```
GUI.cpp
```c++
void Button::attach(Window& win) // 按钮连接到窗口上
int Menu::attach(Button& b) // menu连接到窗口上
```
Simple_window.cpp
```c++
bool Simple_window::wait_for_button() // 等到按钮的点击事件
void Simple_window::cb_next(Address, Address pw) // 将Simple_window::next()连接到
pw
void Simple_window::next()
```
window.cpp
```c++
void Window::draw() // 窗口绘制
void Window::attach(Widget& w) // 窗口链接
void Window::detach(Widget& b) // 取消链接
```
# 二、详细设计与实现
## 2.1 代码组织图
![](https://www.writebug.com/myres/static/uploads/2022/9/12/960b4c954550ca2030330a4c76228b82.writebug)
## 2.2 核心数据结构描述
Point.h
```
struct Point { // 创建一个点结构体 用来存放点的坐标信息 以左上角为(0,0)Point默认(0,0)
int x, y;
Point(int xx, int yy) : x(xx), y(yy) { }
Point() :x(0), y(0) { }
};
```
Simple_window.h
```c++
struct Simple_window : Window { // 简单窗口结构体
Simple_window(Point xy, int w, int h, const string& title ); // 包含初始点信
息,w表示宽度,h表示高度,title表示窗口标题
bool wait_for_button(); // 等待按钮点击事件
private:
Button next_button; // next按钮
bool button_pushed; // implementation detail
static void cb_next(Address, Address); // next_button的回调函数
void next(); // next点击后需要执行的事件
};
```
Graph.h
```c++
struct Color { // 颜色的结构体
enum Color_type { //包含各种颜色的枚举类型
red=FL_RED,
blue=FL_BLUE,
green=FL_GREEN,
yellow=FL_YELLOW,
white=FL_WHITE,
black=FL_BLACK,
magenta=FL_MAGENTA,
cyan=FL_CYAN,
dark_red=FL_DARK_RED,
dark_green=FL_DARK_GREEN,
dark_yellow=FL_DARK_YELLOW,
dark_blue=FL_DARK_BLUE,
dark_magenta=FL_DARK_MAGENTA,
dark_cyan=FL_DARK_CYAN
};
enum Transparency { invisible = 0, visible=255 };
Color(Color_type cc) :c(Fl_Color(cc)), v(visible) { }
Color(Color_type cc, Transparency vv) :c(Fl_Color(cc)), v(vv) { }
Color(int cc) :c(Fl_Color(cc)), v(visible) { }
Color(Transparency vv) :c(Fl_Color()), v(vv) { } // default color
int as_int() const { return c; }
char visibility() const { return v; }
void set_visibility(Transparency vv) { v=vv; }
private:
char v; // invisible and visible for now
Fl_Color c;
};
struct Line_style { // 线的样式的结构体
enum Line_style_type { // 线的样式的枚举
solid=FL_SOLID, // -------
dash=FL_DASH, // - - - -
dot=FL_DOT, // .......
dashdot=FL_DASHDOT, // - . - .
dashdotdot=FL_DASHDOTDOT, // -..-..
};
Line_style(Line_style_type ss) :s(ss), w(0) { }
Line_style(Line_style_type lst, int ww) :s(lst), w(ww) { }
Line_style(int ss) :s(ss), w(0) { }
int width() const { return w; } int style() const { return s; } private: int s;
int w;
};
struct Rectangle : Shape { // 矩形的结构体
Rectangle(Point xy, int ww, int hh) : w(ww), h(hh) // 包含锚点 宽度和高度
{
add(xy);
if (h<=0 || w<=0) error("Bad rectangle: non-positive side"); }
Rectangle(Point x, Point y) : w(y.x-x.x), h(y.y-x.y)
{
add(x);
if (h<=0 || w<=0) error("Bad rectangle: non-positive width or height"); }
void draw_lines() const;
int height() const { return h; } int width() const { return w; } private:
int h; // height
int w; // width
};
struct Open_polyline : Shape { // open sequence of lines
void add(Point p) { Shape::add(p); } void draw_lines() const;
}; //------------------------------------------------------------------------------
struct Text : Shape { // 文本
// 锚点在文字的第一个字的左下方
Text(Point x, const string& s) : lab(s), fnt(fl_font()), fnt_sz(fl_size()) { add(x); }
void draw_lines() const;
void set_label(const string& s) { lab = s; }
string label() const { return lab; }
void set_font(Font f) { fnt = f; }
Font font() const { return Font(fnt); }
void set_font_size(int s) { fnt_sz = s; } int font_size() const { return fnt_sz; } private:
string lab; // label
Font fnt;
int fnt_sz;
}; //------------------------------------------------------------------------------
struct Axis : Shape { // 坐标 enum Orientation { x, y, z };
Axis(Orientation d, Point xy, int length,
int number_of_notches=0, string label = "");
void draw_lines() const;
void move(int dx, int dy);
void set_color(Color c);
Text label;
Lines notches;
}; //------------------------------------------------------------------------------
struct Circle : Shape { // 圆
Circle(Point p, int rr); // center and radius ...
}; //------------------------------------------------------------------------------
struct Ellipse : Shape { // 椭圆
Ellipse(Point p, int w, int h) // center, min, and max distance from center
: w(w), h(h)
{
add(Point(p.x-w,p.y-h));
}
...
}; //------------------------------------------------------------------------------
struct Marks : Marked_polyline { // 标记 ...
}; //------------------------------------------------------------------------------
struct Mark : Marks { // 标记
Mark(Point xy, char c) : Marks(string(1,c))
{
add(xy);
}
}; //------------------------------------------------------------------------------
struct Suffix { // 后缀结构体 none jpg gif
```
## 2.3 绘制图形
![](https://www.writebug.com/myres/static/uploads/2022/9/12/471839249c90a411eb7065e1bb59f0df.writebug)
### 2.3.1 将sin添加进去
![](https://www.writebug.com/myres/static/uploads/2022/9/12/2c094cc84f4ad90053e934618c475ac1.writebug)
### 2.3.2 将矩形添加进去
![](https://www.writebug.com/myres/static/uploads/2022/9/12/42f4042edcc227ad6c7415b81843fcba.writebug)
### 2.3.3 添加颜色等
![](https://www.writebug.com/myres/static/uploads/2022/9/12/f0c7314b9fb4bba437a08bc1622cc318.writebug)
### 2.3.4 最后代码:
没有合适的资源?快使用搜索试试~ 我知道了~
基于C++实现一个支持简单交互绘图小程序【100011698】
共57个文件
h:10个
tlog:9个
cpp:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 92 浏览量
2023-04-07
14:30:04
上传
评论
收藏 54.01MB ZIP 举报
温馨提示
IDE:Visual Studio 2019 Commity
资源推荐
资源详情
资源评论
收起资源包目录
100011698-基于C++实现一个支持简单交互绘图小程序.zip (57个子文件)
commity
Simple_window.h 943B
chap12.rc 6KB
chap12.vcxproj 8KB
chap12.vcxproj.user 165B
Graph.h 11KB
chapter.12.3.cpp 2KB
Makefile 867B
GUI.cpp 2KB
LICENSE 1KB
framework.h 377B
Window.cpp 2KB
chap12.cpp 5KB
chap12.sln 1KB
.vs
chap12
v16
Browse.VC.db 38.19MB
ipch
AutoPCH
8a14819c875660bc
CHAPTER.12.3.ipch 79.13MB
93e2f3a2b41d8155
GRAPH.ipch 79MB
72fc37d2b22a6c0c
CHAP12.ipch 24.69MB
small.ico 45KB
Resource.h 698B
Point.h 783B
chap12.vcxproj.filters 2KB
Window.h 2KB
GUI.h 4KB
Graph.cpp 12KB
std_lib_facilities.h 855B
chap12.h 36B
Debug
chap12.exe.recipe 269B
vc142.idb 675KB
vc142.pdb 756KB
chap12.pdb 3.04MB
chap12.tlog
CL.write.1.tlog 5KB
chap12.lastbuildstate 176B
rc.command.1.tlog 366B
rc.write.1.tlog 250B
rc.read.1.tlog 3KB
CL.command.1.tlog 4KB
link.command.1.tlog 2KB
link.read.1.tlog 5KB
link.write.1.tlog 1KB
CL.read.1.tlog 242KB
chap12.log 2KB
chap12.res 91KB
chapter.12.3.obj 288KB
chap12.ilk 2.68MB
Graph.obj 525KB
chap12.vcxproj.FileListAbsolute.txt 128B
chap12.obj 18KB
GUI.obj 159KB
Simple_window.obj 212KB
chap12.exe 960KB
Window.obj 193KB
README.md 9KB
结构化模块设计图.vsdx 27KB
targetver.h 294B
C++报告.pdf 326KB
Simple_window.cpp 2KB
chap12.ico 45KB
共 57 条
- 1
资源评论
- 2301_774807192023-11-30感谢大佬分享的资源给了我灵感,果断支持!感谢分享~
- 2301_765178712023-12-01这个资源内容超赞,对我来说很有价值,很实用,感谢大佬分享~
神仙别闹
- 粉丝: 2706
- 资源: 7641
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功