Nov 21, 2018 at 9:55pm UTC
Hello. I've faced an interesting task - to create a library for graphical visualization of the console window. I mean that the commands should change the color of the background/text, the place of the text in the window and the font size. Also the ability to create a text box whose color and size can be selected is needed. I already have something. But the problem is that it doesn't even compile.
Win.cpp
#include "win.h"
namespace lng{
HANDLE console=GetStdHandle(STD_OUTPUT_HANDLE);
class colorClass
short color;
public:
bool setcolor(short);
short getcolor();
colorClass::colorClass(){
color = 0b00001111;
};
colorClass::~colorClass(){
SetConsoleTextAttribute(console,15);
};
short colorClass::getcolor(){ return color; };
bool colorClass::setcolor(short color) {
this->spalva = spalva;
return true;
};
cordinatesClass
CORD cordinate;
public:
bool setcord(CORD);
alternative: bool setcord(short, short);
CORD getcord();
alternative: void getcord(short&, short&);
cordinatesClass::cordinatesClass(){
cordinate.X = 5; cordinate.Y = 5;
}
void cordinatesClass::getcord(short& X, short& Y){
X=cordinate.X;
Y=cordinate.Y;
}
bool cordinatesClass::setcord(short X, short Y){
this->cordinate.X = X;
this->cordinate.Y = Y;
return true;
}
winClass :public colorClass
cordinatesClass cord, size;
bool doubleline, frame;
bool setcolor(short);
short getcolor();
winClass();
~winClass();
void draw();
bool setcord(short, short);
bool setsize(short, short);
void setframe(bool);
void setline(bool);
winClass::winClass(){
doubleline=true;
frame=true;
}
void winClass::draw(){
short tempX, tempY;
this->cord.getcord(tempX, tempY);
CORD tempK={tempX, tempY};
SetConsoleTextAttribute(console, this->getcolor());
this->size.getcord(tempX, tempY);
for(int y=0; y<tempY; y++)
{
tempK.Y = tempY + y;
SetConsoleCursorPosition(console, tempK);
std::cout << std::setw(tempX)<< ' ';
}
}
bool winClass::setcord(short cordinateX, short cordinateY){
this->cord.setcord(cordinateX, cordinateY);
};
bool winClass::setsize(short sizeX, short sizeY){
};
void winClass::setframe(bool showframe){
};
void winClass::setline(bool doubleline){
};
}
Win.h
#ifndef WIN_H
#define WIN_H
#include <windows.h>
#include <iostream>
#include <iomanip>
namespace lng{
class colorClass{
private:
short color;
public:
colorClass();
~colorClass();
bool setcolor(short);
short getcolor();
};
class cordinatesClass{
CORD cordinate;
public:
cordinatesClass();
bool setcord(short, short);
void getcord(short&, short&);
};
class winClass:public colorClass {
private:
cordinatesClass cord, size;
bool doubleline, frame;
public:
bool setcolor(short);
short getcolor();
winClass();
void draw();
bool setcord(short, short);
bool setsize(short, short);
void setframe(bool);
void setline(bool);
};
class textClass : public winClass {
private:
std::string text;
public:
bool settext(std::string);
void draw();
};
}
#endif
Main.cpp
#include <iostream>
#include "win.h"
using namespace std;
int main() {
lng::winClass newwin, nextwin;
newwin.setcolor(0b00011010);
newwin.draw();
return 0;
}
Please, help to understand the code. Without an obvious result, I can't identify what is good and what is not in it.
Nov 22, 2018 at 8:22am UTC
What are the error messages ?