Doubt in create Menu of options in the horizontal

Hello Everyone.

I need create menu of options in the Horizontal using class.

My main class :

#include <iostream>
#include <string>
#include <conio2.h>
#include <vector>
#include <fstream>

using namespace std;

#include "Tela.h"
#include "Clientes.h"
#include "Filmes.h"
#include "Emprestimos.h"

main()
{
Tela objTela(WHITE,BLUE);
Clientes objCliente;
Filmes objFilme;
Emprestimos objEmprestimo;

bool encontrei;
string resp, opcao;

vector <string> menu;
menu.push_back("1 - Manter Clientes ");
menu.push_back("2 - Manter Filmes ");
menu.push_back("3 - Registrar Emprestimo");
menu.push_back("4 - Registrar Devolucao ");
menu.push_back("0 - Sair ");

while (true)
{
objTela.prepararTela();

// menu do programa
opcao = objTela.mostrarMenu(1,4,menu);


if (opcao == "0") break;

if (opcao == "1") objCliente.executarCRUD();

if (opcao == "2") objFilme.executarCRUD();

if (opcao == "3") objEmprestimo.registrarEmprestimo();

}

}


now is my class "Tela" :



class Tela
{
public:
// metodo construtor
Tela()
{
this->corTexto = GREEN;
this->corFundo = BLACK;
}


// metodo construtor sobrecarregado
Tela(int corT, int corF)
{
this->corTexto = corT;
this->corFundo = corF;
}


// metodo que prepara a tela para uso
void prepararTela()
{
// configura as cores e limpa a tela
textcolor(this->corTexto);
textbackground(this->corFundo);
clrscr();

// area de mensagem no rodape da tela
//this->montarMoldura(1,23,80,25,1,0);
//this->mostrarMensagem("Escolha uma opcao");

// area de mensagem no topo da tela
this->montarMoldura(1,1,80,3,2,0);
this->mostrarMensagem("Sistema de Video Locadora",2);

}


// exibe um menu de barras
string mostrarMenu(int col, int lin, vector<string> opcoes)
{
string opcao;
int colunaIni, colunaFim, linhaIni, linhaFim, tecla;
int opcaoAtual;

colunaIni = col;
linhaIni = lin;
// calcular a coluna e linha final
colunaFim = colunaIni + opcoes[0].size() + 1;
linhaFim = linhaIni + opcoes.size() + 1;

this->montarMoldura(colunaIni, linhaIni, colunaFim, linhaFim, 2, 1);

// agora mostra o menu
for (int x=0; x<opcoes.size(); x++)
{
gotoxy(colunaIni+1, linhaIni+1+x);
// gotoxy(opcaoAtual+1+(opcaoAtual*50),lin);
cout << opcoes[x];

}\

opcaoAtual = 0;
while (true)
{
this->inverterCoresTela();
gotoxy(colunaIni+1, linhaIni+1+opcaoAtual);
cout << opcoes[opcaoAtual];
this->reverterCoresTela();

tecla = getch();

if (tecla == 13)
{
opcao = opcoes[opcaoAtual][0];
break;
}

if (tecla == 224)
{
gotoxy(colunaIni+1, linhaIni+1+opcaoAtual);
cout << opcoes[opcaoAtual];

tecla = getch();

// seta para baixo
if (tecla == 80)
{
opcaoAtual ++;
if (opcaoAtual == opcoes.size())
{
opcaoAtual = 0;
}
}

// seta para cima
if (tecla == 72)
{
opcaoAtual --;
if (opcaoAtual == -1)
{
opcaoAtual = opcoes.size()-1;
}
}
}
}
return opcao;
}


// inverte as cores da tela
void inverterCoresTela()
{
textcolor(this->corFundo);
textbackground(this->corTexto);
}


// reverte as cores da tela
void reverterCoresTela()
{
textcolor(this->corTexto);
textbackground(this->corFundo);
}


// limpa uma região da tela
void limparArea(int coli, int lini, int colf, int linf)
{
int coluna, linha;
for (coluna=coli; coluna<=colf; coluna++)
{
for (linha=lini; linha<=linf; linha++)
{
gotoxy(coluna, linha); cout << " ";
}
}
}


// monta uma moldura na tela
void montarMoldura(int coli, int lini, int colf, int linf, int tipo, int mold)
{
int coluna, linha;
int cse, csd, cie, cid, hor, ver;

this->limparArea(coli, lini, colf, linf);

if (tipo==1)
{
hor = 196;
ver = 179;
cse = 218;
csd = 191;
cie = 192;
cid = 217;
}
else
{
hor = 205;
ver = 186;
cse = 201;
csd = 187;
cie = 200;
cid = 188;
}

// linhas horizontais
for (coluna=coli; coluna<=colf; coluna++)
{
gotoxy(coluna, lini); cout << char(hor);
gotoxy(coluna, linf); cout << char(hor);
}

// linhas verticais
for (linha=lini; linha<=linf; linha++)
{
gotoxy(coli, linha); cout << char(ver);
gotoxy(colf, linha); cout << char(ver);
}

gotoxy(coli, lini); cout << char(cse);
gotoxy(colf, lini); cout << char(csd);
gotoxy(coli, linf); cout << char(cie);
gotoxy(colf, linf); cout << char(cid);


if (mold==1)
{

// sombra horizontal no canto inferior
for (coluna=coli+1; coluna<=colf+1; coluna++)
{
gotoxy(coluna, linf+1); cout << char(178);
}
// sombra vertical no canto direito
for (linha=lini+1; linha<=linf+1; linha++)
{
gotoxy(colf+1, linha); cout << char(178);
}
}
}


// mostra uma mensagem emoldura na linha 23 da tela
void mostrarMensagem(string msg, int linha=24)
{
int coluna;
this->limparArea(2,24,79,24);
coluna = (80 - msg.size())/2;
gotoxy(coluna, linha); cout << msg;
}


// realiza perguntas na linha 21 da tela
string realizarPergunta(string pergunta, int cor=WHITE)
{
int coluna;
string resposta;
this->montarMoldura(1,20,80,22,1,0);
coluna = (80 - pergunta.size())/2;
gotoxy(coluna, 21); cout << pergunta;
getline(cin, resposta);
this->limparArea(1,20,80,22);

resposta = toupper(resposta[0]);

return resposta;
}


private:
int corTexto;
int corFundo;

};


My doubt is create the menu in horizontal.

help me, please.


my mail is lucasspezziaa@gmail.com
i am the disposition.

Ps- i am Brasilian.







Topic archived. No new replies allowed.