A Basic Messaging Panel

Also see Moving Low Level Graphics (GFX) Objects on your Charts

This first post introduces you to the basic techniques on how to create a matrix of text cells to display messages and system status on your chart. At this stage the cells are not mouse-click sensitive; this and other features will be added later. In this example the number of columns, rows, the font size, and the location of the message panel, can be set from the Param window. In your final application you might want to make these parameters constant and remove the corresponding Param statements. You can combine any number of Panels, here is an example for multiple panels layouts:

image

The following simple panel is produced by the code in this post.

image

The code below will place the above Message panel on your chart. A code description follows below listing.


#include <MessagePanelInclude.afl>

global ColNumber;

CellHeight Param("Cell Height",20,5,200,5);

CellWidth Param("Cell Width",120,5,200,5);

PanelYoffset Param("Cell Row Offset (px)",10,0,Status("pxheight"),5);

PanelXoffset Param("Cell Column Offset (px)",10,0,Status("pxwidth"),5);

FontRatio Param("Font:CellHeight ratio",2,1,20,0.1);

MsgCol_Begin"COLUMNNAME 1"CellHeightCellWidthPanelXoffsetPanelYoffset );

TextCell"Text Message 1"BackgroundColor=1TextColor=2);

TextCell"Text Message 2"23);

TextCell"Text Message 3"84);

TextCell"Text Message 4"75);

TextCell"Text Message 5"46);

TextCell"Text Message 6"37);

TextCell"Text Message 7"28);

MsgCol_End();

MsgCol_Begin" COLUMNNAME 2"CellHeightCellWidthPanelXoffsetPanelYoffset );

TextCell"Text Message 1"92);

TextCell"Text Message 2"83);

TextCell"Text Message 3"74);

TextCell"Text Message 4"65);

TextCell"Text Message 5"56);

TextCell"Text Message 6"47);

TextCell"Text Message 7"38);

MsgCol_End();

Message Panel code above calls the Include file listed at the end of this post. The The MsgCol_Begin() function defines the name and dimensions for the current column:

MsgCol_Begin"COLUMNNAME 1"CellHeightCellWidthPanelXoffsetPanelYoffset );

You can create many columns. The ColName is used in Static variables to allow the code to know to which Column the TextCells belong. The last four arguments are self-explanatory. The Overlay and background modes can be changed inside this function, or you can extract these GFX statements and execute them separately.

The TextCell() function adds one TextCell to the column. It defines the Message, Background color, and TextColor to be used:


TextCell"Text Message 1"colorBlackcolorWhite);

The MsgCol_End() terminates the current column and draws the GFX pgraphics to the chart.

The Include file makes extensive use of static variables that are wrapped in kStaticVar…() to make the static variables unique to the current ChartID. This is needed to call the functions from different panes and windows without interfering with one another. For more on this see Keying Static Variables.


// This is the Include file MessagePanelInclude.afl, copy to your default Include folder

procedure kStaticVarSetSNameSValue )

{

ChartID GetChartID();

InIndicator Status("Action") == 1;

if( InIndicator StaticVarSet(Sname+ChartIDSvalue);

}

function kStaticVarGetSName )

{

ChartID GetChartID();

Var = StaticVarGet(Sname+ChartID);

return Var;

}

procedure kStaticVarSetTextSNameSValue )

{

ChartID GetChartID();

InIndicator Status("Action") == 1;

if( InIndicator StaticVarSetText(Sname+ChartIDSvalue);

}

function kStaticVarGetTextSName )

{

ChartID GetChartID();

return StaticVarGetText(Sname+ChartID);

}

function MsgCol_BeginColNameCellHeightCellWidthPanelXoffsetPanelYoffset )

{

global FontRatioColNameColNumber;

ColNumber VarGet("ColNumber");

if( IsEmptyColNumber ) ) VarSet("ColNumber",1);

else VarSet("ColNumber", ++ColNumber);

ColName ColName+GetChartID();

GfxSetOverlayMode);

GfxSelectFont"Tahoma"CellHeight/FontRatio800 );

GfxSelectPencolorBlack );

GfxSetBkMode);

kStaticVarSet("PanelItemNum"+ColName0);

VarSetText("ColName",ColName);

return ColNumber;

}

function MsgCol_End( )

{

global CellHeightCellWidthPanelYoffsetPanelXoffsetColNumberPanelItemNum;

ChartIDStr NumToStr(GetChartID(),1.0,False);

ColName VarGetText("ColName");

ULCellX PanelXoffset + (ColNumber-1) * CellWidth;

LRCellX ULCellX CellWidth;

for( Row 1Row <= PanelItemNumRow++ )

{

ULCellY = (Row-1) * CellHeight PanelYoffset;

LRCellY ULCellY CellHeight;

TextCell kStaticVarGetText("TextCell"+ColName+Row);

TextColor Nz(kStaticVarGet("TextColor"+ColName+Row));

BackColor Nz(kStaticVarGet("BackColor"+ColName+Row));

if( Row==1TextCell StrReplaceTextCellChartIDStr"");

GfxSelectSolidBrushBackColor);

GfxRectangleULCellXULCellYLRCellXLRCellY );

GfxSetBkColorBackColor);

GfxSetTextColorTextColor );

GfxDrawTextTextCellULCellXULCellYLRCellXLRCellY32 4);

}

}

function TextCellTextCellbackColorTextColor)

{

global InitializePanelsPanelVisible;

ColName VarGetText("ColName");

PanelItemNum Nz(kStaticVarGet("PanelItemNum"+ColName))+1;

kStaticVarSet("PanelItemNum"+ColNamePanelItemNum);

kStaticVarSet("CellState"+ColName+PanelItemNumFalse);

Label StrExtract(TextCell,0);

kStaticVarSetText("TextCell"+ColName+PanelItemNumLabel);

kStaticVarSet("TextColor"+ColName+PanelItemNumTextColor);

kStaticVarSet("BackColor"+ColName+PanelItemNumbackColor);

}

function Newpanel()

{

VarSet("ColNumber"0);

}

For those who want to experiment with multi-panel layouts here is the code used to produce the xample shown earlier:

#include

global ColNumber;
_SECTION_BEGIN("MESSAGE PANEL 1");
CellHeight                Param("Cell Height",20,5,200,1);
CellWidth                 Param("Cell Width",120,5,200,1);
PanelYoffset             Param("Cell Row Offset (px)",10,0,Status("pxheight"),1);
PanelXoffset            Param("Cell Column Offset (px)",10,0,Status("pxwidth"),1);
FontRatio               Param("Font:CellHeight ratio",2,1,20,0.1);

MsgCol_Begin"COLUMNNAME  1"CellHeightCellWidthPanelXoffsetPanelYoffset );
TextCell"PANEL 1"colorBlackcolorWhite);
TextCell"Text Message 2"23);
TextCell"Text Message 3"84);
TextCell"Text Message 4"75);
TextCell"Text Message 5"46);
TextCell"Text Message 6"37);
TextCell"Text Message 7"28);
TextCell"Text Message 8"92);
TextCell"Text Message 9"83);
TextCell"Text Message 10"74);
TextCell"Text Message 11"65);
TextCell"Text Message 12"56);
TextCell"Text Message 13"47);
TextCell"Text Message 14"38);
MsgCol_End();
_SECTION_END();

_SECTION_BEGIN("MESSAGE PANEL 2");
CellHeight                Param("2Cell Height",20,5,200,1);
CellWidth                 Param("2Cell Width",120,5,200,1);
PanelYoffset             Param("2Cell Row Offset (px)",10,0,Status("pxheight"),1);
PanelXoffset            Param("2Cell Column Offset (px)",10,0,Status("pxwidth"),1);
FontRatio               Param("2Font:CellHeight ratio",2,1,20,0.1);

Newpanel();
MsgCol_Begin"COLUMNNAME  1"CellHeightCellWidthPanelXoffsetPanelYoffset );
TextCell"PANEL 2"1colorWhite);
MsgCol_End();
MsgCol_Begin"COLUMNNAME  1"CellHeightCellWidthPanelXoffsetPanelYoffset );
TextCell"Text Message B"21);
MsgCol_End();
MsgCol_Begin"COLUMNNAME  1"CellHeightCellWidthPanelXoffsetPanelYoffset );
TextCell"Text Message C"4colorWhite);
MsgCol_End();
MsgCol_Begin"COLUMNNAME  1"CellHeightCellWidthPanelXoffsetPanelYoffset );
TextCell"Text Message D"5colorWhite);
MsgCol_End();
MsgCol_Begin"COLUMNNAME  1"CellHeightCellWidthPanelXoffsetPanelYoffset );
TextCell"Text Message E"4colorWhite);
MsgCol_End();
MsgCol_Begin"COLUMNNAME  1"CellHeightCellWidthPanelXoffsetPanelYoffset );
TextCell"Text Message F"5colorWhite);
MsgCol_End();
_SECTION_END();

_SECTION_BEGIN("MESSAGE PANEL 3");
Newpanel();
CellHeight                Param("1Cell Height",20,5,200,1);
CellWidth                 Param("1Cell Width",120,5,200,1);
PanelYoffset             Param("1Cell Row Offset (px)",10,0,Status("pxheight"),1);
PanelXoffset            Param("1Cell Column Offset (px)",10,0,Status("pxwidth"),1);
FontRatio               Param("1Font:CellHeight ratio",2,1,20,0.1);

MsgCol_Begin"COLUMNNAME  1"CellHeightCellWidthPanelXoffsetPanelYoffset );
TextCell"PANEL 3"colorBlackcolorWhite);
TextCell"Text Message 22"23);
TextCell"Text Message 23"84);
TextCell"Text Message 24"75);
TextCell"Text Message 25"46);
TextCell"Text Message 26"37);
TextCell"Text Message 27"28);
MsgCol_End();

MsgCol_Begin"COLUMNNAME  2"CellHeightCellWidthPanelXoffsetPanelYoffset );
TextCell"Text Message 28"92);
TextCell"Text Message 29"83);
TextCell"Text Message 30"74);
TextCell"Text Message 31"65);
TextCell"Text Message 32"56);
TextCell"Text Message 33"47);
TextCell"Text Message 34"38);
MsgCol_End();
_SECTION_END();

Comments are closed.