Hallo Leute,
ich versuche gerade mit der SDL eine Art Konsole zu basteln.
Hier mal ein Quelltextausschnitt: Console.hpp
|
C-/C++-Quelltext
|
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
|
#ifndef CCONSOLE
#define CCONSOLE
#include <iostream>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <Framework.hpp>
using namespace std;
class CConsole
{
SDL_Surface *Screen;
SDL_Surface *Console;
SDL_Color TextColor;
TTF_Font *Font;
SDL_Rect Back;
SDL_Rect Text;
Uint8 *Keystate;
string Input;
public:
void Get_String();
};
#endif
|
Console.cpp
|
C-/C++-Quelltext
|
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#include <Console.hpp>
void CConsole::Get_String()
{
string Prompt("Type->");
int key=0;
SDL_ShowCursor(0);
this->Screen=Framework->Get_Screen();
this->Keystate=SDL_GetKeyState(0);
while(!(this->Keystate[SDLK_RETURN] || this->Keystate[SDLK_ESCAPE]))
{
SDL_PumpEvents();
if(this->Keystate[SDLK_LSHIFT] || this-Keystate[SDLK_RSHIFT])
switch(this->Keystate[key])
{
case SDLK_a: this->Input.append("A"); break;
case SDLK_b: this->Input.append("B"); break;
case SDLK_c: this->Input.append("C"); break;
case SDLK_d: this->Input.append("D"); break;
case SDLK_e: this->Input.append("E"); break;
case SDLK_f: this->Input.append("F"); break;
case SDLK_g: this->Input.append("G"); break;
case SDLK_h: this->Input.append("H"); break;
case SDLK_i: this->Input.append("I"); break;
case SDLK_j: this->Input.append("J"); break;
case SDLK_k: this->Input.append("K"); break;
case SDLK_l: this->Input.append("L"); break;
case SDLK_m: this->Input.append("M"); break;
case SDLK_n: this->Input.append("N"); break;
case SDLK_o: this->Input.append("O"); break;
case SDLK_p: this->Input.append("P"); break;
case SDLK_q: this->Input.append("Q"); break;
case SDLK_r: this->Input.append("R"); break;
case SDLK_s: this->Input.append("S"); break;
case SDLK_t: this->Input.append("T"); break;
case SDLK_u: this->Input.append("U"); break;
case SDLK_v: this->Input.append("V"); break;
case SDLK_w: this->Input.append("W"); break;
case SDLK_x: this->Input.append("X"); break;
case SDLK_y: this->Input.append("Y"); break;
case SDLK_z: this->Input.append("Z"); break;
}
switch(this->Keystate[key])
{
case SDLK_BACKSPACE: this->Input.erase(Input.npos); break;
case SDLK_a: this->Input.append("a"); break;
case SDLK_b: this->Input.append("b"); break;
case SDLK_c: this->Input.append("c"); break;
case SDLK_d: this->Input.append("d"); break;
case SDLK_e: this->Input.append("e"); break;
case SDLK_f: this->Input.append("f"); break;
case SDLK_g: this->Input.append("g"); break;
case SDLK_h: this->Input.append("h"); break;
case SDLK_i: this->Input.append("i"); break;
case SDLK_j: this->Input.append("j"); break;
case SDLK_k: this->Input.append("k"); break;
case SDLK_l: this->Input.append("l"); break;
case SDLK_m: this->Input.append("m"); break;
case SDLK_n: this->Input.append("n"); break;
case SDLK_o: this->Input.append("o"); break;
case SDLK_p: this->Input.append("p"); break;
case SDLK_q: this->Input.append("q"); break;
case SDLK_r: this->Input.append("r"); break;
case SDLK_s: this->Input.append("s"); break;
case SDLK_t: this->Input.append("t"); break;
case SDLK_u: this->Input.append("u"); break;
case SDLK_v: this->Input.append("v"); break;
case SDLK_w: this->Input.append("w"); break;
case SDLK_x: this->Input.append("x"); break;
case SDLK_y: this->Input.append("y"); break;
case SDLK_z: this->Input.append("z"); break;
}
cout << "Input: " << Input << endl;
SDL_FillRect(this->Screen, 0, 0x0000ff);
this->Font=TTF_OpenFont("bin/Garamond itc.ttf", 20);
if(!this->Font) cout << "Schriftart konnte nicht geladen werden.\n" << TTF_GetError() << endl;;
this->TextColor={255,0,0};
this->Text.x=10;
this->Text.y=10;
this->Console=TTF_RenderText_Solid(this->Font, Prompt.c_str(), this->TextColor);
SDL_BlitSurface(this->Console, 0, this->Screen, &this->Text);
this->TextColor={0,255,0};
this->Text.x=80;
this->Text.y=10;
this->Console=TTF_RenderText_Solid(this->Font, this->Input.c_str(), this->TextColor);
SDL_BlitSurface(this->Console, 0, this->Screen, &this->Text);
SDL_Flip(this->Screen);
SDL_EnableKeyRepeat (0, 50);
SDL_FreeSurface(Console);
TTF_CloseFont(this->Font);
}
}
|
Vielleicht auch noch die Console_main.cpp
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include <Framework.hpp>
#include <Console.hpp>
int main(int argc, char *argv[])
{
CConsole Console;
Framework->Init(800, 600, 32);
Console.Get_String();
Framework->Quit();
}
|
Die beiden Framework-Dateien setze ich jetzt mal noch nicht dazu.
Beim Kompilieren alles gut und schön bis auf 4 Warnings.
Bei den Tastatur eingaben wird trotzdem nichts an den String 'Input' angehäng.
Wie muss ich das dann anstellen?
Danke schon mal.
Gruß Uwe.