MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / DrawColorPicker

Function DrawColorPicker

Source/GUI/dimgui/dimgui.cpp:401–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

399}
400
401static void DrawColorPicker(Object** selected, unsigned selected_count, SceneGraph* scenegraph) {
402 MapEditor* me = scenegraph->map_editor;
403 bool color_changed = false;
404 vec4 color;
405
406 ImGui::Text("Color history");
407 ImGui::BeginGroup();
408 for (int i = 0; i < MapEditor::kColorHistoryLen; ++i) {
409 vec4 col = me->GetColorHistoryIndex(i);
410 ImVec4 imCol(col.x(), col.y(), col.z(), col.w());
411 ImGui::PushID(i);
412 if (ImGui::ColorButton("##histcolbutt", imCol, false)) {
413 color.x() = imCol.x;
414 color.y() = imCol.y;
415 color.z() = imCol.z;
416 color_changed = true;
417 }
418 ImGui::PopID();
419
420 if (i == 0 || (i + 1) % 10 != 0)
421 ImGui::SameLine(0, -1);
422 }
423 ImGui::EndGroup();
424
425 // Show color picker if no objects are selected
426 bool only_movement_objects_selected = (selected_count != 0);
427 for (unsigned selected_i = 0; selected_i < selected_count; ++selected_i) {
428 if (selected[selected_i]->GetType() != _movement_object) {
429 only_movement_objects_selected = false;
430 break;
431 }
432 }
433
434 const size_t MAX_PALETTES = 24;
435 const char* labeled_colors[MAX_PALETTES];
436 unsigned labeled_color_count = 0;
437
438 if (only_movement_objects_selected) {
439 static int palette_index = 0;
440 int max_palette_index = 0;
441 for (unsigned selected_i = 0; selected_i < selected_count; ++selected_i) {
442 MovementObject* mo = (MovementObject*)selected[selected_i];
443 OGPalette* palette = mo->GetPalette();
444 for (auto& i : *palette) {
445 LabeledColor* labeled_color = &i;
446 bool found = false;
447 for (unsigned palette_i = 0; palette_i < labeled_color_count; palette_i++) {
448 if (strcmp(labeled_colors[palette_i], labeled_color->label.c_str()) == 0) {
449 found = true;
450 break;
451 }
452 }
453
454 if (!found) {
455 if (labeled_color_count < MAX_PALETTES) {
456 labeled_colors[labeled_color_count] = labeled_color->label.c_str();
457 labeled_color_count++;
458 }

Callers 3

DrawObjectInfoFlatFunction · 0.85
DrawObjectInfoFunction · 0.85
DrawImGuiFunction · 0.85

Calls 15

TextClass · 0.85
ColorPickerFunction · 0.85
GetColorHistoryIndexMethod · 0.80
AddColorToHistoryMethod · 0.80
GetOverbrightMethod · 0.80
GetTintMethod · 0.80
SelectedMethod · 0.80
QueueSaveHistoryStateMethod · 0.80
minFunction · 0.50
xMethod · 0.45
yMethod · 0.45
zMethod · 0.45

Tested by

no test coverage detected