-
Sure thing. A quick example:
Code:
// Assume that a map has been loaded into a file the characters
// used are stored in a MAP struct (assume it has two 2D arrays:
// one to hold the map's characters and the other holding the
// respective colours)
MAP mp;
// The size of the map
COORD size = { mapSizeX, mapSizeY };
// The location in the array to start drawing from (usually 0,0)
COORD coord = { 0, 0 };
// WriteConsoleOutput needs to use a CHAR_INFO structure as
// it's source buffer (where it's taking the data from), which makes
// things more complicated. I suppose they do it for just that
// reason.
CHAR_INFO *buffer = new CHAR_INFO[mapSizeX * mapSizeY];
// That ^ declared a 1-dimensional CHAR_INFO array. I guess
// they use CHAR_INFO because it can hold character information
// and colour attributes. Anyways, this made the array be the size
// of the picture (or in this case, map) to draw
// Now set up the region on-screen where we will draw
SMALL_RECT rect;
rect.Top = 0;
rect.Left = 0; // Upper-left corner will be 0,0 (adjust this to your
// needs)
rect.Bottom = mapSizeY;
rect.Right = mapSizeX;
// Standard output handle
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
// Now fill the array with the data from the map
int offset = 0;
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++,offset++)
{
buffer[offset].Char.AsciiChar = mp.mapChars[i][j];
buffer[offset].Attributes = mp.mapColours[i][j];
}
}
// Now output the data all at once with WriteConsoleOutput
WriteConsoleOutput(stdOut, // The output handle
buffer, // The source array
size, // The size of the block to draw
coord, // The place to start copying from the source buffer (0,0)
&rect); // The block on-screen to write to
// Erase the buffer
delete [] buffer;
See? It's quite a bit of work. I recommend sticking to one of those libraries, it'll save boatloads of time. But if you really want to do it, more power to you :).
Brendan
EDIT: I have AIM. My sn is HPotter385. And the newest CGL won't quite work, so I'll upload the fixed version here. Again, the documentation won't help you at all, just IM me or email me at [email protected] for information, cos a LOT has changed.
-
Ok, here it is. Now this is JUST the two required header files. No documentation, no Blitmap Creator, nothing. But this SHOULD work now.
-
HarryP:
Did you take out the M_BUTTON_CLICKED identifier from CGL? cause when i try to run the sample documentation code for the buttons, it gives me the error that M_BUTTON_CLICKED is undeclared... help lar lol
-
Lol yeah. It's now 'M_LEFT_BUTTON_CLICKED' and 'M_RIGHT_BUTTON_CLICKED'. Sorry -sheepish grin-.
Brendan
-
Also, I don't know if you're there yet, but a lot of the graphical functions there now have been superceded with a new class. The GraphicObject class lets you do everything you could before, plus lots more. It takes a reference to a Window object when you create a GraphicObject object. For example:
Code:
GraphicObject gfxObj(wnd);
From there, you can do loads of stuff. Draw lines with the MoveTo and LineTo functions (use MoveTo to specify the end point of the line, and LineTo to specify the beginning point). You can also use MoveTo to set the location of where to draw a point with the PointTo function.
Lines are modified through pens. Use the GraphicObject function CreatePen to make a new pen.
Code:
GraphicObject gfxObj(wnd);
// Make a new pen
gfxObj.CreatePen(2, // 2 characters wide\tall
STYLE_DOT, // Dotted line (use STYLE_SOLID for a solid line or
// STYLE_DASH for a dashed line
F_BLUE | B_BLUE); // Blue
// If you draw a line, point, or rectangle without creating a pen, a
// default pen is used (1 point width, solid, black)
// Draw a line
gfxObj.MoveTo(10,20);
gfxObj.LineTo(0,0);
// Draws a line from 0,0 to 10,20
Yeah there's a lot more but I don't want to clog this thread with this stuff, so email me and I'll send you some information (I'm still working on updates to the documentation).
Brendan