GUI-Menu菜单实例(颜色+线型菜单)

运行代码:

//GUI-Menu菜单实例(颜色+线型菜单)
#include"std_lib_facilities.h"
#include"GUI/Simple_window.h"
#include"GUI/GUI.h"
#include"GUI/Graph.h"
#include"GUI/Point.h"

struct Lines_window :Window
{
	Lines_window(Point xy, int w, int h, const string& title);
	Open_polyline lines;
private:
	Menu color_menu;
	Menu Line_style_menu;
	Button menu_button;
	Button Line_style_button;
	Button next_button;
	Button quit_button;
	In_box next_x;
	In_box next_y;
	Out_box xy_out;


	void change(Color c) { lines.set_color(c); }
	void change_Line_style(Line_style l) { lines.set_style(l); }

	void hide_menu() { color_menu.hide(); menu_button.show(); }
	void hide_Line_style_menu() { Line_style_menu.hide(); Line_style_button.show(); }

	static void cb_red(Address, Address);
	void red_pressed() { change(Color::red); hide_menu(); }
	static void cb_blue(Address, Address);
	void blue_pressed() { change(Color::blue); hide_menu(); }
	static void cb_black(Address, Address);
	void black_pressed() { change(Color::black); hide_menu(); }
	static void cb_solid(Address, Address);
	void solid_pressed() { change_Line_style(Line_style::solid); hide_Line_style_menu(); }
	static void cb_dash(Address, Address);
	void dash_pressed() { change_Line_style(Line_style::dash); hide_Line_style_menu(); }
	static void cb_dot(Address, Address);
	void dot_pressed() { change_Line_style(Line_style::dot); hide_Line_style_menu(); }
	static void cb_menu(Address, Address);
	void menu_pressed() { menu_button.hide(); color_menu.show(); }
	static void cb_Line_style_menu(Address, Address);
	void Line_style_menu_pressed() { Line_style_button.hide(); Line_style_menu.show(); }
	static void cb_next(Address, Address);
	void next();
	static void cb_quit(Address, Address);
	void quit();
};

Lines_window::Lines_window(Point xy, int w, int h, const string& title)
	:Window(xy, w, h, title),
	color_menu(Point(x_max() - 70, 40), 70, 20, Menu::vertical, "color"),
	Line_style_menu(Point(x_max()-190,40),70,20,Menu::vertical,"line style"),
	menu_button(Point(x_max() - 80, 30), 80, 20, "color menu", cb_menu),
	Line_style_button(Point(x_max()-190,30),100,20,"line style menu",cb_Line_style_menu),
	next_button(Point(x_max() - 150, 0), 70, 20, "Next point", cb_next),
	quit_button(Point(x_max() - 70, 0), 70, 20, "Quit", cb_quit),
	next_x(Point(x_max() - 310, 0), 50, 20, "next x:"),
	next_y(Point(x_max() - 210, 0), 50, 20, "next y:"),
	xy_out(Point(100, 0), 100, 20, "current(x,y):")
{
	color_menu.attach(new Button(Point(0, 0), 0, 0, "red", cb_red));
	color_menu.attach(new Button(Point(0, 0), 0, 0, "blue", cb_blue));
	color_menu.attach(new Button(Point(0, 0), 0, 0, "black", cb_black));
	Line_style_menu.attach(new Button(Point(0, 0), 0, 0, "solid", cb_solid));
	Line_style_menu.attach(new Button(Point(0, 0), 0, 0, "dash", cb_dash));
	Line_style_menu.attach(new Button(Point(0, 0), 0, 0, "dot", cb_dot));
	attach(color_menu);
	attach(Line_style_menu);
	attach(next_button);
	attach(quit_button);
	attach(next_x);
	attach(next_y);
	attach(xy_out);
	xy_out.put("no point");
	color_menu.hide();
	Line_style_menu.hide();
	attach(menu_button);
	attach(Line_style_button);
	lines.set_color(Color::black);
	attach(lines);
}

void Lines_window::cb_red(Address, Address pw)
{
	reference_to<Lines_window>(pw).red_pressed();
}

void Lines_window::cb_blue(Address, Address pw)
{
	reference_to<Lines_window>(pw).blue_pressed();
}

void Lines_window::cb_black(Address, Address pw)
{
	reference_to<Lines_window>(pw).black_pressed();
}

void Lines_window::cb_solid(Address, Address pw)
{
	reference_to<Lines_window>(pw).solid_pressed();
}

void Lines_window::cb_dash(Address, Address pw)
{
	reference_to<Lines_window>(pw).dash_pressed();
}

void Lines_window::cb_dot(Address, Address pw)
{
	reference_to<Lines_window>(pw).dot_pressed();
}

void Lines_window::cb_menu(Address, Address pw)
{
	reference_to<Lines_window>(pw).menu_pressed();
}

void Lines_window::cb_Line_style_menu(Address, Address pw)
{
	reference_to<Lines_window>(pw).Line_style_menu_pressed();
}

void Lines_window::cb_quit(Address, Address pw)
{
	reference_to<Lines_window>(pw).quit();
}

void Lines_window::quit()
{
	hide();
}

void Lines_window::cb_next(Address, Address pw)
{
	reference_to<Lines_window>(pw).next();
}

void Lines_window::next()
{
	int x = next_x.get_int();
	int y = next_y.get_int();

	lines.add(Point(x, y));

	stringstream ss;
	ss << '(' << x << ',' << y << ')';
	xy_out.put(ss.str());

	redraw();
}

int main()
try
{
	Lines_window win(Point(100, 100), 600, 400, "lines");
	return gui_main();
}
catch (exception& e) {
	cerr << "error:" << e.what() << '\n';
	keep_window_open();
	return 1;
}
catch (...) {
	cerr << "Oops:unknown exception!\n";
	keep_window_open();
	return 2;
}

运行结果:

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/41560.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Java的数据结构-Map集合

文章目录 Map概述Map常用方法Map遍历元素的方法1.方法一&#xff1a;keySet()2.方法二&#xff1a;entrySet() HashMap Map概述 1、Map和collection没有继承关系2、Map集合以key和value的方式存储数据&#xff1a;键值对key和value都是引用数据类型。key和value都是存储对象的…

【LocalSend】开源跨平台的局域网文件传输工具,支持IOS、Android、Mac、Windows、Linux

工作前提条件&#xff1a;设备使用相同的局域网。 LocalSend is a cross-platform app that enables secure communication between devices using a REST API and HTTPS encryption. Unlike other messaging apps that rely on external servers, LocalSend doesn’t require …

【网络安全】渗透测试工具——Burp Suite

渗透测试工具Burp Suite主要功能详解 前言一、 Proxy模块1.1 界面布局1.1.1 菜单栏&#xff08;1&#xff09; 菜单栏 Burp&#xff08;2&#xff09; 菜单栏 project&#xff08;3&#xff09; 菜单栏 Intruder&#xff08;4&#xff09; 菜单栏 Repeater&#xff08;5&#x…

C# Modbus通信从入门到精通(2)——Modbus RTU协议原理

Modbus RTU是串行链路上的协议,也就是说Modbus RTU是通过串口通信来实现的,它可以通过RS232、RS485物理层的接口来实现,同时它也是一个主从协议,在同一时间总线上只能有一个主站和一个或多个(最多247)个从站。Modbus通信总是由主站发起,从站没有接收到主站的请求时不会发…

Kubernetes轻量级日志工具Loki安装及踩坑记录

Loki简介 Loki是Grafana出品的一个轻量级日志系统&#xff0c;熟悉ELK的都知道ELK使用起来的成本&#xff0c;而且仅仅是日志检索使用ELK的话有点大材小用了。Loki8技术栈中使用了以下组件。 Promtail 用来将容器日志发送到 Loki 或者 Grafana 服务上的日志收集工具&#xff0c…

基于单片机的智能鞋柜的设计与实现

功能介绍 以51单片机作为主控系统&#xff1b;通过DHT11温湿度采集&#xff1b;通过按键设置逻辑处理&#xff1b;通过LED紫外线消毒&#xff1b;通过继电器控制风扇进行换气除湿&#xff1b;通过继电器控制加热片进行加热&#xff1b;整个电路以5v供电; 电路图 PCB 源代码 #i…

OSS对象存储后端实现+Vue实现图片上传【基于若依管理系统开发】

文章目录 基本介绍术语介绍图片上传方式介绍普通上传用户直传应用服务器签名后直传 OSS对象存储后端实现maven配置文件配置类ServiceController 图片上传前端图片上传组件api页面使用组件组件效果 基本介绍 术语介绍 Bucket&#xff08;存储空间&#xff09;&#xff1a;用于…

7-Spring cloud之路由网关zuul

7-Spring cloud之路由网关zuul 1. 前言2. 关于zuul2.1 zuul基本原理2.2 为什么要使用zuul 3. 搭建zuul3.1 项目结构3.2 基本配置3.2.1 pom文件3.2.2 yml文件3.3.3 启动类 3.3 测试看效果3.3.1 演示3.3.1 架构图 4. zuul路由访问映射规则4.1 映射服务提供者的服务名4.2 访问加前…

基于vue3+pinia2仿ChatGPT聊天实例|vite4.x仿chatgpt界面

原文&#xff1a;基于vue3pinia2仿ChatGPT聊天实例|vite4.x仿chatgpt界面 基于vue3pinia2仿ChatGPT聊天实例|vite4.x仿chatgpt界面 使用vue3pinia2开发仿制chatgpt界面聊天实例Vue3-Chatgpt 基于Vue3.xPinia2VueRouterVue3-Markdown等技术构建仿ChatGPT网页端聊天程序。支持经…

《动手学深度学习》(pytorch版本)中`d2lzh_pytorch`包问题

《动手学深度学习》&#xff08;pytorch版本&#xff09;中d2lzh_pytorch包问题

Redis安装与配置指南:适用于Windows、Mac和Linux系统的详细教程

&#x1f337;&#x1f341; 博主 libin9iOak带您 Go to New World.✨&#x1f341; &#x1f984; 个人主页——libin9iOak的博客&#x1f390; &#x1f433; 《面试题大全》 文章图文并茂&#x1f995;生动形象&#x1f996;简单易学&#xff01;欢迎大家来踩踩~&#x1f33…

opencv-07-感兴趣区域(ROI)

在图像处理过程中&#xff0c;我们可能会对图像的某一个特定区域感兴趣&#xff0c;该区域被称为感兴趣区 域&#xff08;Region of Interest&#xff0c;ROI&#xff09;。在设定感兴趣区域 ROI 后&#xff0c;就可以对该区域进行整体操作。 以下是一些 OpenCV ROI应用场景 …

华为认证的题库,不仅能考试,还能帮你提升技能

1、OSPF协议在哪种状态下确定DD报文的主从关系&#xff1f; A. 2-way B.Exchange C. ExStart D. Full 2、在VRP操作系统中&#xff0c;如何进入OSPF区域0的视图&#xff1f;A. [Huawei-ospf-1]area 0 B.[Huawei]ospf area 0 C. [Huawei-ospf-1]area 0 enable D. [Huawe…

Python批量实现Word、EXCLE、PPT转PDF文件

一、绪论背景 在日常办公和文档处理中&#xff0c;有时我们需要将多个Word文档、Excel表格或PPT演示文稿转换为PDF文件。将文档转换为PDF格式的好处是它可以保留文档的布局和格式&#xff0c;并且可以在不同平台上进行方便的查看和共享。 本篇博文将介绍如何使用Python编程语言…

服务机器人应用

随着时代的发展&#xff0c;机器人技术在各个领域越来越普及。在服务领域&#xff0c;服务机器人的应用也越来越受到人们的欢迎。服务机器人将会在商业、医疗、教育、酒店等领域得到应用&#xff0c;并成为未来发展的趋势。 在商业领域中&#xff0c;服务机器人可以承担很多工作…

鲸鱼优化算法MATLAB代码

论文 Seyedali Mirjalili,Andrew Lewis. The Whale Optimization Algorithm[J]. Advances in Engineering Software,2016,95.func_plot.m % This function draw the benchmark functionsfunction func_plot(func_name)[lb,ub,dim,fobj]Get_Functions_details(func_name);switch…

轮廓提取demo

note 步骤&#xff1a; 1.滤波(使用高斯核对原图卷积) 2.取梯度(使用sobel核对步骤1之后的图卷积得到x,y两个方向的梯度分量) 3.合成梯度图(x,y两个方向的梯度分量相加) 4.取梯度平方和矩阵(x*x y*y) 5.取八邻域掩膜(3x3矩阵) 6.根据掩膜&#xff0c;合成梯度图&#x…

2023最新版本Activiti7系列-事件篇

事件篇 事件&#xff08;event&#xff09;通常用于为流程生命周期中发生的事情建模。事件总是图形化为圆圈。在BPMN 2.0中&#xff0c;有两种主要的事件分类&#xff1a;*捕获&#xff08;catching&#xff09;与抛出&#xff08;throwing&#xff09;*事件。 捕获: 当流程执…

1haclon 简单操作

文章目录 *读取图片 read_image(Image,claudia) *转换为灰度 rgb1_to_gray(Image,GrayImage)阈值分割 区域连接 获取最衣服 *读取图片 read_image(Image,claudia) *转换为灰度 select_shape (Connection, SelectedRegions, area, and, 40963.3, 44724.8) rgb1_to_gray(Image,Gr…

TCP实现FTP功能

目录 server client makefile 运行顺序 FTP&#xff08;File Transfer Protocol&#xff09;是一种用于在计算机网络上传输文件的标准协议。 它允许用户通过网络将文件从一个计算机&#xff08;称为FTP服务器&#xff09;传输到另一个计算机&#xff08;称为FTP客户端&…
最新文章