博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
juce Justification 分析
阅读量:5017 次
发布时间:2019-06-12

本文共 7438 字,大约阅读时间需要 24 分钟。

很简单的一个类,一个rect放置在另一个rect中如何放置。只是没有考虑边距等,估且认为是在外层作考虑吧。然后认为是外框比内框大,所以外层怕是要进行检查才行

 

#ifndef JUCE_JUSTIFICATION_H_INCLUDED#define JUCE_JUSTIFICATION_H_INCLUDED//==============================================================================/**    Represents a type of justification to be used when positioning graphical items.    e.g. it indicates whether something should be placed top-left, top-right,    centred, etc.    It is used in various places wherever this kind of information is needed.*/class Justification{public:    //==============================================================================    /** Creates a Justification object using a combination of flags from the Flags enum. */    Justification (int justificationFlags) noexcept   : flags (justificationFlags) {}    /** Creates a copy of another Justification object. */    Justification (const Justification& other) noexcept   : flags (other.flags) {}    /** Copies another Justification object. */    Justification& operator= (const Justification& other) noexcept    {        flags = other.flags;        return *this;    }    bool operator== (const Justification& other) const noexcept     { return flags == other.flags; }    bool operator!= (const Justification& other) const noexcept     { return flags != other.flags; }    //==============================================================================    /** Returns the raw flags that are set for this Justification object. */    inline int getFlags() const noexcept                        { return flags; }    /** Tests a set of flags for this object.        @returns true if any of the flags passed in are set on this object.    */    inline bool testFlags (int flagsToTest) const noexcept      { return (flags & flagsToTest) != 0; }    /** Returns just the flags from this object that deal with vertical layout. */    int getOnlyVerticalFlags() const noexcept                   { return flags & (top | bottom | verticallyCentred); }    /** Returns just the flags from this object that deal with horizontal layout. */    int getOnlyHorizontalFlags() const noexcept                 { return flags & (left | right | horizontallyCentred | horizontallyJustified); }    //==============================================================================    /** Adjusts the position of a rectangle to fit it into a space.        The (x, y) position of the rectangle will be updated to position it inside the        given space according to the justification flags.    */    template 
void applyToRectangle (ValueType& x, ValueType& y, ValueType w, ValueType h, ValueType spaceX, ValueType spaceY, ValueType spaceW, ValueType spaceH) const noexcept { x = spaceX; if ((flags & horizontallyCentred) != 0) x += (spaceW - w) / (ValueType) 2; else if ((flags & right) != 0) x += spaceW - w; y = spaceY; if ((flags & verticallyCentred) != 0) y += (spaceH - h) / (ValueType) 2; else if ((flags & bottom) != 0) y += spaceH - h; } /** Returns the new position of a rectangle that has been justified to fit within a given space. */ template
const Rectangle
appliedToRectangle (const Rectangle
& areaToAdjust, const Rectangle
& targetSpace) const noexcept { ValueType x = areaToAdjust.getX(), y = areaToAdjust.getY(); applyToRectangle (x, y, areaToAdjust.getWidth(), areaToAdjust.getHeight(), targetSpace.getX(), targetSpace.getY(), targetSpace.getWidth(), targetSpace.getHeight()); return areaToAdjust.withPosition (x, y); } //============================================================================== /** Flag values that can be combined and used in the constructor. */ enum Flags { //============================================================================== /** Indicates that the item should be aligned against the left edge of the available space. */ left = 1, /** Indicates that the item should be aligned against the right edge of the available space. */ right = 2, /** Indicates that the item should be placed in the centre between the left and right sides of the available space. */ horizontallyCentred = 4, //============================================================================== /** Indicates that the item should be aligned against the top edge of the available space. */ top = 8, /** Indicates that the item should be aligned against the bottom edge of the available space. */ bottom = 16, /** Indicates that the item should be placed in the centre between the top and bottom sides of the available space. */ verticallyCentred = 32, //============================================================================== /** Indicates that lines of text should be spread out to fill the maximum width available, so that both margins are aligned vertically. */ horizontallyJustified = 64, //============================================================================== /** Indicates that the item should be centred vertically and horizontally. This is equivalent to (horizontallyCentred | verticallyCentred) */ centred = 36, /** Indicates that the item should be centred vertically but placed on the left hand side. This is equivalent to (left | verticallyCentred) */ centredLeft = 33, /** Indicates that the item should be centred vertically but placed on the right hand side. This is equivalent to (right | verticallyCentred) */ centredRight = 34, /** Indicates that the item should be centred horizontally and placed at the top. This is equivalent to (horizontallyCentred | top) */ centredTop = 12, /** Indicates that the item should be centred horizontally and placed at the bottom. This is equivalent to (horizontallyCentred | bottom) */ centredBottom = 20, /** Indicates that the item should be placed in the top-left corner. This is equivalent to (left | top) */ topLeft = 9, /** Indicates that the item should be placed in the top-right corner. This is equivalent to (right | top) */ topRight = 10, /** Indicates that the item should be placed in the bottom-left corner. This is equivalent to (left | bottom) */ bottomLeft = 17, /** Indicates that the item should be placed in the bottom-left corner. This is equivalent to (right | bottom) */ bottomRight = 18 };private: //============================================================================== int flags;};#endif // JUCE_JUSTIFICATION_H_INCLUDED

  

转载于:https://www.cnblogs.com/csxy/p/5496838.html

你可能感兴趣的文章
潭州学院html学习(day02)
查看>>
javascript之Array基础篇
查看>>
C# new()约束简单介绍
查看>>
DataTable添加行的方法
查看>>
算法题-大数相乘问题
查看>>
2.2 不同数据类型的java常量与变量
查看>>
logback新手使用——解决No SLF4J providers were found
查看>>
接口测试框架从设计到开发工程图纸
查看>>
图片链接
查看>>
ZOJ 1649
查看>>
python headers missing
查看>>
[原]unity5 AssetBundle 加载
查看>>
LeetCode19- 删除链表的倒数第N个节点
查看>>
ANSYS经典APDL编程
查看>>
JavaScript奇技淫巧44招
查看>>
AngularJS学习资料
查看>>
mysql高效获取两张表共同字段的交集数据
查看>>
PHP程序员面临的成长瓶颈
查看>>
用python实现逻辑回归
查看>>
程序员的自我修养阅读笔记03
查看>>