JUCE API document - Chinese version - All done!

Value& Slider::getValueObject ( )
返回一个表示推子当前位置的Value对象。

可使用Value对象将推子的位置关联到外部的数值或设置器,也可获取一个Value的副本,被Value::referTo()所使用,使之指向你自己的Value对象。

参见:
Value, getMaxValue, getMinValueObject
void Slider::setRange ( double newMinimum,
double newMaximum,
double newInterval = 0
)
设置推子的最小值、最大值和数值改变的最小单位。

参数:
newMinimum 所允许的最小值
newMaximum 所允许的最大值
newInterval 数值调整的最小单位。如果此值非0,则推子的当前值始终等于(newMinimum + (newInterval * an integer))。
double Slider::getMaximum ( ) const
返回推子的最大值。

参见:
setRange
double Slider::getMinimum ( ) const
返回推子的最小值。

参见:
setRange
double Slider::getInterval ( ) const
返回调整数值的最小单位。

参见:
setRange
double Slider::getMinValue ( ) const
带有两个滑块的推子,此函数返回其中的较小值。

带有两个滑块的推子,其值被getMinValue()和getMaxValue()所控制。带有三个滑块的推子,则使用getValue()和setValue()方法来控制中间值。

参见:
setMinValue, getMaxValue, TwoValueHorizontal, TwoValueVertical, ThreeValueHorizontal, ThreeValueVertical
Value& Slider::getMinValueObject ( ) throw ()
带有两个滑块的推子,此函数返回其中的较小值。

可使用Value对象将推子的位置关联到外部的数值或设置器,也可获取一个Value的副本,被Value::referTo()所使用,使之指向你自己的Value对象。

参见:
Value, getMinValue, getMaxValueObject
void Slider::setMinValue ( double newValue,
bool sendUpdateMessage = true,
bool sendMessageSynchronously = false,
bool allowNudgingOfOtherValues = false
)
带有两个或三个滑块的推子,此函数用来设置较小值。

此函数将触发Slider::Listener::sliderValueChanged()等所有已经绑定的捕获器,并将同步调用需在派生类中重写的valueChanged()方法。

参数:
newValue 要设置的值。该值将做上下限截止,并具有自动“吸附”功能(根据所设置的最小调整单位)。
sendUpdateMessage 如果为false,则数值改变后不触发任何已经绑定的Slider::Listeners捕获器,也不调用valueChanged()方法。
sendMessageSynchronously 如果为true,则同步调用Slider::Listeners捕获器。如果为false,则为非同步调用(异步调用)。
allowNudgingOfOtherValues 如果为false,此值将限制为小于等于最大值(带有两个滑块的推子),或者限制为小于等于中间值(带有三个滑块的推子)。此时,如果设置的值超过限制,则推动所限制的滑块一起移至新的数值位置。
参见:
getMinValue, setMaxValue, setValue
double Slider::getMaxValue ( ) const
带有两个或三个滑块的推子,此函数返回较大的值。

带有两个滑块的推子,其值被getMinValue()和getMaxValue()所控制。 带有三个滑块的推子,则使用getValue()和setValue()方法来控制中间值。

参见:
getMinValue, TwoValueHorizontal, TwoValueVertical, ThreeValueHorizontal, ThreeValueVertical
Value& Slider::getMaxValueObject ( ) throw ()
带有两个或三个滑块的推子,此函数返回较大的值。

可使用Value对象将推子的位置关联到外部的数值或设置器,也可获取一个Value的副本,被Value::referTo()所使用,使之指向你自己的Value对象。

参见:
Value, getMaxValue, getMinValueObject
void Slider::setMaxValue ( double newValue,
bool sendUpdateMessage = true,
bool sendMessageSynchronously = false,
bool allowNudgingOfOtherValues = false
)
带有两个或三个滑块的推子,此函数用来设置较大值。

此函数将触发Slider::Listener::sliderValueChanged()等所有已经绑定的捕获器,并将同步调用需在派生类中重写的valueChanged()方法。

参数:
newValue 要设置的值。该值将做上下限截止,并具有自动“吸附”功能(根据所设置的最小调整单位)。
sendUpdateMessage 如果为false,则数值改变后不触发任何已经绑定的Slider::Listeners捕获器,也不调用valueChanged()方法。
sendMessageSynchronously 如果为true,则同步调用Slider::Listeners捕获器。如果为false,则为非同步调用(异步调用)。
allowNudgingOfOtherValues 如果为false,此值将限制为带有两个滑块的推子的较小值,或者限制为带有三个滑块的中间值。此时,如果设置的值超过限制,则推动所限制的滑块一起移至新的数值位置。
参见:
getMaxValue, setMinValue, setValue
void Slider::addListener ( Listener * listener )
添加捕获器。当推子数值改变时将自动调用该捕获器。

void Slider::removeListener ( Listener * listener )
移除已经绑定的捕获器。

void Slider::setDoubleClickReturnValue ( bool isDoubleClickEnabled,
double valueToSetOnDoubleClick
)
设置鼠标双击后的推子值。

默认情况下,此功能关闭。第二个参数为鼠标双击后,推子的值。

参见:
getDoubleClickReturnValue
double Slider::getDoubleClickReturnValue ( bool & isEnabled ) const
返回鼠标双击后,setDoubleClickReturnValue()函数所设置的数值。

如果鼠标双击为开启状态,则将参数isEnabled设置为true。

参见:
setDoubleClickReturnValue

void Slider::setChangeNotificationOnlyOnRelease ( bool onlyNotifyOnRelease )
用户拖拽推子时,是否持续发送数值改变消息。

如果设置为true,则仅在松开鼠标按键后才发送数值改变消息。如果设置为false(默认),将持续发送消息。

void Slider::setSliderSnapsToMousePosition ( bool shouldSnapToMouse )
点击鼠标后,滑块是否跳到鼠标点击的位置。

默认为true。如果设置为false,则点击鼠标后,滑块按相对位置进行移动。

此函数仅作用于进度条样式的推子,对于具有两个滑块或三个滑块的推子则不起作用。

void Slider::setPopupDisplayEnabled ( bool isEnabled,
Component * parentComponentToUse
)
如果开启,则拖拽鼠标时实时显示当前数值。

当推子设置为不带文本框时,此函数比较有用。此时用户可看到当前所设置的值。

参数parentComponentToUse为一个组件窗口,实时提示将作为子组件置于其中。如果设置为0,实时提示窗口将置于桌面。注意,该窗口为透明的,OS操作系统下,无法设置透明窗口,需要将其置于某个父级组件之内。

void Slider::setPopupMenuEnabled ( bool menuEnabled )
如果设置为true,则鼠标右键点击推子将弹出菜单,供用户改变推子的工作方式。

默认为关闭。开启后,弹出的菜单将包含力度设置、旋钮式推子所采用的鼠标拖拽方式等等。

void Slider::setScrollWheelEnabled ( bool enabled )
是否开启转动鼠标滚轮以调整数值。

默认开启。

int Slider::getThumbBeingDragged ( ) const throw ()
返回当前鼠标所拖拽的滑块。

返回值为0代表主滑块。1代表较小值的滑块。2代表较大值的滑块。-1代表当前没有拖拽滑块。

virtual void Slider::startedDragging ( ) [virtual]
鼠标开始拖拽后自动回调此函数。

参见:
Slider::Listener::sliderDragStarted
virtual void Slider::stoppedDragging ( ) [virtual]
鼠标停止拖拽后自动回调此函数。

参见:
Slider::Listener::sliderDragEnded
virtual void Slider::valueChanged ( ) [virtual]
推子值改变时自动回调此函数。

参见:
Slider::Listener::sliderValueChanged
virtual double Slider::getValueFromText ( const String & text ) [virtual]
派生类可重写此函数,将一个文本字符串转换为推子的当前数值。

当用户在文本框中输入文本时,将自动调用此函数。

默认转换为double类型。

参见:
getTextFromValue
virtual const String Slider::getTextFromValue ( double value ) [virtual]
将推子的当前值转换为文本字符串。

派生类中可重写此函数,以定制文本框的格式。

默认情况下,转换后的小数点位置基于所设置的数值最小单位。如果已通过setTextValueSuffix()函数设置了文本框显示数值时自带的后缀,则后缀一并转换为文本。

参见:
getValueFromText
void Slider::setTextValueSuffix ( const String & suffix )
设置所显示的数字后缀。比如“%”、“dB”等等。

所设置的后缀可通过getTextFromValue()来获取,并自动追加到数字的最后。要实现更高级的格式,可重写getTextFromValue()函数。

const String Slider::getTextValueSuffix ( ) const
返回setTextValueSuffix()所设置的后缀。

virtual double Slider::proportionOfLengthToValue ( double proportion ) [virtual]
自定义数值与距离的相对关系。

该函数默认返回由setSkewFactor()所设置的对数式推子的当前值。如果需要定制距离和数值的映射关系,可重写此函数,但要确保已经实现了相反的函数:valueToProportionOfLength()。

参数:
proportion 数值范围:0到1.0,表示距离和数值的映射比率。
返回:
推子位于该处的数值
参见:
valueToProportionOfLength
virtual double Slider::valueToProportionOfLength ( double value ) [virtual]
通过推子的长度自定义数值与位置的相对关系。

该函数默认返回由setSkewFactor()所设置的对数式推子的当前值。 如果需要定制映射关系,可重写此函数,但要确保已经实现了相反的函数:proportionOfLengthToValue()。

参数:
value 由setRange()所设置的有效值
返回:
0到1.0之间的数值,表示推子数值所在的位置。
参见:
proportionOfLengthToValue

float Slider::getPositionOfValue ( double value )
返回X坐标或Y坐标,该坐标值参照基准为推子的长度。

如果推子为水平式的,则返回X坐标,基准原点为推子的左边缘。如果推子为垂直式的,则返回Y坐标,基准原点为推子的顶边缘。

如果为旋钮式推子,将抛出断言并返回0。 如果给出的参数值超出当前推子的数值范围,则强制为推子的上下限数值。

virtual double Slider::snapValue ( double attemptedValue,
bool userIsDragging
) [virtual]
可重写此函数,使推子自动吸附到自定义的数值。

如果重写,则在用户移动推子到指定位置时自动调用该函数,并且允许派生类理智的校验该值。因此,有可能返回一个不同的值。

参数:
attemptedValue 用户试图输入的值
userIsDragging true代表鼠标拖拽时,false代表文本框手工输入数值时。
返回:
要吸附的值
void Slider::updateText ( )
强制文本框刷新内容。

(通常不需要,因为该操作是自动完成的)。

bool Slider::isHorizontal ( ) const
如果是水平式推子,返回true。

bool Slider::isVertical ( ) const
如果是垂直式推子,返回true。

void Slider::labelTextChanged ( Label * labelThatHasChanged ) [protected, virtual]
文本标签的内容改变后调用此函数。

重新实现:Label::Listener

void Slider::paint ( Graphics & g ) [protected, virtual]
组件可重写此函数以绘制其内容。

当组件的某个区域或完整区域需要重新绘制时,将调用paint()函数。当使用repaint()函数,或者屏幕显示的内容有所变化时,均自动调用本函数。

任何子组件将调用自己的同名函数来绘制自身。当然,如果要绘制位于前面的子组件,也可以使用paintOverChildren()函数来完成此事。

如果要使组件绘制自身,可使用以下的异步调用流程:调用repaint()方法标记需要绘制的区域,稍后,将自动调用paint()函数。JUCE一定类库和大多数现代UI库一样,绘制操作均采用异步调用,程序员永远无法实现同步调用绘制操作。

基本上,程序员永远无需直接调用此函数 - 要获取屏幕快照,可使用createComponentSnapshot()或paintEntireComponent()这两个函数。

参数:
g 完成绘制所必需的图形环境。
参见:
repaint, paintOverChildren, Graphics
重写自:Component

void Slider::resized ( ) [protected, virtual]
组件的大小发生变化时自动调用此函数。

当组件的大小发生变化时,通常利用该函数来重新定位其子组件。

此函数被setBounds或setSize函数所同步调用,因此重复改变组件的大小将不断调用resized方法。这一点与repaint截然不同,多次调用repaint只能在稍后某一时刻进行集中重绘。

如果当前组件为桌面顶级窗口,其大小由操作系统控制,程序所设置的大小也许将不起作用。

参见:
moved, setSize
重写自:Component

void Slider::mouseDown ( const MouseEvent & e ) [protected, virtual]
当鼠标指针位于此组件并且点击某个鼠标键,尚未释放时,自动调用此函数。

参数为MouseEvent类的对象,包含大量的方法以判断哪个鼠标键被按下、同时还按下了哪个功能键,比如Shift键、Ctrl键等等。

一旦按下了某个鼠标键并移动鼠标时,将调用mouseDrag方法,直至松开按键。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseUp, mouseDrag, mouseDoubleClick, contains
重写自:Component

void Slider::mouseUp ( const MouseEvent & e ) [protected, virtual]
鼠标点击并释放某个鼠标按键时自动调用此函数。

mouseUp回调将发送给此组件,即使当释放鼠标按键时它实际上正指向不同的组件。

MouseEvent对象包含大量的鼠标按键信息以判断哪个鼠标键被按下了。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseDown, mouseDrag, mouseDoubleClick, contains
重写自:Component

void Slider::mouseDrag ( const MouseEvent & e ) [protected, virtual]
当鼠标拖拽时,自动调用此函数。

当鼠标指针位于组件内并按下某个鼠标键后,则每次移动鼠标,组件将收到mouseDrag回调消息,即使鼠标指针位于边界之外也依然如此。

如果打算执行某些离开组件边界的拖拽处理,并且组件产生滚屏效果,函数beginDragAutoRepeat()也许更有用。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseDown, mouseUp, mouseMove, contains, beginDragAutoRepeat
重写自:Component

void Slider::mouseDoubleClick ( const MouseEvent & e ) [protected, virtual]
鼠标在此组件中双击时自动调用此函数。

参数为MouseEvent类的对象,包含大量的方法以判断哪个鼠标键被按下、同时还按下了哪个功能键,比如Shift键、Ctrl键等等。

要改变两次点击的时间限定,则参见:MouseEvent::setDoubleClickTimeout。

参数:
e 关于鼠标指针的位置和状态的详细信息。
参见:
mouseDown, mouseUp, MouseEvent::setDoubleClickTimeout, MouseEvent::getDoubleClickTimeout
重写自:Component

void Slider::mouseWheelMove ( const MouseEvent & e,
float wheelIncrementX,
float wheelIncrementY
) [protected, virtual]
转动鼠标滚轮键时自动调用此函数。

当鼠标指针指向该组件并转动滚动键时,此自动调用此函数。

如果不重写,该组件将把消息转发给父级组件,由父级组件收集子组件不感兴趣的鼠标滚轮消息。

参数:
e 关于鼠标指针的位置和状态的详细信息。
wheelIncrementX 水平滚动的速率和方向,正数代表向右滚动,负数代表向左滚动。
wheelIncrementY 垂直滚动的速率和方向,正数代表向上滚动,负数代表向下滚动。
重写自:Component

void Slider::modifierKeysChanged ( const ModifierKeys & modifiers ) [protected, virtual]
按下或释放某个功能键时自动调用此函数。

每当按下或松开Shift、Ctrl、Alt、Command键时,当前拥有键盘焦点的组件将自动调用此函数。可使用setWantsKeyboardFocus()方法使组件拥有焦点。

默认调用父级组件的modifierKeysChanged方法,这种情况下,对按键不感兴趣的组件将给予其父级组件一个处理按键事件的机会。

参见:
keyStateChanged, ModifierKeys
重写自:Component

void Slider::buttonClicked ( Button * button ) [protected]
void Slider::lookAndFeelChanged ( ) [protected, virtual]
当该组件所使用的外观与感觉发生变化时,自动调用此函数。

当组件的外观和感觉改变时,该组件及其所有的子组件将自动调用此函数。子组件采用递归的方式调用。

此函数也可通过sendLookAndFeelChange()方法来手动触发,如果应用程序使用了LookAndFeel类,则有可能进行内部进行改变。

参见:
sendLookAndFeelChange, getLookAndFeel
重写自:Component

void Slider::enablementChanged ( ) [protected, virtual]
启用或禁用此组件时自动调用此函数。

此组件的某个上级组件改变开启或禁用状态时将触发此函数,同时也将影响到该组件的状态。

默认情况下,此函数不起任何作用,但派生类如果需要重绘自身或利用状态改变之际做某事,则可以重写此函数。

参见:
setEnabled, isEnabled
重写自:Component

void Slider::focusOfChildComponentChanged ( FocusChangeType cause ) [protected, virtual]
此组件的子组件拥有或失去键盘焦点时自动调用此函数。

实质上,返回值为hasKeyboardFocus (true)改变后的结果。当子组件的焦点转移时,调用此函数。

参见:
focusGained, setWantsKeyboardFocus, getCurrentlyFocusedComponent, hasKeyboardFocus
重写自:Component

void Slider::handleAsyncUpdate ( ) [protected, virtual]
如果该类需要完成额外的功能,可重写此函数。

此方法将在调用triggerAsyncUpdate()之后的下一个适当的时候被消息线程所调用。

重新实现:AsyncUpdater

void Slider::colourChanged ( ) [protected, virtual]
当setColour()函数改变某个颜色时,自动调用此函数。

参见:
setColour, findColour
重写自:Component

void Slider::valueChanged ( Value & value ) [protected, virtual]
当Value对象改变后自动调用该函数。

注意,所传递的Value对象参数也许不是捕获器已经绑定的相同类型对象 - 它也许是一个引用到相同基础值的副本。可使用Value::refersToSameSourceAs()找到该对象。

重新实现:Value::Listener

int Slider::getNumDecimalPlacesToDisplay ( ) const throw () [protected]
返回要显示数字时的最佳小数位。

此值根据推子内部的设置参数来决定结果。

定义该类的头文件:
juce_Slider.h

[size=150]File 文件类[/size]

本地文件或目录。 更多…

所有成员

Public类型

enum TypesOfFileToFind { findDirectories = 1, findFiles = 2, findFilesAndDirectories = 3, ignoreHiddenFiles = 4 }

搜索文件时使用,指定要返回的文件、目录或者同时返回文件和目录。

更多…
enum SpecialLocationType {
userHomeDirectory, userDocumentsDirectory, userDesktopDirectory, userApplicationDataDirectory,
commonApplicationDataDirectory, tempDirectory, currentExecutableFile, currentApplicationFile,
invokedExecutableFile, hostApplicationPath, globalApplicationsDirectory, userMusicDirectory,
userMoviesDirectory
}

getSpecialLocation()方法所使用的类型集合。

更多…

Public成员函数

File ()
创建一个无效的文件对象。 
File (const String &path)
在给出的绝对路径下创建一个文件。 
File (const File &other)
创建一个其它文件对象的副本(拷贝构造函数)。 
~File ()
 析构函数。 

File & operator= (const String &newFilePath)
基于绝对路径名设置该文件。
File & operator= (const File &otherFile)
另一个文件对象的副本。赋值操作。
bool exists () const
检测该文件或者目录是否实际存在。
bool existsAsFile () const
检测文件是否存在(不是检测目录)。
bool isDirectory () const
检测该对象是否为现有的目录。
int64 getSize () const
返回文件的字节数。
const String & getFullPathName () const throw ()
返回该文件完整的绝对路径。
const String getFileName () const
返回路径名中的最后部分(文件名及其扩展名)。
const String getRelativePathFrom (const File &directoryToBeRelativeTo) const
创建一个指向该文件的多层相对路径。
const String getFileExtension () const
返回文件的扩展名。
bool hasFileExtension (const String &extensionToTest) const
检测文件是否使用给定的扩展名。
const File withFileExtension (const String &newExtension) const
返回此文件的不同扩展名的另一个副本。
const String getFileNameWithoutExtension () const
返回路径名最后的部分(文件名),不包含文件扩展名。
int hashCode () const
返回32位哈希编码以识别该文件。
int64 hashCode64 () const
返回64位哈希编码以识别该文件。
const File getChildFile (String relativePath) const
基于相对路径返回一个文件。
const File getSiblingFile (const String &siblingFileName) const
返回此文件所位于的同一个目录下的另一个文件。
const File getParentDirectory () const
返回包含此文件或目录的上级目录。
bool isAChildOf (const File &potentialParentDirectory) const
检测该文件或目录是否位于某个目录下。
const File getNonexistentChildFile (const String &prefix, const String &suffix, bool putNumbersInBrackets=true) const
选择一个相对于此文件尚不存在的文件名,并返回。
const File getNonexistentSibling (bool putNumbersInBrackets=true) const
选择一个同级于此文件且尚不存在的文件名。
bool operator== (const File &otherFile) const
比较两个文件是否一致。
bool operator!= (const File &otherFile) const
比较两个文件是否一致。
bool operator< (const File &otherFile) const
比较两个文件是否一致。
bool operator> (const File &otherFile) const
比较两个文件是否一致。
bool hasWriteAccess () const
检测该文件是否能被创建或写入。
bool setReadOnly (bool shouldBeReadOnly, bool applyRecursively=false) const
改变文件或目录的只读属性。
bool isHidden () const
如果为隐藏文件或系统文件,则返回true。
const File getLinkedTarget () const
如果此文件为一个链接,将返回链接所指向的文件。
const Time getLastModificationTime () const
返回此文件的最后修改时间。
const Time getLastAccessTime () const
返回此文件最后的访问时间。
const Time getCreationTime () const
返回文件的创建时间。
bool setLastModificationTime (const Time &newTime) const
设置此文件的最后修改时间。
bool setLastAccessTime (const Time &newTime) const
设置此文件的最后访问时间。
bool setCreationTime (const Time &newTime) const
设置此文件的创建日期。
const String getVersion () const
如果可能,此函数将尝试为此文件创建一个包含版本信息的字符串。
bool create () const
如果不存在,则创建一个空白文件。
bool createDirectory () const
用此文件名创建一个新目录。
bool deleteFile () const
删除一个文件。
bool deleteRecursively () const
删除一个文件或者一个目录(一并删除该目录下的所有子目录)。
bool moveToTrash () const
将文件或文件夹移动到回收站。
bool moveFileTo (const File &targetLocation) const
移动或重命名文件。
bool copyFileTo (const File &targetLocation) const
复制一个文件。
bool copyDirectoryTo (const File &newDirectory) const
复制一个目录。
int findChildFiles (Array< File > &results, int whatToLookFor, bool searchRecursively, const String &wildCardPattern="") const
使用通配符搜索该目录下的文件。
int getNumberOfChildFiles (int whatToLookFor, const String &wildCardPattern="
") const
搜索该目录下符号条件的文件总数。
bool containsSubDirectories () const
如果该对象为目录,并且包含子目录,则返回true。
FileInputStream * createInputStream () const
创建一个数据流以读取此文件。

FileOutputStream * createOutputStream (int bufferSize=0x8000) const
创建一个写入此文件的数据流。
bool loadFileAsData (MemoryBlock &result) const
将文件内容以二进制数据块的形式加载到内存中。
const String loadFileAsString () const
将文件的字符串内容读取到内存中。
bool appendData (const void *dataToAppend, int numberOfBytes) const
将一个二进制数据块追加到文件末尾。
bool replaceWithData (const void *dataToWrite, int numberOfBytes) const
用给定的数据块替换该文件的内容。
bool appendText (const String &textToAppend, bool asUnicode=false, bool writeUnicodeHeaderBytes=false) const
将一个字符串追加到该文件的末尾。
bool replaceWithText (const String &textToWrite, bool asUnicode=false, bool writeUnicodeHeaderBytes=false) const
以给定的文本字符串替换此文件的内容。
bool hasIdenticalContentTo (const File &other) const
尝试扫描该文件的内容,并按“字节对字节”的形式和另一个文件相比较,如果可以进行比较并且互相匹配,则返回true。
const String getVolumeLabel () const
返回此文件所在的硬盘卷标。
int getVolumeSerialNumber () const
返回此文件所在的卷的序列号。
int64 getBytesFreeOnVolume () const
返回此文件所在的驱动器的剩余空间数。单位:字节。
int64 getVolumeTotalSize () const
返回此文件所在的驱动器的总容量。
bool isOnCDRomDrive () const
如果此文件位于CD或DVD光盘上,则返回true。
bool isOnHardDisk () const
如果此文件位于硬盘上,则返回true。
bool isOnRemovableDrive () const
如果该文件位于可移动的磁盘驱动器,则返回true。
bool startAsProcess (const String &parameters=String::empty) const
作为一个进程启动该文件。
void revealToUser () const
打开该文件所在的文件夹。
bool setAsCurrentWorkingDirectory () const
将当前的工作目录设置为此文件(目录)。

静态Public成员函数

static const String descriptionOfSizeInBytes (int64 bytes)
比较有用的函数,可将文件的字节数转换为字符串。
static void findFileSystemRoots (Array< File > &results)
创建一个包含每个文件根目录的数组。
static const File JUCE_CALLTYPE getSpecialLocation (const SpecialLocationType type)
查找指定类型的文件或文件夹的位置,比如根目录或文档目录。
static const File createTempFile (const String &fileNameEnding)
返回在系统临时目录下创建的临时文件。
static const File getCurrentWorkingDirectory ()
返回当前的工作目录。
static const String createLegalFileName (const String &fileNameToFix)
从文件名中移除非法字符。
static const String createLegalPathName (const String &pathNameToFix)
从路径名中移除非法字符。
static bool areFileNamesCaseSensitive ()
当前操作系统是否区分文件名中的大小写。
static bool isAbsolutePath (const String &path)
如果字符串看起来是完整的绝对路径,则返回true。
static const File createFileWithoutCheckingPath (const String &path)
创建一个包含该字符串的文件,不进行普通的构造函数所执行的理智校验。
static const String addTrailingSeparator (const String &path)
如果路径最后没有分隔符,则添加之。

静态Public属性

static const File nonexistent
此静态常量被“无效”文件所使用。
static const juce_wchar separator
系统专属的文件分隔符。
static const String separatorString
系统专属的文件分隔符。

详细说明

本地文件或目录。

此类封装文件或目录的绝对路径,并给出与其相关的各类方法并可更改其属性。

读取或写入文件时,以下方法可输入或输出数据流:

参见:
FileInputStream, FileOutputStream

成员函数文档

enum File::TypesOfFileToFind
搜索文件时使用,指定要返回的文件、目录或者同时返回文件和目录。

枚举常量:
findDirectories
此常量表示要查找目录。

findFiles
此常量表示要查找文件。

findFilesAndDirectories
此常量表示同时查找文件和目录。

ignoreHiddenFiles
添加此常量表示不返回任何隐藏文件。

enum File::SpecialLocationType
getSpecialLocation()方法所使用的类型集合。

枚举常量:
userHomeDirectory
用户的主文件夹。

此常量等同于File ("~")。

userDocumentsDirectory
用户的默认文档文件夹。

Windows系统下,此常量为用户的"My Documents"文件夹。Mac系统下,为"Documents"文件夹。Linux系统下没有默认的用户文件夹,将返回主文件夹。

userDesktopDirectory
包含用户桌面对象的文件夹。

userApplicationDataDirectory
应用程序目录下保存用户设置信息的文件夹。

Windows系统下为"\Documents and Settings\username\Application Data"。Mac系统为"~/Library"。如果要在此处保存设置,要在该目录下创建你自己的子文件夹,以避免混乱。

commonApplicationDataDirectory
此常量表示计算机中所有用户共享的应用程序数据文件夹,而不是当前用户的程序数据文件夹。与userApplicationDataDirectory文件夹的性质基本一致。

Mac系统下为"/Library",Windows系统下类似于"\Documents and Settings\All Users\Application Data"。

根据用户自己的定制和操作系统的相关设置,此文件夹也许具有只读属性。

tempDirectory
可供临时文件使用的文件夹(临时文件夹)。

程序结束后最好始终删除临时文件夹,以保持硬盘目录和文件的整洁有序,避免混乱。

currentExecutableFile
返回此程序的可执行文件。

如果程序为插件或DLL文件,此常量也许代表DLL文件,而不是宿主程序本身。

Mac系统下将返回unix二进制,并非打包文件夹,参见currentApplicationFile。

另参见invokedExecutableFile,与此类似,但是如果exe文件是以链接的方式而运行的,invokedExecutableFile将返回链接的名称。

currentApplicationFile
返回此程序。

如果程序为插件或DLL文件,此常量也许代表DLL文件,而不是宿主程序本身。

Mac系统下将返回打包文件夹(如果有的话),而不是返回它所包含的unix二进制。参见currentExecutableFile。

invokedExecutableFile
返回调用此程序的文件。

如果程序是以链接的方式启动的,此常量将不同于currentExecutableFile,它返回所使用的链接的名称,反之, currentExecutableFile将返回目标程序。

hostApplicationPath
如果程序为插件,此常量将返回宿主程序的路径。

globalApplicationsDirectory
正常情况下的程序安装目录。

Windows系统下,此常量类似于"c:\program files",Mac系统则为"/Applications",Linux下则为"/usr"。

userMusicDirectory
用户最有可能保存音乐文件的目录。

userMoviesDirectory
用户最有可能保存视频文件的目录。

构造函数和析构函数文档

File::File ( )
创建一个无效的文件对象。

文件初始化为空路径,如果调用getFullPath(),将返回一个空字符串。调用文件比较函数File::nonexistent(不存在)将返回true。

可使用赋值运算符“=”为其赋一个适当的文件。

File::File ( const String & path )
在给出的绝对路径下创建一个文件。

如果所给出的路径为相对路径,则以当前工作目录为相对基准。参见:File::getCurrentWorkingDirectory()。但是,不建议在创建文件时给出相对路径,因为程序员不可能知道CWD(当前工作目录)位于何处。

Mac和Linux系统下,路径中包含的"~"代表用户的根目录。

File::File ( const File & other )
创建一个其它文件对象的副本(拷贝构造函数)。

File::~File ( )
析构函数。

成员函数文档

File& File::operator= ( const String & newFilePath )
基于绝对路径名设置该文件。

如果所给出的路径为相对路径,则以当前工作目录为相对基准。参见:File::getCurrentWorkingDirectory()。但是,不建议在创建文件时给出相对路径,因为程序员不可能知道CWD(当前工作目录)位于何处。

Mac和Linux系统下,路径中包含的"~"代表用户的根目录。

File& File::operator= ( const File & otherFile )
另一个文件对象的副本。赋值操作。

bool File::exists ( ) const
检测该文件或者目录是否实际存在。

返回:
如果文件或目录存在,则返回true。
参见:
existsAsFile, isDirectory
bool File::existsAsFile ( ) const
检测文件是否存在(不是检测目录)。

返回:
如果文件实际存在,则返回true。如果对象为目录,或者不存在,则返回false。
参见:
exists, isDirectory
bool File::isDirectory ( ) const
检测该对象是否为现有的目录。

返回:
如果为现有的目录,则返回true,如果对象为文件,或者不存在,则返回false。
参见:
exists, existsAsFile
int64 File::getSize ( ) const
返回文件的字节数。

返回:
文件的字节数。如果不存在,则返回0。
static const String File::descriptionOfSizeInBytes ( int64 bytes ) [static]
比较有用的函数,可将文件的字节数转换为字符串。

比如:文件大小为100,将返回"100 bytes", 2000将"2 KB", 2000000将返回"2 MB",等等。

const String& File::getFullPathName ( ) const throw ()
返回该文件完整的绝对路径。

包含所有的上级文件夹和文件名。Windows系统下,返回值中包含盘符。Mac或Linux系统下则返回从根目录开始的完整路径。

如果仅为了获取文件名,则可使用getFileName()或getFileNameWithoutExtension()。

参见:
getFileName, getRelativePathFrom
const String File::getFileName ( ) const
返回路径名中的最后部分(文件名及其扩展名)。

仅返回路径中的最后部分。比如:如果完整的路径为"/moose/fish/foo.txt",此函数将返回"foo.txt"。

如果对象为目录,则返回最后一层目录名。比如:"/moose/fish"的返回值为"fish"。

如果文件名以“.”开头,将返回完整的文件名。比如:"/moose/.fish"返回值为".fish"。

参见:
getFullPathName, getFileNameWithoutExtension
const String File::getRelativePathFrom ( const File & directoryToBeRelativeTo ) const
创建一个指向该文件的多层相对路径。

比如:File ("/moose/foo.txt").getRelativePathFrom ("/moose/fish/haddock")将返回"…/…/foo.txt"。

如果不可能返回这种类型的多层相对目录,则返回一个绝对路径。如果路径无效,将返回空字符串。

参数:
directoryToBeRelativeTo 返回值所参照的基准路径。如果为文件而非目录,将自动使用该文件所在的目录。如果不存在,则假定它是一个目录。
参见:
getChildFile, isAbsolutePath
const String File::getFileExtension ( ) const
返回文件的扩展名。

返回的文件扩展名中包含“.”。

比如:"/moose/fish/foo.txt"将返回".txt"。

参见:
hasFileExtension, withFileExtension, getFileNameWithoutExtension
bool File::hasFileExtension ( const String & extensionToTest ) const
检测文件是否使用给定的扩展名。

参数:
extensionToTest 进行检测的文件扩展名。开头是否为“.”均可以。比如:".wav"和"wav"是一样的。给出的扩展名,不区分大小写。此参数可包含多个字符串,以便进行多个扩展名的检测,字符串内容中使用小写的分号隔开即可。比如::hasFileExtension (".jpeg;png;gif")。
参见:
getFileExtension, withFileExtension, getFileNameWithoutExtension

const File File::withFileExtension ( const String & newExtension ) const
返回此文件的不同扩展名的另一个副本。

比如:File ("/moose/fish/foo.txt").withFileExtension (“html”)将返回"/moose/fish/foo.html"。

参数:
newExtension 返回文件所采用的扩展名,开头是否为“.”均可以,没有差别。也可使用该函数移除文件的扩展名,设为空字符串即可。
参见:
getFileName, getFileExtension, hasFileExtension, getFileNameWithoutExtension
const String File::getFileNameWithoutExtension ( ) const
返回路径名最后的部分(文件名),不包含文件扩展名。

比如:"/moose/fish/foo.txt"将返回"foo"。

参见:
getFileName, getFileExtension, hasFileExtension, withFileExtension
int File::hashCode ( ) const
返回32位哈希编码以识别该文件。

此函数基于路径和文件名。显然,两个不同的文件有可能具有相同的哈希编码,尽管这种情况极其罕见。

int64 File::hashCode64 ( ) const
返回64位哈希编码以识别该文件。

此函数基于路径和文件名。 显然,两个不同的文件有可能具有相同的哈希编码,尽管这种情况极其罕见。

const File File::getChildFile ( String relativePath ) const
基于相对路径返回一个文件。

此函数将返回当前对象的子目录或位于其下的文件。

比如:File ("/moose/fish").getChildFile (“foo.txt”)将返回"/moose/fish/foo.txt"。File ("/moose/fish").getChildFile ("…/foo.txt")将返回"/moose/foo.txt"。

如果字符串参数实际上是一个绝对路径,将返回其自身。比如:File ("/moose/fish").getChildFile ("/foo.txt")将返回"/foo.txt"。

参见:
getSiblingFile, getParentDirectory, getRelativePathFrom, isAChildOf
const File File::getSiblingFile ( const String & siblingFileName ) const
返回此文件所位于的同一个目录下的另一个文件。

此函数等价于:getParentDirectory().getChildFile (name)

参见:
getChildFile, getParentDirectory
const File File::getParentDirectory ( ) const
返回包含此文件或目录的上级目录。

比如:"/moose/fish/foo.txt"将返回"/moose/fish"。

bool File::isAChildOf ( const File & potentialParentDirectory ) const
检测该文件或目录是否位于某个目录下。

如果是,则返回true。实际上,文件不必实际存在,因为此函数仅检测路径。

比如:File ("/moose/fish/foo.txt").isAChildOf ("/moose")将返回true。File ("/moose/fish/foo.txt").isAChildOf ("/moose/fish")也返回true。

const File File::getNonexistentChildFile ( const String & prefix,
const String & suffix,
bool putNumbersInBrackets = true
) const
选择一个相对于此文件尚不存在的文件名,并返回。

如果此文件为目录,将返回此目录下的一个尚不存在的子文件,并在前缀之后依次添加数字编号,直到出现当前尚不存在的文件名为止。

如果前缀 + 后缀不存在,将不打乱所添加的编号。

比如:File ("/moose/fish").getNonexistentChildFile (“foo”, “.txt”, true),也许返回"/moose/fish/foo(2).txt",前提是已经存在一个名为"foo.txt"的文件。.

参数:
prefix 自动添加的数字编号之前的文件名
suffix 自动添加的数字编号之后的文件名
putNumbersInBrackets 如果为true,则创建的文件名格式为"prefix(number)suffix"。如果为false,则不包含括号。
const File File::getNonexistentSibling ( bool putNumbersInBrackets = true ) const
选择一个同级于此文件且尚不存在的文件名。

如果此文件不存在,此函数将返回其自身。否则将返回一个不存在的同级文件。比如:文件"/moose/fish/foo.txt"已经存在,也许将返回"/moose/fish/foo(2).txt"。

参数:
putNumbersInBrackets 是否自动添加括号。
bool File::operator== ( const File & otherFile ) const
比较两个文件是否一致。

bool File::operator!= ( const File & otherFile ) const
比较两个文件是否一致。

bool File::operator< ( const File & otherFile ) const
比较两个文件是否一致。

bool File::operator> ( const File & otherFile ) const
比较两个文件是否一致。

bool File::hasWriteAccess ( ) const
检测该文件是否能被创建或写入。

返回:
如果可创建并写入,则返回true。如果此文件不存在,将检测上级目录是否可被写入。
参见:
setReadOnly
bool File::setReadOnly ( bool shouldBeReadOnly,
bool applyRecursively = false
) const
改变文件或目录的只读属性。

参数:
shouldBeReadOnly 是否只读
applyRecursively 如果此对象为目录,并且此参数为true,将递归所有的子目录,其下的所有文件和目录的属性
返回:
如果完成设置则返回true。
参见:
hasWriteAccess
bool File::isHidden ( ) const
如果为隐藏文件或系统文件,则返回true。

检测结果取决于操作系统的有关设置和文件管理机制。

const File File::getLinkedTarget ( ) const
如果此文件为一个链接,将返回链接所指向的文件。

如果不是链接,则返回其自身。

const Time File::getLastModificationTime ( ) const
返回此文件的最后修改时间。

返回:
返回时间。如果文件不存在,则返回一个无效的时间。
参见:
setLastModificationTime, getLastAccessTime, getCreationTime
const Time File::getLastAccessTime ( ) const
返回此文件最后的访问时间。

返回:
返回时间。如果文件不存在,则返回一个无效的时间。
参见:
setLastAccessTime, getLastModificationTime, getCreationTime
const Time File::getCreationTime ( ) const
返回文件的创建时间。

返回:
返回时间。如果文件不存在,则返回一个无效的时间。
参见:
getLastModificationTime, getLastAccessTime
bool File::setLastModificationTime ( const Time & newTime ) const
设置此文件的最后修改时间。

参数:
newTime 要设置的时间
返回:
如果完成此设置,则返回true。
参见:
getLastModificationTime, setLastAccessTime, setCreationTime
bool File::setLastAccessTime ( const Time & newTime ) const
设置此文件的最后访问时间。

参数:
newTime 要设置的时间
返回:
如果完成此设置,则返回true。
参见:
getLastAccessTime, setLastModificationTime, setCreationTime
bool File::setCreationTime ( const Time & newTime ) const
设置此文件的创建日期。

参数:
newTime 要设置的时间
返回:
如果完成此设置,则返回true。
参见:
getCreationTime, setLastModificationTime, setLastAccessTime
const String File::getVersion ( ) const
如果可能,此函数将尝试为此文件创建一个包含版本信息的字符串。

操作系统也许能够自动给文件赋予一个版本号,比如:可执行文件、打包文件、DLL文件等等。如果没有可用的版本信息,此函数将返回空字符串。

bool File::create ( ) const
如果不存在,则创建一个空白文件。

如果此对象引用的文件不存在,将创建大小为0的空白文件。

如果已经存在,或者是目录,此函数将不起作用。

返回:
如果文件被创建,或者如果已经存在,则返回true。
参见:
createDirectory
bool File::createDirectory ( ) const
用此文件名创建一个新目录。

此函数尝试将该文件创建为目录,如果需要,则依次创建所有的上级目录。

返回:
如果目录成功创建,或者已经存在,则返回true。
参见:
create
bool File::deleteFile ( ) const
删除一个文件。

如果该对象为目录且包含文件,则不会删除。删除目录的更好做法,参见:deleteRecursively()。

返回:
如果文件被成功删除或原本就不存在,则返回true。
参见:
deleteRecursively
bool File::deleteRecursively ( ) const
删除一个文件或者一个目录(一并删除该目录下的所有子目录)。

如果该对象为目录,此函数将尝试删除该目录和其下所有的子目录。如果该对象是文件,则直接删除该文件。

返回:
如果文件和所有的子目录均被成功删除,或者对象原本就不存在,则返回true 。
参见:
deleteFile
bool File::moveToTrash ( ) const
将文件或文件夹移动到回收站。

返回:
如果操作成功则返回true。如果回收站已满,或者文件具有写保护属性,则此函数将运行失败,所以应检测该函数的返回值,以确保程序不出现BUG。
bool File::moveFileTo ( const File & targetLocation ) const
移动或重命名文件。

尝试将文件移动到不同的位置。如果目标文件已经存在,此函数将尝试先删除之。如果操作无法完成,则此函数运行失败。

注意,此函数并非把文件转移到目标文件所在的目录下,而是直接替代该文件,也就是,参数是实际文件,而非目录。

返回:
如果操作成功则返回true

bool File::copyFileTo ( const File & targetLocation ) const
复制一个文件。

尝试将文件复制到不同的位置。如果目标文件已经存在,此函数将尝试先删除之。如果操作无法完成,则此函数运行失败。

返回:
如果操作成功则返回true
bool File::copyDirectoryTo ( const File & newDirectory ) const
复制一个目录。

尝试复制完整的目录,递归方式。

如果该对象不是目录,或者一旦有任何文件无法被创建,此函数将返回false。

参数:
newDirectory 复制到该目录下。注意,此参数为将要创建的实际目录,并非复制到此的已有目录。因此,如果该目录不存在,则必须有写入权限才可创建。此目录下,任何已有的同名文件将被覆盖。
int File::findChildFiles ( Array< File > & results,
int whatToLookFor,
bool searchRecursively,
const String & wildCardPattern = “*”
) const
使用通配符搜索该目录下的文件。

假定此文件是一个目录,则此方法将搜索其下的所有文件和子目录。

参数:
results 元素为File对象的数组,用户保存搜索结果。
whatToLookFor 该值为TypesOfFileToFind枚举常量,指定要返回的文件或目录类型。如果此值包含ignoreHiddenFiles,则不返回隐藏文件。
searchRecursively 如果为true,则递归搜索其下的所有子目录。
wildCardPattern 文件名通配符。比如:".txt"。
返回:
搜索到的结果数量
参见:
getNumberOfChildFiles, DirectoryIterator
int File::getNumberOfChildFiles ( int whatToLookFor,
const String & wildCardPattern = "
"
) const
搜索该目录下符号条件的文件总数。

假定此对象是一个目录,此方法将搜索该目录下的所有文件和子目录,并将返回搜索到的匹配数目。

此函数不采用递归方式,仅搜索当前目录,不包含其下的子目录。

参数:
whatToLookFor TypesOfFileToFind枚举常量,指定要搜索的文件类型。如果此值中包含ignoreHiddenFiles常量,返回的结果中将不包含隐藏文件。
wildCardPattern 文件名通配符。比如:"*.txt"。
返回:
符合条件的总数
参见:
findChildFiles, DirectoryIterator
bool File::containsSubDirectories ( ) const
如果该对象为目录,并且包含子目录,则返回true。

参见:
isDirectory, findChildFiles
FileInputStream* File::createInputStream ( ) const
创建一个数据流以读取此文件。

返回:
数据流将从文件的开始处读取,如果不能打开该文件,则返回0。
参见:
createOutputStream, loadFileAsData
FileOutputStream* File::createOutputStream ( int bufferSize = 0x8000 ) const
创建一个写入此文件的数据流。

如果文件存在,则返回的数据流将准备写入文件的末尾,可使用deleteFile()方法先删除该文件,而后写入空白的文件中。

返回:
返回准备追加到此文件末尾的数据流,如果不能打开该文件,则返回0。
参见:
createInputStream, appendData, appendText
bool File::loadFileAsData ( MemoryBlock & result ) const
将文件内容以二进制数据块的形式加载到内存中。

当然,尝试加载一个非常大的文件将有可能导致崩溃,因此,加载之前进行检测是比较稳妥的做法。

参数:
result 用于存放和不断追加文件内容的数据块。注意,如果数据块已经包含某些数据,通常情况下需首先清除之。
返回:
如果加载成功则返回true
const String File::loadFileAsString ( ) const
将文件的字符串内容读取到内存中。

尝试将整个文件加载为一个0结束符的字符串。

此函数使用InputStream::readEntireStreamAsString,可自动处理Unicode/ACSI这两种文件格式。

bool File::appendData ( const void * dataToAppend,
int numberOfBytes
) const
将一个二进制数据块追加到文件末尾。

此函数尝试把给定的缓冲写入到文件末尾。

返回:
如果无法写入文件,则返回false
bool File::replaceWithData ( const void * dataToWrite,
int numberOfBytes
) const
用给定的数据块替换该文件的内容。

此函数将删除文件并以给定的数据替换之。

此方法是安全的,并非首先删除该文件,而后再重新写入。它的实现思路是:创建一个新的临时文件,写入数据,然后用新文件替换现有的文件。这意味着如果掉电或者程序崩溃,将不太可能以无效的文件而告终…

如果操作成功则返回true,操作失败则返回false。

参见:
appendText

bool File::appendText ( const String & textToAppend,
bool asUnicode = false,
bool writeUnicodeHeaderBytes = false
) const
将一个字符串追加到该文件的末尾。

此函数尝试将文本字符串追加到文件中,默认采用的系统编码为16位Unicode或8位字符。

此函数也将在文本之前写入“ff fe”Unicode头字节,以表示文件的字节顺序。

字符串中的单个字符\n在写入之前将替换为\r\n。

参见:
replaceWithText
bool File::replaceWithText ( const String & textToWrite,
bool asUnicode = false,
bool writeUnicodeHeaderBytes = false
) const
以给定的文本字符串替换此文件的内容。

此函数将删除该文件并用给定的文本替换之。

此方法是安全的,并非首先删除文件,而后重新写入。它的实现思路是:首先创建一个新的临时文件,写入文本,而后用新文件替换现有的文件。这意味着如果掉电或者程序崩溃,将不太可能以无效的文件而告终…

参数的说明可参见:appendText()。

如果操作成功则返回true,操作失败则返回false。

参见:
appendText
bool File::hasIdenticalContentTo ( const File & other ) const
尝试扫描该文件的内容,并按“字节对字节”的形式和另一个文件相比较,如果可以进行比较并且互相匹配,则返回true。

static void File::findFileSystemRoots ( Array< File > & results ) [static]
创建一个包含每个文件根目录的数组。

比如,Windows系统将根据一个可用的数组元素为"c:", “d:“等根目录创建文件。Mac和Linux系统下,为”/”。

const String File::getVolumeLabel ( ) const
返回此文件所在的硬盘卷标。

返回:
返回驱动器卷标。如果不可能有,则返回空字符串。
int File::getVolumeSerialNumber ( ) const
返回此文件所在的卷的序列号。

返回:
返回序列号。如果不可能有,则返回0。
int64 File::getBytesFreeOnVolume ( ) const
返回此文件所在的驱动器的剩余空间数。单位:字节。

返回:
剩余空间的字节数。如果有问题,则返回0。
参见:
getVolumeTotalSize
int64 File::getVolumeTotalSize ( ) const
返回此文件所在的驱动器的总容量。

返回:
该卷能容纳的字节总数
参见:
getBytesFreeOnVolume
bool File::isOnCDRomDrive ( ) const
如果此文件位于CD或DVD光盘上,则返回true。

bool File::isOnHardDisk ( ) const
如果此文件位于硬盘上,则返回true。

该函数适用于移动硬盘上的文件。但如果文件位于网络驱动器中,则此函数执行失败。

bool File::isOnRemovableDrive ( ) const
如果该文件位于可移动的磁盘驱动器,则返回true。

适用于U盘、光驱、移动硬盘、网络驱动器等等。

bool File::startAsProcess ( const String & parameters = String::empty ) const
作为一个进程启动该文件。

如果文件为可执行程序,此函数将直接运行之。
如果为文档文件,将打开该文档(自动调用相关的程序)。
如果为文件夹,将打开该文件夹。
参见:
revealToUser
void File::revealToUser ( ) const
打开该文件所在的文件夹。

参见:
startAsProcess

static const File JUCE_CALLTYPE File::getSpecialLocation ( const SpecialLocationType type ) [static]
查找指定类型的文件或文件夹的位置,比如根目录或文档目录。

参见:
SpecialLocationType
static const File File::createTempFile ( const String & fileNameEnding ) [static]
返回在系统临时目录下创建的临时文件。

此函数将返回一个不存在的临时文件的名称。

要获取临时文件夹,可使用:getSpecialLocation (File::tempDirectory)。

static const File File::getCurrentWorkingDirectory ( ) [static]
返回当前的工作目录。

参见:
setAsCurrentWorkingDirectory
bool File::setAsCurrentWorkingDirectory ( ) const
将当前的工作目录设置为此文件(目录)。

此文件必须指向有效的目录。

返回:
如果当前工作目录被改变,则返回true。
参见:
getCurrentWorkingDirectory
static const String File::createLegalFileName ( const String & fileNameToFix ) [static]
从文件名中移除非法字符。

此函数在移除非法字符后将返回给定字符串的副本,如果字符串太长,则有可能缩短之。

此函数将移除斜杠,因此不要在绝对路径中使用斜杠。

参见:
createLegalPathName
static const String File::createLegalPathName ( const String & pathNameToFix ) [static]
从路径名中移除非法字符。

类似于:createLegalFileName(),但是此函数不移除斜杠,因此可用于完整的路径名。

参见:
createLegalFileName
static bool File::areFileNamesCaseSensitive ( ) [static]
当前操作系统是否区分文件名中的大小写。

static bool File::isAbsolutePath ( const String & path ) [static]
如果字符串看起来是完整的绝对路径,则返回true。

static const File File::createFileWithoutCheckingPath ( const String & path ) [static]
创建一个包含该字符串的文件,不进行普通的构造函数所执行的理智校验。

尽量避免使用此函数,除非确有把握。

static const String File::addTrailingSeparator ( const String & path ) [static]
如果路径最后没有分隔符,则添加之。

成员数据文档

const File File::nonexistent [static]
此静态常量被“无效”文件所使用。

const juce_wchar File::separator [static]
系统专属的文件分隔符。

Windows系统下为’’,Mac和Linux系统下为’/’。

const String File::separatorString [static]
系统专属的文件分隔符。

Windows系统下为’’,Mac和Linux系统下为’/’。

定义该类的头文件:
juce_File.h

[size=150]Graphics 图形类[/size]

图形环境,供绘制组件或图像。 更多…

所有成员

class ScopedSaveState
使用RAII保存和恢复图形环境的状态。 更多…

Public类型

enum ResamplingQuality { lowResamplingQuality = 0, mediumResamplingQuality = 1, highResamplingQuality = 2 }

绘制图像时可设置的渲染质量。

更多…

Public成员函数

Graphics (const Image &imageToDrawOnto)
创建一个Graphics对象,以便直接完成参数图像的绘制。 
~Graphics ()
析构函数。 

void setColour (const Colour &newColour)
改变当前的绘制颜色。
void setOpacity (float newOpacity)
更改当前所使用的颜色的不透明度。
void setGradientFill (const ColourGradient &gradient)
设置颜色渐变。
void setTiledImageFill (const Image &imageToUse, int anchorX, int anchorY, float opacity)
使用图像平铺。
void setFillType (const FillType &newFill)
改变当前的填充设置。
void setFont (const Font &newFont)
设置随后的文本绘制函数所使用的字体。
void setFont (float newFontHeight, int fontStyleFlags=Font::plain)
设置当前所选用的字体的大小和样式。
const Font getCurrentFont () const
返回当前所选用的字体。
void drawSingleLineText (const String &text, int startX, int baselineY) const
绘制一个单行字符串。
void drawMultiLineText (const String &text, int startX, int baselineY, int maximumLineWidth) const
绘制多行文本。
void drawTextAsPath (const String &text, const AffineTransform &transform) const
以向量轨迹的方式将字符串渲染为文本。
void drawText (const String &text, int x, int y, int width, int height, const Justification &justificationType, bool useEllipsesIfTooBig) const
在指定的矩形区域中绘制一行文本。
void drawFittedText (const String &text, int x, int y, int width, int height, const Justification &justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale=0.7f) const
尝试在给定的区域中绘制文本。
void fillAll () const
使用当前所设置的颜色或画刷填充整个区域。
void fillAll (const Colour &colourToUse) const
使用指定的颜色填充整个区域。
void fillRect (int x, int y, int width, int height) const
使用已经设置的颜色或画刷填充一个矩形区域。
void fillRect (const Rectangle< int > &rectangle) const
使用已经设置的颜色或画刷填充一个矩形区域。
void fillRect (float x, float y, float width, float height) const
使用已经设置的颜色或画刷填充一个矩形区域。
void fillRoundedRectangle (float x, float y, float width, float height, float cornerSize) const
使用已经设置的颜色或画刷填充一个圆角矩形。
void fillRoundedRectangle (const Rectangle< float > &rectangle, float cornerSize) const
使用已经设置的颜色或画刷填充一个圆角矩形。
void fillCheckerBoard (const Rectangle< int > &area, int checkWidth, int checkHeight, const Colour &colour1, const Colour &colour2) const
交替使用两种颜色,填充一个类似国际象棋棋盘的区域。
void drawRect (int x, int y, int width, int height, int lineThickness=1) const
使用已经设置的颜色或画刷绘制四条线,形成一个矩形边框(绘制矩形边框)。
void drawRect (float x, float y, float width, float height, float lineThickness=1.0f) const
使用已经设置的颜色或画刷绘制四条线,形成一个矩形边框(绘制矩形边框)。
void drawRect (const Rectangle< int > &rectangle, int lineThickness=1) const
使用已经设置的颜色或画刷绘制四条线,形成一个矩形边框(绘制矩形边框)。
void drawRoundedRectangle (float x, float y, float width, float height, float cornerSize, float lineThickness) const
使用已经设置的颜色或画刷绘制一个带有圆角矩形边框。
void drawRoundedRectangle (const Rectangle< float > &rectangle, float cornerSize, float lineThickness) const
使用已经设置的颜色或画刷绘制一个带有圆角矩形边框。
void drawBevel (int x, int y, int width, int height, int bevelThickness, const Colour &topLeftColour=Colours::white, const Colour &bottomRightColour=Colours::black, bool useGradient=true, bool sharpEdgeOnOutside=true) const
使用两种颜色绘制一个3D凸起或凹陷的斜面。

void setPixel (int x, int y) const
使用当前颜色或画刷绘制一个像素点。
void fillEllipse (float x, float y, float width, float height) const
使用当前颜色或画刷填充一个椭圆。
void drawEllipse (float x, float y, float width, float height, float lineThickness) const
使用当前颜色或画刷绘制一个椭圆边框。
void drawLine (float startX, float startY, float endX, float endY) const
两点连一线。
void drawLine (float startX, float startY, float endX, float endY, float lineThickness) const
两点连一线,并可设置线宽。
void drawLine (const Line< float > &line) const
两点连一线。
void drawLine (const Line< float > &line, float lineThickness) const
两点连一线,并可设置线宽。
void drawDashedLine (float startX, float startY, float endX, float endY, const float *dashLengths, int numDashLengths, float lineThickness=1.0f) const
使用当前颜色或画刷绘制虚线。
void drawVerticalLine (int x, float top, float bottom) const
在给定的x坐标处绘制竖线。
void drawHorizontalLine (int y, float left, float right) const
在给定的y坐标处绘制横线。
void fillPath (const Path &path, const AffineTransform &transform=AffineTransform::identity) const
使用当前颜色或画刷填充一个轨迹。
void strokePath (const Path &path, const PathStrokeType &strokeType, const AffineTransform &transform=AffineTransform::identity) const
使用当前颜色或画刷绘制轨迹的轮廓(边框)。
void drawArrow (const Line< float > &line, float lineThickness, float arrowheadWidth, float arrowheadLength) const
绘制一条尾部带有箭头的线。
void setImageResamplingQuality (const ResamplingQuality newQuality)
图像重采样的质量。
void drawImageAt (const Image &imageToDraw, int topLeftX, int topLeftY, bool fillAlphaChannelWithCurrentBrush=false) const
绘制一个图像。
void drawImage (const Image &imageToDraw, int destX, int destY, int destWidth, int destHeight, int sourceX, int sourceY, int sourceWidth, int sourceHeight, bool fillAlphaChannelWithCurrentBrush=false) const
绘制图像的其中一部分,缩放其大小以匹配给定的目标区域。
void drawImageTransformed (const Image &imageToDraw, const AffineTransform &transform, bool fillAlphaChannelWithCurrentBrush=false) const
绘制一个图像,并使用无损变换来缩放或旋转之。
void drawImageWithin (const Image &imageToDraw, int destX, int destY, int destWidth, int destHeight, const RectanglePlacement &placementWithinTarget, bool fillAlphaChannelWithCurrentBrush=false) const
绘制一个匹配目标矩形的图像。
const Rectangle< int > getClipBounds () const
返回当前裁剪区域的边框位置。
bool clipRegionIntersects (const Rectangle< int > &area) const
检测给出的矩形是否重叠图形环境的裁剪区域。
bool reduceClipRegion (int x, int y, int width, int height)
检测是否重叠给定区域。
bool reduceClipRegion (const Rectangle< int > &area)
检测是否重叠给定区域。
bool reduceClipRegion (const RectangleList &clipRegion)
用给定区域来重叠当前裁剪区域。
bool reduceClipRegion (const Path &path, const AffineTransform &transform=AffineTransform::identity)
用给定轨迹来重叠当前裁剪区域。
bool reduceClipRegion (const Image &image, const AffineTransform &transform)
用给定图像的alpha通道来重叠当前裁剪区域。
void excludeClipRegion (const Rectangle< int > &rectangleToExclude)
绘制操作中排除一个矩形,不绘制该矩形。
bool isClipEmpty () const
如果裁剪区域为0,无法完成绘制,则返回true。
void saveState ()
堆内存中保存当前图形的状态。
void restoreState ()
恢复由saveState()所保存的图形状态。
void beginTransparencyLayer (float layerOpacity)
渲染离屏位图,而后整合到给定透明度的图形环境中。
void endTransparencyLayer ()
完成临时的半透明缓冲区的绘制操作。
void setOrigin (int newOriginX, int newOriginY)
设置图形环境的原点位置。
void addTransform (const AffineTransform &transform)
添加无损变换,影响到随后所设置的所有图形环境。
void resetToDefaultState ()
将当前颜色、画刷和字体重置为默认值。
bool isVectorDevice () const
如果图形环境绘制到基于矢量的设备,如打印机,则返回true。
Graphics (LowLevelGraphicsContext *internalContext) throw ()
创建一个图形对象,使用低级渲染器。
LowLevelGraphicsContext * getInternalContext () const throw ()

详细说明

图形环境,供绘制组件或图像。

当某个组件(Component)需要绘制时,Graphics图形环境对象将传递给该组件的Component::paint()方法,此时可通过图形环境对象调用不同的方法来绘制组件的内容。

也可由图像创建Graphics,以便直接绘制该图像。

参见:
Component::paint

枚举成员文档

enum Graphics::ResamplingQuality
绘制图像时可设置的渲染质量。

参见:
blendImage, Graphics::setImageResamplingQuality
枚举常量:
lowResamplingQuality
重采样使用“最近邻值”的算法,质量较低。

mediumResamplingQuality
过采样使用双线性插值算法,负采样使用区域均值算法,中等质量。

highResamplingQuality
过采样使用双三次插值算法,负采样使用区域均值算法,质量较好。

构造函数和析构函数文档

Graphics::Graphics ( const Image & imageToDrawOnto ) [explicit]
创建一个Graphics对象,以便直接完成参数图像的绘制。

所创建的图形对象将设置为在图像上绘制,图形环境的裁剪区域为图像的完整大小,其原点为图像的原点。要绘制到图像的子区域,使用reduceClipRegion()和setOrigin()方法。

显然,在图形环境销毁之前,不应该先销毁图像。

Graphics::~Graphics ( )
析构函数。

Graphics::Graphics ( LowLevelGraphicsContext * internalContext ) throw ()
创建一个图形对象,使用低级渲染器。

仅供内部使用。注意:销毁该对象,并不会销毁参数对象。

成员函数文档

void Graphics::setColour ( const Colour & newColour )
改变当前的绘制颜色。

设置绘制的颜色,还可以一并设置颜色的透明度。

当调用此方法时使用了画刷,则已用的画刷将被销毁,随后的所有绘制将使用新的纯色画刷。

参见:
setOpacity
引用给:LassoComponent< SelectableItemType >::paint()

void Graphics::setOpacity ( float newOpacity )
更改当前所使用的颜色的不透明度。

如果正在使用纯色,此函数将改变其透明度。

如果使用了颜色渐变,此函数将不起作用。

0.0为完全透明,1.0为完全不透明。

void Graphics::setGradientFill ( const ColourGradient & gradient )
设置颜色渐变。

void Graphics::setTiledImageFill ( const Image & imageToUse,
int anchorX,
int anchorY,
float opacity
)
使用图像平铺。

如果正在使用参数图像,确保不要销毁之。

void Graphics::setFillType ( const FillType & newFill )
改变当前的填充设置。

参见:
setColour, setGradientFill, setTiledImageFill
void Graphics::setFont ( const Font & newFont )
设置随后的文本绘制函数所使用的字体。

注意:setFont (float, int)方法也可以快速改变当前字体的大小和样式。

参见:
drawSingleLineText, drawMultiLineText, drawTextAsPath, drawText, drawFittedText
void Graphics::setFont ( float newFontHeight,
int fontStyleFlags = Font::plain
)
设置当前所选用的字体的大小和样式。

此函数可以快速改变当前字体的大小和样式,使用起来比较方便。注意:此函数不改变字体。

参见:
Font
const Font Graphics::getCurrentFont ( ) const
返回当前所选用的字体。

void Graphics::drawSingleLineText ( const String & text,
int startX,
int baselineY
) const
绘制一个单行字符串。

此函数使用当前设置的颜色或画刷来填充文本(文本颜色)。字体则由setFont()所设置。

参数:
text 要绘制的字符串
startX 文本的起始位置
baselineY 文本的基线位置
参见:
drawMultiLineText, drawText, drawFittedText, GlyphArrangement::addLineOfText
void Graphics::drawMultiLineText ( const String & text,
int startX,
int baselineY,
int maximumLineWidth
) const
绘制多行文本。

当文本中包含换行符,或者文本的宽度超过maximumLineWidth时,将分行显示。

参见:
setFont, drawSingleLineText, drawFittedText, GlyphArrangement::addJustifiedText

void Graphics::drawTextAsPath ( const String & text,
const AffineTransform & transform
) const
以向量轨迹的方式将字符串渲染为文本。

此函数允许字符串使用任意AffineTransform进行变换,并使用当前的颜色或画刷进行渲染。此函数的执行速度低于正常的文本绘制函数,但比较精确。

参见:
setFont
void Graphics::drawText ( const String & text,
int x,
int y,
int width,
int height,
const Justification & justificationType,
bool useEllipsesIfTooBig
) const
在指定的矩形区域中绘制一行文本。

文本在矩形区域中的位置,比如居中、左对齐、右对齐等等,基于justification类型的参数。如果文本太长,将自动做横向缩短处理,或者在末尾添加省略号(前提是useEllipsesIfTooBig设置为true)。

参见:
drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText
void Graphics::drawFittedText ( const String & text,
int x,
int y,
int width,
int height,
const Justification & justificationFlags,
int maximumNumberOfLines,
float minimumHorizontalScale = 0.7f
) const
尝试在给定的区域中绘制文本。

此函数绘制的文本将匹配给定的区域大小,具有最佳的阅读效果,因此比较适合于绘制标签类文本。

如果文本太长,将自动横向缩短,或者多行显示。最多可显示几行由参数maximumLinesToUse来指定。如果文本不想匹配到区域,将尽可能的填充其中,并在文本末尾添加省略号。

参数Justification用于设置文本在区域中的对齐方式,包括水平和垂直这两个方向上的对齐。

参数minimumHorizontalScale用于设置横向缩放的最大比例。如果不打算进行横向缩短,可设置为1.0f。

参见:
GlyphArrangement::addFittedText
void Graphics::fillAll ( ) const
使用当前所设置的颜色或画刷填充整个区域。

(参见:fillAll (const Colour&),使用指定的颜色快速填充)。

引用给:LassoComponent< SelectableItemType >::paint()

void Graphics::fillAll ( const Colour & colourToUse ) const
使用指定的颜色填充整个区域。

此方法不使用、也不改变当前已经设置的颜色或画刷,参数为要使用的颜色,该颜色仅仅是临时使用,不影响随后的绘制方法。

void Graphics::fillRect ( int x,
int y,
int width,
int height
) const
使用已经设置的颜色或画刷填充一个矩形区域。

参见:
drawRect, fillRoundedRectangle
void Graphics::fillRect ( const Rectangle< int > & rectangle ) const
使用已经设置的颜色或画刷填充一个矩形区域。

void Graphics::fillRect ( float x,
float y,
float width,
float height
) const
使用已经设置的颜色或画刷填充一个矩形区域。

此函数使用亚像素来定位要绘制的矩形起止点和大小,执行速度慢于使用整型数值定位的同类方法,优点是定位精确。

void Graphics::fillRoundedRectangle ( float x,
float y,
float width,
float height,
float cornerSize
) const
使用已经设置的颜色或画刷填充一个圆角矩形。

参见:
drawRoundedRectangle, Path::addRoundedRectangle
void Graphics::fillRoundedRectangle ( const Rectangle< float > & rectangle,
float cornerSize
) const
使用已经设置的颜色或画刷填充一个圆角矩形。

参见:
drawRoundedRectangle, Path::addRoundedRectangle
void Graphics::fillCheckerBoard ( const Rectangle< int > & area,
int checkWidth,
int checkHeight,
const Colour & colour1,
const Colour & colour2
) const
交替使用两种颜色,填充一个类似国际象棋棋盘的区域。