GuiLineCtrl
by Charlie Sibbach · 07/03/2006 (11:15 am) · 5 comments
Download Code File
GuiLineCtrl is a very simple gui element. All it does is draw a line from top left to bottom right, or if the Invert flag is set, from bottom left to top right. The line will scale and translate as a normal GUI element, and can respond to clicks and interaction as any other GUI element. This could also be used as a very, very simple example of how to make your own GUI type.
How To Use:
Unzip the guiLineCtrl.rar file. There are three files there. Copy the engine folder into your project, it places guiLineCtrl.cc and guiLineCtrl.h into the engine/gui/game folder. Include them both in your project and rebuild the project. The guiLineUtilities.cs file contains a useful script function for drawing lines between two arbitrary points. You can place this file wherever you want, although the example/client/scripts folder is a good choice. Make sure to exec the file somewhere in your script. Or, you can just copy the drawLine function into your own code file.
What Is It:
A GuiLineCtrl is derived from a basic GuiControl, and hence follows all the ordinary conventions for GUI objects. You can add them directly through the built-in Gui Editor, but they are most useful for dynamically building up information displays.
There are five primary properties for a GuiLineCtrl- "position", "Extent", "Invert", "LineColor", and "LineSize". "position" is part of the standard GuiControl, and defines the upper-left hand corner of the line. "Extent" is also part of the standard control, and defines the offset to the lower-right hand corner of the line. The line will be drawn from corner to corner. The Invert field will cause the line to be drawn from the other set of corners, allowing any line to be drawn. The LineColor and LineSize fields define the properties of the line.
The drawLine() script function simplifies the dynamic use of GuiLineCtrl. The parameters are two arbitrary points, a color, and a floating-point line size. The function returns a new GuiLineCtrl that matches these parameters, which should be added to the proper GUI to complete the task.
GuiLineCtrl is a very simple gui element. All it does is draw a line from top left to bottom right, or if the Invert flag is set, from bottom left to top right. The line will scale and translate as a normal GUI element, and can respond to clicks and interaction as any other GUI element. This could also be used as a very, very simple example of how to make your own GUI type.
How To Use:
Unzip the guiLineCtrl.rar file. There are three files there. Copy the engine folder into your project, it places guiLineCtrl.cc and guiLineCtrl.h into the engine/gui/game folder. Include them both in your project and rebuild the project. The guiLineUtilities.cs file contains a useful script function for drawing lines between two arbitrary points. You can place this file wherever you want, although the example/client/scripts folder is a good choice. Make sure to exec the file somewhere in your script. Or, you can just copy the drawLine function into your own code file.
What Is It:
A GuiLineCtrl is derived from a basic GuiControl, and hence follows all the ordinary conventions for GUI objects. You can add them directly through the built-in Gui Editor, but they are most useful for dynamically building up information displays.
There are five primary properties for a GuiLineCtrl- "position", "Extent", "Invert", "LineColor", and "LineSize". "position" is part of the standard GuiControl, and defines the upper-left hand corner of the line. "Extent" is also part of the standard control, and defines the offset to the lower-right hand corner of the line. The line will be drawn from corner to corner. The Invert field will cause the line to be drawn from the other set of corners, allowing any line to be drawn. The LineColor and LineSize fields define the properties of the line.
The drawLine() script function simplifies the dynamic use of GuiLineCtrl. The parameters are two arbitrary points, a color, and a floating-point line size. The function returns a new GuiLineCtrl that matches these parameters, which should be added to the proper GUI to complete the task.
About the author
#3
06/16/2007 (9:29 am)
It was very useful for understanding the basics. Thanks.
#4
This change makes the minimum %extent = to the %size parameter.
In function drawLine Just above the creation of the control, add this new block:
09/17/2007 (4:03 pm)
I made a small addition to the GuiLineUtilities.cs script to keep the controls from disappearing when they were requested parallel to the Gui X or Y axes. (In these cases, the extent of the line control was zero in the parallel direction.) This change makes the minimum %extent = to the %size parameter.
In function drawLine Just above the creation of the control, add this new block:
// extent adjustments for lines parallel to Gui X or Y axes
// (If extent is too small, (smaller than %size) the lines will not show up)
if (%ex < %size) {
%ex = %size;
%extent = %ex SPC %ey;
} else if (%ey < %size) {
%ey = %size;
%extent = %ex SPC %ey;
}
#5
1) in guiLineCtrl.h, change "sim/sceneObject.h" to "scene/sceneObject.h"
2) in guiLineCtrl.h, replace platformGL.h with gfxDrawUtil.h:
3) at the top of guiLineCtrl.cpp (I made it cpp instead of cc), comment out the following:
4) and then for the real deal, in GuiLineCtrl::onRender, here's my new function:
I didn't bother with colors since I only needed black, but you can probably figure that part out on your own.
05/16/2012 (6:34 pm)
Hey, this is a pretty old thread, but since this code still isn't in the engine, thought it might be useful to somebody besides me to have it updated to current T3D. I ripped out the openGL stuff and plugged it into gfxDrawUtil, like so:1) in guiLineCtrl.h, change "sim/sceneObject.h" to "scene/sceneObject.h"
2) in guiLineCtrl.h, replace platformGL.h with gfxDrawUtil.h:
//#include "platformWin32/platformGL.h" #include "gfx/gfxDrawUtil.h"
3) at the top of guiLineCtrl.cpp (I made it cpp instead of cc), comment out the following:
//#include "dgl/dgl.h" //#include "game/game.h"
4) and then for the real deal, in GuiLineCtrl::onRender, here's my new function:
void GuiLineCtrl::onRender(Point2I offset, const RectI &updateRect)
{
RectI ctrlRect(offset, mBounds.extent + offset);
Point2I start,end;
if (!mInvertLine)
{
start.set(ctrlRect.point.x, ctrlRect.point.y);
end.set(ctrlRect.extent.x, ctrlRect.extent.y);
} else {
start.set(ctrlRect.point.x, ctrlRect.extent.y);
end.set(ctrlRect.extent.x, ctrlRect.point.y);
}
GFX->getDrawUtil()->drawLine(start, end, ColorI(0,0,0));
renderChildControls(offset, updateRect);
}I didn't bother with colors since I only needed black, but you can probably figure that part out on your own.

Torque 3D Owner Jesse Liles