很简单的一个类,一个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 分析的更多相关文章

  1. Juce源代码分析(一)Juce的优势

    为什么学习Juce JUCE (Jules' Utility Class Extensions)是由Raw MaterialSoftware公布的一套基于c++的跨平台应用程序框架类库(Windows ...

  2. Juce源代码分析(九)应用程序基类ApplicationBase

    在前面的几篇文章,分析的都是Juce库里面Core模块的内存部分,除了骨灰级C++爱好者之外,貌似大家对这些都不是非常感兴趣.相信大家更想知道Juce是怎么用于产品开发,而对于它的构成不是非常感兴趣. ...

  3. juce AsyncUpdaterMessage 分析

    这个类同样是基于 CallbackMessage, 主要目的是为了在主线程中进行回调,只不过在收到消息的时候进行检测,检测消息发送对象是否已经删除,如果消息发送对象已经没了.消息回调最终调用了调用者的 ...

  4. LeetCode(68) Text Justification

    题目 Given an array of words and a length L, format the text such that each line has exactly L charact ...

  5. juce 中的WeakReference分析

    juce中的WeakReference设计得比较巧妙,巧妙就是使用delete之后就可以通知道WeakReference,原理其实也很间单,其实就是在对象里添加了一个子对象masterReferenc ...

  6. 分析nuget源码,用nuget + nuget.server实现winform程序的自动更新

    源起 (个人理解)包管理最开始应该是从java平台下的maven开始吧,因为java的开发大多数是基于开源组件开发的,一个开源包在使用时很可能要去依赖其他的开源包,而且必须是特定的版本才可以.以往在找 ...

  7. LeetCode:Text Justification

    题目链接 Given an array of words and a length L, format the text such that each line has exactly L chara ...

  8. juce: 跨平台的C++用户界面库

    如果你用过QT和MFC,那你必然知道QT是基于C++的跨平台库,而MFC是微软针对widows平台推出来基础类库.且不论MFC的设计如何,从我个人和身边朋友的经历来看,MFC是一些非常难以理解的类的组 ...

  9. LeetCode_Text Justification

    Given an array of words and a length L, format the text such that each line has exactly L characters ...

随机推荐

  1. JavaScript实现div宽、高自动缓慢拉伸

    最近打算实现一个带有滤镜效果的地自动拉伸图片.发现使用css3浏览器兼容性得需要特别关注.这里我使用js实现了一个div边框自动拉伸和缩小.源码如下: <!DOCTYPE html>< ...

  2. nginx+webpy 出现 upstream timed out

    关于nginx配置webpy应用出现的错误 upstream timed out (: Connection timed out) while reading response header from ...

  3. Linux Power(一): kernel/power/earlysuspend.c

    /* kernel/power/earlysuspend.c * * Copyright (C) 2005-2008 Google, Inc. * * This software is license ...

  4. [转]Linux下转换字符集(UTF8转换)

    今天在Linux 下使用 Iconv 命令转换一个UTF8文件时,总是转换不成功.提示: iconv: 未知 0 处的非法输入序列 后来使用 man iconv 查看,还是没发现异常,因为命令格式都是 ...

  5. Android 展示键盘时候布局被修改的问题

    解决方法,在mainfest.xml中,对那个Activity加: <activity android:name=".activity.HomeActivity"androi ...

  6. windows程序设计读书笔记1——创建窗口

    第一个win32程序,简单的创建窗口: #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ...

  7. 【C语言】单片机上的按键检测框架

    又好久没来写blog,最近在做项目发现之前写的stm32操作都忘了,还好做了个记录,回来看了下很多忘了的就又知道怎么做了. 下面是我之前写的一个按键检测的框架,适合比较多的按键操作,从信号接收.滤波. ...

  8. 只有勇敢的人、鲁莽的人和绝望的人才会追求大的变革 – D.J. Anderson

    只有勇敢的人.鲁莽的人和绝望的人才会追求大的变革 – D.J. Anderson http://www.cnblogs.com/lchrennew/p/Why-The-Future-Of-Agile- ...

  9. java中内存结构及堆栈详解

    一. java内存结构 1. Heap(堆):实例分配的地方,通过-Xms与-Xmx来设置 2. MethodArea(方法区域):类的信息及静态变量. 对应是Permanet Generation, ...

  10. Ubuntu 安装 Eclipse C/C++开发环境

    所需软件清单: 1.eclipse-linuxtools-indigo-SR1-incubation-linux-gtk.tar.gz 2.jre-7u2-linux-i586.tar.gz 先将上述 ...