diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-22 14:14:17 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-22 14:14:17 (GMT) |
| commit | 9abe51526cac2634af0541c3de69834dd30e9f78 (patch) | |
| tree | 6ae4deadfe00a83094b9d288d8c11d8ce823577a /src/console | |
| parent | 2c311b9a36a88fadd96f3d39acb1ab2590835d81 (diff) | |
| download | powder-9abe51526cac2634af0541c3de69834dd30e9f78.zip powder-9abe51526cac2634af0541c3de69834dd30e9f78.tar.gz | |
Move all GUI source files into gui/
Diffstat (limited to 'src/console')
| -rw-r--r-- | src/console/ConsoleCommand.h | 23 | ||||
| -rw-r--r-- | src/console/ConsoleController.cpp | 74 | ||||
| -rw-r--r-- | src/console/ConsoleController.h | 31 | ||||
| -rw-r--r-- | src/console/ConsoleModel.cpp | 75 | ||||
| -rw-r--r-- | src/console/ConsoleModel.h | 28 | ||||
| -rw-r--r-- | src/console/ConsoleView.cpp | 102 | ||||
| -rw-r--r-- | src/console/ConsoleView.h | 30 |
7 files changed, 0 insertions, 363 deletions
diff --git a/src/console/ConsoleCommand.h b/src/console/ConsoleCommand.h deleted file mode 100644 index 31e41b0..0000000 --- a/src/console/ConsoleCommand.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef CONSOLECOMMAND_H_ -#define CONSOLECOMMAND_H_ - -class ConsoleCommand -{ -public: - ConsoleCommand(std::string command, int returnStatus, std::string returnValue): - Command(command), ReturnStatus(returnStatus), ReturnValue(returnValue) - { - - } - std::string Command; - int ReturnStatus; - std::string ReturnValue; - - operator std::string() const - { - return Command; - } -}; - - -#endif /* CONSOLECOMMAND_H_ */ diff --git a/src/console/ConsoleController.cpp b/src/console/ConsoleController.cpp deleted file mode 100644 index 602636f..0000000 --- a/src/console/ConsoleController.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include <stack> -#include "ConsoleController.h" - -ConsoleController::ConsoleController(ControllerCallback * callback, CommandInterface * commandInterface): - HasDone(false) -{ - consoleModel = new ConsoleModel(); - consoleView = new ConsoleView(); - consoleView->AttachController(this); - consoleModel->AddObserver(consoleView); - - this->callback = callback; - this->commandInterface = commandInterface; -} - -void ConsoleController::EvaluateCommand(std::string command) -{ - if (command.substr(0, 6) == "!load ") - CloseConsole(); - int returnCode = commandInterface->Command(command); - if(command.length()) - consoleModel->AddLastCommand(ConsoleCommand(command, returnCode, commandInterface->GetLastError())); - else - CloseConsole(); -} - -void ConsoleController::CloseConsole() -{ - if(ui::Engine::Ref().GetWindow() == consoleView) - ui::Engine::Ref().CloseWindow(); -} - -std::string ConsoleController::FormatCommand(std::string command) -{ - return commandInterface->FormatCommand(command); -} - -void ConsoleController::NextCommand() -{ - int cIndex = consoleModel->GetCurrentCommandIndex(); - if(cIndex < consoleModel->GetPreviousCommands().size()) - consoleModel->SetCurrentCommandIndex(cIndex+1); -} - -void ConsoleController::PreviousCommand() -{ - int cIndex = consoleModel->GetCurrentCommandIndex(); - if(cIndex > 0) - consoleModel->SetCurrentCommandIndex(cIndex-1); -} - -void ConsoleController::Exit() -{ - if(ui::Engine::Ref().GetWindow() == consoleView) - ui::Engine::Ref().CloseWindow(); - if(callback) - callback->ControllerExit(); - HasDone = true; -} - -ConsoleView * ConsoleController::GetView() -{ - return consoleView; -} - -ConsoleController::~ConsoleController() { - if(ui::Engine::Ref().GetWindow() == consoleView) - ui::Engine::Ref().CloseWindow(); - if(callback) - delete callback; - delete consoleModel; - delete consoleView; -} - diff --git a/src/console/ConsoleController.h b/src/console/ConsoleController.h deleted file mode 100644 index cf8b36e..0000000 --- a/src/console/ConsoleController.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CONSOLECONTROLLER_H_ -#define CONSOLECONTROLLER_H_ - -#include <string> -#include "Controller.h" -#include "ConsoleView.h" -#include "ConsoleModel.h" -#include "ConsoleCommand.h" -#include "cat/CommandInterface.h" - -class ConsoleModel; -class ConsoleView; -class ConsoleController { - ControllerCallback * callback; - ConsoleView * consoleView; - ConsoleModel * consoleModel; - CommandInterface * commandInterface; -public: - bool HasDone; - ConsoleController(ControllerCallback * callback, CommandInterface * commandInterface); - std::string FormatCommand(std::string command); - void EvaluateCommand(std::string command); - void NextCommand(); - void PreviousCommand(); - void Exit(); - void CloseConsole(); - ConsoleView * GetView(); - virtual ~ConsoleController(); -}; - -#endif /* CONSOLECONTROLLER_H_ */ diff --git a/src/console/ConsoleModel.cpp b/src/console/ConsoleModel.cpp deleted file mode 100644 index ceb6b32..0000000 --- a/src/console/ConsoleModel.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "client/Client.h" -#include "ConsoleModel.h" - -ConsoleModel::ConsoleModel() { - std::vector<std::string> previousHistory = Client::Ref().GetPrefStringArray("Console.History"); - for(std::vector<std::string>::reverse_iterator iter = previousHistory.rbegin(), end = previousHistory.rend(); iter != end; ++iter) - { - if(previousCommands.size()<25) - { - previousCommands.push_front(ConsoleCommand(*iter, 0, "")); - currentCommandIndex = previousCommands.size(); - } - } -} - -void ConsoleModel::AddObserver(ConsoleView * observer) -{ - observers.push_back(observer); - observer->NotifyPreviousCommandsChanged(this); -} - -int ConsoleModel::GetCurrentCommandIndex() -{ - return currentCommandIndex; -} - -void ConsoleModel::SetCurrentCommandIndex(int index) -{ - currentCommandIndex = index; - notifyCurrentCommandChanged(); -} - -ConsoleCommand ConsoleModel::GetCurrentCommand() -{ - if(currentCommandIndex < 0 || currentCommandIndex >= previousCommands.size()) - { - return ConsoleCommand("", 0, ""); - } - return previousCommands[currentCommandIndex]; -} - -void ConsoleModel::AddLastCommand(ConsoleCommand command) -{ - previousCommands.push_back(command); - if(previousCommands.size()>25) - previousCommands.pop_front(); - currentCommandIndex = previousCommands.size(); - notifyPreviousCommandsChanged(); -} - -std::deque<ConsoleCommand> ConsoleModel::GetPreviousCommands() -{ - return previousCommands; -} - -void ConsoleModel::notifyPreviousCommandsChanged() -{ - for(int i = 0; i < observers.size(); i++) - { - observers[i]->NotifyPreviousCommandsChanged(this); - } -} - -void ConsoleModel::notifyCurrentCommandChanged() -{ - for(int i = 0; i < observers.size(); i++) - { - observers[i]->NotifyCurrentCommandChanged(this); - } -} - -ConsoleModel::~ConsoleModel() { - Client::Ref().SetPref("Console.History", std::vector<std::string>(previousCommands.begin(), previousCommands.end())); -} - diff --git a/src/console/ConsoleModel.h b/src/console/ConsoleModel.h deleted file mode 100644 index 312739a..0000000 --- a/src/console/ConsoleModel.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef CONSOLEMODEL_H_ -#define CONSOLEMODEL_H_ - -#include <vector> -#include <deque> -#include "ConsoleView.h" -#include "ConsoleCommand.h" - -class ConsoleView; -class ConsoleModel { - int currentCommandIndex; - std::vector<ConsoleView*> observers; - std::deque<ConsoleCommand> previousCommands; - void notifyPreviousCommandsChanged(); - void notifyCurrentCommandChanged(); -public: - int GetCurrentCommandIndex(); - void SetCurrentCommandIndex(int index); - ConsoleCommand GetCurrentCommand(); - - std::deque<ConsoleCommand> GetPreviousCommands(); - ConsoleModel(); - void AddObserver(ConsoleView * observer); - void AddLastCommand(ConsoleCommand command); - virtual ~ConsoleModel(); -}; - -#endif /* CONSOLEMODEL_H_ */ diff --git a/src/console/ConsoleView.cpp b/src/console/ConsoleView.cpp deleted file mode 100644 index 9a51366..0000000 --- a/src/console/ConsoleView.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "ConsoleView.h" -#include "interface/Keys.h" - -ConsoleView::ConsoleView(): - ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, 150)), - commandField(NULL) -{ - class CommandHighlighter: public ui::TextboxAction - { - ConsoleView * v; - public: - CommandHighlighter(ConsoleView * v_) { v = v_; } - virtual void TextChangedCallback(ui::Textbox * sender) - { - sender->SetDisplayText(v->c->FormatCommand(sender->GetText())); - } - }; - commandField = new ui::Textbox(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), ""); - commandField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; - commandField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - commandField->SetActionCallback(new CommandHighlighter(this)); - AddComponent(commandField); - FocusComponent(commandField); - commandField->SetBorder(false); -} - -void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) -{ - switch(key) - { - case KEY_ESCAPE: - case '`': - if (character != '~') - c->CloseConsole(); - else - Window::DoKeyPress(key, character, shift, ctrl, alt); - break; - case KEY_RETURN: - case KEY_ENTER: - c->EvaluateCommand(commandField->GetText()); - commandField->SetText(""); - commandField->SetDisplayText(""); - break; - case KEY_DOWN: - c->NextCommand(); - break; - case KEY_UP: - c->PreviousCommand(); - break; - default: - Window::DoKeyPress(key, character, shift, ctrl, alt); - break; - } -} - -void ConsoleView::NotifyPreviousCommandsChanged(ConsoleModel * sender) -{ - for(int i = 0; i < commandList.size(); i++) - { - RemoveComponent(commandList[i]); - delete commandList[i]; - } - commandList.clear(); - std::deque<ConsoleCommand> commands = sender->GetPreviousCommands(); - int currentY = Size.Y - 32; - if(commands.size()) - for(int i = commands.size()-1; i >= 0; i--) - { - if(currentY <= 0) - break; - ui::Label * tempLabel = new ui::Label(ui::Point(Size.X/2, currentY), ui::Point(Size.X/2, 16), commands[i].ReturnValue); - tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; - commandList.push_back(tempLabel); - AddComponent(tempLabel); - tempLabel = new ui::Label(ui::Point(0, currentY), ui::Point(Size.X/2, 16), commands[i].Command); - tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; - commandList.push_back(tempLabel); - AddComponent(tempLabel); - currentY-=16; - } -} - -void ConsoleView::NotifyCurrentCommandChanged(ConsoleModel * sender) -{ - commandField->SetText(sender->GetCurrentCommand().Command); - commandField->SetDisplayText(c->FormatCommand(commandField->GetText())); -} - - -void ConsoleView::OnDraw() -{ - Graphics * g = ui::Engine::Ref().g; - g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 0, 0, 0, 110); - g->draw_line(Position.X, Position.Y+Size.Y-16, Position.X+Size.X, Position.Y+Size.Y-16, 255, 255, 255, 160); - g->draw_line(Position.X, Position.Y+Size.Y, Position.X+Size.X, Position.Y+Size.Y, 255, 255, 255, 200); -} - -ConsoleView::~ConsoleView() { -} - diff --git a/src/console/ConsoleView.h b/src/console/ConsoleView.h deleted file mode 100644 index de1c48e..0000000 --- a/src/console/ConsoleView.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef CONSOLEVIEW_H_ -#define CONSOLEVIEW_H_ - -#include <vector> -#include <queue> -#include "interface/Label.h" -#include "interface/Window.h" -#include "ConsoleController.h" -#include "ConsoleModel.h" -#include "interface/Textbox.h" -#include "ConsoleCommand.h" - - -class ConsoleController; -class ConsoleModel; -class ConsoleView: public ui::Window { - ConsoleController * c; - ui::Textbox * commandField; - std::vector<ui::Label*> commandList; -public: - ConsoleView(); - virtual void OnDraw(); - virtual void DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - void AttachController(ConsoleController * c_) { c = c_; } - void NotifyPreviousCommandsChanged(ConsoleModel * sender); - void NotifyCurrentCommandChanged(ConsoleModel * sender); - virtual ~ConsoleView(); -}; - -#endif /* CONSOLEVIEW_H_ */ |
