problem with a pointer to a 2d vector

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 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//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);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef Window_H  
#define Window_H   
  
class Window   
{
      protected:
                Form form;  
                Border border;
                Image image;                
      public:
             //constructor
             Window(short xPos, short yPos)
             {  
                //setting screen position   
                form.screen_position.X = xPos;    
                form.screen_position.Y = yPos;
                
                //setting border colour combinations
                border.topRightCorner.Char.AsciiChar = 191;
                border.topRightCorner.Attributes = FI_GREEN | B_GREEN; 
                    
                border.topLeftCorner.Char.AsciiChar = 218;
                border.topLeftCorner.Attributes = FI_GREEN | B_GREEN;
                     
                border.bottomRightCorner.Char.AsciiChar = 217;
                border.bottomRightCorner.Attributes = FI_GREEN | B_GREEN;
                     
                border.bottomLeftCorner.Char.AsciiChar = 192; 
                border.bottomLeftCorner.Attributes = FI_GREEN | B_GREEN; 
                    
                border.horizontalLine.Char.AsciiChar = 196;
                border.horizontalLine.Attributes = FI_GREEN | B_GREEN; 
                        
                border.verticalLine.Char.AsciiChar = 179;
                border.verticalLine.Attributes = FI_GREEN | B_GREEN; 
                 
                _CHAR_INFO background; background.Char.AsciiChar = ' ';
                background.Attributes = FI_GREEN | B_GREEN;
                
                //creating image with border     
                Image image = Image( 10, std::vector <_CHAR_INFO>(6,background));
                
                for(short y = 0; y < image[0].size(); y++)
                  for(short x = 0; x < image.size(); x++)
                  { 
                     if((y == 0) && (x == 0))
                        image[x][y] = border.topLeftCorner;
                     else if((y == 0 || (y == (image[0].size() - 1))) && ((x != 0) && (x != (image.size() - 1))))
                        image[x][y] = border.horizontalLine;
                     else if((y == 0) && ((x == image.size() - 1)))
                        image[x][y] = border.topRightCorner;
                     else if(((y != 0) && (y != (image[0].size() - 1))) && ((x == 0) || ( x == (image.size() - 1))))
                        image[x][y] = border.verticalLine;
                     else if((y == (image[0].size() - 1)) && (x == 0))
                        image[x][y] = border.bottomLeftCorner;
                     else if((y == (image[0].size() - 1)) && (x == (image.size() - 1)))
                        image[x][y] = border.bottomRightCorner;
                     else
                        image[x][y] = background;
                  } 
                  
                form.image_ptr = &image;
                                 
                //registering form with engine
                engine.putForm(&form);
             
             }
             //Window(short length = 0, short width = 0, short xPos = 0, short yPos = 0)
             //destructor
             ~Window(){engine.deleteForm( &form);}           
}; 
#endif    


Any help i get with this will be greatly apreciated :)
Last edited on
Topic archived. No new replies allowed.