this is an attempt to eventualy create a simple gui in console on the windows platform(i apologize in advance if some of my code doesn´t make alot of sense, i am self taught and a novice therefore it´s a bit chaotic). Part of this is off a tutorial i picked up somewhere.
The idea is that i can create window objects, that has a 2d vector of _CHAR_INFO(typedefed to Image to be read more easily)and a COORD to store its position on the screen.
These go in a form object ( a struct which hasa pointer to the image and a COORD) which is sent to the engine object when the window object is initialized.
The form is stored in a vector of Form pointers in the engine object, when the function PrintToScreen() is called it loops through all the forms in the vector of forms and all the images copied to the offScreenBuffer in their correct positions.
I get no error messages, program runs fine exept there are no windows, just the purple background :(
1 2 3 4 5 6 7 8 9 10 11
#ifndef Form_H
#define Form_H
//forms will be used tiles or menus to send their image and screen pos to the engine class
struct Form
{
public:
COORD screen_position;
Image *image_ptr;
};
#endif
//post was too big so i only left the bit that matters of this class
class Engine
{
protected:
std::vector <Form *> formList; //holds pointers to all forms to be displayed
public:
void putForm(Form * form){ formList.push_back(form);}
void printToScreen()
{
if(numEvents != 0)
{
//print background to off screen buffer
for(short y = 0; y < offScreenBufferSize.Y; y++)
for(short x = 0; x < offScreenBufferSize.X; x++)
offScreenBuffer[x + offScreenBufferSize.X * y] = DEFAULT_CHAR;
// >>>>>>problem is here somewhere<<<<<<<
//print forms to off screen buffer
for(short i = 0; i < formList.size(); i++)
{
//set up temporary objects
Form form = *formList[i];
Image image = *form.image_ptr;
COORD screenPos = form.screen_position;
//copy form to off screen buffer
for(short y = 0; y < image[0].size(); y++)
for(short x = 0; x < image.size(); x++)
offScreenBuffer[(screenPos.X + x) + ((screenPos.Y + y) * offScreenBufferSize.X)] = image[x][y];
}//------------------------------------------------*/
//send to console buffer
WriteConsoleOutput(wHnd, offScreenBuffer, offScreenBufferSize, characterPos, &writeArea);
}
}
}engine("ello world", 125, 59);