#include "SetAndDisHalcon.h"
void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box)
{
// Local iconic variables
// Local control variables
HTuple hv_Red, hv_Green, hv_Blue, hv_Row1Part;
HTuple hv_Column1Part, hv_Row2Part, hv_Column2Part, hv_RowWin;
HTuple hv_ColumnWin, hv_WidthWin, hv_HeightWin, hv_MaxAscent;
HTuple hv_MaxDescent, hv_MaxWidth, hv_MaxHeight, hv_R1;
HTuple hv_C1, hv_FactorRow, hv_FactorColumn, hv_UseShadow;
HTuple hv_ShadowColor, hv_Exception, hv_Width, hv_Index;
HTuple hv_Ascent, hv_Descent, hv_W, hv_H, hv_FrameHeight;
HTuple hv_FrameWidth, hv_R2, hv_C2, hv_DrawMode, hv_CurrentColor;
//This procedure displays text in a graphics window.
//
//Input parameters:
//WindowHandle: The WindowHandle of the graphics window, where
// the message should be displayed
//String: A tuple of strings containing the text message to be displayed
//CoordSystem: If set to 'window', the text position is given
// with respect to the window coordinate system.
// If set to 'image', image coordinates are used.
// (This may be useful in zoomed images.)
//Row: The row coordinate of the desired text position
// If set to -1, a default value of 12 is used.
//Column: The column coordinate of the desired text position
// If set to -1, a default value of 12 is used.
//Color: defines the color of the text as string.
// If set to [], '' or 'auto' the currently set color is used.
// If a tuple of strings is passed, the colors are used cyclically
// for each new textline.
//Box: If Box[0] is set to 'true', the text is written within an orange box.
// If set to' false', no box is displayed.
// If set to a color string (e.g. 'white', '#FF00CC', etc.),
// the text is written in a box of that color.
// An optional second value for Box (Box[1]) controls if a shadow is displayed:
// 'true' -> display a shadow in a default color
// 'false' -> display no shadow (same as if no second value is given)
// otherwise -> use given string as color string for the shadow color
//
//Prepare window
GetRgb(hv_WindowHandle, &hv_Red, &hv_Green, &hv_Blue);
GetPart(hv_WindowHandle, &hv_Row1Part, &hv_Column1Part, &hv_Row2Part, &hv_Column2Part);
GetWindowExtents(hv_WindowHandle, &hv_RowWin, &hv_ColumnWin, &hv_WidthWin, &hv_HeightWin);
SetPart(hv_WindowHandle, 0, 0, hv_HeightWin - 1, hv_WidthWin - 1);
//
//default settings
if (0 != (hv_Row == -1))
{
hv_Row = 12;
}
if (0 != (hv_Column == -1))
{
hv_Column = 12;
}
if (0 != (hv_Color == HTuple()))
{
hv_Color = "";
}
//
hv_String = (("" + hv_String) + "").TupleSplit("\n");
//
//Estimate extentions of text depending on font size.
GetFontExtents(hv_WindowHandle, &hv_MaxAscent, &hv_MaxDescent, &hv_MaxWidth, &hv_MaxHeight);
if (0 != (hv_CoordSystem == HTuple("window")))
{
hv_R1 = hv_Row;
hv_C1 = hv_Column;
}
else
{
//Transform image to window coordinates
hv_FactorRow = (1.*hv_HeightWin) / ((hv_Row2Part - hv_Row1Part) + 1);
hv_FactorColumn = (1.*hv_WidthWin) / ((hv_Column2Part - hv_Column1Part) + 1);
hv_R1 = ((hv_Row - hv_Row1Part) + 0.5)*hv_FactorRow;
hv_C1 = ((hv_Column - hv_Column1Part) + 0.5)*hv_FactorColumn;
}
//
//Display text box depending on text size
hv_UseShadow = 1;
hv_ShadowColor = "gray";
if (0 != (HTuple(hv_Box[0]) == HTuple("true")))
{
hv_Box[0] = "#fce9d4";
hv_ShadowColor = "#f28d26";
}
if (0 != ((hv_Box.TupleLength()) > 1))
{
if (0 != (HTuple(hv_Box[1]) == HTuple("true")))
{
//Use default ShadowColor set above
}
else if (0 != (HTuple(hv_Box[1]) == HTuple("false")))
{
hv_UseShadow = 0;
}
else
{
hv_ShadowColor = ((const HTuple&)hv_Box)[1];
//Valid color?
try
{
SetColor(hv_WindowHandle, HTuple(hv_Box[1]));
}
// catch (Exception)
catch (HalconCpp::HException &HDevExpDefaultException)
{
HDevExpDefaultException.ToHTuple(&hv_Exception);
hv_Exception = "Wrong value of control parameter Box[1] (must be a 'true', 'false', or a valid color string)";
throw HalconCpp::HException(hv_Exception);
}
}
}
if (0 != (HTuple(hv_Box[0]) != HTuple("false")))
{
//Valid color?
try
{
SetColor(hv_WindowHandle, HTuple(hv_Box[0]));
}
// catch (Exception)
catch (HalconCpp::HException &HDevExpDefaultException)
{
HDevExpDefaultException.ToHTuple(&hv_Exception);
hv_Exception = "Wrong value of control parameter Box[0] (must be a 'true', 'false', or a valid color string)";
throw HalconCpp::HException(hv_Exception);
}
//Calculate box extents
hv_String = (" " + hv_String) + " ";
hv_Width = HTuple();
{
HTuple end_val93 = (hv_String.TupleLength()) - 1;
HTuple step_val93 = 1;
for (hv_Index = 0; hv_Index.Continue(end_val93, step_val93); hv_Index += step_val93)
{
GetStringExtents(hv_WindowHandle, HTuple(hv_String[hv_Index]), &hv_Ascent,
&hv_Descent, &hv_W, &hv_H);
hv_Width = hv_Width.TupleConcat(hv_W);
}
}
hv_FrameHeight = hv_MaxHeight * (hv_String.TupleLength());
hv_FrameWidth = (HTuple(0).TupleConcat(hv_Width)).TupleMax();
hv_R2 = hv_R1 + hv_FrameHeight;
hv_C2 = hv_C1 + hv_FrameWidth;
//Display rectangles
GetDraw(hv_WindowHandle, &hv_DrawMode);
SetDraw(hv_WindowHandle, "fill");
//Set shadow color
SetColor(hv_WindowHandle, hv_ShadowColor);
if (0 != hv_UseShadow)
{
DispRectangle1(hv_WindowHandle, hv_R1 + 1, hv_C1 + 1, hv_R2 + 1, hv_C2 + 1);
}
//Set box color
SetColor(hv_WindowHandle, HTuple(hv_Box[0]));
DispRectangle1(hv_WindowHandle, hv_R1, hv_C1, hv_R2, hv_C2);
SetDraw(hv_WindowHandle, hv_DrawMode);
}
//Write text.
{
HTuple end_val115 = (hv_String.TupleLength()) - 1;
HTuple step_val115 = 1;
for (hv_Index = 0; hv_Index.Continue(end_val115, step_val115); hv_Index += step_val115)
{
hv_CurrentColor = ((const HTuple&)hv_Color)[hv_Index % (hv_Color.TupleLength())];
if (0 != (HTuple(hv_CurrentColor != HTuple("")).TupleAnd(hv_CurrentColor != HTuple("auto"))))
{
SetColor(hv_WindowHandle, hv_CurrentColor);
}
else
{
SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
}
hv_Row = hv_R1 + (hv_MaxHeight*hv_Index);
SetTposition(hv_WindowHandle, hv_Row, hv_C1);
WriteString(hv_WindowHandle, HTuple(hv_String[hv_Index]));
}
}
//Reset changed window settings
SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
SetPart(hv_WindowHandle, hv_Row1Part, hv_Column1Part, hv_Row2Part, hv_Column2Part);
return;
}
// Chapter: Graphics / Text
// Short Description: Set font independent of OS
void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font, HTuple hv_Bold,
HTuple hv_Slant)
{
// Local iconic variables
// Local control variables
HTuple hv_OS, hv_BufferWindowHandle, hv_Ascent;
HTuple hv_Descent, hv_Width, hv_Height, hv_Scale, hv_Exception;
HTuple hv_SubFamily, hv_Fonts, hv_SystemFonts, hv_Guess;
HTuple hv_I, hv_Index, hv_AllowedFontSizes, hv_Distances;
HTuple hv_Indices, hv_FontSelRegexp, hv_FontsCourier;
//This procedure sets the text font of the current window with
//the specified attributes.
//It is assumed that following fonts are installed on the system:
//Windows: Courier New, Arial Times New Roman
//Mac OS X: CourierNewPS, Arial, TimesNewRomanPS
//Linux: courier, helvetica, times
//Because fonts are displayed smaller on Linux than on Windows,
//a scaling factor of 1.25 is used the get comparable results.
//For Linux, only a limited number of font sizes is supported,
//to get comparable results, it is recommended to use one of the
//following sizes: 9, 11, 14, 16, 20, 27
//(which will be mapped internally on Linux systems to 11, 14, 17, 20, 25, 34)
//
//Input parameters:
//WindowHandle: The graphics window for which the font will be set
//Size: The font size. If Size=-1, the default of 16 is used.
//Bold: If set to 'true', a bold font is used
//Slant: If set to 'true', a
Halcon联合MFC混合编程使用带通滤波器提取线(bandpass_image)
需积分: 50 41 浏览量
2022-06-27
10:39:49
上传
评论
收藏 135KB RAR 举报
yangyang_z
- 粉丝: 335
- 资源: 8
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0