chatRoom.cpp
00001
00002
00003
00004
00005
00006
00007 #include "chatRoom.h"
00008
00009
00010 ChatRoom::ChatRoom(void) : message_area(NULL) {
00011 }
00012
00013
00014 ChatRoom::~ChatRoom(void) {
00015 deleteObject();
00016 }
00017
00018
00019 void ChatRoom::deleteObject(void) {
00020 delete message_back;
00021 }
00022
00023
00024 void ChatRoom::recreate(void) {
00025 win->lock();
00026 win->clear(ForeDepth);
00027 deleteObject();
00028 Initialize(0, NULL);
00029 win->unlock();
00030 }
00031
00032
00033 int ChatRoom::Initialize(int argc, char *argv[]) {
00034 win->clear(ForeDepth);
00035
00036
00037
00038
00039
00040
00041 Rect message_rect(win->w - 64, win->h/2 - 64);
00042 message_back = new FillSurface(message_rect, Black);
00043 Grid position(win->w/2, win->h -48);
00044 win->add((new LabelComponent(message_back))
00045 ->setPosition(position, Center|Bottom), ForeDepth);
00046 message_area = new ScrollAreaComponent(*ttf, message_rect);
00047 message_area->setPxelSize(MiniSize);
00048 message_area->setPosition(position, Center | Bottom);
00049 win->add(message_area, ForeDepth);
00050 message_area->printf("Welcome!\n");
00051
00052
00053 message_input = new TextInputComponent(*ttf, MiniSize,
00054 Rect(message_rect.w, MiniSize));
00055 message_input->setPosition(Grid(win->w/2, win->h - 16), Center | Bottom);
00056 message_input->activate(true);
00057 win->add(message_input, ForeDepth);
00058
00059 return 0;
00060 }
00061
00062
00063 int ChatRoom::MainLoop(void) {
00064 bool quit = false;
00065 do {
00066 win->lock();
00067
00068 UserInput::userInput_t ui = UserInput::getInputed();
00069 quit = ui.quit | ui.isPressedCode(SDLK_ESCAPE);
00070 win->unlock();
00071
00072 SDL_Delay(10);
00073 } while (!quit);
00074
00075 return 0;
00076 }
00077