juce Justification 分析
很简单的一个类,一个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 <typename ValueType>
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 <typename ValueType>
const Rectangle<ValueType> appliedToRectangle (const Rectangle<ValueType>& areaToAdjust,
const Rectangle<ValueType>& 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
juce Justification 分析的更多相关文章
- Juce源代码分析(一)Juce的优势
为什么学习Juce JUCE (Jules' Utility Class Extensions)是由Raw MaterialSoftware公布的一套基于c++的跨平台应用程序框架类库(Windows ...
- Juce源代码分析(九)应用程序基类ApplicationBase
在前面的几篇文章,分析的都是Juce库里面Core模块的内存部分,除了骨灰级C++爱好者之外,貌似大家对这些都不是非常感兴趣.相信大家更想知道Juce是怎么用于产品开发,而对于它的构成不是非常感兴趣. ...
- juce AsyncUpdaterMessage 分析
这个类同样是基于 CallbackMessage, 主要目的是为了在主线程中进行回调,只不过在收到消息的时候进行检测,检测消息发送对象是否已经删除,如果消息发送对象已经没了.消息回调最终调用了调用者的 ...
- LeetCode(68) Text Justification
题目 Given an array of words and a length L, format the text such that each line has exactly L charact ...
- juce 中的WeakReference分析
juce中的WeakReference设计得比较巧妙,巧妙就是使用delete之后就可以通知道WeakReference,原理其实也很间单,其实就是在对象里添加了一个子对象masterReferenc ...
- 分析nuget源码,用nuget + nuget.server实现winform程序的自动更新
源起 (个人理解)包管理最开始应该是从java平台下的maven开始吧,因为java的开发大多数是基于开源组件开发的,一个开源包在使用时很可能要去依赖其他的开源包,而且必须是特定的版本才可以.以往在找 ...
- LeetCode:Text Justification
题目链接 Given an array of words and a length L, format the text such that each line has exactly L chara ...
- juce: 跨平台的C++用户界面库
如果你用过QT和MFC,那你必然知道QT是基于C++的跨平台库,而MFC是微软针对widows平台推出来基础类库.且不论MFC的设计如何,从我个人和身边朋友的经历来看,MFC是一些非常难以理解的类的组 ...
- LeetCode_Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters ...
随机推荐
- CentOS 7 U盘安装解决找不到U盘问题
在使用U盘进入CentOS7系统安装选项时,按下Tab键,在屏幕下方出现:vmlinuz initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x ...
- 一个纯CSS DIV天气动画图标【转扒的】
<p> </p> <style><!-- /* SUNNY */ .sunny { -webkit-animation: sunny 15s linear i ...
- LayoutInflater的获取方式
1.LayoutInflater是什么? 通俗而讲,就是将xml中定义的布局找出来. 2.获取LayoutInflater的三种方式 1. LayoutInflater inflater = ge ...
- PHP 表单防止刷新提交的方法
当然,最直接的办法就是尽量不要使用自动提交的表单,然而,当我们需要网页主动post表单进行初始化时,就不得不面对这个问题了 -------------------------------------- ...
- http status 400,http 400,400 错误
转载:http://blog.csdn.net/xu_zh_h/article/details/2294233 4 请求失败4xx 4xx应答定义了特定服务器响应的请求失败的情况.客户端不应当在不更改 ...
- CodeForces 190A Vasya and the Bus
本题是比较简单的,有几个坑要注意一下: 1.n==0&&m!=0 时输出 "Impossible" : 2.n==0&&m==0 时输出 ”0 0 ...
- 恶补ASP.NET基础【1】枚举和结构
有时我们希望变量提取的是一个固定集合中的值,此时就可以用枚举类型, 例: enum OpenMode : byte { 新增=, 编辑=, 查看= } class Program { static v ...
- gdal读写图像分块处理(精华版)
一.gdal进行数据操作在安装好gdal后,即可调用gdal库中的函数.(需要包含的头文件:gdal_priv.h)1.打开数据集使用gdal库进行数据(影像)操作的第一步就是打开一个数据集.对于“数 ...
- USB 传输协议
Pipe USB的pipe的两端分别指的是USB host端的内存区域,和设备端的endpoint. pipe分为两类,一类是stream pipe, 另一类是message pipe. 两类的主要区 ...
- QT:使用“状态模式”绘制界面
QT与很多GUI库不同(如MFC),它不能随时随地地在界面上画图,只能在界面类的painterEvent中画图,如此一来,想在绘制QT界面时使用状态模式(GOF的23种设计模式之一)就有点困难了,作为 ...