EasyX测试布局代码

news2024/9/22 9:43:45

在这里插入图片描述

#include <iostream>
#include <algorithm>
#include <graphics.h>		// 引用图形库头文件
#include <conio.h>
#include <unordered_map>
#include <Windows.h>
#include "layout/LayoutSystem.h"

#define DEFAULT_PANELS_LAYOUT_PADDING 0.03
#define DEFAULT_PANELS_LAYOUT_CELL_SIZE 0.01

using namespace boxing::layout;

int SCRW = 640;
int SCRH = 480;
int main()
{
    HWND hConsole = GetConsoleWindow();

	initgraph(SCRW, SCRH);	// 创建绘图窗口,大小为 640x480 像素
    // 设置控制台窗口不最小化
    SetWindowPos(hConsole, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);

    auto getX = [](float x1)->int {return (int)((x1 + 1.0) / 2.0 * SCRW); };
    auto getY = [](float y1)->int {return (int)(abs(y1 - 1.0) / 2.0 * SCRH); };
    auto getW = [](float w)->int {return  w / 2.0 * SCRW; };
    auto getH = [](float h)->int {return  h / 2.0 * SCRH; };
    auto drawRectText = [&](float x,float y, LPCTSTR str,float w,float h, COLORREF color) {
        int new_x = getX(x);
        int new_y = getY(y);
        int new_w = getW(w);
        int new_h = getH(h);
        setfillcolor( color);
        fillrectangle( new_x- new_w/2, new_y- new_h/2, new_x + new_w / 2, new_y + new_h / 2 );
        int textW = textwidth(str);
        int textH = textheight(str);
        setfillcolor(RGB(255,255,255));
        outtextxy(new_x - textW / 2.0, new_y - textH / 2.0,str );
    };

    auto drawRectCharText = [&](float x, float y, char* str, float w, float h, COLORREF color) {
        int num = MultiByteToWideChar(0, 0, str, -1, NULL, 0);
        wchar_t* wide = new wchar_t[num];
        MultiByteToWideChar(0, 0, str, -1, wide, num);
        drawRectText(x, y, wide, w, h, color);
        free(wide);
    };

    auto drawRectInt = [&](float x, float y, int text, float w, float h, COLORREF color) {
        char str[50] = { 0 };
        sprintf(str, "%d", text);
        drawRectCharText(x, y, str, w, h, color);
    };
    auto drawRectFloat = [&](float x, float y, float text, float w, float h, COLORREF color) {
        char str[50] = { 0 };
        sprintf(str, "%f", text);
        drawRectCharText(x, y, str, w, h, color);
    };

    auto drawLine = [&](float start_x, float start_y, float end_x, float end_y, COLORREF color) {
        setlinecolor(color);
        line(getX(start_x), getY(start_y), getX(end_x), getY(end_y));
    };
    srand(time(NULL));
    bool loop = false;
    for (int count = 100; count >0; count--) {
        cleardevice();
        float aspect = 1.0 / 0.618; // w/h
        int col = min(count, (int)std::ceil(sqrt(count * aspect)));
        int row = std::ceil((float)count / col);

        std::unordered_map<int,float> widthInCol;
        std::unordered_map<int,float> heightInRow;

        int rowMin = row / 2 - (count - 1) / col;
        int rowMax = row / 2 - ((int)0) / col;
        int colMax = (col - 1) % col - col / 2;
        int colMin = ((int)0) % col - col / 2;
        float col_centre = (colMax + colMin) / 2.0;
        float row_centre = (rowMax + rowMin) / 2.0;
        drawLine(-1,0,1,0, RGB(0 ,255, 0));
        drawLine(0, 1, 0, -1, RGB(0, 255, 0));
        char str[100] = { 0 };
        sprintf(str, "r:%d,c:%d", row,col);
        drawRectCharText(-0.9,0.95, str, 0.2, 0.1, RGB(255, 250, 0));
        printf(" count: %d,colMax: %d,colMin:%d,rowMax:%d ,rowMin:%d, tt:%f,row_centre:%f\n", count, colMax, colMin, rowMax, rowMin, col_centre, row_centre);
        

        LayoutSystem::Ptr layoutSystem = LayoutSystem::NEW(PAGE_LAYOUT_PLANE, DEFAULT_PANELS_LAYOUT_CENTRE, DEFAULT_PANEL_POSITION);
        for (int index = 0; index < count; index++) {
         /*   int tmpIndex = count - 1 - index;
            int prow = row / 2 - tmpIndex / col;
            int pcol = tmpIndex % col - col / 2;
            int prow_new = abs(prow - rowMax);
            prow_new = prow_new % 2 == 0 ? (prow_new / 2) : ((prow_new + 1) / -2);
            int pcol_new = abs(pcol - colMin);
            pcol_new = pcol_new % 2 == 0 ? (pcol_new / 2) : ((pcol_new + 1) / -2);

            float element_row = prow_new + row_centre;
            float element_col = pcol_new - col_centre;
            printf(" count: %d,index: %d,row:%d, col:%d, [%d,%d],prow_new:%d,pcol_new:%d\n", count, index, row, col, prow, pcol, prow_new, pcol_new);

            int color = (float)tmpIndex / count * 255;*/

            float randW = max(0.1,rand() / double(RAND_MAX)/5.0);
            float randH = max(0.1, rand() / double(RAND_MAX) / 5.0);
            layoutSystem->addLayoutElement(index, randW, randH);
     /*       if (widthInCol.count(pcol_new) > 0) {
                widthInCol[pcol_new] += randW;
            }else {
                widthInCol[pcol_new] = randW;
            }
            if (heightInRow.count(prow_new) > 0) {
                heightInRow[prow_new] += randH;
            }else {
                heightInRow[prow_new] = randH;
            }*/
            //drawRectInt(element_col /(max(abs(colMax), abs(colMin))+1), element_row / (max(abs(rowMax), abs(rowMin)) + 1), index, randW, randH, RGB(255, color, 0));
        }
        layoutSystem->startCompositor(false);
        auto layout_results = layoutSystem->getLayoutResults();
        for (auto [k, v] : layout_results) {
            int color = (float)k / count * 255;
            //drawRectInt(v->position.x / (max(abs(colMax), abs(colMin)) + 1), v->position.y / (max(abs(rowMax), abs(rowMin)) + 1), k, 0.1, 0.1, RGB(255, color, 0));
            auto element = layoutSystem->getLayoutElement(k);
            drawRectInt(v->position.x, v->position.y , k, element->mWidth, element->mHeight, RGB(255, color, 0));
        }

        //auto tmpC = std::max_element(widthInCol.begin(), widthInCol.end(), [](std::pair<int, float> left, std::pair<int, float> right) { return left.second < right.second; });
        //float maxWidth = tmpC->second;
        //auto tmpR = std::max_element(heightInRow.begin(), heightInRow.end(), [](std::pair<int, float> left, std::pair<int, float> right) { return left.second < right.second; });
        //float maxHeight = tmpR->second;



        //drawRectFloat(-0.5, 0.95, maxWidth, 0.2, 0.1, RGB(25, 25, 250));
        //drawRectFloat(0, 0.95, maxHeight, 0.2, 0.1, RGB(25, 25, 250));
        Sleep(1000);
        if (!loop)
            break;
    }
	_getch();				
	closegraph();			
	return 0;
}

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

谈二级索引

前提&#xff1a; 在数据库中&#xff0c;1、索引分为聚簇索引和非聚簇索引两类。2、所有索引的数据结构都是树&#xff0c;查找树上的节点数据时通过用二分法来锁定数据范围&#xff0c;指定数据排序的规则&#xff0c;比如&#xff1a;有小到大&#xff0c;对比之后最终确定…

Sequencer使用心得

在关卡序列中设置了触发蓝图的关键帧&#xff0c;为什么播放的时候没有触发蓝图事件呢&#xff1f; 在关卡序列中触发蓝图&#xff0c;一般是将蓝图添加到轨道中&#xff0c;设置触发器&#xff0c;在对应的关键帧中&#xff0c;绑定蓝图事件。 一般的话&#xff0c;点击播…

栈、队列、优先级队列详解【c++】

目录 &#x1f3c0;stack的介绍和使用⚽stack的介绍⚽stack的使用 &#x1f3c0;queue的介绍和使用⚽queue的介绍⚽queue的使用 &#x1f3c0;priority_queue的介绍和使用⚽priority_queue的介绍⚽priority_queue的使用 &#x1f3c0;总结 &#x1f3c0;stack的介绍和使用 ⚽s…

尝试-InsCode Stable Diffusion 美图活动一期

一、 Stable Diffusion 模型在线使用地址&#xff1a; https://inscode.csdn.net/inscode/Stable-Diffusion 二、模型相关版本和参数配置&#xff1a; 活动地址 三、图片生成提示词与反向提示词&#xff1a; 提示词&#xff1a;realistic portrait painting of a japanese…

OPENMV的形状和颜色组合识别

使用openmv&#xff0c;通过阈值颜色和形状来去真假宝藏。调试过程发现颜色的阈值比较重要&#xff0c;因为不准的话&#xff0c;它会把一些颜色相近的物体也识别了。识别的精度有待提高&#xff0c;可以使用YOLOV5来精确识别&#xff0c;奈何本人没精力来弄这个。 打开机器视觉…

Proxmox VE 为 Windows 虚拟机添加硬盘遇到的问题

环境&#xff1a;PVE 8.x、Windows 11/Windows Server 2019 &#x1f449;问题一&#xff1a; 为 windows 虚拟机添加磁盘&#xff0c;重启虚拟机后&#xff08;在 windows 系统中重启&#xff09;磁盘未能生效&#xff0c;并显示为橘色。 ❗橘色 意味需要重启VM才能生效&…

BIO实战、NIO编程与直接内存、零拷贝深入辨析-02

网络通信编程基本常识 什么是 Socket &#xff1f; Socket 是应用层与 TCP/IP 协议族通信的中间软件抽象层&#xff0c;它是一组接口&#xff0c;一般由操作 系统提供。在设计模式中&#xff0c;Socket 其实就是一个门面模式&#xff0c;它把复杂的 TCP/IP 协议处理和…

RocketMQ学习笔记(基础篇)

目录 RocketMQ简介 单Master模式 多Master模式 多Master多Slave模式&#xff08;异步&#xff09; 多Master多Slave模式&#xff08;同步&#xff09; 双主双从集群 事务消息 事务消息发送及提交 事务补偿 事务消息状态 RocketMQ高级功能 消息存储 存储介质 消息的…

vue upload 下载

目录 上传 下载 get post 对象/文件流 download处理返回 文件流 axios.post 封装axios 后端直接返回文件流&#xff0c;打开下载文件是 [object Object]&#xff0c;将res改成res.data即可 1.请求设置类型responseType: blob&#xff08;如果没有设置&#xff0c;打…

14_Linux设备树下的platform驱动编写

目录 设备树下的platform驱动简介 运行测试 设备树下的platform驱动简介 platform驱动框架分为总线、设备和驱动,其中总线不需要我们这些驱动程序员去管理&#xff0c;这个是Linux内核提供的,我们在编写驱动的时候只要关注于设备和驱动的具体实现即可。在没有设备树的Linux内…

1770_VirtualBox下安装Debian

全部学习汇总&#xff1a; GreyZhang/little_bits_of_linux: My notes on the trip of learning linux. (github.com) 作为我自己的日常使用&#xff0c;Debian基本上没有出现过。最多是让它运行在某个设备上作为一个服务的平台&#xff0c;因为很多东西我懒得去配置。 Debia…

前端 | (二)各种各样的常用标签 | 尚硅谷前端html+css零基础教程2023最新

学习来源&#xff1a;尚硅谷前端htmlcss零基础教程&#xff0c;2023最新前端开发html5css3视频 文章目录 &#x1f4da;HTML排版标签&#x1f4da;HTML语义化标签&#x1f4da;块级元素与行内元素&#x1f4da;文本标签&#x1f407;常用的文本标签&#x1f407;不常用的文本标…

模版模式在Spring中的应用

前言 模式模式在Spring中的应用较多&#xff0c;这里结合JdbcTemplate的源码来和大家一起学习下&#xff0c;更加深刻滴认识下模版模式&#xff0c;以便在日常开发中&#xff0c;能灵活运用模版模式&#xff0c;来减少重复代码&#xff0c;增强代码的可拓展性。 何为模版模式…

Python学习(七)

#字典 #字典的定义&#xff0c;同样是使用{}&#xff0c;不过存储的元素是一个个的&#xff1a;键值对。如下语法&#xff1a; my_dict{"周杰伦":99,"林俊杰":99} print(f"字典的内容是&#xff1a;{my_dict},类型是&#xff1a;{type(my_dict)}"…

Vue条件渲染

v-if 和 v-show <body> <div id"root"><!--用v-show做条件渲染--> <!-- <h2 v-show"false">欢迎来到{{name}}</h2>--><!--使用v-if做条件渲染--><h2 v-if"false">欢迎来到{{name}}</h2&g…

一文读懂STM32芯片总线

目录 一、前言 二、总线基础知识概述 (1)、总线在芯片中的角色 (2)、总线的类型 (3)、总线的指标 (4)、AHB和APB 三、总线框架结构 (1)、结构类型 (2)、总线模块 (3)、总线交互 四、总结 一、前言 本篇介绍STM32芯片内部的总线系统结构&#xff0c;嵌入式芯片内部的…

C++11左值和右值、左值引用和右值引用浅析

从字面意思来讲&#xff0c;左值就是“能用在赋值语句等号左侧的内容&#xff08;它得代表一个地址&#xff09;”&#xff1b;右值就是不能作为左值的值&#xff0c;即右值不能出现在赋值语句中等号的左侧。C中的一条表达式&#xff0c;要么就是右值&#xff0c;要么就是左值&…

钉钉监控Hippo4j线程池通知报警

&#x1f680; 线程池管理工具-Hippo4j &#x1f680; &#x1f332; AI工具、AI绘图、AI专栏 &#x1f340; &#x1f332; 如果你想学到最前沿、最火爆的技术&#xff0c;赶快加入吧✨ &#x1f332; 作者简介&#xff1a;硕风和炜&#xff0c;CSDN-Java领域优质创作者&#…

软考03海明校验码

文章目录 前言一、练习一二、练习二总结 前言 海明校验码可以用来纠正错误 公式&#xff1a; 2k-1≥nk n为数据位&#xff0c;k为校验位 编码规则&#xff1a;校验位为2的次方&#xff0c;其他为数据位。 一、练习一 数据位为4&#xff0c;校验位最小为多少位&#xff1f; 答&…

《微服务架构设计模式》第十二章 部署微服务应用

内容总结自《微服务架构设计模式》 部署微服务应用 一、部署模式分类二、编程语言特定的发布包格式1、概述2、利弊 三、将服务部署为虚拟机1、概览2、利弊 四、将服务部署为容器1、概述2、利弊3、K8S部署 五、Serverless部署1、概述2、利弊3、示例 六、总结 一、部署模式分类 …