Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions code/missioneditor/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ constexpr float DEFAULT_NEBULA_RANGE = 3000.0f;
// Smallest meaningful change in an orientation input field (degrees)
constexpr float ORIENT_INPUT_THRESHOLD = 0.01f;

// Field of view (zoom) of the editor viewport. The projection matrix and the g3 view matrix must use the same
// value. If they do not, the labels and the mouse picking do not align with the rendered objects.
constexpr float EDITOR_DEFAULT_FOV = 0.485f;

// Normalize a degree value into the range [-180, 180]
float normalize_degrees(float deg);

Expand Down
7 changes: 7 additions & 0 deletions code/missioneditor/sexp_annotation_model.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include "missioneditor/sexp_annotation_model.h"
#include "missioneditor/sexp_tree_model.h"

bool annotation_text_is_dark(int r, int g, int b)
{
// The source of this contrast rule:
// https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color
return (r * 0.299 + g * 0.587 + b * 0.114) > 149;
}

SCP_vector<event_annotation> Event_annotations;

// -----------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions code/missioneditor/sexp_annotation_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ struct event_annotation {
};
extern SCP_vector<event_annotation> Event_annotations;

// Returns true if black text is readable on the annotation background color, and false if white text is better.
// Both editors use this rule, so that an annotation has the same text color in FRED2 and in QtFRED.
bool annotation_text_is_dark(int r, int g, int b);

struct sexp_tree_item;

class SexpAnnotationModel {
Expand Down
4 changes: 1 addition & 3 deletions fred2/eventeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1991,9 +1991,7 @@ void event_sexp_tree::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
if (ea->r != 255 || ea->g != 255 || ea->b != 255)
{
// contrast color calculation taken from here:
// https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color
if ((ea->r*0.299 + ea->g*0.587 + ea->b*0.114) > 149)
if (annotation_text_is_dark(ea->r, ea->g, ea->b))
pcd->clrText = RGB(0, 0, 0);
else
pcd->clrText = RGB(255, 255, 255);
Expand Down
8 changes: 4 additions & 4 deletions fred2/fredrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ static char THIS_FILE[] = __FILE__;
#define FRED_COLOUR_WHITE 0xffffff
#define FRED_COLOUR_YELLOW_GREEN 0xc8ff00

const float FRED_DEFAULT_HTL_FOV = 0.485f;
const float FRED_BRIEFING_HTL_FOV = 0.325f;
const float FRED_DEAFULT_HTL_DRAW_DIST = 300000.0f;

Expand Down Expand Up @@ -844,7 +843,8 @@ void fred_disable_htl() {
}

void fred_enable_htl() {
gr_set_proj_matrix((4.0f / 9.0f) * PI * (Briefing_dialog ? Briefing_window_FOV : FRED_DEFAULT_HTL_FOV), gr_screen.aspect*(float) gr_screen.clip_width / (float) gr_screen.clip_height, 1.0f, FRED_DEAFULT_HTL_DRAW_DIST);
// g3_set_view_matrix() sets Proj_fov from its zoom, so the projection always uses the field of view of the g3 view
gr_set_proj_matrix(Proj_fov, gr_screen.aspect*(float) gr_screen.clip_width / (float) gr_screen.clip_height, 1.0f, FRED_DEAFULT_HTL_DRAW_DIST);
gr_set_view_matrix(&Eye_position, &Eye_matrix);
}

Expand Down Expand Up @@ -1712,7 +1712,7 @@ void render_frame() {
font::set_font(font::FONT1);
light_reset();

g3_set_view_matrix(&eye_pos, &eye_orient, (Briefing_dialog ? Briefing_window_FOV : FRED_DEFAULT_HTL_FOV));
g3_set_view_matrix(&eye_pos, &eye_orient, (Briefing_dialog ? Briefing_window_FOV : EDITOR_DEFAULT_FOV));
Viewer_pos = eye_pos; // for starfield code

fred_enable_htl();
Expand Down Expand Up @@ -1821,7 +1821,7 @@ void render_frame() {
gr_set_clip(0, 0, True_rw, True_rh);

g3_start_frame(0); // ** Accounted for
g3_set_view_matrix(&eye_pos, &eye_orient, (Briefing_dialog ? Briefing_window_FOV : FRED_DEFAULT_HTL_FOV));
g3_set_view_matrix(&eye_pos, &eye_orient, (Briefing_dialog ? Briefing_window_FOV : EDITOR_DEFAULT_FOV));
}

void render_models(void) {
Expand Down
6 changes: 3 additions & 3 deletions fred2/fredview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,7 @@ void view_universe(int just_marked)

dist = std::max(radius, fl_sqrt(20.0f)) + 1.0f;
vm_vec_scale_add(&view_pos, &center, &view_orient.vec.fvec, -dist);
g3_set_view_matrix(&view_pos, &view_orient, 0.5f);
g3_set_view_matrix(&view_pos, &view_orient, EDITOR_DEFAULT_FOV);

ptr = GET_FIRST(&obj_used_list);
while (ptr != END_OF_LIST(&obj_used_list)) {
Expand All @@ -2330,7 +2330,7 @@ void view_universe(int just_marked)
while (v.codes & CC_OFF) { // is point off screen?
dist += 5.0f; // zoom out a little and check again.
vm_vec_scale_add(&view_pos, &center, &view_orient.vec.fvec, -dist);
g3_set_view_matrix(&view_pos, &view_orient, 0.5f);
g3_set_view_matrix(&view_pos, &view_orient, EDITOR_DEFAULT_FOV);
g3_rotate_vertex(&v, &ptr->pos);
if (g3_project_vertex(&v) & PF_OVERFLOW)
Int3();
Expand All @@ -2342,7 +2342,7 @@ void view_universe(int just_marked)

dist *= 1.1f;
vm_vec_scale_add(&view_pos, &center, &view_orient.vec.fvec, -dist);
g3_set_view_matrix(&view_pos, &view_orient, 0.5f);
g3_set_view_matrix(&view_pos, &view_orient, EDITOR_DEFAULT_FOV);
Update_window = 1;
}

Expand Down
2 changes: 1 addition & 1 deletion fred2/management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ bool fred_init(std::unique_ptr<os::GraphicsOperations>&& graphicsOps)

gr_reset_clip();
g3_start_frame(0);
g3_set_view_matrix(&eye_pos, &eye_orient, 0.5f);
g3_set_view_matrix(&eye_pos, &eye_orient, EDITOR_DEFAULT_FOV);

Fred_main_wnd -> init_tools();

Expand Down
2 changes: 2 additions & 0 deletions qtfred/source_groups.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ add_file_folder("Source/UI/Widgets"
src/ui/widgets/ShipFlagCheckbox.cpp
src/ui/widgets/SimpleListSelectDialog.cpp
src/ui/widgets/SimpleListSelectDialog.h
src/ui/widgets/TransformToolBar.cpp
src/ui/widgets/TransformToolBar.h
src/ui/widgets/MusicComboWidget.cpp
src/ui/widgets/MusicComboWidget.h
)
Expand Down
83 changes: 31 additions & 52 deletions qtfred/src/mission/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,71 +1705,50 @@ void Editor::cancel_select_subsystem() {
}
void Editor::select_next_object()
{
object* ptr;

select_adjacent_object(true);
}
void Editor::select_previous_object()
{
select_adjacent_object(false);
}
void Editor::select_adjacent_object(bool forward)
{
if (EMPTY(&obj_used_list))
return;

if (query_valid_object(currentObject)) {
ptr = Objects[currentObject].next;
// Step through the circular object list, and jump over the list head
auto step = [forward](object* ptr) {
ptr = forward ? GET_NEXT(ptr) : GET_PREV(ptr);
if (ptr == END_OF_LIST(&obj_used_list))
ptr = GET_NEXT(ptr);
} else {
ptr = GET_FIRST(&obj_used_list);
}
ptr = forward ? GET_NEXT(ptr) : GET_PREV(ptr);
return ptr;
};

object* ptr;
if (query_valid_object(currentObject))
ptr = step(&Objects[currentObject]);
else
ptr = forward ? GET_FIRST(&obj_used_list) : GET_LAST(&obj_used_list);

if (getNumMarked() > 1) {
// Cycle current object through marked objects only
while (!Objects[OBJ_INDEX(ptr)].flags[Object::Object_Flags::Marked]) {
ptr = GET_NEXT(ptr);
if (ptr == END_OF_LIST(&obj_used_list))
ptr = GET_NEXT(ptr);
}
while (!ptr->flags[Object::Object_Flags::Marked])
ptr = step(ptr);
setupCurrentObjectIndices(OBJ_INDEX(ptr));
} else {
if (getNumMarked())
unmarkObject(currentObject);
markObject(OBJ_INDEX(ptr));
}
}
void Editor::select_previous_object()
{
int arr[MAX_OBJECTS], i = 0, n = 0;
object* ptr;

if (EMPTY(&obj_used_list))
return;

ptr = GET_FIRST(&obj_used_list);
while (ptr != END_OF_LIST(&obj_used_list)) {
if (currentObject == OBJ_INDEX(ptr))
i = n;
arr[n++] = OBJ_INDEX(ptr);
ptr = GET_NEXT(ptr);
}

Assert(n);
if (query_valid_object(currentObject)) {
i--;
if (i < 0)
i = n - 1;
} else {
i = n - 1;
// Skip the locked objects. Like a click in the viewport, this command does not select them.
const object* start = ptr;
while (ptr->flags[Object::Object_Flags::Locked_from_editing]) {
ptr = step(ptr);
if (ptr == start)
return; // all objects are locked
}

if (getNumMarked() > 1) {
// Cycle current object through marked objects only
while (!Objects[arr[i]].flags[Object::Object_Flags::Marked]) {
i--;
if (i < 0)
i = n - 1;
}
setupCurrentObjectIndices(arr[i]);
} else {
if (getNumMarked())
unmarkObject(currentObject);
markObject(arr[i]);
}
if (getNumMarked())
unmarkObject(currentObject);
markObject(OBJ_INDEX(ptr));
}
int Editor::get_visible_sub_system_count(ship * shipp) {
int count = 0;
Expand Down
8 changes: 7 additions & 1 deletion qtfred/src/mission/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,16 @@ class Editor : public QObject {
*/
int create_wing();

enum class LockedObjects { Include, Skip };

/**
* @brief Mark all ships within this wing
*
* @param[in] wing Index of the wing to mark
* @param[in] locked Skip for the Select Wing commands: like a click in the viewport, they do not select
* a locked ship. Include for a selection of the wing by name, for example in the Wing Editor.
*/
void mark_wing(int wing);
void mark_wing(int wing, LockedObjects locked);

bool query_single_wing_marked();

Expand Down Expand Up @@ -275,6 +279,8 @@ class Editor : public QObject {
void initialSetup();

void setupCurrentObjectIndices(int obj);
// Next or previous object: moves the selection one object forward or back in obj_used_list
void select_adjacent_object(bool forward);

SCP_vector<std::unique_ptr<EditorViewport>> _viewports;
EditorViewport* _lastActiveViewport = nullptr;
Expand Down
62 changes: 13 additions & 49 deletions qtfred/src/mission/EditorViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,7 @@ void EditorViewport::game_do_frame(const int cur_object_index) {
objp = GET_NEXT(objp);
}

objp = GET_FIRST(&obj_used_list);
while (objp != END_OF_LIST(&obj_used_list)) {
if (objp->flags[Object::Object_Flags::Marked]) {
object_moved(objp);
}

objp = GET_NEXT(objp);
}
marked_objects_moved();

editor->missionChanged();
}
Expand Down Expand Up @@ -545,7 +538,7 @@ void EditorViewport::game_do_frame(const int cur_object_index) {
}

void EditorViewport::level_controlled() {
int cmode, count = 0;
int cmode;
object* objp;

cmode = camera.getControlMode();
Expand Down Expand Up @@ -577,18 +570,8 @@ void EditorViewport::level_controlled() {
objp = GET_NEXT(objp);
}

objp = GET_FIRST(&obj_used_list);
while (objp != END_OF_LIST(&obj_used_list)) {
if (objp->flags[Object::Object_Flags::Marked]) {
object_moved(objp);
count++;
}

objp = GET_NEXT(objp);
}

///! \todo Notify.
if (count) {
if (marked_objects_moved() > 0) {
editor->missionChanged();
}

Expand All @@ -599,7 +582,7 @@ void EditorViewport::level_controlled() {
}

void EditorViewport::verticalize_controlled() {
int cmode, count = 0;
int cmode;
object* objp;

cmode = camera.getControlMode();
Expand Down Expand Up @@ -631,18 +614,8 @@ void EditorViewport::verticalize_controlled() {
objp = GET_NEXT(objp);
}

objp = GET_FIRST(&obj_used_list);
while (objp != END_OF_LIST(&obj_used_list)) {
if (objp->flags[Object::Object_Flags::Marked]) {
object_moved(objp);
count++;
}

objp = GET_NEXT(objp);
}

///! \todo Notify.
if (count) {
if (marked_objects_moved() > 0) {
editor->missionChanged();
}

Expand Down Expand Up @@ -1612,13 +1585,7 @@ int EditorViewport::drag_objects(int x, int y)
objp = GET_NEXT(objp);
}

objp = GET_FIRST(&obj_used_list);
while (objp != END_OF_LIST(&obj_used_list)) {
if (objp->flags[Object::Object_Flags::Marked])
object_moved(objp);

objp = GET_NEXT(objp);
}
marked_objects_moved();
}

editor->missionChanged();
Expand Down Expand Up @@ -1725,13 +1692,7 @@ int EditorViewport::drag_rotate_objects(int mouse_dx, int mouse_dy) {
objp = GET_NEXT(objp);
}

objp = GET_FIRST(&obj_used_list);
while (objp != END_OF_LIST(&obj_used_list)) {
if (objp->flags[Object::Object_Flags::Marked])
object_moved(objp);

objp = GET_NEXT(objp);
}
marked_objects_moved();

editor->missionChanged();
return rval;
Expand All @@ -1756,6 +1717,9 @@ void EditorViewport::cancel_drag() {
objp = GET_NEXT(objp);
}

// Put the docked partners back with the restored objects
marked_objects_moved();

button_down = false;
moved = false;
Dup_drag = 0;
Expand All @@ -1772,7 +1736,7 @@ void EditorViewport::view_universe(bool just_marked) {

dist = std::max(radius, fl_sqrt(20.0f)) + 1.0f;
vm_vec_scale_add(&camera.view_pos, &center, &camera.view_orient.vec.fvec, -dist);
g3_set_view_matrix(&camera.view_pos, &camera.view_orient, 0.5f);
g3_set_view_matrix(&camera.view_pos, &camera.view_orient, EDITOR_DEFAULT_FOV);

ptr = GET_FIRST(&obj_used_list);
while (ptr != END_OF_LIST(&obj_used_list)) {
Expand All @@ -1785,7 +1749,7 @@ void EditorViewport::view_universe(bool just_marked) {
while (v.codes & CC_OFF) {
dist += 5.0f;
vm_vec_scale_add(&camera.view_pos, &center, &camera.view_orient.vec.fvec, -dist);
g3_set_view_matrix(&camera.view_pos, &camera.view_orient, 0.5f);
g3_set_view_matrix(&camera.view_pos, &camera.view_orient, EDITOR_DEFAULT_FOV);
g3_rotate_vertex(&v, &ptr->pos);
if (g3_project_vertex(&v) & PF_OVERFLOW)
Int3();
Expand All @@ -1797,7 +1761,7 @@ void EditorViewport::view_universe(bool just_marked) {

dist *= 1.1f;
vm_vec_scale_add(&camera.view_pos, &center, &camera.view_orient.vec.fvec, -dist);
g3_set_view_matrix(&camera.view_pos, &camera.view_orient, 0.5f);
g3_set_view_matrix(&camera.view_pos, &camera.view_orient, EDITOR_DEFAULT_FOV);

needsUpdate();
}
Expand Down
Loading
Loading