📄 dispdigit.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <pwd.h>
#include <math.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "common.h"
#include "fonts.h"
#include "dispdigit.h"
//通过channel_disp结构体中
//color
//tagname,
//unit来传递参数
void DrawDigitalRect(HDC hdc,int i, int l, int t, int w, int h)
{
unsigned char str[10];
int id;
gal_pixel colorl_text;
id=i;
colorl_text=RGB2Pixel(hdc,0,0,0);//PIXEL_lightgray
SetPenColor (hdc,PIXEL_lightgray);//COLOR_darkgray
Rectangle(hdc, l, t, l + w, t + h); //channel_disp[id].color
SetBrushColor(hdc,channel_disp[id].color); //RGB2Pixel(hmemDC,id*30,128,abs(8-id)*64)
FillBox(hdc, l+1, t+1, w-1, h-1);
SelectFont(hdc,songgb16font); //设置字体
TextOut(hdc,l+w/2,t+h/2,channel_disp[id].data);
bzero(str,10);
sprintf(str,"%ds",channel_conf[id].interval);
TextOut(hdc,l+w-30,t+h-16,str);//采样时间间隔
memcpy(str,channel_conf[id].name,sizeof(channel_conf[id].name));
TextOut(hdc,l,t,str);//channel_disp[id].tagname
TextOut(hdc,l+w-30,t,channel_conf[id].unit);//单位
}
/*
根据通道个数计算出坐标,大小
根据坐标,大小,颜色显示
入口:当前页计数器,当前页显示的个数
number:总共启用的通道数目
*/
void DrawDigital(HDC hdc,int first,int number,int add_x,int add_h)
{
int i;
int x,y,w,h;
int add_y,add_w;
HDC hmemDC;
gal_pixel rect_color_back;
hmemDC=CreateCompatibleDC(hdc);
SetBrushColor(hmemDC,PIXEL_black);//PIXEL_lightwhite
SetBkMode(hmemDC,BM_TRANSPARENT);
add_w=WIDTH-add_x;
FillBox(hmemDC,add_x,TOP,add_w,add_h);
// SetBkMode(hmemDC,PIXEL_lightwhite);
for (i=first;i<number+first;i++)
{
x=channel_disp[i].x;
y=channel_disp[i].y;
w=channel_disp[i].width;
h=channel_disp[i].height;
DrawDigitalRect(hmemDC,i,x,y,w,h);
}
BitBlt(hmemDC,0,TOP,add_w,add_h,hdc,add_x,TOP,0);//
DeleteCompatibleDC(hmemDC);
// rect_color_back=RGB2Pixel(hdc,0,0,100);
// SetBrushColor(hdc,rect_color_back);
// FillBox(hdc,1,1,WIDTH,TOP);
}
//刚进入此页面时候调用通道坐标生成
//设置显示坐标
void SetCoordinate(int first,int n,int x,int h)
{
int channum;
int rows;
int cols;
int i;//行计数器
int j;//列计数器
int r;//余数
int LastRowCols;
int sn;
int temp_row;
unsigned char tempstr[20];
unsigned int y,w;
y=TOP;
w=WIDTH-x;
//规范化
if( first<0)first=0;
//加入n=1那么cols=1,rows=1
/*设置坐标*/
channum=n;
cols=sqrt(channum);//列
rows=channum/cols;
r=channum-(cols*rows); /*余数*/
while((r>0)&&((r<=cols/2) ||( r>cols)))
{
cols=cols+1;
rows=channum/cols;
r=channum-(cols*rows);
}
//正好整除
if(cols*rows==channum)
{
for(i=0;i<rows;i++)
for(j=0;j<cols;j++)
{sn=first+i*cols+j;
channel_disp[sn].x=j*w/cols;
channel_disp[sn].y=i*h /rows+y;
channel_disp[sn].width=w/cols-1;
channel_disp[sn].height=h /rows-1;
}
}
if(cols*rows<channum)
{
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{sn=first+i*cols+j;
channel_disp[sn].x=j*w/cols;
channel_disp[sn].y=i*h/(rows+1)+y;
if(j==(cols-1))channel_disp[sn].width=w/cols-1;
else channel_disp[sn].width=w/cols;
channel_disp[sn].height=h /(rows+1);
}
}
LastRowCols=channum-cols*(rows);
for(i=1;i<=LastRowCols;i++)
{
sn=cols*(rows)+i-1;
if(i==LastRowCols){
channel_disp[sn].x=(i-1)*w/LastRowCols-1;
channel_disp[sn].width=w/LastRowCols+1;
}
else {
channel_disp[sn].x=(i-1)*w/LastRowCols;
channel_disp[sn].width=w/LastRowCols;
}
channel_disp[sn].y=h-h /(rows+1)+y;
channel_disp[sn].height=h /(rows+1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -