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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "backends/imgui/IconsMaterialSymbols.h"
#include "backends/imgui/imgui_utils.h"
#include "director/director.h"
#include "director/debugger/dt-internal.h"
#include "director/cast.h"
#include "director/castmember/bitmap.h"
#include "director/castmember/text.h"
#include "director/castmember/script.h"
#include "director/movie.h"
#include "director/types.h"
namespace Director {
namespace DT {
static const char *toString(ScriptType scriptType) {
static const char *scriptTypes[] = {
"Score",
"Cast",
"Movie",
"Event",
"Test",
"???",
"???",
"Parent",
};
if (scriptType < 0 || scriptType > kMaxScriptType)
return "???";
return scriptTypes[(int)scriptType];
}
static const char *toIcon(CastType castType) {
static const char *castTypes[] = {
"", // Empty
ICON_MS_BACKGROUND_DOT_LARGE, // Bitmap
ICON_MS_THEATERS, // FilmLoop
ICON_MS_MATCH_CASE, // Text
ICON_MS_PALETTE, // Palette
ICON_MS_IMAGESMODE, // Picture
ICON_MS_VOLUME_UP, // Sound
ICON_MS_SLAB_SERIF, // Button
ICON_MS_SHAPES, // Shape
ICON_MS_MOVIE, // Movie
ICON_MS_ANIMATED_IMAGES, // DigitalVideo
ICON_MS_FORMS_APPS_SCRIPT, // Script
ICON_MS_BRAND_FAMILY, // RTE
"?", // ???
ICON_MS_TRANSITION_FADE}; // Transition
if (castType < 0 || castType > kCastTransition)
return "";
return castTypes[(int)castType];
}
const char *toString(CastType castType) {
static const char *castTypes[] = {
"Empty",
"Bitmap",
"FilmLoop",
"Text",
"Palette",
"Picture",
"Sound",
"Button",
"Shape",
"Movie",
"DigitalVideo",
"Script",
"RTE",
"???",
"Transition"};
if (castType < 0 || castType > kCastTransition)
return "???";
return castTypes[(int)castType];
}
Common::String getDisplayName(CastMember *castMember) {
const CastMemberInfo *castMemberInfo = castMember->getInfo();
Common::String name(castMemberInfo ? castMemberInfo->name : "");
if (!name.empty())
return name;
if (castMember->_type == kCastText) {
TextCastMember *textCastMember = (TextCastMember *)castMember;
return textCastMember->getText();
}
return Common::String::format("%u", castMember->getID());
}
void showCast() {
if (!_state->_w.cast)
return;
ImGui::SetNextWindowPos(ImVec2(20, 160), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(520, 240), ImGuiCond_FirstUseEver);
if (ImGui::Begin("Cast", &_state->_w.cast)) {
// display a toolbar with: grid/list/filters buttons + name filter
ImGuiEx::toggleButton(ICON_MS_LIST, &_state->_cast._listView);
ImGui::SetItemTooltip("List");
ImGui::SameLine();
ImGuiEx::toggleButton(ICON_MS_GRID_VIEW, &_state->_cast._listView, true);
ImGui::SetItemTooltip("Grid");
ImGui::SameLine();
if (ImGui::Button(ICON_MS_FILTER_ALT)) {
ImGui::OpenPopup("filters_popup");
}
ImGui::SameLine();
if (ImGui::BeginPopup("filters_popup")) {
ImGui::CheckboxFlags("All", &_state->_cast._typeFilter, 0x7FFF);
ImGui::Separator();
for (int i = 0; i <= 14; i++) {
ImGui::PushID(i);
Common::String option(Common::String::format("%s %s", toIcon((CastType)i), toString((CastType)i)));
ImGui::CheckboxFlags(option.c_str(), &_state->_cast._typeFilter, 1 << i);
ImGui::PopID();
}
ImGui::EndPopup();
}
_state->_cast._nameFilter.Draw();
ImGui::Separator();
// display a list or a grid
const float sliderHeight = _state->_cast._listView ? 0.f : 38.f;
const ImVec2 childsize = ImGui::GetContentRegionAvail();
Movie *movie = g_director->getCurrentMovie();
ImGui::BeginChild("##cast", ImVec2(childsize.x, childsize.y - sliderHeight));
if (_state->_cast._listView) {
if (ImGui::BeginTable("Resources", 5, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg)) {
ImGui::TableSetupColumn("Name", 0, 120.f);
ImGui::TableSetupColumn("#", 0, 20.f);
ImGui::TableSetupColumn("Script", 0, 80.f);
ImGui::TableSetupColumn("Type", 0, 80.f);
ImGui::TableSetupColumn("Preview", 0, 32.f);
ImGui::TableHeadersRow();
for (auto it : *movie->getCasts()) {
Cast *cast = it._value;
if (!cast->_loadedCast)
continue;
for (auto castMember : *cast->_loadedCast) {
if (!castMember._value->isLoaded())
continue;
Common::String name(getDisplayName(castMember._value));
if (!_state->_cast._nameFilter.PassFilter(name.c_str()))
continue;
if ((castMember._value->_type != kCastTypeAny) && !(_state->_cast._typeFilter & (1 << (int)castMember._value->_type)))
continue;
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("%s %s", toIcon(castMember._value->_type), name.c_str());
ImGui::TableNextColumn();
ImGui::Text("%d", castMember._key);
ImGui::TableNextColumn();
if (castMember._value->_type == CastType::kCastLingoScript) {
ScriptCastMember *scriptMember = (ScriptCastMember *)castMember._value;
ImGui::Text("%s", toString(scriptMember->_scriptType));
}
ImGui::TableNextColumn();
ImGui::Text("%s", toString(castMember._value->_type));
ImGui::TableNextColumn();
ImGuiImage imgID = getImageID(castMember._value);
if (imgID.id) {
showImage(imgID, name.c_str(), 32.f);
}
}
}
ImGui::EndTable();
}
} else {
const float thumbnailSize = (float)_state->_cast._thumbnailSize;
const float contentWidth = ImGui::GetContentRegionAvail().x;
int columns = contentWidth / (thumbnailSize + 8.f);
columns = columns < 1 ? 1 : columns;
if (ImGui::BeginTable("Cast", columns)) {
for (auto it : *movie->getCasts()) {
const Cast *cast = it._value;
if (!cast->_loadedCast)
continue;
for (auto castMember : *cast->_loadedCast) {
if (!castMember._value->isLoaded())
continue;
Common::String name(getDisplayName(castMember._value));
if (!_state->_cast._nameFilter.PassFilter(name.c_str()))
continue;
if ((castMember._value->_type != kCastTypeAny) && !(_state->_cast._typeFilter & (1 << (int)castMember._value->_type)))
continue;
ImGui::TableNextColumn();
ImGui::BeginGroup();
const ImVec2 textSize = ImGui::CalcTextSize(name.c_str());
float textWidth = textSize.x;
float textHeight = textSize.y;
if (textWidth > thumbnailSize) {
textWidth = thumbnailSize;
textHeight *= (textSize.x / textWidth);
}
ImGuiImage imgID = getImageID(castMember._value);
if (imgID.id) {
showImage(imgID, name.c_str(), thumbnailSize);
} else {
ImGui::PushID(castMember._key);
ImGui::InvisibleButton("##canvas", ImVec2(thumbnailSize, thumbnailSize));
ImGui::PopID();
const ImVec2 p0 = ImGui::GetItemRectMin();
const ImVec2 p1 = ImGui::GetItemRectMax();
ImGui::PushClipRect(p0, p1, true);
ImDrawList *draw_list = ImGui::GetWindowDrawList();
draw_list->AddRect(p0, p1, IM_COL32_WHITE);
const ImVec2 pos = p0 + ImVec2((thumbnailSize - textWidth) * 0.5f, (thumbnailSize - textHeight) * 0.5f);
draw_list->AddText(nullptr, 0.f, pos, IM_COL32_WHITE, name.c_str(), 0, thumbnailSize);
draw_list->AddText(nullptr, 0.f, p1 - ImVec2(16, 16), IM_COL32_WHITE, toIcon(castMember._value->_type));
ImGui::PopClipRect();
}
ImGui::EndGroup();
}
}
ImGui::EndTable();
}
}
ImGui::EndChild();
// in the footer display a slider for the grid view: thumbnail size
if (!_state->_cast._listView) {
ImGui::Spacing();
ImGui::Separator();
ImGui::Spacing();
ImGui::SliderInt("Thumbnail Size", &_state->_cast._thumbnailSize, 32, 256);
}
}
ImGui::End();
}
} // namespace DT
} // namespace Director
|