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 ...
随机推荐
- asp.net httpmodule问题
以前学过IHttpModule实现,这次用到了(.net2013),注册完成后出现如下错误: An ASP.NET setting has been detected that does not ap ...
- spring 配置和实例
Spring 是一个开源框架.Spring 为简化企业级应用开发而生. 使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能.Spring 是一个 IOC(DI) ...
- K - Digital Roots(第二季水)
Description The digital root of a positive integer is found by summing the digits of the integer. If ...
- WindowsAPI一日一练
1.SetWindowLong和GetWindowLong 函数原型: LONG SetWindowLong( __in HWND hWnd, __in int nIndex, __in LONG d ...
- oracle recyclebin详解(闪回删除的表)
今天在SOA应用数据库上运用DBMS_REDEFITION包进行在线非分区表转换分区表操作时,本想DROP掉建的临时表cube_scope_temp不小心后面忘记加"temp"直接 ...
- Zend Framework 框架搭建
通过手工方法搭建Zend Framework的MVC框架结构.首先看一下zend framework mvc的目录结构 1. 在根目录下面创建 public ,并在 public 下创建 index. ...
- bzoj 1188 : [HNOI2007]分裂游戏 sg函数
题目链接 给n个位置, 每个位置有一个小球. 现在两个人进行操作, 每次操作可以选择一个位置i, 拿走一个小球.然后在位置j, k(i<j<=k)处放置一个小球. 问你先进行什么操作会先手 ...
- bzoj2719[Violet 4]银河之星
Description Input Output 一道坑爹的搜索……题意是可以往任意方向移动3格,或者如果旁边有格子的时候可以越过它移动,然后把它吃掉.要求吃到最后一个的位置在x0,y0 注意到可以越 ...
- VMware双网卡实现虚拟机连开发板和Internet
前面已经介绍过关于VMware产生的虚拟交换机和虚拟网卡,当宿主机拥有两个网卡时,可以让虚拟系统同时实现上网和连接开发板的功能. 首先,在设置中虚拟出两块虚拟机网卡,一块连接VMnet0交换机一块连接 ...
- 【LeetCode练习题】Multiply Strings
Multiply Strings Given two numbers represented as strings, return multiplication of the numbers as a ...