Skip to content

Commit

Permalink
Center the position of the label if dir-name-position is 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallLars committed May 30, 2019
1 parent ff0e887 commit 22104ce
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/dirnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,22 +901,24 @@ void RDirNode::calcEdges() {
void RDirNode::updateLabelOffset(float dt) {
if (!parent) return;

const vec2 topLeft_align(-4.0f);
const vec2 bottomRight_align = label_size - topLeft_align;

vec2 new_offset(topLeft_align);
if (parent->getProjectedPos().x > projected_pos.x) {
new_offset.x = bottomRight_align.x;
}
if (parent->getProjectedPos().y < projected_pos.y) {
new_offset.y = bottomRight_align.y;
}

if (gGourceSettings.dir_name_position > 0.5f) {
const vec2 dirVec = glm::abs(parent->getProjectedPos() - projected_pos);
if (dirVec.x > dirVec.y) {
new_offset.x = (new_offset.x == topLeft_align.x ? bottomRight_align.x : topLeft_align.x);
new_offset.y = (new_offset.y == topLeft_align.y ? bottomRight_align.y : topLeft_align.y);
vec2 new_offset;
if (gGourceSettings.dir_name_position == 0.5f) {
//center the label
new_offset = label_size / vec2(2.0f);
} else {
const vec2 topLeft_align(-4.0f);
const vec2 bottomRight_align = label_size - topLeft_align;

new_offset.x = (parent->getProjectedPos().x > projected_pos.x ? bottomRight_align.x : topLeft_align.x);
new_offset.y = (parent->getProjectedPos().y < projected_pos.y ? bottomRight_align.y : topLeft_align.y);

//invert the alignment if dir_name_position > 0.5 and the angle is flat
if (gGourceSettings.dir_name_position > 0.5f) {
const vec2 dirVec = glm::abs(parent->getProjectedPos() - projected_pos);
if (dirVec.x > dirVec.y) {
new_offset.x = (new_offset.x == topLeft_align.x ? bottomRight_align.x : topLeft_align.x);
new_offset.y = (new_offset.y == topLeft_align.y ? bottomRight_align.y : topLeft_align.y);
}
}
}

Expand Down

0 comments on commit 22104ce

Please sign in to comment.