Skyscraper 2.0
console.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 Alpha - Script Console
3 Copyright (C)2003-2024 Ryan Thoryk
4 https://www.skyscrapersim.net
5 https://sourceforge.net/projects/skyscraper/
6 Contact - ryan@skyscrapersim.net
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21*/
22
23#include <mutex>
24#include "globals.h"
25#include "sbs.h"
26#include "debugpanel.h"
27#include "scriptproc.h"
28#include "vm.h"
29#include "vmconsole.h"
30#include "enginecontext.h"
31#include "console.h"
32
33//(*InternalHeaders(Console)
34#include <wx/intl.h>
35#include <wx/string.h>
36//*)
37
38namespace Skyscraper {
39
40//(*IdInit(Console)
41const long Console::ID_tConsole = wxNewId();
42const long Console::ID_tCommand = wxNewId();
43const long Console::ID_bSend = wxNewId();
44const long Console::ID_bClear = wxNewId();
45const long Console::ID_chkEcho = wxNewId();
46const long Console::ID_PANEL1 = wxNewId();
47//*)
48
49BEGIN_EVENT_TABLE(Console,wxFrame)
50 //(*EventTable(Console)
51 //*)
52END_EVENT_TABLE()
53
54std::mutex mtx;
55
56Console::Console(VM *root, wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
57{
58 //(*Initialize(Console)
59 wxBoxSizer* BoxSizer1;
60 wxFlexGridSizer* FlexGridSizer1;
61 wxFlexGridSizer* FlexGridSizer2;
62 wxFlexGridSizer* FlexGridSizer3;
63
64 Create(parent, id, _("Console"), wxDefaultPosition, wxDefaultSize, wxCAPTION|wxSYSTEM_MENU|wxRESIZE_BORDER|wxCLOSE_BOX|wxMAXIMIZE_BOX|wxMINIMIZE_BOX, _T("id"));
65 SetClientSize(wxDefaultSize);
66 Move(wxPoint(0,0));
67 FlexGridSizer1 = new wxFlexGridSizer(2, 1, 0, 0);
68 FlexGridSizer1->AddGrowableCol(0);
69 FlexGridSizer1->AddGrowableRow(0);
70 Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
71 FlexGridSizer3 = new wxFlexGridSizer(2, 1, 0, 0);
72 FlexGridSizer3->AddGrowableCol(0);
73 FlexGridSizer3->AddGrowableRow(0);
74 tConsole = new wxTextCtrl(Panel1, ID_tConsole, wxEmptyString, wxDefaultPosition, wxSize(600,400), wxTE_MULTILINE|wxTE_READONLY|wxTE_DONTWRAP|wxVSCROLL|wxHSCROLL, wxDefaultValidator, _T("ID_tConsole"));
75 tConsole->SetForegroundColour(wxColour(255,255,255));
76 tConsole->SetBackgroundColour(wxColour(0,0,0));
77 FlexGridSizer3->Add(tConsole, 1, wxALL|wxEXPAND, 5);
78 FlexGridSizer2 = new wxFlexGridSizer(1, 2, 0, 0);
79 FlexGridSizer2->AddGrowableCol(0);
80 FlexGridSizer2->AddGrowableRow(0);
81 tCommand = new wxTextCtrl(Panel1, ID_tCommand, wxEmptyString, wxDefaultPosition, wxSize(500,100), wxTE_MULTILINE, wxDefaultValidator, _T("ID_tCommand"));
82 FlexGridSizer2->Add(tCommand, 1, wxALL|wxEXPAND, 5);
83 BoxSizer1 = new wxBoxSizer(wxVERTICAL);
84 bSend = new wxButton(Panel1, ID_bSend, _("Send"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_bSend"));
85 BoxSizer1->Add(bSend, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_LEFT, 5);
86 bClear = new wxButton(Panel1, ID_bClear, _("Clear"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_bClear"));
87 BoxSizer1->Add(bClear, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
88 chkEcho = new wxCheckBox(Panel1, ID_chkEcho, _("Echo"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_chkEcho"));
89 chkEcho->SetValue(true);
90 BoxSizer1->Add(chkEcho, 1, wxALL|wxALIGN_LEFT, 5);
91 FlexGridSizer2->Add(BoxSizer1, 1, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
92 FlexGridSizer3->Add(FlexGridSizer2, 1, wxEXPAND, 5);
93 Panel1->SetSizer(FlexGridSizer3);
94 FlexGridSizer1->Add(Panel1, 1, wxEXPAND, 5);
95 SetSizer(FlexGridSizer1);
96 FlexGridSizer1->SetSizeHints(this);
97
98 Connect(ID_bSend,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Console::On_bSend_Click);
99 Connect(ID_bClear,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Console::On_bClear_Click);
100 Connect(wxID_ANY,wxEVT_CLOSE_WINDOW,(wxObjectEventFunction)&Console::On_Close);
101 //*)
102 Simcore = 0;
103 this->vm = root;
104}
105
107{
108 //(*Destroy(Console)
109 //*)
110}
111
112void Console::On_bSend_Click(wxCommandEvent& event)
113{
114 vm->GetConsole()->Process(tCommand->GetValue().ToStdString(), chkEcho->GetValue());
115 tCommand->Clear();
116}
117
118void Console::On_bClose_Click(wxCommandEvent& event)
119{
120 this->Close();
121}
122
123void Console::On_Close(wxCloseEvent& event)
124{
125 this->Hide();
126}
127
128void Console::Write(const std::string &message, const std::string &color)
129{
130#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
131 //due to hangs, don't allow Windows to write to the console from multiple threads
132 if (mtx.try_lock() == false)
133 return;
134#else
135 mtx.lock();
136#endif
137
138 if (color == "black")
139 tConsole->SetDefaultStyle(wxTextAttr(*wxBLACK));
140 else if (color == "blue")
141 tConsole->SetDefaultStyle(wxTextAttr(*wxBLUE));
142 else if (color == "cyan")
143 tConsole->SetDefaultStyle(wxTextAttr(*wxCYAN));
144 else if (color == "green")
145 tConsole->SetDefaultStyle(wxTextAttr(*wxGREEN));
146 else if (color == "yellow")
147 tConsole->SetDefaultStyle(wxTextAttr(*wxYELLOW));
148 else if (color == "gray")
149 tConsole->SetDefaultStyle(wxTextAttr(*wxLIGHT_GREY));
150 else if (color == "red")
151 tConsole->SetDefaultStyle(wxTextAttr(*wxRED));
152 else if (color == "white")
153 tConsole->SetDefaultStyle(wxTextAttr(*wxWHITE));
154 tConsole->AppendText(message + wxT("\n"));
155 tConsole->SetInsertionPointEnd();
156 mtx.unlock();
157}
158
159void Console::On_bClear_Click(wxCommandEvent& event)
160{
161 tConsole->Clear();
162}
163
164}
165
wxCheckBox * chkEcho
Definition console.h:47
void On_bClear_Click(wxCommandEvent &event)
Definition console.cpp:159
static const long ID_tCommand
Definition console.h:58
static const long ID_tConsole
Definition console.h:57
void On_bSend_Click(wxCommandEvent &event)
Definition console.cpp:112
static const long ID_chkEcho
Definition console.h:61
static const long ID_bSend
Definition console.h:59
void On_Close(wxCloseEvent &event)
Definition console.cpp:123
static const long ID_bClear
Definition console.h:60
wxTextCtrl * tConsole
Definition console.h:50
wxTextCtrl * tCommand
Definition console.h:49
void Write(const std::string &message, const std::string &color)
Definition console.cpp:128
static const long ID_PANEL1
Definition console.h:62
void On_bClose_Click(wxCommandEvent &event)
Definition console.cpp:118
void Process(const std::string &text="", bool echo=true)
VMConsole * GetConsole()
Definition vm.cpp:955
std::mutex mtx
Definition console.cpp:54
Definition XrUuid.h:70