From b0bd3a33cc1cdc973ac3b97f448f41011b6badba Mon Sep 17 00:00:00 2001 From: Kenny Shields Date: Mon, 11 Feb 2013 16:15:40 -0500 Subject: [PATCH] Version 0.9.5 - Alpha (see changelog.txt) --- changelog.txt | 957 ++--- debug.lua | 1590 +++++---- init.lua | 592 ++-- objects/base.lua | 2244 ++++++------ objects/button.lua | 51 +- objects/checkbox.lua | 753 ++-- objects/collapsiblecategory.lua | 31 +- objects/columnlist.lua | 66 +- objects/frame.lua | 32 +- objects/image.lua | 738 ++-- objects/imagebutton.lua | 588 +-- objects/internal/closebutton.lua | 2 +- .../internal/columnlist/columnlistarea.lua | 21 +- objects/internal/columnlist/columnlistrow.lua | 2 +- .../internal/columnlist/coulmnlistheader.lua | 2 +- objects/internal/linenumberspanel.lua | 318 +- objects/internal/modalbackground.lua | 200 +- .../internal/multichoice/multichoicelist.lua | 50 +- .../internal/multichoice/multichoicerow.lua | 2 +- objects/internal/scrollable/scrollarea.lua | 472 +-- objects/internal/scrollable/scrollbar.lua | 698 ++-- objects/internal/scrollable/scrollbody.lua | 346 +- objects/internal/scrollable/scrollbutton.lua | 328 +- objects/internal/sliderbutton.lua | 486 +-- objects/internal/tabbutton.lua | 462 ++- objects/internal/tooltip.lua | 490 +-- objects/list.lua | 281 +- objects/multichoice.lua | 620 ++-- objects/numberbox.lua | 478 +++ objects/panel.lua | 314 +- objects/progressbar.lua | 16 +- objects/slider.lua | 795 +++-- objects/tabs.lua | 1100 +++--- objects/text.lua | 1065 +++--- objects/textinput.lua | 3091 ++++++++-------- readme.md | 34 +- skins.lua | 138 +- skins/Blue (basic)/images/arrow-down.png | Bin 180 -> 344 bytes skins/Blue (basic)/images/arrow-left.png | Bin 188 -> 337 bytes skins/Blue (basic)/images/arrow-right.png | Bin 185 -> 336 bytes skins/Blue (basic)/images/arrow-up.png | Bin 188 -> 366 bytes .../Blue (basic)/images/multichoice-arrow.png | Bin 231 -> 284 bytes skins/Blue (basic)/skin.lua | 2976 ++++++++-------- skins/Blue/images/arrow-down.png | Bin 180 -> 344 bytes skins/Blue/images/arrow-left.png | Bin 188 -> 337 bytes skins/Blue/images/arrow-right.png | Bin 185 -> 336 bytes skins/Blue/images/arrow-up.png | Bin 188 -> 366 bytes skins/Blue/images/multichoice-arrow.png | Bin 231 -> 284 bytes skins/Blue/skin.lua | 3148 ++++++++--------- skins/Orange (basic)/images/arrow-down.png | Bin 180 -> 344 bytes skins/Orange (basic)/images/arrow-left.png | Bin 188 -> 337 bytes skins/Orange (basic)/images/arrow-right.png | Bin 185 -> 336 bytes skins/Orange (basic)/images/arrow-up.png | Bin 188 -> 366 bytes .../images/multichoice-arrow.png | Bin 231 -> 284 bytes skins/Orange (basic)/skin.lua | 2976 ++++++++-------- skins/Orange/images/arrow-down.png | Bin 180 -> 344 bytes skins/Orange/images/arrow-left.png | Bin 188 -> 337 bytes skins/Orange/images/arrow-right.png | Bin 185 -> 336 bytes skins/Orange/images/arrow-up.png | Bin 188 -> 366 bytes skins/Orange/images/multichoice-arrow.png | Bin 231 -> 284 bytes skins/Orange/skin.lua | 3148 ++++++++--------- templates.lua | 348 +- templates/base.lua | 2 +- util.lua | 560 +-- 64 files changed, 16988 insertions(+), 15623 deletions(-) create mode 100644 objects/numberbox.lua diff --git a/changelog.txt b/changelog.txt index cd6b6fa..6f0735d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,458 +1,501 @@ -================================================ -Version 0.9.4.15 - Alpha (January 5 - 2013) -================================================ -[ADDED] a new base method: GetInternals() -[ADDED] a new tooltip method: SetFollowObject(bool) - -================================================ -Version 0.9.4.14 - Alpha (January 4 - 2013) -================================================ -[ADDED] a new util library function: loveframes.util.CheckForUpdates() (note: this function is meant to be used by the developer and is never called internally by Love Frames) -[ADDED] a new callback for the tabbutton object: OnOpened(object) -[ADDED] a new callback for the tabbutton object: OnClosed(object) - -[CHANGED] tabs:AddTab(name, object, tip, image) now accepts two new optional arguments for tabbutton callbacks (ex: tabs:AddTab(name, object, tip, image, onopened, onclosed)) - -================================================ -Version 0.9.4.13 - Alpha (January 4 - 2013) -================================================ -[ADDED] a new base method: IsInList() - -[FIXED] not being able to add the boolean "false" to a template as a property with loveframes.templates.AddProperty(templatename, object, property, value) - -[CHANGED] small code cleanup -[CHANGED] improved performance of the text object while parented within a list object - -================================================ -Version 0.9.4.12 - Alpha (December 30 - 2012) -================================================ -[CHANGED] newlines created on the text object with \n now display properly -[CHANGED] Love Frames now resets the current drawing color to the last color used before calling loveframes.draw() after it has finished all drawing operations - -================================================ -Version 0.9.4.11 - Alpha (December 28 - 2012) -================================================ -[ADDED] a new textinput method: SetAutoScroll(bool) -[ADDED] a new textinput method: GetAutoScroll() - -[FIXED] a couple of typos in the changelog -[FIXED] a sliderbutton calculation error that caused the sliderbutton object to flash while moving the cursor out of it's bounding box while it was down - -[CHANGED] cleaned up a lot of code -[CHANGED] the text object's shadow color now defaults to black - -================================================ -Version 0.9.4.10 - Alpha (December 26 - 2012) -================================================ -[FIXED] registration errors for the new default skins - -================================================ -Version 0.9.4.9 - Alpha (December 26 - 2012) -================================================ -[ADDED] a new default skin: Blue (basic) -[ADDED] a new default skin: Orange (basic) -[ADDED] a new skins library function: loveframes.skins.GetAvailable() - -[CHANGED] the license from CC BY-SA 3.0 to CC BY 3.0 -[CHANGED] made minor improvements to the default skins - -================================================ -Version 0.9.4.8 - Alpha (December 24 - 2012) -================================================ -[ADDED] a new text method: SetShadow(bool) -[ADDED] a new text method: GetShadow() -[ADDED] a new text method: SetShadowOffsets(offsetx, offsety) -[ADDED] a new text method: GetShadowOffsets() -[ADDED] a new text method: SetShadowColor(r, g, b, a) -[ADDED] a new text method: GetShadowColor() -[ADDED] a new columnlist method: SetColumnHeight(height) - -[FIXED] templates not being applied to objects - -[CHANGED] the columnlistarea object now has better sorting -[CHANGED] the frame object no longer sets the size of it's close button - -================================================ -Version 0.9.4.7 - Alpha (December 19 - 2012) -================================================ -[FIXED] textinput:SetFocus(focus) not working properly - -[CHANGED] the tooltip object is now positionable via the standard positioning methods when not set to follow the cursor - -================================================ -Version 0.9.4.6 - Alpha (December 10 - 2012) -================================================ -[ADDED] a new textinput event callback: OnFocusGained(object) -[ADDED] a new textinput event callback: OnFocusLost(object) - -[FIXED] the textinput object accepting input from the tab and delete keys when object.editable was set to false - -[CHANGED] all "." are now replaced with "/" in loveframes.config["DIRECTORY"] after all inernal Love Frames libraries have been loaded (this is to prevent filesystem errors) - -[REMOVED] loveframes.util.TrimString(string) - -================================================ -Version 0.9.4.5 - Alpha (November 28 - 2012) -================================================ -[FIXED] text inputs not losing focus in certain situations - -================================================ -Version 0.9.4.4 - Alpha (November 24 - 2012) -================================================ -[ADDED] a new text input method: SetButtonScrollAmount(amount) -[ADDED] a new text input method: GetButtonScrollAmount() -[ADDED] a new text input method: SetMouseWheelScrollAmount(amount) -[ADDED] a new text input method: GetMouseWheelScrollAmount() -[ADDED] a new multichoice method: SetButtonScrollAmount(amount) -[ADDED] a new multichoice method: GetButtonScrollAmount() -[ADDED] a new multichoice method: SetMouseWheelScrollAmount(amount) -[ADDED] a new multichoice method: GetMouseWheelScrollAmount() -[ADDED] a new column list method: SetButtonScrollAmount(amount) -[ADDED] a new column list method: GetButtonScrollAmount() -[ADDED] a new column list method: SetMouseWheelScrollAmount(amount) -[ADDED] a new column list method: GetMouseWheelScrollAmount() -[ADDED] a new frame method: SetParentLocked(bool) -[ADDED] a new frame method: GetParentLocked() -[ADDED] a new base method: CenterWithinArea(x, y, width, height) -[ADDED] a new library function: loveframes.NewObject(id, name, inherit_from_base) - -[FIXED] an error that would occur when clicking a scroll button on a multiline text input or a multichoice list -[FIXED] a button calculation error that caused the button object to flash while moving the cursor out of it's bounding box while it was down -[FIXED] several errors that could occur when a collapsible category did not have an object -[FIXED] the value of the slider object becoming -0 in certain situations - -[CHANGED] the close button object is no longer positioned internally by the frame object and should now be positioned by it's skin drawing function -[CHANGED] all Love Frames objects are now stored within loveframes.objects -[CHANGED] frames are now draggable when parented to any object -[CHANGED] the look of the debug overlay - -================================================ -Version 0.9.4.3 - Alpha (November 20 - 2012) -================================================ -[ADDED] a new base method: SetProperty(name, value) -[ADDED] a new base method: GetProperty(name) -[ADDED] a new list method: SetButtonScrollAmount(amount) -[ADDED] a new list method: GetButtonScrollAmount() -[ADDED] a new list method: SetMouseWheelScrollAmount(amount) -[ADDED] a new list method: GetMouseWheelScrollAmount() - -[FIXED] a typo in the changelog -[FIXED] image:SetScale(scalex, scaley) not working correctly - -[CHANGED] loveframes.util.GetDirContents(dir, t) to loveframes.util.GetDirectoryContents(dir, t) -[CHANGED] arguments passed to require() to use "." instead of "/" which should fix file loading issues on certain systems - -================================================ -Version 0.9.4.2 - Alpha (November 5 - 2012) -================================================ -[ADDED] a new text object method: SetIgnoreNewlines(bool) -[ADDED] a new text object method: GetIgnoreNewlines() -[ADDED] a new text image method: SetOrientation(orientation) -[ADDED] a new text image method: GetOrientation() -[ADDED] a new text image method: SetScaleX(scalex) -[ADDED] a new text image method: GetScaleX() -[ADDED] a new text image method: SetScaleY(scaley) -[ADDED] a new text image method: GetScaleY() -[ADDED] a new text image method: SetScale(scalex, scaley) -[ADDED] a new text image method: GetScale() -[ADDED] a new text image method: SetOffsetX(x) -[ADDED] a new text image method: GetOffsetX() -[ADDED] a new text image method: SetOffsetY(y) -[ADDED] a new text image method: GetOffsetY() -[ADDED] a new text image method: SetOffset(x, y) -[ADDED] a new text image method: GetOffset() -[ADDED] a new text image method: SetShearX(x) -[ADDED] a new text image method: GetShearX() -[ADDED] a new text image method: SetShearY(y) -[ADDED] a new text image method: GetShearY() -[ADDED] a new text image method: SetShear(x, y) -[ADDED] a new text image method: GetShear() - -[FIXED] an error that ocurred after pressing enter on a multiline text input while all of it's text was selected -[FIXED] text in a single line text input always being cleared when the enter key was pressed -[FIXED] a syntax error in both default skin files that caused imaged to draw incorrect when they had a custom color -[FIXED] an error that would occur when a tab button was being drawn while no font had been set -[FIXED] textinput.OnTextChanged being called too early when using the backspace key or the delete key - -[CHANGED] tab buttons no longer calculate their width from within their internal drawing function and should be sized externally from now on -[CHANGED] the text object now calculates what characters should be drawn while in a list object to improve performance with list objects that contain large amounts of text - -================================================ -Version 0.9.4.1 - Alpha (October 25 - 2012) -================================================ -[ADDED] support for using the delete key in text input objects - -[FIXED] textinupt:GetText() only returning the first line of a multiline text input -[FIXED] an error that occurred when clicking a multiline text input object after setting the object's text to an empty string with textinput:SetText("") -[FIXED] incorrect positioning of the text input object's indicator when using the left or right arrow keys to move the object's indicator to a different line -[FIXED] the text input object not creating a new line correctly in certain situations - -[CHANGED] textinput:GetText() now returns the object's text with line breaks - -================================================ -Version 0.9.4 - Alpha (October 22 - 2012) -================================================ -[ADDED] a new base method: SetDrawOrder() -[ADDED] a new base method: GetDrawOrder() -[ADDED] a new text method: GetFormattedText() -[ADDED] a new text input method: SetEditable(bool) -[ADDED] a new text input method: GetEditable() -[ADDED] a new text input method: GetUsable() -[ADDED] a new text input method: GetUnusable() -[ADDED] a new system for creating and applying templates to objects - -[FIXED] a few incorrent entries in the changelog and added a few entries that were meant to be in the last upadte's changelog -[FIXED] an error that occured when clicking on a frame that was parented to another frame -[FIXED] frames not being positioned properly if they were parented to another object -[FIXED] modal background object not drawing over umodaled objects in certain situations -[FIXED] an error that would occur when a multichoice list object would become scrollable -[FIXED] an error that would occur when a the column list object had no columns -[FIXED] multichoice object not positioning itself properly if it's parent was the base object - -[CHANGED] text:GetText() now returns a string of the object's text -[CHANGED] parented frames can no longer be modaled - -================================================ -Version 0.9.3.2 - Alpha (Spetember 29 - 2012) -================================================ -[ADDED] a new base method: SetDrawOrder() -[ADDED] a new text input method: SetMultiline(bool) -[ADDED] a new text input method: GetVerticalScrollBody() -[ADDED] a new text input method: GetHorizontalScrollBody() -[ADDED] a new text input method: SetText(text) -[ADDED] a new text input method: HasVerticalScrollBar() -[ADDED] a new text input method: HasHorizontalScrollBar() -[ADDED] a new text input method: GetFont() -[ADDED] a new text input method: GetLineNumbersPanel() -[ADDED] a new text input method: GetMultiline() -[ADDED] a new text input method: GetTextX() -[ADDED] a new text input method: GetTextY() -[ADDED] a new text input method: IsAllTextSelected() -[ADDED] a new text input method: GetLines() -[ADDED] a new text input method: GetOffsetX() -[ADDED] a new text input method: GetOffsetY() -[ADDED] a new text input method: GetIndicatorX() -[ADDED] a new text input method: GetIndicatorY() -[ADDED] a new text input method: SetLineNumbersEnabled(enabled) -[ADDED] a new text input method: GetLineNumbersEnabled() -[ADDED] a new text input method: GetItemWidth() -[ADDED] a new text input method: GetItemHeight() -[ADDED] a new text input method: SetTabReplacement(tabreplacement) -[ADDED] a new text input method: GetTabReplacement() -[ADDED] a new scroll area method: GetBarType() -[ADDED] a new scroll bar method: IsDragging() -[ADDED] a new scroll bar method: GetBarType() -[ADDED] a new scroll button method: GetScrollType() -[ADDED] a new tab button method: GetText() -[ADDED] a new tab button method: GetImage() -[ADDED] a new tab button method: GetTabNumber() -[ADDED] a new column list header method: GetName() -[ADDED] a new column list row method: GetColumnData() -[ADDED] a new multichoice method: SetText(text) -[ADDED] a new multichoice method: GetText() -[ADDED] a new multichoice row method: GetText() -[ADDED] a new progressbar method: GetBarWidth() -[ADDED] a new internal object: linenumberspanel -[ADDED] multiline support for the text input object -[ADDED] ability to select all text within a text input - -[FIXED] progressbar object not positioning itself properly if it's parent was the base object -[FIXED] a typo in the syntax of loveframes.util.SplitString (was "SplitSring", changed to "SplitString") -[FIXED] the tooltip object not disapearing if it was visible when it's object's visibility was changed to false -[FIXED] the text input object's x offset not being adjusted initially when the width of it's text would would become wider than it's drawing area - -[CHANGED] massive code cleanup for optimization and -[CHANGED] frames can now be parent to other objects -[CHANGED] textinput:RunBlink() to textinput:UpdateIndicator() -[CHANGED] textinput:GetBlinkerVisisbility() to textinput:GetIndicatorVisisbility() -[CHANGED] textinput:MoveBlinker(num, exact) to textinput:MoveIndicator(num, exact) -[CHANGED] scrollbars now only autoscroll when their list's item width/height is greater thant their previous list's previous item width/height -[CHANGED] cleaned up the code for the default skins -[CHANGED] the text input object's text is no longer drawn internally by the object and should now be draw within the object's skin drawing function -[CHANGED] the column list row object's text is no longer drawn internally by the object and should now be draw within the object's skin drawing function - -[REMOVED] textinput:SetTextColor(color) -[REMOVED] columnlistrow:SetTextColor() - -================================================ -Version 0.9.3.1 - Alpha (Spetember 2 - 2012) -================================================ -[ADDED] numpad enter key support for textinput.OnEnter - -[FIXED] duplicate progressbar:GetCompleted() in progressbar.lua - -[CHANGED] textinput.OnTextEnterd to textinput.OnTextChanged -[CHANGED] textinput.OnTextChanged is now also called when the backspace key is pressed - -================================================ -Version 0.9.3 - Alpha (Spetember 1 - 2012) -================================================ -[ADDED] a new base method: GetParents() -[ADDED] a new base method: IsTopInternal() -[ADDED] a new base method: IsInternal() -[ADDED] a new base method: GetType() -[ADDED] a new checkbox method: GetFont() -[ADDED] a new checkbox method: GetBoxSize() -[ADDED] a new checkbox method: GetBoxWidth() -[ADDED] a new checkbox method: GetBoxHeight() -[ADDED] a new image method: GetImage() -[ADDED] a new image method: GetColor() -[ADDED] a new progressbar method: GetCompleted() -[ADDED] a new tabs method: GetTabNumber() -[ADDED] a new text method: GetLines() -[ADDED] a new text input method: SetLimit(limit) -[ADDED] a new text input method: SetUsable(usable) -[ADDED] a new text input method: SetUnusable(unusable) -[ADDED] a new text input method: Clear() -[ADDED] a new text input method: GetText() -[ADDED] support for line breaks in the text object (please refer to the wiki on how to format your text with line breaks) -[ADDED] more information to the debug overlay - -[FIXED] tooltips and multichoice lists not functioning properly when a frame was modaled -[FIXED] the text object not moving it's base parent to the top when clicked if it's base parent was a frame -[FIXED] the list object not scrolling via the mouse wheel due to certain collision detection issues -[FIXED] tooltips flickering when in a hover state -[FIXED] slider calculation errors -[FIXED] skin.DrawRepeatingImage creating a new image every frame -[FIXED] checkbox text not scrolling properly when in a list -[FIXED] the collapsible category's object not scrolling properly when in a list -[FIXED] skins not assuming the drawing functions of the default skins if drawing functions in the active skin were missing -[FIXED] some objects not being removed -[FIXED] sliders not scrolling properly when in a list - -[CHANGED] various code for a small cleanup -[CHANGED] tooltips from being children of the base object to internals of the base object -[CHANGED] tooltips from never being removed to being removed when their assigned object is removed -[CHANGED] tooltips are now not able to be assigned to the base object (this would cause an error due to the way the tooltip currently functions) -[CHANGED] the text object now positions it's text when SetText is called instead of positioning it's text every frame -[CHANGED] slider:SetMax(max), slider:SetMin(min) and slider:SetMinMax(min, max) now adjust the slider's value if the slider's value is out of the range specified -[CHANGED] loveframes.Create(data, parent) now activates an error screen if the object specified is invalid - -================================================ -Version 0.9.2.5 - Alpha (June 1 - 2012) -================================================ -[FIXED] the text object not drawing numbers in certain situations -[FIXED] a typo in the changelog - -================================================ -Version 0.9.2.4 - Alpha (May 29 - 2012) -================================================ -[FIXED] the SetSkin(skin) method causing a stack overflow - -================================================ -Version 0.9.2.3 - Alpha (May 27 - 2012) -================================================ -[FIXED] imagebutton.OnClick not working -[FIXED] text being added into the text input object at incorrect positions when the value of textinput.blinknum was 0 -[FIXED] a bug that would cause an error when running SetVisible on a frame object when the value of frame.showclose was true - -================================================ -Version 0.9.2.2 - Alpha (May 23 - 2012) -================================================ -[FIXED] vertical slider value direction (top is now max value and bottom is 0) -[FIXED] text flashing in the text input object when moving the text blinker to the right -[FIXED] text blinker in the text input object not appearing in certain situations - -================================================ -Version 0.9.2 - Alpha (May 22 - 2012) -================================================ -[ADDED] a new slider method: SetButtonSize(width, height) -[ADDED] a new slider method: GetButtonSize() -[ADDED] a new slider method: SetSlideType(slidetype) -[ADDED] a new slider button method: MoveToY(y) - -[REMOVED] slider method: SetButtonYCenter(y) -[REMOVED] slider method: GetButtonYCenter() - -[FIXED] the column list row object not setting it's text's font to it's font -[FIXED] a small graient error in the default skins -[FIXED] an error that caused tab buttons to be overscrolled with the middle mouse button -[FIXED] the scroll area object not moving it's base parent to the top when clicked (only in situatuions where it'sbase parent was a frame) - -[CHANGED] sliders no longer use ycenter for button positioning -[CHANGED] slider functionality, sliders can now be horizontal or vertical (use slider:SetSlideType("horizontal" or "vertical")) -[CHANGED] lots of code for optimization and general cleanliness -[CHANGED] a few minor things in the default skins -[CHANGED] scrollbar hover behavior when being moved via it's scroll area being clicked (will no longer auto hover when it reaches the mouse position) - -================================================ -Version 0.9.1.6 - Alpha (May 17 - 2012) -================================================ -[ADDED] a new column list method: Clear() -[ADDED] a new column list method: SetAutoScroll(bool) -[ADDED] "autoscroll" property for the column list object -[ADDED] a new column list area method: Clear() -[ADDED] a new skin function: DrawOverTextInput() - -[FIXED] not being able to move the column list object's scrollbar by clicking on it's scroll area -[FIXED] column list rows color indexs becoming disorderd when the list was sorted via a column list header - -[CHANGED] a few minor things in the default skins - -================================================ -Version 0.9.1.5 - Alpha (May 16 - 2012) -================================================ -[FIXED] a bug that caused scrollbars to always autoscroll - -================================================ -Version 0.9.1.4 - Alpha (May 16 - 2012) -================================================ -[FIXED] list:SetAutoScroll() not working - -================================================ -Version 0.9.1.3 - Alpha (May 14 - 2012) -================================================ -[ADDED] modal system for frames -[ADDED] a new frame method: SetModal(bool) -[ADDED] a new frame method: GetModal() -[ADDED] a new frame method: SetVisible(bool) - this override is part of a frame bug fix -[ADDED] "showclose" property for the frame object -[ADDED] a new internal object: modal background -[ADDED] a new base method: IsActive() -[ADDED] a new base method: CenterX() -[ADDED] a new base method: CenterY() -[ADDED] a new skin function: DrawOverColumList() - -[FIXED] a bug that made the frame's close button become visisble when the frame was made visible and show close button was set to false - -================================================ -Version 0.9.1.2 - Alpha (May 12 - 2012) -================================================ -[ADDED] a system for preventing objects from being hovered over when another object is being pressed or is "down" -[ADDED] "down" property for the checkbox object -[ADDED] "down" property for the collapsible category object -[ADDED] a new method for the tabs object: SetToolTipFont(font) - -[FIXED] list:GetScrollBar() crashing when the list had no scroll bar -[FIXED] not being able to move the text input blinker to the front or end of the it's text by clicking on it's whitespace -[FIXED] the multichoice row object being "down" when mouse buttons other than the left mouse button were pressed - -[CHANGED] collapsible category opening and closing system (will now only open or close when "down") - -================================================ -Version 0.9.1 - Alpha (May 8 - 2012) -================================================ -[ADDED] a new object: image button -[ADDED] a new skin: Orange -[ADDED] a new column list row method: SetTextPos(x, y) -[ADDED] a new column list row method: SetFont(font) -[ADDED] a new column list row method: GetFont() -[ADDED] a new column list row method: GetColorIndex() -[ADDED] a new column list row method: SetTextColor(color) -[ADDED] a new debug function: SkinSelector() -[ADDED] license.txt -[ADDED] changelog.txt - -[CHANGED] the name of the default skin to Blue -[CHANGED] the drawing system of the image object, the image object will now draw it's image from it's skin function instead of it's internal drawing function -[CHANGED] argument type for adding an image to a tab in tabs:AddTab(), the image argument can now be either an image object or a string containg the path to an image -[CHANGED] the look of the debug overlay -[CHANGED] some of the code within the default skins to improve performance (as suggested by kikito) - -[REMOVED] license.html -[REMOVED] loveframes.graphics and graphics.lua - -================================================ -Version 0.9 - Alpha (May 5 - 2012) -================================================ +================================================ +Version 0.9.5 - Alpha (February 11 - 2013) +================================================ +[ADDED] state system +[ADDED] a new base method: SetState(name) +[ADDED] a new base method: GetState() +[ADDED] a new list method: EnableHorizontalStacking(bool) +[ADDED] a new list method: GetHorizontalStacking() +[ADDED] a new list method: SetDTScrolling(bool) +[ADDED] a new list method: GetDTScrolling() +[ADDED] a new image method: GetImageSize() +[ADDED] a new image method: GetImageWidth() +[ADDED] a new image method: GetImageHeight() +[ADDED] a new imagebutton method: GetImageSize() +[ADDED] a new imagebutton method: GetImageWidth() +[ADDED] a new imagebutton method: GetImageHeight() +[ADDED] a new tabs method: RemoveTab(id) +[ADDED] a new tabs method: SetButtonScrollAmount(amount) +[ADDED] a new tabs method: GetButtonScrollAmount() +[ADDED] a new tabs method: SetMouseWheelScrollAmount(amount) +[ADDED] a new tabs method: GetMouseWheelScrollAmount() +[ADDED] a new tabs method: SetDTScrolling(bool) +[ADDED] a new tabs method: GetDTScrolling() +[ADDED] a new columlist method: SetDTScrolling(bool) +[ADDED] a new columlist method: GetDTScrolling() +[ADDED] a new multichoice method: SetDTScrolling(bool) +[ADDED] a new multichoice method: GetDTScrolling() +[ADDED] a new base library function: loveframes.SetState(name) +[ADDED] a new base library function: loveframes.GetState() +[ADDED] a new object: numberbox +[ADDED] support for horizontal stacking of list object items when the list object's display mode is set to vertical + +[FIXED] an error that would occur when providing a number as the text argument for textinput:SetText(text) +[FIXED] default skin images becoming distorted at certain positions on the screen +[FIXED] being able to clear a textinput's text by pressing an unusable key while all of the object's text was selected +[FIXED] several typos in the changelog + +[CHANGED] the SetColor method for the image object now checks for four arguments (r, g, b, a) instead of one (table) +[CHANGED] major code cleanup for the default skins +[CHANGED] list:RemoveItem now accepts either an object or a number as an argument +[CHANGED] miscellaneous changes/improvements to various sections of code +[CHANGED] the images of the default skins + +================================================ +Version 0.9.4.15 - Alpha (January 5 - 2013) +================================================ +[ADDED] a new base method: GetInternals() +[ADDED] a new tooltip method: SetFollowObject(bool) + +================================================ +Version 0.9.4.14 - Alpha (January 4 - 2013) +================================================ +[ADDED] a new util library function: loveframes.util.CheckForUpdates() (note: this function is meant to be used by the developer and is never called internally by Love Frames) +[ADDED] a new callback for the tabbutton object: OnOpened(object) +[ADDED] a new callback for the tabbutton object: OnClosed(object) + +[CHANGED] tabs:AddTab(name, object, tip, image) now accepts two new optional arguments for tabbutton callbacks (ex: tabs:AddTab(name, object, tip, image, onopened, onclosed)) + +================================================ +Version 0.9.4.13 - Alpha (January 4 - 2013) +================================================ +[ADDED] a new base method: IsInList() + +[FIXED] not being able to add the boolean "false" to a template as a property with loveframes.templates.AddProperty(templatename, object, property, value) + +[CHANGED] small code cleanup +[CHANGED] improved performance of the text object while parented within a list object + +================================================ +Version 0.9.4.12 - Alpha (December 30 - 2012) +================================================ +[CHANGED] newlines created on the text object with \n now display properly +[CHANGED] Love Frames now resets the current drawing color to the last color used before calling loveframes.draw() after it has finished all drawing operations + +================================================ +Version 0.9.4.11 - Alpha (December 28 - 2012) +================================================ +[ADDED] a new textinput method: SetAutoScroll(bool) +[ADDED] a new textinput method: GetAutoScroll() + +[FIXED] a couple of typos in the changelog +[FIXED] a sliderbutton calculation error that caused the sliderbutton object to flash while moving the cursor out of it's bounding box while it was down + +[CHANGED] cleaned up a lot of code +[CHANGED] the text object's shadow color now defaults to black + +================================================ +Version 0.9.4.10 - Alpha (December 26 - 2012) +================================================ +[FIXED] registration errors for the new default skins + +================================================ +Version 0.9.4.9 - Alpha (December 26 - 2012) +================================================ +[ADDED] a new default skin: Blue (basic) +[ADDED] a new default skin: Orange (basic) +[ADDED] a new skins library function: loveframes.skins.GetAvailable() + +[CHANGED] the license from CC BY-SA 3.0 to CC BY 3.0 +[CHANGED] made minor improvements to the default skins + +================================================ +Version 0.9.4.8 - Alpha (December 24 - 2012) +================================================ +[ADDED] a new text method: SetShadow(bool) +[ADDED] a new text method: GetShadow() +[ADDED] a new text method: SetShadowOffsets(offsetx, offsety) +[ADDED] a new text method: GetShadowOffsets() +[ADDED] a new text method: SetShadowColor(r, g, b, a) +[ADDED] a new text method: GetShadowColor() +[ADDED] a new columnlist method: SetColumnHeight(height) + +[FIXED] templates not being applied to objects + +[CHANGED] the columnlistarea object now has better sorting +[CHANGED] the frame object no longer sets the size of it's close button + +================================================ +Version 0.9.4.7 - Alpha (December 19 - 2012) +================================================ +[FIXED] textinput:SetFocus(focus) not working properly + +[CHANGED] the tooltip object is now positionable via the standard positioning methods when not set to follow the cursor + +================================================ +Version 0.9.4.6 - Alpha (December 10 - 2012) +================================================ +[ADDED] a new textinput event callback: OnFocusGained(object) +[ADDED] a new textinput event callback: OnFocusLost(object) + +[FIXED] the textinput object accepting input from the tab and delete keys when object.editable was set to false + +[CHANGED] all "." are now replaced with "/" in loveframes.config["DIRECTORY"] after all inernal Love Frames libraries have been loaded (this is to prevent filesystem errors) + +[REMOVED] loveframes.util.TrimString(string) + +================================================ +Version 0.9.4.5 - Alpha (November 28 - 2012) +================================================ +[FIXED] text inputs not losing focus in certain situations + +================================================ +Version 0.9.4.4 - Alpha (November 24 - 2012) +================================================ +[ADDED] a new text input method: SetButtonScrollAmount(amount) +[ADDED] a new text input method: GetButtonScrollAmount() +[ADDED] a new text input method: SetMouseWheelScrollAmount(amount) +[ADDED] a new text input method: GetMouseWheelScrollAmount() +[ADDED] a new multichoice method: SetButtonScrollAmount(amount) +[ADDED] a new multichoice method: GetButtonScrollAmount() +[ADDED] a new multichoice method: SetMouseWheelScrollAmount(amount) +[ADDED] a new multichoice method: GetMouseWheelScrollAmount() +[ADDED] a new column list method: SetButtonScrollAmount(amount) +[ADDED] a new column list method: GetButtonScrollAmount() +[ADDED] a new column list method: SetMouseWheelScrollAmount(amount) +[ADDED] a new column list method: GetMouseWheelScrollAmount() +[ADDED] a new frame method: SetParentLocked(bool) +[ADDED] a new frame method: GetParentLocked() +[ADDED] a new base method: CenterWithinArea(x, y, width, height) +[ADDED] a new library function: loveframes.NewObject(id, name, inherit_from_base) + +[FIXED] an error that would occur when clicking a scroll button on a multiline text input or a multichoice list +[FIXED] a button calculation error that caused the button object to flash while moving the cursor out of it's bounding box while it was down +[FIXED] several errors that could occur when a collapsible category did not have an object +[FIXED] the value of the slider object becoming -0 in certain situations + +[CHANGED] the close button object is no longer positioned internally by the frame object and should now be positioned by it's skin drawing function +[CHANGED] all Love Frames objects are now stored within loveframes.objects +[CHANGED] frames are now draggable when parented to any object +[CHANGED] the look of the debug overlay + +================================================ +Version 0.9.4.3 - Alpha (November 20 - 2012) +================================================ +[ADDED] a new base method: SetProperty(name, value) +[ADDED] a new base method: GetProperty(name) +[ADDED] a new list method: SetButtonScrollAmount(amount) +[ADDED] a new list method: GetButtonScrollAmount() +[ADDED] a new list method: SetMouseWheelScrollAmount(amount) +[ADDED] a new list method: GetMouseWheelScrollAmount() + +[FIXED] a typo in the changelog +[FIXED] image:SetScale(scalex, scaley) not working correctly + +[CHANGED] loveframes.util.GetDirContents(dir, t) to loveframes.util.GetDirectoryContents(dir, t) +[CHANGED] arguments passed to require() to use "." instead of "/" which should fix file loading issues on certain systems + +================================================ +Version 0.9.4.2 - Alpha (November 5 - 2012) +================================================ +[ADDED] a new text object method: SetIgnoreNewlines(bool) +[ADDED] a new text object method: GetIgnoreNewlines() +[ADDED] a new text image method: SetOrientation(orientation) +[ADDED] a new text image method: GetOrientation() +[ADDED] a new text image method: SetScaleX(scalex) +[ADDED] a new text image method: GetScaleX() +[ADDED] a new text image method: SetScaleY(scaley) +[ADDED] a new text image method: GetScaleY() +[ADDED] a new text image method: SetScale(scalex, scaley) +[ADDED] a new text image method: GetScale() +[ADDED] a new text image method: SetOffsetX(x) +[ADDED] a new text image method: GetOffsetX() +[ADDED] a new text image method: SetOffsetY(y) +[ADDED] a new text image method: GetOffsetY() +[ADDED] a new text image method: SetOffset(x, y) +[ADDED] a new text image method: GetOffset() +[ADDED] a new text image method: SetShearX(x) +[ADDED] a new text image method: GetShearX() +[ADDED] a new text image method: SetShearY(y) +[ADDED] a new text image method: GetShearY() +[ADDED] a new text image method: SetShear(x, y) +[ADDED] a new text image method: GetShear() + +[FIXED] an error that occurred after pressing enter on a multiline text input while all of it's text was selected +[FIXED] text in a single line text input always being cleared when the enter key was pressed +[FIXED] a syntax error in both default skin files that caused imaged to draw incorrect when they had a custom color +[FIXED] an error that would occur when a tab button was being drawn while no font had been set +[FIXED] textinput.OnTextChanged being called too early when using the backspace key or the delete key + +[CHANGED] tab buttons no longer calculate their width from within their internal drawing function and should be sized externally from now on +[CHANGED] the text object now calculates what characters should be drawn while in a list object to improve performance with list objects that contain large amounts of text + +================================================ +Version 0.9.4.1 - Alpha (October 25 - 2012) +================================================ +[ADDED] support for using the delete key in text input objects + +[FIXED] textinupt:GetText() only returning the first line of a multiline text input +[FIXED] an error that occurred when clicking a multiline text input object after setting the object's text to an empty string with textinput:SetText("") +[FIXED] incorrect positioning of the text input object's indicator when using the left or right arrow keys to move the object's indicator to a different line +[FIXED] the text input object not creating a new line correctly in certain situations + +[CHANGED] textinput:GetText() now returns the object's text with line breaks + +================================================ +Version 0.9.4 - Alpha (October 22 - 2012) +================================================ +[ADDED] a new base method: SetDrawOrder() +[ADDED] a new base method: GetDrawOrder() +[ADDED] a new text method: GetFormattedText() +[ADDED] a new text input method: SetEditable(bool) +[ADDED] a new text input method: GetEditable() +[ADDED] a new text input method: GetUsable() +[ADDED] a new text input method: GetUnusable() +[ADDED] a new system for creating and applying templates to objects + +[FIXED] a few incorrect entries in the changelog and added a few entries that were meant to be in the last upadte's changelog +[FIXED] an error that occurred when clicking on a frame that was parented to another frame +[FIXED] frames not being positioned properly if they were parented to another object +[FIXED] modal background object not drawing over umodaled objects in certain situations +[FIXED] an error that would occur when a multichoice list object would become scrollable +[FIXED] an error that would occur when a the column list object had no columns +[FIXED] multichoice object not positioning itself properly if it's parent was the base object + +[CHANGED] text:GetText() now returns a string of the object's text +[CHANGED] parented frames can no longer be modaled + +================================================ +Version 0.9.3.2 - Alpha (Spetember 29 - 2012) +================================================ +[ADDED] a new base method: SetDrawOrder() +[ADDED] a new text input method: SetMultiline(bool) +[ADDED] a new text input method: GetVerticalScrollBody() +[ADDED] a new text input method: GetHorizontalScrollBody() +[ADDED] a new text input method: SetText(text) +[ADDED] a new text input method: HasVerticalScrollBar() +[ADDED] a new text input method: HasHorizontalScrollBar() +[ADDED] a new text input method: GetFont() +[ADDED] a new text input method: GetLineNumbersPanel() +[ADDED] a new text input method: GetMultiline() +[ADDED] a new text input method: GetTextX() +[ADDED] a new text input method: GetTextY() +[ADDED] a new text input method: IsAllTextSelected() +[ADDED] a new text input method: GetLines() +[ADDED] a new text input method: GetOffsetX() +[ADDED] a new text input method: GetOffsetY() +[ADDED] a new text input method: GetIndicatorX() +[ADDED] a new text input method: GetIndicatorY() +[ADDED] a new text input method: SetLineNumbersEnabled(enabled) +[ADDED] a new text input method: GetLineNumbersEnabled() +[ADDED] a new text input method: GetItemWidth() +[ADDED] a new text input method: GetItemHeight() +[ADDED] a new text input method: SetTabReplacement(tabreplacement) +[ADDED] a new text input method: GetTabReplacement() +[ADDED] a new scroll area method: GetBarType() +[ADDED] a new scroll bar method: IsDragging() +[ADDED] a new scroll bar method: GetBarType() +[ADDED] a new scroll button method: GetScrollType() +[ADDED] a new tab button method: GetText() +[ADDED] a new tab button method: GetImage() +[ADDED] a new tab button method: GetTabNumber() +[ADDED] a new column list header method: GetName() +[ADDED] a new column list row method: GetColumnData() +[ADDED] a new multichoice method: SetText(text) +[ADDED] a new multichoice method: GetText() +[ADDED] a new multichoice row method: GetText() +[ADDED] a new progressbar method: GetBarWidth() +[ADDED] a new internal object: linenumberspanel +[ADDED] multiline support for the text input object +[ADDED] ability to select all text within a text input + +[FIXED] progressbar object not positioning itself properly if it's parent was the base object +[FIXED] a typo in the syntax of loveframes.util.SplitString (was "SplitSring", changed to "SplitString") +[FIXED] the tooltip object not disappearing if it was visible when it's object's visibility was changed to false +[FIXED] the text input object's x offset not being adjusted initially when the width of it's text would would become wider than it's drawing area + +[CHANGED] massive code cleanup for optimization and +[CHANGED] frames can now be parent to other objects +[CHANGED] textinput:RunBlink() to textinput:UpdateIndicator() +[CHANGED] textinput:GetBlinkerVisisbility() to textinput:GetIndicatorVisisbility() +[CHANGED] textinput:MoveBlinker(num, exact) to textinput:MoveIndicator(num, exact) +[CHANGED] scrollbars now only autoscroll when their list's item width/height is greater than their previous list's previous item width/height +[CHANGED] cleaned up the code for the default skins +[CHANGED] the text input object's text is no longer drawn internally by the object and should now be draw within the object's skin drawing function +[CHANGED] the column list row object's text is no longer drawn internally by the object and should now be draw within the object's skin drawing function + +[REMOVED] textinput:SetTextColor(color) +[REMOVED] columnlistrow:SetTextColor() + +================================================ +Version 0.9.3.1 - Alpha (Spetember 2 - 2012) +================================================ +[ADDED] numpad enter key support for textinput.OnEnter + +[FIXED] duplicate progressbar:GetCompleted() in progressbar.lua + +[CHANGED] textinput.OnTextEnterd to textinput.OnTextChanged +[CHANGED] textinput.OnTextChanged is now also called when the backspace key is pressed + +================================================ +Version 0.9.3 - Alpha (Spetember 1 - 2012) +================================================ +[ADDED] a new base method: GetParents() +[ADDED] a new base method: IsTopInternal() +[ADDED] a new base method: IsInternal() +[ADDED] a new base method: GetType() +[ADDED] a new checkbox method: GetFont() +[ADDED] a new checkbox method: GetBoxSize() +[ADDED] a new checkbox method: GetBoxWidth() +[ADDED] a new checkbox method: GetBoxHeight() +[ADDED] a new image method: GetImage() +[ADDED] a new image method: GetColor() +[ADDED] a new progressbar method: GetCompleted() +[ADDED] a new tabs method: GetTabNumber() +[ADDED] a new text method: GetLines() +[ADDED] a new text input method: SetLimit(limit) +[ADDED] a new text input method: SetUsable(usable) +[ADDED] a new text input method: SetUnusable(unusable) +[ADDED] a new text input method: Clear() +[ADDED] a new text input method: GetText() +[ADDED] support for line breaks in the text object (please refer to the wiki on how to format your text with line breaks) +[ADDED] more information to the debug overlay + +[FIXED] tooltips and multichoice lists not functioning properly when a frame was modaled +[FIXED] the text object not moving it's base parent to the top when clicked if it's base parent was a frame +[FIXED] the list object not scrolling via the mouse wheel due to certain collision detection issues +[FIXED] tooltips flickering when in a hover state +[FIXED] slider calculation errors +[FIXED] skin.DrawRepeatingImage creating a new image every frame +[FIXED] checkbox text not scrolling properly when in a list +[FIXED] the collapsible category's object not scrolling properly when in a list +[FIXED] skins not assuming the drawing functions of the default skins if drawing functions in the active skin were missing +[FIXED] some objects not being removed +[FIXED] sliders not scrolling properly when in a list + +[CHANGED] various code for a small cleanup +[CHANGED] tooltips from being children of the base object to internals of the base object +[CHANGED] tooltips from never being removed to being removed when their assigned object is removed +[CHANGED] tooltips are now not able to be assigned to the base object (this would cause an error due to the way the tooltip currently functions) +[CHANGED] the text object now positions it's text when SetText is called instead of positioning it's text every frame +[CHANGED] slider:SetMax(max), slider:SetMin(min) and slider:SetMinMax(min, max) now adjust the slider's value if the slider's value is out of the range specified +[CHANGED] loveframes.Create(data, parent) now activates an error screen if the object specified is invalid + +================================================ +Version 0.9.2.5 - Alpha (June 1 - 2012) +================================================ +[FIXED] the text object not drawing numbers in certain situations +[FIXED] a typo in the changelog + +================================================ +Version 0.9.2.4 - Alpha (May 29 - 2012) +================================================ +[FIXED] the SetSkin(skin) method causing a stack overflow + +================================================ +Version 0.9.2.3 - Alpha (May 27 - 2012) +================================================ +[FIXED] imagebutton.OnClick not working +[FIXED] text being added into the text input object at incorrect positions when the value of textinput.blinknum was 0 +[FIXED] a bug that would cause an error when running SetVisible on a frame object when the value of frame.showclose was true + +================================================ +Version 0.9.2.2 - Alpha (May 23 - 2012) +================================================ +[FIXED] vertical slider value direction (top is now max value and bottom is 0) +[FIXED] text flashing in the text input object when moving the text blinker to the right +[FIXED] text blinker in the text input object not appearing in certain situations + +================================================ +Version 0.9.2 - Alpha (May 22 - 2012) +================================================ +[ADDED] a new slider method: SetButtonSize(width, height) +[ADDED] a new slider method: GetButtonSize() +[ADDED] a new slider method: SetSlideType(slidetype) +[ADDED] a new slider button method: MoveToY(y) + +[REMOVED] slider method: SetButtonYCenter(y) +[REMOVED] slider method: GetButtonYCenter() + +[FIXED] the column list row object not setting it's text's font to it's font +[FIXED] a small gradient error in the default skins +[FIXED] an error that caused tab buttons to be over-scrolled with the middle mouse button +[FIXED] the scroll area object not moving it's base parent to the top when clicked (only in situations where it's base parent was a frame) + +[CHANGED] sliders no longer use ycenter for button positioning +[CHANGED] slider functionality, sliders can now be horizontal or vertical (use slider:SetSlideType("horizontal" or "vertical")) +[CHANGED] lots of code for optimization and general cleanliness +[CHANGED] a few minor things in the default skins +[CHANGED] scrollbar hover behavior when being moved via it's scroll area being clicked (will no longer auto hover when it reaches the mouse position) + +================================================ +Version 0.9.1.6 - Alpha (May 17 - 2012) +================================================ +[ADDED] a new column list method: Clear() +[ADDED] a new column list method: SetAutoScroll(bool) +[ADDED] "autoscroll" property for the column list object +[ADDED] a new column list area method: Clear() +[ADDED] a new skin function: DrawOverTextInput() + +[FIXED] not being able to move the column list object's scrollbar by clicking on it's scroll area +[FIXED] column list rows color indexes becoming disordered when the list was sorted via a column list header + +[CHANGED] a few minor things in the default skins + +================================================ +Version 0.9.1.5 - Alpha (May 16 - 2012) +================================================ +[FIXED] a bug that caused scrollbars to always autoscroll + +================================================ +Version 0.9.1.4 - Alpha (May 16 - 2012) +================================================ +[FIXED] list:SetAutoScroll() not working + +================================================ +Version 0.9.1.3 - Alpha (May 14 - 2012) +================================================ +[ADDED] modal system for frames +[ADDED] a new frame method: SetModal(bool) +[ADDED] a new frame method: GetModal() +[ADDED] a new frame method: SetVisible(bool) - this override is part of a frame bug fix +[ADDED] "showclose" property for the frame object +[ADDED] a new internal object: modal background +[ADDED] a new base method: IsActive() +[ADDED] a new base method: CenterX() +[ADDED] a new base method: CenterY() +[ADDED] a new skin function: DrawOverColumList() + +[FIXED] a bug that made the frame's close button become visible when the frame was made visible and show close button was set to false + +================================================ +Version 0.9.1.2 - Alpha (May 12 - 2012) +================================================ +[ADDED] a system for preventing objects from being hovered over when another object is being pressed or is "down" +[ADDED] "down" property for the checkbox object +[ADDED] "down" property for the collapsible category object +[ADDED] a new method for the tabs object: SetToolTipFont(font) + +[FIXED] list:GetScrollBar() crashing when the list had no scroll bar +[FIXED] not being able to move the text input blinker to the front or end of the it's text by clicking on it's whitespace +[FIXED] the multichoice row object being "down" when mouse buttons other than the left mouse button were pressed + +[CHANGED] collapsible category opening and closing system (will now only open or close when "down") + +================================================ +Version 0.9.1 - Alpha (May 8 - 2012) +================================================ +[ADDED] a new object: image button +[ADDED] a new skin: Orange +[ADDED] a new column list row method: SetTextPos(x, y) +[ADDED] a new column list row method: SetFont(font) +[ADDED] a new column list row method: GetFont() +[ADDED] a new column list row method: GetColorIndex() +[ADDED] a new column list row method: SetTextColor(color) +[ADDED] a new debug function: SkinSelector() +[ADDED] license.txt +[ADDED] changelog.txt + +[CHANGED] the name of the default skin to Blue +[CHANGED] the drawing system of the image object, the image object will now draw it's image from it's skin function instead of it's internal drawing function +[CHANGED] argument type for adding an image to a tab in tabs:AddTab(), the image argument can now be either an image object or a string containg the path to an image +[CHANGED] the look of the debug overlay +[CHANGED] some of the code within the default skins to improve performance (as suggested by kikito) + +[REMOVED] license.html +[REMOVED] loveframes.graphics and graphics.lua + +================================================ +Version 0.9 - Alpha (May 5 - 2012) +================================================ Initial commit \ No newline at end of file diff --git a/debug.lua b/debug.lua index 13ee880..11963a5 100644 --- a/debug.lua +++ b/debug.lua @@ -1,769 +1,823 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- debug library -loveframes.debug = {} - -local font = loveframes.basicfontsmall -local centerarea = {210, 5, 585, 590} -local loremipsum = -[[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean laoreet massa mattis tortor faucibus non congue mauris mattis. Aliquam ultricies scelerisque mi, sit amet tempor metus pharetra vel. Etiam eu arcu a dolor porttitor condimentum in malesuada urna. Mauris vel nulla mi, quis aliquet neque. In aliquet turpis eget purus malesuada tincidunt. Donec rutrum purus vel diam suscipit vehicula. Cras sem nibh, tempus at dictum non, consequat non justo. In sed tellus nec orci scelerisque scelerisque id vitae leo. Maecenas pharetra, nibh eget commodo gravida, augue nisl blandit dui, ut malesuada augue dui nec erat. Phasellus nec mauris pharetra metus iaculis viverra sit amet ut tortor. Duis et viverra magna. Nunc orci dolor, placerat a iaculis non, mattis sed nibh. - - Mauris ac erat sit amet ante condimentum scelerisque. Cras eleifend lorem dictum mi euismod non placerat lorem gravida. Vestibulum sodales dapibus eros, non iaculis risus commodo eu. Maecenas dapibus purus accumsan metus euismod suscipit. Etiam eleifend lorem eget quam ornare interdum sed at nulla. Suspendisse viverra sapien ut felis viverra pellentesque. Ut convallis hendrerit est, in imperdiet purus placerat ut. Curabitur sapien nibh, molestie et elementum a, sagittis et tortor. Vestibulum sed quam eu velit euismod rutrum vitae et sem. Morbi accumsan quam vitae sapien scelerisque tincidunt. Nulla ipsum leo, scelerisque at consequat sit amet, venenatis eget mauris. Aliquam at nibh vel lorem hendrerit dignissim. Cras et risus sit amet est vehicula auctor at a leo. Curabitur euismod mi sit amet nunc consequat sed fringilla justo sagittis. - - Nulla ut arcu felis, a laoreet tellus. Vivamus ligula nibh, bibendum ut ultrices sed, ullamcorper et est. Pellentesque nisi diam, sollicitudin lacinia fermentum quis, aliquam fermentum elit. Donec egestas vestibulum mollis. Vivamus sollicitudin nisl vestibulum nisi fermentum scelerisque. Nunc enim magna, posuere ornare faucibus a, bibendum vestibulum felis. Etiam laoreet molestie elit, vitae ultrices sem faucibus in. Fusce rutrum convallis lacus, vitae scelerisque eros tincidunt sed. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. - - Quisque ornare arcu sed enim sodales dictum. Suspendisse at convallis mi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas et nibh odio, eu lacinia lacus. Mauris at pulvinar urna. Pellentesque vel justo erat, a congue nibh. Nunc tristique mattis euismod. Suspendisse potenti. - - Sed dictum faucibus cursus. Integer nisi ipsum, dapibus vel blandit laoreet, bibendum congue massa. Vestibulum tincidunt vulputate nunc, facilisis consequat lacus posuere at. Aenean sed mollis urna. Vivamus congue neque non arcu malesuada lobortis. Curabitur suscipit pretium massa eu rutrum. Nulla vehicula imperdiet dui in blandit. Curabitur vitae felis ut massa scelerisque consequat. Nulla a magna quis risus consequat hendrerit. Maecenas quis lacus sit amet ipsum condimentum interdum. Proin condimentum erat id enim elementum ut tincidunt neque vulputate. -]] - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws debug information ---]]--------------------------------------------------------- -function loveframes.debug.draw() - - -- get the current debug setting - local debug = loveframes.config["DEBUG"] - - -- do not draw anthing if debug is off - if not debug then - return - end - - local cols = loveframes.util.GetCollisions() - local topcol = {type = none, children = {}, x = 0, y = 0, width = 0, height = 0} - local objects = loveframes.util.GetAllObjects() - local author = loveframes.info.author - local version = loveframes.info.version - local stage = loveframes.info.stage - local basedir = loveframes.config["DIRECTORY"] - local loveversion = love._version - local fps = love.timer.getFPS() - local deltatime = love.timer.getDelta() - - -- set the top most collision object - for k, v in ipairs(cols) do - if v:IsTopCollision() then - topcol = v - break - end - end - - -- main font - love.graphics.setFont(font) - - -- main box - love.graphics.setColor(0, 0, 0, 200) - love.graphics.rectangle("fill", 5, 30, 200, 220) - - ------------------------------------------------------- - -- library information section - ------------------------------------------------------- - love.graphics.setColor(255, 0, 0, 255) - love.graphics.print("Library Information", 10, 35) - - love.graphics.setColor(255, 255, 255, 255) - love.graphics.print("Author: " ..author, 15, 50) - love.graphics.print("Version: " ..version, 15, 60) - love.graphics.print("Stage: " ..stage, 15, 70) - love.graphics.print("Base Directory: " ..basedir, 15, 80) - - ------------------------------------------------------- - -- object information section - ------------------------------------------------------- - love.graphics.setColor(255, 0, 0, 255) - love.graphics.print("Object Information", 10, 95) - - love.graphics.setColor(255, 255, 255, 255) - - if #cols > 0 then - love.graphics.print("Type: " ..topcol.type, 15, 110) - else - love.graphics.print("Type: none", 10, 120) - end - - if topcol.children then - love.graphics.print("# of children: " .. #topcol.children, 15, 120) - else - love.graphics.print("# of children: 0", 15, 120) - end - - if topcol.internals then - love.graphics.print("# of internals: " .. #topcol.internals, 15, 130) - else - love.graphics.print("# of internals: 0", 15, 130) - end - - love.graphics.print("X: " ..topcol.x, 15, 140) - love.graphics.print("Y: " ..topcol.y, 15, 150) - love.graphics.print("Width: " ..topcol.width, 15, 160) - love.graphics.print("Height: " ..topcol.height, 15, 170) - - ------------------------------------------------------- - -- miscellaneous section - ------------------------------------------------------- - love.graphics.setColor(255, 0, 0, 255) - love.graphics.print("Miscellaneous", 10, 185) - - love.graphics.setColor(255, 255, 255, 255) - love.graphics.print("LOVE Version: " ..loveversion, 15, 200) - love.graphics.print("FPS: " ..fps, 15, 210) - love.graphics.print("Delta Time: " ..deltatime, 15, 220) - love.graphics.print("Total Objects: " ..#objects, 15, 230) - - -- outline the object that the mouse is hovering over - love.graphics.setColor(255, 204, 51, 255) - love.graphics.setLine(2, "smooth") - love.graphics.rectangle("line", topcol.x - 1, topcol.y - 1, topcol.width + 2, topcol.height + 2) - -end - ---[[--------------------------------------------------------- - - func: ExamplesMenu() - - desc: generates a list of examples of Love Frames - objects ---]]--------------------------------------------------------- -function loveframes.debug.ExamplesMenu() - - ------------------------------------ - -- examples frame - ------------------------------------ - local examplesframe = loveframes.Create("frame") - examplesframe:SetName("Examples List") - examplesframe:SetSize(200, love.graphics.getHeight() - 325) - examplesframe:SetPos(5, 320) - - ------------------------------------ - -- examples list - ------------------------------------ - local exampleslist = loveframes.Create("list", examplesframe) - exampleslist:SetSize(200, exampleslist:GetParent():GetHeight() - 25) - exampleslist:SetPos(0, 25) - exampleslist:SetPadding(5) - exampleslist:SetSpacing(5) - exampleslist:SetDisplayType("vertical") - - ------------------------------------ - -- button example - ------------------------------------ - local buttonexample = loveframes.Create("button") - buttonexample:SetText("Button") - buttonexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Button") - frame1:CenterWithinArea(unpack(centerarea)) - - local button1 = loveframes.Create("button", frame1) - button1:SetWidth(200) - button1:SetText("Button") - button1:Center() - button1.OnClick = function(object2, x, y) - object2:SetText("You clicked the button!") - end - button1.OnMouseEnter = function(object2) - object2:SetText("The mouse entered the button.") - end - button1.OnMouseExit = function(object2) - object2:SetText("The mouse exited the button.") - end - - end - exampleslist:AddItem(buttonexample) - - ------------------------------------ - -- checkbox example - ------------------------------------ - local checkboxexample = loveframes.Create("button") - checkboxexample:SetText("Checkbox") - checkboxexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Checkbox") - frame1:CenterWithinArea(unpack(centerarea)) - frame1:SetHeight(85) - - local checkbox1 = loveframes.Create("checkbox", frame1) - checkbox1:SetText("Checkbox 1") - checkbox1:SetPos(5, 30) - checkbox1.OnChanged = function(object2) - end - - local checkbox2 = loveframes.Create("checkbox", frame1) - checkbox2:SetText("Checkbox 2") - checkbox2:SetPos(5, 60) - checkbox2.OnChanged = function(object3) - end - - end - exampleslist:AddItem(checkboxexample) - - ------------------------------------ - -- collapsible category example - ------------------------------------ - local collapsiblecategoryexample = loveframes.Create("button") - collapsiblecategoryexample:SetText("Collapsible Category") - collapsiblecategoryexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Collapsible Category") - frame1:SetSize(500, 300) - frame1:CenterWithinArea(unpack(centerarea)) - - local panel1 = loveframes.Create("panel") - panel1:SetHeight(230) - - local collapsiblecategory1 = loveframes.Create("collapsiblecategory", frame1) - collapsiblecategory1:SetPos(5, 30) - collapsiblecategory1:SetSize(490, 265) - collapsiblecategory1:SetText("Category 1") - collapsiblecategory1:SetObject(panel1) - - end - exampleslist:AddItem(collapsiblecategoryexample) - - ------------------------------------ - -- cloumnlist example - ------------------------------------ - local cloumnlistexample = loveframes.Create("button") - cloumnlistexample:SetText("Column List") - cloumnlistexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Column List") - frame1:SetSize(500, 300) - frame1:CenterWithinArea(unpack(centerarea)) - - local list1 = loveframes.Create("columnlist", frame1) - list1:SetPos(5, 30) - list1:SetSize(490, 265) - list1:AddColumn("Column 1") - list1:AddColumn("Column 2") - list1:AddColumn("Column 3") - list1:AddColumn("Column 4") - - for i=1, 20 do - list1:AddRow("Row " ..i.. ", column 1", "Row " ..i.. ", column 2", "Row " ..i.. ", column 3", "Row " ..i.. ", column 4") - end - - end - exampleslist:AddItem(cloumnlistexample) - - ------------------------------------ - -- frame example - ------------------------------------ - local frameexample = loveframes.Create("button") - frameexample:SetText("Frame") - frameexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Frame") - frame1:CenterWithinArea(unpack(centerarea)) - - local text1 = loveframes.Create("text", frame1) - text1:SetText("This is an example frame.") - text1.Update = function(object2, dt) - object2:CenterX() - object2:SetY(40) - end - - local button1 = loveframes.Create("button", frame1) - button1:SetText("Modal") - button1:SetWidth(100) - button1:Center() - button1.Update = function(object2, dt) - local modal = object2:GetParent():GetModal() - - if modal == true then - object2:SetText("Remove Modal") - object2.OnClick = function() - object2:GetParent():SetModal(false) - end - else - object2:SetText("Set Modal") - object2.OnClick = function() - object2:GetParent():SetModal(true) - end - end - end - - end - exampleslist:AddItem(frameexample) - - ------------------------------------ - -- image example - ------------------------------------ - local imageexample = loveframes.Create("button") - imageexample:SetText("Image") - imageexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Image") - frame1:SetSize(138, 315) - frame1:CenterWithinArea(unpack(centerarea)) - - local image1 = loveframes.Create("image", frame1) - image1:SetImage("resources/images/carlsagan.png") - image1:SetPos(5, 30) - - local panel1 = loveframes.Create("panel", frame1) - panel1:SetPos(5, 160) - panel1:SetSize(128, 150) - - - local text1 = loveframes.Create("text", panel1) - text1:SetPos(5, 5) - text1:SetText("Orientation: ") - - local slider1 = loveframes.Create("slider", panel1) - slider1:SetPos(5, 20) - slider1:SetWidth(118) - slider1:SetMinMax(0, 360) - slider1:SetDecimals(0) - slider1.OnValueChanged = function(object) - image1:SetOrientation(object:GetValue()) - end - - text1.Update = function(object, dt) - object:SetText("Orientation: " ..slider1:GetValue()) - end - - local text2 = loveframes.Create("text", panel1) - text2:SetPos(5, 40) - text2:SetText("Scale") - - local slider2 = loveframes.Create("slider", panel1) - slider2:SetPos(5, 55) - slider2:SetWidth(118) - slider2:SetMinMax(1, 2) - slider2:SetDecimals(5) - slider2.OnValueChanged = function(object) - image1:SetScale(object:GetValue(), object:GetValue()) - end - - text2.Update = function(object, dt) - object:SetText("Scale: " ..slider2:GetValue()) - end - - local text3 = loveframes.Create("text", panel1) - text3:SetPos(5, 75) - text3:SetText("Offset") - - local slider3 = loveframes.Create("slider", panel1) - slider3:SetPos(5, 90) - slider3:SetWidth(118) - slider3:SetMinMax(1, 50) - slider3:SetDecimals(5) - slider3.OnValueChanged = function(object) - image1:SetOffset(object:GetValue(), object:GetValue()) - end - - text3.Update = function(object, dt) - object:SetText("Offset: " ..slider3:GetValue()) - end - - local text4 = loveframes.Create("text", panel1) - text4:SetPos(5, 110) - text4:SetText("Shear") - - local slider4 = loveframes.Create("slider", panel1) - slider4:SetPos(5, 125) - slider4:SetWidth(118) - slider4:SetMinMax(0, 10) - slider4:SetDecimals(5) - slider4.OnValueChanged = function(object) - image1:SetShear(object:GetValue(), object:GetValue()) - end - - text4.Update = function(object, dt) - object:SetText("Shear: " ..slider4:GetValue()) - end - - end - exampleslist:AddItem(imageexample) - - ------------------------------------ - -- image button example - ------------------------------------ - local imagebuttonexample = loveframes.Create("button") - imagebuttonexample:SetText("Image Button") - imagebuttonexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Image Button") - frame1:SetSize(138, 163) - frame1:CenterWithinArea(unpack(centerarea)) - - local imagebutton1 = loveframes.Create("imagebutton", frame1) - imagebutton1:SetImage("resources/images/carlsagan.png") - imagebutton1:SetPos(5, 30) - imagebutton1:SizeToImage() - - end - exampleslist:AddItem(imagebuttonexample) - - ------------------------------------ - -- list example - ------------------------------------ - local listexample = loveframes.Create("button") - listexample:SetText("List") - listexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("List") - frame1:SetSize(500, 455) - frame1:CenterWithinArea(unpack(centerarea)) - - local list1 = loveframes.Create("list", frame1) - list1:SetPos(5, 30) - list1:SetSize(490, 300) - - local panel1 = loveframes.Create("panel", frame1) - panel1:SetPos(5, 335) - panel1:SetSize(490, 115) - - local slider1 = loveframes.Create("slider", panel1) - slider1:SetPos(5, 20) - slider1:SetWidth(480) - slider1:SetMinMax(0, 100) - slider1:SetText("Padding") - slider1:SetDecimals(0) - slider1.OnValueChanged = function(object2, value) - list1:SetPadding(value) - end - - local text1 = loveframes.Create("text", panel1) - text1:SetPos(5, 5) - text1:SetFont(love.graphics.newFont(10)) - text1:SetText(slider1:GetText()) - - local text2 = loveframes.Create("text", panel1) - text2:SetFont(love.graphics.newFont(10)) - text2.Update = function(object, dt) - object:SetPos(slider1:GetWidth() - object:GetWidth(), 5) - object:SetText(slider1:GetValue()) - end - - local slider2 = loveframes.Create("slider", panel1) - slider2:SetPos(5, 60) - slider2:SetWidth(480) - slider2:SetMinMax(0, 100) - slider2:SetText("Spacing") - slider2:SetDecimals(0) - slider2.OnValueChanged = function(object2, value) - list1:SetSpacing(value) - end - - local text3 = loveframes.Create("text", panel1) - text3:SetPos(5, 45) - text3:SetFont(love.graphics.newFont(10)) - text3:SetText(slider2:GetText()) - - local text4 = loveframes.Create("text", panel1) - text4:SetFont(love.graphics.newFont(10)) - text4.Update = function(object, dt) - object:SetPos(slider2:GetWidth() - object:GetWidth(), 45) - object:SetText(slider2:GetValue()) - end - - local button1 = loveframes.Create("button", panel1) - button1:SetPos(5, 85) - button1:SetSize(480, 25) - button1:SetText("Change List Type") - button1.OnClick = function(object2, x, y) - if list1:GetDisplayType() == "vertical" then - list1:SetDisplayType("horizontal") - else - list1:SetDisplayType("vertical") - end - end - - for i=1, 50 do - local button2 = loveframes.Create("button") - button2:SetText(i) - list1:AddItem(button2) - end - - end - exampleslist:AddItem(listexample) - - ------------------------------------ - -- multichoice example - ------------------------------------ - local multichoiceexample = loveframes.Create("button") - multichoiceexample:SetText("Multichoice") - multichoiceexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Multichoice") - frame1:SetSize(210, 60) - frame1:CenterWithinArea(unpack(centerarea)) - - local multichoice1 = loveframes.Create("multichoice", frame1) - multichoice1:SetPos(5, 30) - - for i=1, 20 do - multichoice1:AddChoice(i) - end - - end - exampleslist:AddItem(multichoiceexample) - - ------------------------------------ - -- panel example - ------------------------------------ - local panelexample = loveframes.Create("button") - panelexample:SetText("Panel") - panelexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Panel") - frame1:SetSize(210, 85) - frame1:CenterWithinArea(unpack(centerarea)) - - local panel1 = loveframes.Create("panel", frame1) - panel1:SetPos(5, 30) - - end - exampleslist:AddItem(panelexample) - - ------------------------------------ - -- progressbar example - ------------------------------------ - local progressbarexample = loveframes.Create("button") - progressbarexample:SetText("Progress Bar") - progressbarexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Progress Bar") - frame1:SetSize(500, 160) - frame1:CenterWithinArea(unpack(centerarea)) - - local progressbar1 = loveframes.Create("progressbar", frame1) - progressbar1:SetPos(5, 30) - progressbar1:SetWidth(490) - progressbar1:SetLerpRate(1) - - local button1 = loveframes.Create("button", frame1) - button1:SetPos(5, 60) - button1:SetWidth(490) - button1:SetText("Change bar value") - button1.OnClick = function(object2, x, y) - progressbar1:SetValue(math.random(progressbar1:GetMin(), progressbar1:GetMax())) - end - - local button2 = loveframes.Create("button", frame1) - button2:SetPos(5, 90) - button2:SetWidth(490) - button2:SetText("Toggle bar lerp") - button2.OnClick = function(object2, x, y) - if progressbar1:GetLerp() == true then - progressbar1:SetLerp(false) - else - progressbar1:SetLerp(true) - end - end - - local slider1 = loveframes.Create("slider", frame1) - slider1:SetPos(5, 135) - slider1:SetWidth(490) - slider1:SetText("Progressbar lerp rate") - slider1:SetMinMax(0, 50) - slider1:SetDecimals(0) - slider1.OnValueChanged = function(object2, value) - progressbar1:SetLerpRate(value) - end - - local text1 = loveframes.Create("text", frame1) - text1:SetPos(5, 120) - text1:SetText("Lerp Rate") - text1:SetFont(love.graphics.newFont(10)) - - local text2 = loveframes.Create("text", frame1) - text2:SetFont(love.graphics.newFont(10)) - text2.Update = function(object, dt) - object:SetPos(slider1:GetWidth() - object:GetWidth(), 120) - object:SetText(slider1:GetValue()) - end - - end - exampleslist:AddItem(progressbarexample) - - ------------------------------------ - -- slider example - ------------------------------------ - local sliderexample = loveframes.Create("button") - sliderexample:SetText("Slider") - sliderexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Slider") - frame1:SetSize(300, 275) - frame1:CenterWithinArea(unpack(centerarea)) - - local slider1 = loveframes.Create("slider", frame1) - slider1:SetPos(5, 30) - slider1:SetWidth(290) - slider1:SetMinMax(0, 100) - - local slider2 = loveframes.Create("slider", frame1) - slider2:SetPos(5, 60) - slider2:SetHeight(200) - slider2:SetMinMax(0, 100) - slider2:SetButtonSize(20, 10) - slider2:SetSlideType("vertical") - slider2.Update = function(object, dt) - object:CenterX() - end - - end - exampleslist:AddItem(sliderexample) - - ------------------------------------ - -- tabs example - ------------------------------------ - local tabsexample = loveframes.Create("button") - tabsexample:SetText("Tabs") - tabsexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Tabs") - frame1:SetSize(500, 300) - frame1:CenterWithinArea(unpack(centerarea)) - - local tabs1 = loveframes.Create("tabs", frame1) - tabs1:SetPos(5, 30) - tabs1:SetSize(490, 265) - - local images = {"accept.png", "add.png", "application.png", "building.png", "bin.png", "database.png", "box.png", "brick.png"} - - for i=1, 20 do - local image = "resources/images/" .. images[math.random(1, #images)] - local panel1 = loveframes.Create("panel") - panel1.Draw = function() - end - local text1 = loveframes.Create("text", panel1) - text1:SetText("Tab " ..i) - tabs1:AddTab("Tab " ..i, panel1, "Tab " ..i, image) - text1:SetAlwaysUpdate(true) - text1.Update = function(object, dt) - object:Center() - end - end - - end - exampleslist:AddItem(tabsexample) - - ------------------------------------ - -- text example - ------------------------------------ - local textexample = loveframes.Create("button") - textexample:SetText("Text") - textexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Text") - frame1:SetSize(500, 330) - frame1:CenterWithinArea(unpack(centerarea)) - - local list1 = loveframes.Create("list", frame1) - list1:SetPos(5, 30) - list1:SetSize(490, 265) - list1:SetPadding(5) - list1:SetSpacing(5) - - local text1 = loveframes.Create("text") - text1:SetText(loremipsum) - text1:SetShadowColor(200, 200, 200, 255) - list1:AddItem(text1) - - local shadowbutton = loveframes.Create("button", frame1) - shadowbutton:SetSize(490, 25) - shadowbutton:SetPos(5, 300) - shadowbutton:SetText("Toggle Text Shadow") - shadowbutton.OnClick = function() - text1:SetShadow(not text1:GetShadow()) - end - - end - exampleslist:AddItem(textexample) - - ------------------------------------ - -- text input example - ------------------------------------ - local textinputexample = loveframes.Create("button") - textinputexample:SetText("Text Input") - textinputexample.OnClick = function(object1, x, y) - - local frame1 = loveframes.Create("frame") - frame1:SetName("Text Input") - frame1:SetSize(500, 90) - frame1:CenterWithinArea(unpack(centerarea)) - - local textinput1 = loveframes.Create("textinput", frame1) - textinput1:SetPos(5, 30) - textinput1:SetWidth(490) - textinput1.OnEnter = function(object) - if not textinput1.multiline then - object:Clear() - end - end - textinput1:SetFont(love.graphics.newFont(12)) - - local togglebutton = loveframes.Create("button", frame1) - togglebutton:SetPos(5, 60) - togglebutton:SetWidth(490) - togglebutton:SetText("Toggle Multiline") - togglebutton.OnClick = function(object) - if textinput1.multiline then - frame1:SetHeight(90) - frame1:CenterWithinArea(unpack(centerarea)) - togglebutton:SetPos(5, 60) - textinput1:SetMultiline(false) - textinput1:SetHeight(25) - textinput1:SetText("") - else - frame1:SetHeight(365) - frame1:CenterWithinArea(unpack(centerarea)) - togglebutton:SetPos(5, 335) - textinput1:SetMultiline(true) - textinput1:SetHeight(300) - textinput1:SetText("") - end - end - - end - exampleslist:AddItem(textinputexample) - -end - ---[[--------------------------------------------------------- - - func: SkinSelector() - - desc: opens a skin selector menu ---]]--------------------------------------------------------- -function loveframes.debug.SkinSelector() - - local skins = loveframes.skins.available - - local frame = loveframes.Create("frame") - frame:SetName("Skin Selector") - frame:SetSize(200, 60) - frame:SetPos(5, 255) - - local skinslist = loveframes.Create("multichoice", frame) - skinslist:SetPos(5, 30) - skinslist:SetWidth(190) - skinslist:SetChoice("Choose a skin") - skinslist.OnChoiceSelected = function(object, choice) - loveframes.util.SetActiveSkin(choice) - end - - for k, v in pairs(skins) do - skinslist:AddChoice(v.name) - end - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- debug library +loveframes.debug = {} + +local font = loveframes.basicfontsmall +local centerarea = {210, 5, 585, 590} +local loremipsum = +[[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean laoreet massa mattis tortor faucibus non congue mauris mattis. Aliquam ultricies scelerisque mi, sit amet tempor metus pharetra vel. Etiam eu arcu a dolor porttitor condimentum in malesuada urna. Mauris vel nulla mi, quis aliquet neque. In aliquet turpis eget purus malesuada tincidunt. Donec rutrum purus vel diam suscipit vehicula. Cras sem nibh, tempus at dictum non, consequat non justo. In sed tellus nec orci scelerisque scelerisque id vitae leo. Maecenas pharetra, nibh eget commodo gravida, augue nisl blandit dui, ut malesuada augue dui nec erat. Phasellus nec mauris pharetra metus iaculis viverra sit amet ut tortor. Duis et viverra magna. Nunc orci dolor, placerat a iaculis non, mattis sed nibh. + + Mauris ac erat sit amet ante condimentum scelerisque. Cras eleifend lorem dictum mi euismod non placerat lorem gravida. Vestibulum sodales dapibus eros, non iaculis risus commodo eu. Maecenas dapibus purus accumsan metus euismod suscipit. Etiam eleifend lorem eget quam ornare interdum sed at nulla. Suspendisse viverra sapien ut felis viverra pellentesque. Ut convallis hendrerit est, in imperdiet purus placerat ut. Curabitur sapien nibh, molestie et elementum a, sagittis et tortor. Vestibulum sed quam eu velit euismod rutrum vitae et sem. Morbi accumsan quam vitae sapien scelerisque tincidunt. Nulla ipsum leo, scelerisque at consequat sit amet, venenatis eget mauris. Aliquam at nibh vel lorem hendrerit dignissim. Cras et risus sit amet est vehicula auctor at a leo. Curabitur euismod mi sit amet nunc consequat sed fringilla justo sagittis. + + Nulla ut arcu felis, a laoreet tellus. Vivamus ligula nibh, bibendum ut ultrices sed, ullamcorper et est. Pellentesque nisi diam, sollicitudin lacinia fermentum quis, aliquam fermentum elit. Donec egestas vestibulum mollis. Vivamus sollicitudin nisl vestibulum nisi fermentum scelerisque. Nunc enim magna, posuere ornare faucibus a, bibendum vestibulum felis. Etiam laoreet molestie elit, vitae ultrices sem faucibus in. Fusce rutrum convallis lacus, vitae scelerisque eros tincidunt sed. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. + + Quisque ornare arcu sed enim sodales dictum. Suspendisse at convallis mi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas et nibh odio, eu lacinia lacus. Mauris at pulvinar urna. Pellentesque vel justo erat, a congue nibh. Nunc tristique mattis euismod. Suspendisse potenti. + + Sed dictum faucibus cursus. Integer nisi ipsum, dapibus vel blandit laoreet, bibendum congue massa. Vestibulum tincidunt vulputate nunc, facilisis consequat lacus posuere at. Aenean sed mollis urna. Vivamus congue neque non arcu malesuada lobortis. Curabitur suscipit pretium massa eu rutrum. Nulla vehicula imperdiet dui in blandit. Curabitur vitae felis ut massa scelerisque consequat. Nulla a magna quis risus consequat hendrerit. Maecenas quis lacus sit amet ipsum condimentum interdum. Proin condimentum erat id enim elementum ut tincidunt neque vulputate. +]] + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws debug information +--]]--------------------------------------------------------- +function loveframes.debug.draw() + + -- get the current debug setting + local debug = loveframes.config["DEBUG"] + + -- do not draw anthing if debug is off + if not debug then + return + end + + local cols = loveframes.util.GetCollisions() + local topcol = {type = none, children = {}, x = 0, y = 0, width = 0, height = 0} + local objects = loveframes.util.GetAllObjects() + local author = loveframes.info.author + local version = loveframes.info.version + local stage = loveframes.info.stage + local basedir = loveframes.config["DIRECTORY"] + local loveversion = love._version + local fps = love.timer.getFPS() + local deltatime = love.timer.getDelta() + + -- set the top most collision object + for k, v in ipairs(cols) do + if v:IsTopCollision() then + topcol = v + break + end + end + + -- main font + love.graphics.setFont(font) + + -- main box + love.graphics.setColor(0, 0, 0, 200) + love.graphics.rectangle("fill", 5, 30, 200, 220) + + ------------------------------------------------------- + -- library information section + ------------------------------------------------------- + love.graphics.setColor(255, 0, 0, 255) + love.graphics.print("Library Information", 10, 35) + + love.graphics.setColor(255, 255, 255, 255) + love.graphics.print("Author: " ..author, 15, 50) + love.graphics.print("Version: " ..version, 15, 60) + love.graphics.print("Stage: " ..stage, 15, 70) + love.graphics.print("Base Directory: " ..basedir, 15, 80) + + ------------------------------------------------------- + -- object information section + ------------------------------------------------------- + love.graphics.setColor(255, 0, 0, 255) + love.graphics.print("Object Information", 10, 95) + + love.graphics.setColor(255, 255, 255, 255) + + if #cols > 0 then + love.graphics.print("Type: " ..topcol.type, 15, 110) + else + love.graphics.print("Type: none", 10, 120) + end + + if topcol.children then + love.graphics.print("# of children: " .. #topcol.children, 15, 120) + else + love.graphics.print("# of children: 0", 15, 120) + end + + if topcol.internals then + love.graphics.print("# of internals: " .. #topcol.internals, 15, 130) + else + love.graphics.print("# of internals: 0", 15, 130) + end + + love.graphics.print("X: " ..topcol.x, 15, 140) + love.graphics.print("Y: " ..topcol.y, 15, 150) + love.graphics.print("Width: " ..topcol.width, 15, 160) + love.graphics.print("Height: " ..topcol.height, 15, 170) + + ------------------------------------------------------- + -- miscellaneous section + ------------------------------------------------------- + love.graphics.setColor(255, 0, 0, 255) + love.graphics.print("Miscellaneous", 10, 185) + + love.graphics.setColor(255, 255, 255, 255) + love.graphics.print("LOVE Version: " ..loveversion, 15, 200) + love.graphics.print("FPS: " ..fps, 15, 210) + love.graphics.print("Delta Time: " ..deltatime, 15, 220) + love.graphics.print("Total Objects: " ..#objects, 15, 230) + + -- outline the object that the mouse is hovering over + love.graphics.setColor(255, 204, 51, 255) + love.graphics.setLine(2, "smooth") + love.graphics.rectangle("line", topcol.x - 1, topcol.y - 1, topcol.width + 2, topcol.height + 2) + +end + +--[[--------------------------------------------------------- + - func: ExamplesMenu() + - desc: generates a list of examples of Love Frames + objects +--]]--------------------------------------------------------- +function loveframes.debug.ExamplesMenu() + + ------------------------------------ + -- examples frame + ------------------------------------ + local examplesframe = loveframes.Create("frame") + examplesframe:SetName("Examples List") + examplesframe:SetSize(200, love.graphics.getHeight() - 325) + examplesframe:SetPos(5, 320) + + ------------------------------------ + -- examples list + ------------------------------------ + local exampleslist = loveframes.Create("list", examplesframe) + exampleslist:SetSize(200, exampleslist:GetParent():GetHeight() - 25) + exampleslist:SetPos(0, 25) + exampleslist:SetPadding(5) + exampleslist:SetSpacing(5) + exampleslist:SetDisplayType("vertical") + + ------------------------------------ + -- button example + ------------------------------------ + local buttonexample = loveframes.Create("button") + buttonexample:SetText("Button") + buttonexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Button") + frame1:CenterWithinArea(unpack(centerarea)) + + local button1 = loveframes.Create("button", frame1) + button1:SetWidth(200) + button1:SetText("Button") + button1:Center() + button1.OnClick = function(object2, x, y) + object2:SetText("You clicked the button!") + end + button1.OnMouseEnter = function(object2) + object2:SetText("The mouse entered the button.") + end + button1.OnMouseExit = function(object2) + object2:SetText("The mouse exited the button.") + end + + end + exampleslist:AddItem(buttonexample) + + ------------------------------------ + -- checkbox example + ------------------------------------ + local checkboxexample = loveframes.Create("button") + checkboxexample:SetText("Checkbox") + checkboxexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Checkbox") + frame1:CenterWithinArea(unpack(centerarea)) + frame1:SetHeight(85) + + local checkbox1 = loveframes.Create("checkbox", frame1) + checkbox1:SetText("Checkbox 1") + checkbox1:SetPos(5, 30) + checkbox1.OnChanged = function(object2) + end + + local checkbox2 = loveframes.Create("checkbox", frame1) + checkbox2:SetText("Checkbox 2") + checkbox2:SetPos(5, 60) + checkbox2.OnChanged = function(object3) + end + + end + exampleslist:AddItem(checkboxexample) + + ------------------------------------ + -- collapsible category example + ------------------------------------ + local collapsiblecategoryexample = loveframes.Create("button") + collapsiblecategoryexample:SetText("Collapsible Category") + collapsiblecategoryexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Collapsible Category") + frame1:SetSize(500, 300) + frame1:CenterWithinArea(unpack(centerarea)) + + local panel1 = loveframes.Create("panel") + panel1:SetHeight(230) + + local collapsiblecategory1 = loveframes.Create("collapsiblecategory", frame1) + collapsiblecategory1:SetPos(5, 30) + collapsiblecategory1:SetSize(490, 265) + collapsiblecategory1:SetText("Category 1") + collapsiblecategory1:SetObject(panel1) + + end + exampleslist:AddItem(collapsiblecategoryexample) + + ------------------------------------ + -- cloumnlist example + ------------------------------------ + local cloumnlistexample = loveframes.Create("button") + cloumnlistexample:SetText("Column List") + cloumnlistexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Column List") + frame1:SetSize(500, 300) + frame1:CenterWithinArea(unpack(centerarea)) + + local list1 = loveframes.Create("columnlist", frame1) + list1:SetPos(5, 30) + list1:SetSize(490, 265) + list1:AddColumn("Column 1") + list1:AddColumn("Column 2") + list1:AddColumn("Column 3") + list1:AddColumn("Column 4") + + for i=1, 20 do + list1:AddRow("Row " ..i.. ", column 1", "Row " ..i.. ", column 2", "Row " ..i.. ", column 3", "Row " ..i.. ", column 4") + end + + end + exampleslist:AddItem(cloumnlistexample) + + ------------------------------------ + -- frame example + ------------------------------------ + local frameexample = loveframes.Create("button") + frameexample:SetText("Frame") + frameexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Frame") + frame1:CenterWithinArea(unpack(centerarea)) + + local text1 = loveframes.Create("text", frame1) + text1:SetText("This is an example frame.") + text1.Update = function(object2, dt) + object2:CenterX() + object2:SetY(40) + end + + local button1 = loveframes.Create("button", frame1) + button1:SetText("Modal") + button1:SetWidth(100) + button1:Center() + button1.Update = function(object2, dt) + local modal = object2:GetParent():GetModal() + + if modal then + object2:SetText("Remove Modal") + object2.OnClick = function() + object2:GetParent():SetModal(false) + end + else + object2:SetText("Set Modal") + object2.OnClick = function() + object2:GetParent():SetModal(true) + end + end + end + + end + exampleslist:AddItem(frameexample) + + ------------------------------------ + -- image example + ------------------------------------ + local imageexample = loveframes.Create("button") + imageexample:SetText("Image") + imageexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Image") + frame1:SetSize(138, 315) + frame1:CenterWithinArea(unpack(centerarea)) + + local image1 = loveframes.Create("image", frame1) + image1:SetImage("resources/images/carlsagan.png") + image1:SetPos(5, 30) + + local panel1 = loveframes.Create("panel", frame1) + panel1:SetPos(5, 160) + panel1:SetSize(128, 150) + + local text1 = loveframes.Create("text", panel1) + text1:SetPos(5, 5) + text1:SetText("Orientation: ") + + local slider1 = loveframes.Create("slider", panel1) + slider1:SetPos(5, 20) + slider1:SetWidth(118) + slider1:SetMinMax(0, 360) + slider1:SetDecimals(0) + slider1.OnValueChanged = function(object) + image1:SetOrientation(object:GetValue()) + end + + text1.Update = function(object, dt) + object:SetText("Orientation: " ..slider1:GetValue()) + end + + local text2 = loveframes.Create("text", panel1) + text2:SetPos(5, 40) + text2:SetText("Scale") + + local slider2 = loveframes.Create("slider", panel1) + slider2:SetPos(5, 55) + slider2:SetWidth(118) + slider2:SetMinMax(1, 2) + slider2:SetDecimals(5) + slider2.OnValueChanged = function(object) + image1:SetScale(object:GetValue(), object:GetValue()) + end + + text2.Update = function(object, dt) + object:SetText("Scale: " ..slider2:GetValue()) + end + + local text3 = loveframes.Create("text", panel1) + text3:SetPos(5, 75) + text3:SetText("Offset") + + local slider3 = loveframes.Create("slider", panel1) + slider3:SetPos(5, 90) + slider3:SetWidth(118) + slider3:SetMinMax(1, 50) + slider3:SetDecimals(5) + slider3.OnValueChanged = function(object) + image1:SetOffset(object:GetValue(), object:GetValue()) + end + + text3.Update = function(object, dt) + object:SetText("Offset: " ..slider3:GetValue()) + end + + local text4 = loveframes.Create("text", panel1) + text4:SetPos(5, 110) + text4:SetText("Shear") + + local slider4 = loveframes.Create("slider", panel1) + slider4:SetPos(5, 125) + slider4:SetWidth(118) + slider4:SetMinMax(0, 10) + slider4:SetDecimals(5) + slider4.OnValueChanged = function(object) + image1:SetShear(object:GetValue(), object:GetValue()) + end + + text4.Update = function(object, dt) + object:SetText("Shear: " ..slider4:GetValue()) + end + + end + exampleslist:AddItem(imageexample) + + ------------------------------------ + -- image button example + ------------------------------------ + local imagebuttonexample = loveframes.Create("button") + imagebuttonexample:SetText("Image Button") + imagebuttonexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Image Button") + frame1:SetSize(138, 163) + frame1:CenterWithinArea(unpack(centerarea)) + + local imagebutton1 = loveframes.Create("imagebutton", frame1) + imagebutton1:SetImage("resources/images/carlsagan.png") + imagebutton1:SetPos(5, 30) + imagebutton1:SizeToImage() + + end + exampleslist:AddItem(imagebuttonexample) + + ------------------------------------ + -- list example + ------------------------------------ + local listexample = loveframes.Create("button") + listexample:SetText("List") + listexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("List") + frame1:SetSize(500, 455) + frame1:CenterWithinArea(unpack(centerarea)) + + local list1 = loveframes.Create("list", frame1) + list1:SetPos(5, 30) + list1:SetSize(490, 300) + list1:SetPadding(5) + list1:SetSpacing(5) + + local panel1 = loveframes.Create("panel", frame1) + panel1:SetPos(5, 335) + panel1:SetSize(490, 115) + + local slider1 = loveframes.Create("slider", panel1) + slider1:SetPos(5, 20) + slider1:SetWidth(480) + slider1:SetMinMax(0, 100) + slider1:SetValue(5) + slider1:SetText("Padding") + slider1:SetDecimals(0) + slider1.OnValueChanged = function(object2, value) + list1:SetPadding(value) + end + + local text1 = loveframes.Create("text", panel1) + text1:SetPos(5, 5) + text1:SetFont(love.graphics.newFont(10)) + text1:SetText(slider1:GetText()) + + local text2 = loveframes.Create("text", panel1) + text2:SetFont(love.graphics.newFont(10)) + text2.Update = function(object, dt) + object:SetPos(slider1:GetWidth() - object:GetWidth(), 5) + object:SetText(slider1:GetValue()) + end + + local slider2 = loveframes.Create("slider", panel1) + slider2:SetPos(5, 60) + slider2:SetWidth(480) + slider2:SetMinMax(0, 100) + slider2:SetValue(5) + slider2:SetText("Spacing") + slider2:SetDecimals(0) + slider2.OnValueChanged = function(object2, value) + list1:SetSpacing(value) + end + + local text3 = loveframes.Create("text", panel1) + text3:SetPos(5, 45) + text3:SetFont(love.graphics.newFont(10)) + text3:SetText(slider2:GetText()) + + local text4 = loveframes.Create("text", panel1) + text4:SetFont(love.graphics.newFont(10)) + text4.Update = function(object, dt) + object:SetPos(slider2:GetWidth() - object:GetWidth(), 45) + object:SetText(slider2:GetValue()) + end + + local button1 = loveframes.Create("button", panel1) + button1:SetPos(5, 85) + button1:SetSize(237, 25) + button1:SetText("Change List Type") + button1.OnClick = function(object2, x, y) + if list1:GetDisplayType() == "vertical" then + list1:SetDisplayType("horizontal") + else + list1:SetDisplayType("vertical") + end + list1:Clear() + for i=1, 100 do + local button = loveframes.Create("button") + button:SetText(i) + list1:AddItem(button) + end + end + + local button2 = loveframes.Create("button", panel1) + button2:SetPos(247, 85) + button2:SetSize(237, 25) + button2:SetText("Toggle Horizontal Stacking") + button2.OnClick = function(object2, x, y) + local enabled = list1:GetHorizontalStacking() + list1:EnableHorizontalStacking(not enabled) + list1:Clear() + for i=1, 100 do + local button = loveframes.Create("button") + button:SetSize(100, 25) + button:SetText(i) + list1:AddItem(button) + end + end + button2.Update = function(object) + local displaytype = list1:GetDisplayType() + if displaytype ~= "vertical" then + object:SetEnabled(false) + object:SetClickable(false) + else + object:SetEnabled(true) + object:SetClickable(true) + end + end + + for i=1, 100 do + local button = loveframes.Create("button") + button:SetText(i) + list1:AddItem(button) + end + + end + exampleslist:AddItem(listexample) + + ------------------------------------ + -- multichoice example + ------------------------------------ + local multichoiceexample = loveframes.Create("button") + multichoiceexample:SetText("Multichoice") + multichoiceexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Multichoice") + frame1:SetSize(210, 60) + frame1:CenterWithinArea(unpack(centerarea)) + + local multichoice1 = loveframes.Create("multichoice", frame1) + multichoice1:SetPos(5, 30) + + for i=1, 20 do + multichoice1:AddChoice(i) + end + + end + exampleslist:AddItem(multichoiceexample) + + ------------------------------------ + -- numberbox example + ------------------------------------ + local numberboxexample = loveframes.Create("button") + numberboxexample:SetText("Numberbox") + numberboxexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Numberbox") + frame1:SetSize(210, 60) + frame1:CenterWithinArea(unpack(centerarea)) + + local numberbox1 = loveframes.Create("numberbox", frame1) + numberbox1:SetPos(5, 30) + numberbox1:SetSize(200, 25) + + end + exampleslist:AddItem(numberboxexample) + + ------------------------------------ + -- panel example + ------------------------------------ + local panelexample = loveframes.Create("button") + panelexample:SetText("Panel") + panelexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Panel") + frame1:SetSize(210, 85) + frame1:CenterWithinArea(unpack(centerarea)) + + local panel1 = loveframes.Create("panel", frame1) + panel1:SetPos(5, 30) + + end + exampleslist:AddItem(panelexample) + + ------------------------------------ + -- progressbar example + ------------------------------------ + local progressbarexample = loveframes.Create("button") + progressbarexample:SetText("Progress Bar") + progressbarexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Progress Bar") + frame1:SetSize(500, 160) + frame1:CenterWithinArea(unpack(centerarea)) + + local progressbar1 = loveframes.Create("progressbar", frame1) + progressbar1:SetPos(5, 30) + progressbar1:SetWidth(490) + progressbar1:SetLerpRate(1) + + local button1 = loveframes.Create("button", frame1) + button1:SetPos(5, 60) + button1:SetWidth(490) + button1:SetText("Change bar value") + button1.OnClick = function(object2, x, y) + progressbar1:SetValue(math.random(progressbar1:GetMin(), progressbar1:GetMax())) + end + + local button2 = loveframes.Create("button", frame1) + button2:SetPos(5, 90) + button2:SetWidth(490) + button2:SetText("Toggle bar lerp") + button2.OnClick = function(object2, x, y) + if progressbar1:GetLerp() == true then + progressbar1:SetLerp(false) + else + progressbar1:SetLerp(true) + end + end + + local slider1 = loveframes.Create("slider", frame1) + slider1:SetPos(5, 135) + slider1:SetWidth(490) + slider1:SetText("Progressbar lerp rate") + slider1:SetMinMax(0, 50) + slider1:SetDecimals(0) + slider1.OnValueChanged = function(object2, value) + progressbar1:SetLerpRate(value) + end + + local text1 = loveframes.Create("text", frame1) + text1:SetPos(5, 120) + text1:SetText("Lerp Rate") + text1:SetFont(love.graphics.newFont(10)) + + local text2 = loveframes.Create("text", frame1) + text2:SetFont(love.graphics.newFont(10)) + text2.Update = function(object, dt) + object:SetPos(slider1:GetWidth() - object:GetWidth(), 120) + object:SetText(slider1:GetValue()) + end + + end + exampleslist:AddItem(progressbarexample) + + ------------------------------------ + -- slider example + ------------------------------------ + local sliderexample = loveframes.Create("button") + sliderexample:SetText("Slider") + sliderexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Slider") + frame1:SetSize(300, 275) + frame1:CenterWithinArea(unpack(centerarea)) + + local slider1 = loveframes.Create("slider", frame1) + slider1:SetPos(5, 30) + slider1:SetWidth(290) + slider1:SetMinMax(0, 100) + + local slider2 = loveframes.Create("slider", frame1) + slider2:SetPos(5, 60) + slider2:SetHeight(200) + slider2:SetMinMax(0, 100) + slider2:SetButtonSize(20, 10) + slider2:SetSlideType("vertical") + slider2.Update = function(object, dt) + object:CenterX() + end + + end + exampleslist:AddItem(sliderexample) + + ------------------------------------ + -- tabs example + ------------------------------------ + local tabsexample = loveframes.Create("button") + tabsexample:SetText("Tabs") + tabsexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Tabs") + frame1:SetSize(500, 300) + frame1:CenterWithinArea(unpack(centerarea)) + + local tabs1 = loveframes.Create("tabs", frame1) + tabs1:SetPos(5, 30) + tabs1:SetSize(490, 265) + + local images = {"accept.png", "add.png", "application.png", "building.png", "bin.png", "database.png", "box.png", "brick.png"} + + for i=1, 20 do + local image = "resources/images/" .. images[math.random(1, #images)] + local panel1 = loveframes.Create("panel") + panel1.Draw = function() + end + local text1 = loveframes.Create("text", panel1) + text1:SetText("Tab " ..i) + text1:SetAlwaysUpdate(true) + text1.Update = function(object, dt) + object:Center() + end + tabs1:AddTab("Tab " ..i, panel1, "Tab " ..i, image) + end + + end + exampleslist:AddItem(tabsexample) + + ------------------------------------ + -- text example + ------------------------------------ + local textexample = loveframes.Create("button") + textexample:SetText("Text") + textexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Text") + frame1:SetSize(500, 330) + frame1:CenterWithinArea(unpack(centerarea)) + + local list1 = loveframes.Create("list", frame1) + list1:SetPos(5, 30) + list1:SetSize(490, 265) + list1:SetPadding(5) + list1:SetSpacing(5) + + local text1 = loveframes.Create("text") + text1:SetText(loremipsum) + text1:SetShadowColor(200, 200, 200, 255) + list1:AddItem(text1) + + local shadowbutton = loveframes.Create("button", frame1) + shadowbutton:SetSize(490, 25) + shadowbutton:SetPos(5, 300) + shadowbutton:SetText("Toggle Text Shadow") + shadowbutton.OnClick = function() + text1:SetShadow(not text1:GetShadow()) + end + + end + exampleslist:AddItem(textexample) + + ------------------------------------ + -- text input example + ------------------------------------ + local textinputexample = loveframes.Create("button") + textinputexample:SetText("Text Input") + textinputexample.OnClick = function(object1, x, y) + + local frame1 = loveframes.Create("frame") + frame1:SetName("Text Input") + frame1:SetSize(500, 90) + frame1:CenterWithinArea(unpack(centerarea)) + + local textinput1 = loveframes.Create("textinput", frame1) + textinput1:SetPos(5, 30) + textinput1:SetWidth(490) + textinput1.OnEnter = function(object) + if not textinput1.multiline then + object:Clear() + end + end + textinput1:SetFont(love.graphics.newFont(12)) + + local togglebutton = loveframes.Create("button", frame1) + togglebutton:SetPos(5, 60) + togglebutton:SetWidth(490) + togglebutton:SetText("Toggle Multiline") + togglebutton.OnClick = function(object) + if textinput1.multiline then + frame1:SetHeight(90) + frame1:CenterWithinArea(unpack(centerarea)) + togglebutton:SetPos(5, 60) + textinput1:SetMultiline(false) + textinput1:SetHeight(25) + textinput1:SetText("") + else + frame1:SetHeight(365) + frame1:CenterWithinArea(unpack(centerarea)) + togglebutton:SetPos(5, 335) + textinput1:SetMultiline(true) + textinput1:SetHeight(300) + textinput1:SetText("") + end + end + + end + exampleslist:AddItem(textinputexample) + +end + +--[[--------------------------------------------------------- + - func: SkinSelector() + - desc: opens a skin selector menu +--]]--------------------------------------------------------- +function loveframes.debug.SkinSelector() + + local skins = loveframes.skins.available + + local frame = loveframes.Create("frame") + frame:SetName("Skin Selector") + frame:SetSize(200, 60) + frame:SetPos(5, 255) + + local skinslist = loveframes.Create("multichoice", frame) + skinslist:SetPos(5, 30) + skinslist:SetWidth(190) + skinslist:SetChoice("Choose a skin") + skinslist.OnChoiceSelected = function(object, choice) + loveframes.util.SetActiveSkin(choice) + end + + for k, v in pairs(skins) do + skinslist:AddChoice(v.name) + end + end \ No newline at end of file diff --git a/init.lua b/init.lua index 3226bfa..d86c405 100644 --- a/init.lua +++ b/init.lua @@ -1,286 +1,308 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- central library table -loveframes = {} - --- library info -loveframes.info = {} -loveframes.info.author = "Kenny Shields" -loveframes.info.version = "0.9.4.15" -loveframes.info.stage = "Alpha" - --- library configurations -loveframes.config = {} -loveframes.config["DIRECTORY"] = "" -loveframes.config["DEFAULTSKIN"] = "Blue" -loveframes.config["ACTIVESKIN"] = "Blue" -loveframes.config["INDEXSKINIMAGES"] = true -loveframes.config["DEBUG"] = false - --- misc library vars -loveframes.drawcount = 0 -loveframes.hoverobject = false -loveframes.modalobject = false -loveframes.inputobject = false -loveframes.basicfont = love.graphics.newFont(12) -loveframes.basicfontsmall = love.graphics.newFont(10) -loveframes.objects = {} - ---[[--------------------------------------------------------- - - func: load() - - desc: loads the library ---]]--------------------------------------------------------- -function loveframes.load() - - -- install directory of the library - local dir = loveframes.config["DIRECTORY"] - - -- require the internal base libraries - require(dir .. ".third-party.middleclass") - require(dir .. ".util") - require(dir .. ".skins") - require(dir .. ".templates") - require(dir .. ".debug") - - -- replace all "." with "/" in the directory setting - dir = dir:gsub("%.", "/") - loveframes.config["DIRECTORY"] = dir - - -- create a list of gui objects, skins and templates - local objects = loveframes.util.GetDirectoryContents(dir .. "/objects") - local skins = loveframes.util.GetDirectoryContents(dir .. "/skins") - local templates = loveframes.util.GetDirectoryContents(dir .. "/templates") - - -- loop through a list of all gui objects and require them - for k, v in ipairs(objects) do - if v.extension == "lua" then - require(v.requirepath) - end - end - - -- loop through a list of all gui templates and require them - for k, v in ipairs(templates) do - if v.extension == "lua" then - require(v.requirepath) - end - end - - -- loop through a list of all gui skins and require them - for k, v in ipairs(skins) do - if v.extension == "lua" then - require(v.requirepath) - end - end - - -- create the base gui object - local base = loveframes.objects["base"] - loveframes.base = base:new() - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates all library objects ---]]--------------------------------------------------------- -function loveframes.update(dt) - - local base = loveframes.base - base:update(dt) - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws all library objects ---]]--------------------------------------------------------- -function loveframes.draw() - - local base = loveframes.base - local r, g, b, a = love.graphics.getColor() - - base:draw() - - loveframes.drawcount = 0 - loveframes.debug.draw() - - love.graphics.setColor(r, g, b, a) - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function loveframes.mousepressed(x, y, button) - - local base = loveframes.base - base:mousepressed(x, y, button) - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function loveframes.mousereleased(x, y, button) - - local base = loveframes.base - base:mousereleased(x, y, button) - - -- reset the hover object - if button == "l" then - loveframes.hoverobject = false - loveframes.selectedobject = false - end - -end - ---[[--------------------------------------------------------- - - func: keypressed(key) - - desc: called when the player presses a key ---]]--------------------------------------------------------- -function loveframes.keypressed(key, unicode) - - local base = loveframes.base - base:keypressed(key, unicode) - -end - ---[[--------------------------------------------------------- - - func: keyreleased(key) - - desc: called when the player releases a key ---]]--------------------------------------------------------- -function loveframes.keyreleased(key) - - local base = loveframes.base - base:keyreleased(key) - -end - ---[[--------------------------------------------------------- - - func: Create(type, parent) - - desc: creates a new object or multiple new objects - (based on the method used) and returns said - object or objects for further manipulation ---]]--------------------------------------------------------- -function loveframes.Create(data, parent) - - if type(data) == "string" then - - local objects = loveframes.objects - local object = objects[data] - - if not object then - loveframes.util.Error("Error creating object: Invalid object '" ..data.. "'.") - end - - -- create the object - local newobject = object:new() - - -- apply template properties to the object - loveframes.templates.ApplyToObject(newobject) - - -- if the object is a tooltip, return it and go no further - if data == "tooltip" then - return newobject - end - - -- remove the object if it is an internal - if newobject.internal then - newobject:Remove() - return - end - - -- parent the new object by default to the base gui object - newobject.parent = loveframes.base - table.insert(loveframes.base.children, newobject) - - -- if the parent argument is not nil, make that argument the object's new parent - if parent then - newobject:SetParent(parent) - end - - -- return the object for further manipulation - return newobject - - elseif type(data) == "table" then - - -- table for creation of multiple objects - local objects = {} - - -- this function reads a table that contains a layout of object properties and then - -- creates objects based on those properties - local function CreateObjects(t, o, c) - local child = c or false - for k, v in pairs(t) do - -- current default object - local object = _G[v.type]:new() - -- indert the object into the table of objects being created - table.insert(objects, object) - -- parent the new object by default to the base gui object - object.parent = loveframes.base - table.insert(loveframes.base.children, object) - if o then - object:SetParent(o) - end - -- loop through the current layout table and assign the properties found - -- to the current object - for i, j in pairs(v) do - if i ~= "children" and i ~= "func" then - if child == true then - if i == "x" then - object["staticx"] = j - elseif i == "y" then - object["staticy"] = j - else - object[i] = j - end - else - object[i] = j - end - elseif i == "children" then - CreateObjects(j, object, true) - end - end - if v.func then - v.func(object) - end - end - end - - -- create the objects - CreateObjects(data) - - return objects - - end - -end - ---[[--------------------------------------------------------- - - func: NewObject(id, name, inherit_from_base) - - desc: creates a new object ---]]--------------------------------------------------------- -function loveframes.NewObject(id, name, inherit_from_base) - - local objects = loveframes.objects - local object = false - - if inherit_from_base then - local base = objects["base"] - object = class(name, base) - objects[id] = object - else - object = class(name) - objects[id] = object - end - - return object - -end - --- load the library +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- central library table +loveframes = {} + +-- library info +loveframes.info = {} +loveframes.info.author = "Kenny Shields" +loveframes.info.version = "0.9.5" +loveframes.info.stage = "Alpha" + +-- library configurations +loveframes.config = {} +loveframes.config["DIRECTORY"] = "" +loveframes.config["DEFAULTSKIN"] = "Blue" +loveframes.config["ACTIVESKIN"] = "Blue" +loveframes.config["INDEXSKINIMAGES"] = true +loveframes.config["DEBUG"] = false + +-- misc library vars +loveframes.state = "none" +loveframes.drawcount = 0 +loveframes.hoverobject = false +loveframes.modalobject = false +loveframes.inputobject = false +loveframes.basicfont = love.graphics.newFont(12) +loveframes.basicfontsmall = love.graphics.newFont(10) +loveframes.objects = {} + +--[[--------------------------------------------------------- + - func: load() + - desc: loads the library +--]]--------------------------------------------------------- +function loveframes.load() + + -- install directory of the library + local dir = loveframes.config["DIRECTORY"] + + -- require the internal base libraries + require(dir .. ".third-party.middleclass") + require(dir .. ".util") + require(dir .. ".skins") + require(dir .. ".templates") + require(dir .. ".debug") + + -- replace all "." with "/" in the directory setting + dir = dir:gsub("%.", "/") + loveframes.config["DIRECTORY"] = dir + + -- create a list of gui objects, skins and templates + local objects = loveframes.util.GetDirectoryContents(dir .. "/objects") + local skins = loveframes.util.GetDirectoryContents(dir .. "/skins") + local templates = loveframes.util.GetDirectoryContents(dir .. "/templates") + + -- loop through a list of all gui objects and require them + for k, v in ipairs(objects) do + if v.extension == "lua" then + require(v.requirepath) + end + end + + -- loop through a list of all gui templates and require them + for k, v in ipairs(templates) do + if v.extension == "lua" then + require(v.requirepath) + end + end + + -- loop through a list of all gui skins and require them + for k, v in ipairs(skins) do + if v.extension == "lua" then + require(v.requirepath) + end + end + + -- create the base gui object + local base = loveframes.objects["base"] + loveframes.base = base:new() + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates all library objects +--]]--------------------------------------------------------- +function loveframes.update(dt) + + local base = loveframes.base + base:update(dt) + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws all library objects +--]]--------------------------------------------------------- +function loveframes.draw() + + local base = loveframes.base + local r, g, b, a = love.graphics.getColor() + + base:draw() + + loveframes.drawcount = 0 + loveframes.debug.draw() + + love.graphics.setColor(r, g, b, a) + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function loveframes.mousepressed(x, y, button) + + local base = loveframes.base + base:mousepressed(x, y, button) + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function loveframes.mousereleased(x, y, button) + + local base = loveframes.base + base:mousereleased(x, y, button) + + -- reset the hover object + if button == "l" then + loveframes.hoverobject = false + loveframes.selectedobject = false + end + +end + +--[[--------------------------------------------------------- + - func: keypressed(key) + - desc: called when the player presses a key +--]]--------------------------------------------------------- +function loveframes.keypressed(key, unicode) + + local base = loveframes.base + base:keypressed(key, unicode) + +end + +--[[--------------------------------------------------------- + - func: keyreleased(key) + - desc: called when the player releases a key +--]]--------------------------------------------------------- +function loveframes.keyreleased(key) + + local base = loveframes.base + base:keyreleased(key) + +end + +--[[--------------------------------------------------------- + - func: Create(type, parent) + - desc: creates a new object or multiple new objects + (based on the method used) and returns said + object or objects for further manipulation +--]]--------------------------------------------------------- +function loveframes.Create(data, parent) + + if type(data) == "string" then + + local objects = loveframes.objects + local object = objects[data] + + if not object then + loveframes.util.Error("Error creating object: Invalid object '" ..data.. "'.") + end + + -- create the object + local newobject = object:new() + + -- apply template properties to the object + loveframes.templates.ApplyToObject(newobject) + + -- if the object is a tooltip, return it and go no further + if data == "tooltip" then + return newobject + end + + -- remove the object if it is an internal + if newobject.internal then + newobject:Remove() + return + end + + -- parent the new object by default to the base gui object + newobject.parent = loveframes.base + table.insert(loveframes.base.children, newobject) + + -- if the parent argument is not nil, make that argument the object's new parent + if parent then + newobject:SetParent(parent) + end + + -- return the object for further manipulation + return newobject + + elseif type(data) == "table" then + + -- table for creation of multiple objects + local objects = {} + + -- this function reads a table that contains a layout of object properties and then + -- creates objects based on those properties + local function CreateObjects(t, o, c) + local child = c or false + for k, v in pairs(t) do + -- current default object + local object = _G[v.type]:new() + -- indert the object into the table of objects being created + table.insert(objects, object) + -- parent the new object by default to the base gui object + object.parent = loveframes.base + table.insert(loveframes.base.children, object) + if o then + object:SetParent(o) + end + -- loop through the current layout table and assign the properties found + -- to the current object + for i, j in pairs(v) do + if i ~= "children" and i ~= "func" then + if child == true then + if i == "x" then + object["staticx"] = j + elseif i == "y" then + object["staticy"] = j + else + object[i] = j + end + else + object[i] = j + end + elseif i == "children" then + CreateObjects(j, object, true) + end + end + if v.func then + v.func(object) + end + end + end + + -- create the objects + CreateObjects(data) + + return objects + + end + +end + +--[[--------------------------------------------------------- + - func: NewObject(id, name, inherit_from_base) + - desc: creates a new object +--]]--------------------------------------------------------- +function loveframes.NewObject(id, name, inherit_from_base) + + local objects = loveframes.objects + local object = false + + if inherit_from_base then + local base = objects["base"] + object = class(name, base) + objects[id] = object + else + object = class(name) + objects[id] = object + end + + return object + +end + +--[[--------------------------------------------------------- + - func: SetState(name) + - desc: sets the current state +--]]--------------------------------------------------------- +function loveframes.SetState(name) + + loveframes.state = name + loveframes.base.state = name + +end + +--[[--------------------------------------------------------- + - func: GetState() + - desc: gets the current state +--]]--------------------------------------------------------- +function loveframes.GetState() + + return loveframes.state + +end + +-- load the library loveframes.load() \ No newline at end of file diff --git a/objects/base.lua b/objects/base.lua index 1b5c1f0..de8a0f4 100644 --- a/objects/base.lua +++ b/objects/base.lua @@ -1,1083 +1,1161 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- base object -local newobject = loveframes.NewObject("base", "loveframes_object_base") - ---[[--------------------------------------------------------- - - func: initialize() - - desc: intializes the element ---]]--------------------------------------------------------- -function newobject:initialize() - - -- width and height of the window - local w = love.graphics.getWidth() - local h = love.graphics.getHeight() - - self.type = "base" - self.width = w - self.height = h - self.internal = true - self.children = {} - self.internals = {} - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local children = self.children - - for k, v in ipairs(children) do - v:update(dt) - end - - for k, v in ipairs(self.internals) do - v:update(dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local children = self.children - - -- set the object's draw order - self:SetDrawOrder() - - for k, v in ipairs(children) do - v:draw() - end - - for k, v in ipairs(self.internals) do - v:draw() - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - local children = self.children - local internals = self.internals - - if not visible then - return - end - - if children then - for k, v in ipairs(children) do - v:mousepressed(x, y, button) - end - end - - if internals then - for k, v in ipairs(internals) do - v:mousepressed(x, y, button) - end - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - local children = self.children - local internals = self.internals - - if not visible then - return - end - - if children then - for k, v in ipairs(children) do - v:mousereleased(x, y, button) - end - end - - if internals then - for k, v in ipairs(internals) do - v:mousereleased(x, y, button) - end - end - -end - ---[[--------------------------------------------------------- - - func: keypressed(key) - - desc: called when the player presses a key ---]]--------------------------------------------------------- -function newobject:keypressed(key, unicode) - - local visible = self.visible - local children = self.children - local internals = self.internals - - if not visible then - return - end - - if children then - for k, v in ipairs(children) do - v:keypressed(key, unicode) - end - end - - if internals then - for k, v in ipairs(internals) do - v:keypressed(key, unicode) - end - end - -end - ---[[--------------------------------------------------------- - - func: keyreleased(key) - - desc: called when the player releases a key ---]]--------------------------------------------------------- -function newobject:keyreleased(key) - - local visible = self.visible - local children = self.children - local internals = self.internals - - if not visible then - return - end - - if children then - for k, v in ipairs(children) do - v:keyreleased(key) - end - end - - if internals then - for k, v in ipairs(internals) do - v:keyreleased(key) - end - end - -end - - - ---[[--------------------------------------------------------- - - func: SetPos(x, y) - - desc: sets the object's position ---]]--------------------------------------------------------- -function newobject:SetPos(x, y) - - local base = loveframes.base - local parent = self.parent - - if parent == base then - self.x = x - self.y = y - else - self.staticx = x - self.staticy = y - end - -end - ---[[--------------------------------------------------------- - - func: SetX(x) - - desc: sets the object's x position ---]]--------------------------------------------------------- -function newobject:SetX(x) - - local base = loveframes.base - local parent = self.parent - - if parent == base then - self.x = x - else - self.staticx = x - end - -end - ---[[--------------------------------------------------------- - - func: SetY(y) - - desc: sets the object's y position ---]]--------------------------------------------------------- -function newobject:SetY(y) - - local base = loveframes.base - local parent = self.parent - - if parent == base then - self.y = y - else - self.staticy = y - end - -end - ---[[--------------------------------------------------------- - - func: GetPos() - - desc: gets the object's position ---]]--------------------------------------------------------- -function newobject:GetPos() - - return self.x, self.y - -end - ---[[--------------------------------------------------------- - - func: GetX() - - desc: gets the object's x position ---]]--------------------------------------------------------- -function newobject:GetX() - - return self.x - -end - ---[[--------------------------------------------------------- - - func: GetY() - - desc: gets the object's y position ---]]--------------------------------------------------------- -function newobject:GetY() - - return self.y - -end - ---[[--------------------------------------------------------- - - func: GetStaticPos() - - desc: gets the object's static position ---]]--------------------------------------------------------- -function newobject:GetStaticPos() - - return self.staticx, self.staticy - -end - ---[[--------------------------------------------------------- - - func: GetStaticX() - - desc: gets the object's static x position ---]]--------------------------------------------------------- -function newobject:GetStaticX() - - return self.staticx - -end - ---[[--------------------------------------------------------- - - func: GetStaticY() - - desc: gets the object's static y position ---]]--------------------------------------------------------- -function newobject:GetStaticY() - - return self.staticy - -end - ---[[--------------------------------------------------------- - - func: Center() - - desc: centers the object in the game window or in - it's parent if it has one ---]]--------------------------------------------------------- -function newobject:Center(area) - - local base = loveframes.base - local parent = self.parent - - if parent == base then - local width = love.graphics.getWidth() - local height = love.graphics.getHeight() - - self.x = width/2 - self.width/2 - self.y = height/2 - self.height/2 - else - local width = parent.width - local height = parent.height - - self.staticx = width/2 - self.width/2 - self.staticy = height/2 - self.height/2 - end - -end - ---[[--------------------------------------------------------- - - func: CenterX() - - desc: centers the object by it's x value ---]]--------------------------------------------------------- -function newobject:CenterX() - - local base = loveframes.base - local parent = self.parent - - if parent == base then - local width = love.graphics.getWidth() - self.x = width/2 - self.width/2 - else - local width = parent.width - self.staticx = width/2 - self.width/2 - end - -end - ---[[--------------------------------------------------------- - - func: CenterY() - - desc: centers the object by it's y value ---]]--------------------------------------------------------- -function newobject:CenterY() - - local base = loveframes.base - local parent = self.parent - - if parent == base then - local height = love.graphics.getHeight() - self.y = height/2 - self.height/2 - else - local height = parent.height - self.staticy = height/2 - self.height/2 - end - -end - ---[[--------------------------------------------------------- - - func: CenterWithinArea() - - desc: centers the object within the given area ---]]--------------------------------------------------------- -function newobject:CenterWithinArea(x, y, width, height) - - local selfwidth = self.width - local selfheight = self.height - - self.x = x + width/2 - selfwidth/2 - self.y = y + height/2 - selfheight/2 - -end - ---[[--------------------------------------------------------- - - func: SetSize(width, height) - - desc: sets the object's size ---]]--------------------------------------------------------- -function newobject:SetSize(width, height) - - self.width = width - self.height = height - -end - ---[[--------------------------------------------------------- - - func: SetWidth(width) - - desc: sets the object's width ---]]--------------------------------------------------------- -function newobject:SetWidth(width) - - self.width = width - -end - ---[[--------------------------------------------------------- - - func: SetHeight(height) - - desc: sets the object's height ---]]--------------------------------------------------------- -function newobject:SetHeight(height) - - self.height = height - -end - ---[[--------------------------------------------------------- - - func: GetSize() - - desc: gets the object's size ---]]--------------------------------------------------------- -function newobject:GetSize() - - return self.width, self.height - -end - ---[[--------------------------------------------------------- - - func: GetWidth() - - desc: gets the object's width ---]]--------------------------------------------------------- -function newobject:GetWidth() - - return self.width - -end - ---[[--------------------------------------------------------- - - func: GetHeight() - - desc: gets the object's height ---]]--------------------------------------------------------- -function newobject:GetHeight() - - return self.height - -end - ---[[--------------------------------------------------------- - - func: SetVisible(bool) - - desc: sets the object's visibility ---]]--------------------------------------------------------- -function newobject:SetVisible(bool) - - local children = self.children - local internals = self.internals - - self.visible = bool - - if children then - for k, v in ipairs(children) do - v:SetVisible(bool) - end - end - - if internals then - for k, v in ipairs(internals) do - v:SetVisible(bool) - end - end - -end - ---[[--------------------------------------------------------- - - func: GetVisible() - - desc: gets the object's visibility ---]]--------------------------------------------------------- -function newobject:GetVisible() - - return self.visible - -end - ---[[--------------------------------------------------------- - - func: SetParent(parent) - - desc: sets the object's parent ---]]--------------------------------------------------------- -function newobject:SetParent(parent) - - local tparent = parent - local cparent = self.parent - local ptype = tparent.type - local stype = self.type - - if ptype ~= "frame" and ptype ~= "panel" and ptype ~= "list" then - return - end - - self:Remove() - self.parent = tparent - - table.insert(tparent.children, self) - -end - ---[[--------------------------------------------------------- - - func: GetParent() - - desc: gets the object's parent ---]]--------------------------------------------------------- -function newobject:GetParent() - - local parent = self.parent - return parent - -end - ---[[--------------------------------------------------------- - - func: Remove() - - desc: removes the object ---]]--------------------------------------------------------- -function newobject:Remove() - - local pinternals = self.parent.internals - local pchildren = self.parent.children - - if pinternals then - for k, v in ipairs(pinternals) do - if v == self then - table.remove(pinternals, k) - end - end - end - - if pchildren then - for k, v in ipairs(pchildren) do - if v == self then - table.remove(pchildren, k) - end - end - end - -end - ---[[--------------------------------------------------------- - - func: SetClickBounds(x, y, width, height) - - desc: sets a boundary box for the object's collision - detection ---]]--------------------------------------------------------- -function newobject:SetClickBounds(x, y, width, height) - - local internals = self.internals - local children = self.children - - self.clickbounds = {x = x, y = y, width = width, height = height} - - if internals then - for k, v in ipairs(internals) do - v:SetClickBounds(x, y, width, height) - end - end - - if children then - for k, v in ipairs(children) do - v:SetClickBounds(x, y, width, height) - end - end - -end - ---[[--------------------------------------------------------- - - func: GetClickBounds() - - desc: gets the boundary box for the object's collision - detection ---]]--------------------------------------------------------- -function newobject:GetClickBounds() - - return self.clickbounds - -end - ---[[--------------------------------------------------------- - - func: RemoveClickBounds() - - desc: removes the collision detection boundary for the - object ---]]--------------------------------------------------------- -function newobject:RemoveClickBounds() - - local internals = self.internals - local children = self.children - - self.clickbounds = nil - - if internals then - for k, v in ipairs(internals) do - v:RemoveClickBounds() - end - end - - if children then - for k, v in ipairs(children) do - v:RemoveClickBounds() - end - end - -end - ---[[--------------------------------------------------------- - - func: InClickBounds() - - desc: checks if the mouse is inside the object's - collision detection boundaries ---]]--------------------------------------------------------- -function newobject:InClickBounds() - - local x, y = love.mouse.getPosition() - local bounds = self.clickbounds - - if bounds then - local col = loveframes.util.BoundingBox(x, bounds.x, y, bounds.y, 1, bounds.width, 1, bounds.height) - return col - else - return false - end - -end - ---[[--------------------------------------------------------- - - func: IsTopCollision() - - desc: checks if the object the top most object in a - collision table ---]]--------------------------------------------------------- -function newobject:IsTopCollision() - - local cols = loveframes.util.GetCollisions() - local draworder = self.draworder - local found = false - local top = true - - for k, v in ipairs(cols) do - if v == self then - found = true - end - end - - if not found then - return false - end - - -- loop through the object's parent's children - for k, v in ipairs(cols) do - if v.draworder > draworder then - top = false - end - end - - return top - -end - ---[[--------------------------------------------------------- - - func: GetBaseParent(object, t) - - desc: finds the object's base parent ---]]--------------------------------------------------------- -function newobject:GetBaseParent(t) - - local t = t or {} - local base = loveframes.base - local parent = self.parent - - if parent ~= base then - table.insert(t, parent) - parent:GetBaseParent(t) - end - - return t[#t] - -end - ---[[--------------------------------------------------------- - - func: CheckHover() - - desc: checks to see if the object should be in a - hover state ---]]--------------------------------------------------------- -function newobject:CheckHover() - - local x, y = love.mouse.getPosition() - local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height) - local hoverobject = loveframes.hoverobject - local modalobject = loveframes.modalobject - local clickbounds = self.clickbounds - - -- is the mouse inside the object? - if selfcol then - local top = self:IsTopCollision() - if top then - if not hoverobject then - self.hover = true - else - if hoverobject == self then - self.hover = true - else - self.hover = false - end - end - else - self.hover = false - end - if clickbounds then - if not self:InClickBounds() then - self.hover = false - end - end - else - self.hover = false - end - - if modalobject then - if modalobject ~= self then - local baseparent = self:GetBaseParent() - if baseparent ~= modalobject and self.type ~= "multichoicerow" then - self.hover = false - if self.focus then - self.focus = false - end - end - end - end - - -- this chunk of code handles mouse enter and exit - if self.hover then - if not self.calledmousefunc then - if self.OnMouseEnter then - self.OnMouseEnter(self) - self.calledmousefunc = true - else - self.calledmousefunc = true - end - end - else - if self.calledmousefunc then - if self.OnMouseExit then - self.OnMouseExit(self) - self.calledmousefunc = false - else - self.calledmousefunc = false - end - end - end - -end - ---[[--------------------------------------------------------- - - func: GetHover() - - desc: return if the object is in a hover state or not ---]]--------------------------------------------------------- -function newobject:GetHover() - - return self.hover - -end - ---[[--------------------------------------------------------- - - func: GetChildren() - - desc: returns the object's children ---]]--------------------------------------------------------- -function newobject:GetChildren() - - local children = self.children - - if children then - return children - end - -end - ---[[--------------------------------------------------------- - - func: GetInternals() - - desc: returns the object's internals ---]]--------------------------------------------------------- -function newobject:GetChildren() - - local internals = self.internals - - if internals then - return internals - end - -end - - ---[[--------------------------------------------------------- - - func: IsTopList() - - desc: returns true if the object is the top most list - object or false if not ---]]--------------------------------------------------------- -function newobject:IsTopList() - - local cols = loveframes.util.GetCollisions() - local children = self:GetChildren() - local order = self.draworder - local top = true - local found = false - - local function IsChild(object) - local parents = object:GetParents() - for k, v in ipairs(parents) do - if v == self then - return true - end - end - return false - end - - for k, v in ipairs(cols) do - if v == self then - found = true - else - if v.draworder > order then - if IsChild(v) ~= true then - top = false - break - end - end - end - end - - if found == false then - top = false - end - - return top - -end - ---[[--------------------------------------------------------- - - func: IsTopChild() - - desc: returns true if the object is the top most child - in it's parent's children table or false if not ---]]--------------------------------------------------------- -function newobject:IsTopChild() - - local children = self.parent.children - local num = #children - - if children[num] == self then - return true - else - return false - end - -end - ---[[--------------------------------------------------------- - - func: MoveToTop() - - desc: moves the object to the top of it's parent's - children table ---]]--------------------------------------------------------- -function newobject:MoveToTop() - - local pchildren = self.parent.children - local pinternals = self.parent.internals - - local internal = false - - for k, v in ipairs(pinternals) do - if v == self then - internal = true - end - end - - self:Remove() - - if internal then - table.insert(pinternals, self) - else - table.insert(pchildren, self) - end - -end - ---[[--------------------------------------------------------- - - func: SetSkin(name) - - desc: sets the object's skin ---]]--------------------------------------------------------- -function newobject:SetSkin(name) - - local children = self.children - local internals = self.internals - - self.skin = name - - if children then - for k, v in ipairs(children) do - v:SetSkin(name) - end - end - - if internals then - for k, v in ipairs(internals) do - v:SetSkin(name) - end - end - -end - ---[[--------------------------------------------------------- - - func: GetSkin(name) - - desc: gets the object's skin ---]]--------------------------------------------------------- -function newobject:GetSkin(name) - - return self.skin - -end - ---[[--------------------------------------------------------- - - func: SetAlwaysUpdate(bool) - - desc: sets the object's skin ---]]--------------------------------------------------------- -function newobject:SetAlwaysUpdate(bool) - - self.alwaysupdate = bool - -end - ---[[--------------------------------------------------------- - - func: GetAlwaysUpdate() - - desc: gets whether or not the object will always update ---]]--------------------------------------------------------- -function newobject:GetAlwaysUpdate() - - return self.alwaysupdate - -end - ---[[--------------------------------------------------------- - - func: SetRetainSize(bool) - - desc: sets whether or not the object should retain it's - size when another object tries to resize it ---]]--------------------------------------------------------- -function newobject:SetRetainSize(bool) - - self.retainsize = bool - -end - ---[[--------------------------------------------------------- - - func: GetRetainSize() - - desc: gets whether or not the object should retain it's - size when another object tries to resize it ---]]--------------------------------------------------------- -function newobject:GetRetainSize() - - return self.retainsize - -end - ---[[--------------------------------------------------------- - - func: IsActive() - - desc: gets whether or not the object is active within - it's parent's child table ---]]--------------------------------------------------------- -function newobject:IsActive() - - local parent = self.parent - local pchildren = parent.children - local valid = false - - for k, v in ipairs(pchildren) do - if v == self then - valid = true - end - end - - return valid - -end - ---[[--------------------------------------------------------- - - func: GetParents() - - desc: returns a table of the object's parents and it's - sub-parents ---]]--------------------------------------------------------- -function newobject:GetParents() - - local function GetParents(object, t) - local t = t or {} - local type = object.type - local parent = object.parent - if type ~= "base" then - table.insert(t, parent) - GetParents(parent, t) - end - return t - end - - local parents = GetParents(self) - return parents - -end - ---[[--------------------------------------------------------- - - func: IsTopInternal() - - desc: returns true if the object is the top most - internal in it's parent's internals table or - false if not ---]]--------------------------------------------------------- -function newobject:IsTopInternal() - - local parent = self.parent - local internals = parent.internals - local topitem = internals[#internals] - - if topitem ~= self then - return false - else - return true - end - -end - ---[[--------------------------------------------------------- - - func: IsInternal() - - desc: returns true if the object is internal or - false if not ---]]--------------------------------------------------------- -function newobject:IsInternal() - - return self.internal - -end - ---[[--------------------------------------------------------- - - func: GetType() - - desc: gets the type of the object ---]]--------------------------------------------------------- -function newobject:GetType() - - return self.type - -end - ---[[--------------------------------------------------------- - - func: SetDrawOrder() - - desc: sets the object's draw order ---]]--------------------------------------------------------- -function newobject:SetDrawOrder() - - loveframes.drawcount = loveframes.drawcount + 1 - self.draworder = loveframes.drawcount - -end - ---[[--------------------------------------------------------- - - func: GetDrawOrder() - - desc: sets the object's draw order ---]]--------------------------------------------------------- -function newobject:GetDrawOrder() - - return self.draworder - -end - ---[[--------------------------------------------------------- - - func: SetProperty(name, value) - - desc: sets a property on the object ---]]--------------------------------------------------------- -function newobject:SetProperty(name, value) - - self[name] = value - -end - ---[[--------------------------------------------------------- - - func: GetProperty(name) - - desc: gets the value of an object's property ---]]--------------------------------------------------------- -function newobject:GetProperty(name) - - return self[name] - -end - ---[[--------------------------------------------------------- - - func: IsInList() - - desc: checks to see if an object is in a list ---]]--------------------------------------------------------- -function newobject:IsInList() - - local parents = self:GetParents() - - for k, v in ipairs(parents) do - if v.type == "list" then - return true, v - end - end - - return false, false - -end \ No newline at end of file +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- base object +local newobject = loveframes.NewObject("base", "loveframes_object_base") + +--[[--------------------------------------------------------- + - func: initialize() + - desc: intializes the element +--]]--------------------------------------------------------- +function newobject:initialize() + + -- width and height of the window + local w = love.graphics.getWidth() + local h = love.graphics.getHeight() + + self.type = "base" + self.width = w + self.height = h + self.internal = true + self.children = {} + self.internals = {} + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local children = self.children + + for k, v in ipairs(children) do + v:update(dt) + end + + for k, v in ipairs(self.internals) do + v:update(dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local children = self.children + + -- set the object's draw order + self:SetDrawOrder() + + for k, v in ipairs(children) do + v:draw() + end + + for k, v in ipairs(self.internals) do + v:draw() + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local children = self.children + local internals = self.internals + + if not visible then + return + end + + if children then + for k, v in ipairs(children) do + v:mousepressed(x, y, button) + end + end + + if internals then + for k, v in ipairs(internals) do + v:mousepressed(x, y, button) + end + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local children = self.children + local internals = self.internals + + if not visible then + return + end + + if children then + for k, v in ipairs(children) do + v:mousereleased(x, y, button) + end + end + + if internals then + for k, v in ipairs(internals) do + v:mousereleased(x, y, button) + end + end + +end + +--[[--------------------------------------------------------- + - func: keypressed(key) + - desc: called when the player presses a key +--]]--------------------------------------------------------- +function newobject:keypressed(key, unicode) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local children = self.children + local internals = self.internals + + if not visible then + return + end + + if children then + for k, v in ipairs(children) do + v:keypressed(key, unicode) + end + end + + if internals then + for k, v in ipairs(internals) do + v:keypressed(key, unicode) + end + end + +end + +--[[--------------------------------------------------------- + - func: keyreleased(key) + - desc: called when the player releases a key +--]]--------------------------------------------------------- +function newobject:keyreleased(key) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local children = self.children + local internals = self.internals + + if not visible then + return + end + + if children then + for k, v in ipairs(children) do + v:keyreleased(key) + end + end + + if internals then + for k, v in ipairs(internals) do + v:keyreleased(key) + end + end + +end + + + +--[[--------------------------------------------------------- + - func: SetPos(x, y) + - desc: sets the object's position +--]]--------------------------------------------------------- +function newobject:SetPos(x, y) + + local base = loveframes.base + local parent = self.parent + + if parent == base then + self.x = x + self.y = y + else + self.staticx = x + self.staticy = y + end + +end + +--[[--------------------------------------------------------- + - func: SetX(x) + - desc: sets the object's x position +--]]--------------------------------------------------------- +function newobject:SetX(x) + + local base = loveframes.base + local parent = self.parent + + if parent == base then + self.x = x + else + self.staticx = x + end + +end + +--[[--------------------------------------------------------- + - func: SetY(y) + - desc: sets the object's y position +--]]--------------------------------------------------------- +function newobject:SetY(y) + + local base = loveframes.base + local parent = self.parent + + if parent == base then + self.y = y + else + self.staticy = y + end + +end + +--[[--------------------------------------------------------- + - func: GetPos() + - desc: gets the object's position +--]]--------------------------------------------------------- +function newobject:GetPos() + + return self.x, self.y + +end + +--[[--------------------------------------------------------- + - func: GetX() + - desc: gets the object's x position +--]]--------------------------------------------------------- +function newobject:GetX() + + return self.x + +end + +--[[--------------------------------------------------------- + - func: GetY() + - desc: gets the object's y position +--]]--------------------------------------------------------- +function newobject:GetY() + + return self.y + +end + +--[[--------------------------------------------------------- + - func: GetStaticPos() + - desc: gets the object's static position +--]]--------------------------------------------------------- +function newobject:GetStaticPos() + + return self.staticx, self.staticy + +end + +--[[--------------------------------------------------------- + - func: GetStaticX() + - desc: gets the object's static x position +--]]--------------------------------------------------------- +function newobject:GetStaticX() + + return self.staticx + +end + +--[[--------------------------------------------------------- + - func: GetStaticY() + - desc: gets the object's static y position +--]]--------------------------------------------------------- +function newobject:GetStaticY() + + return self.staticy + +end + +--[[--------------------------------------------------------- + - func: Center() + - desc: centers the object in the game window or in + it's parent if it has one +--]]--------------------------------------------------------- +function newobject:Center(area) + + local base = loveframes.base + local parent = self.parent + + if parent == base then + local width = love.graphics.getWidth() + local height = love.graphics.getHeight() + + self.x = width/2 - self.width/2 + self.y = height/2 - self.height/2 + else + local width = parent.width + local height = parent.height + + self.staticx = width/2 - self.width/2 + self.staticy = height/2 - self.height/2 + end + +end + +--[[--------------------------------------------------------- + - func: CenterX() + - desc: centers the object by it's x value +--]]--------------------------------------------------------- +function newobject:CenterX() + + local base = loveframes.base + local parent = self.parent + + if parent == base then + local width = love.graphics.getWidth() + self.x = width/2 - self.width/2 + else + local width = parent.width + self.staticx = width/2 - self.width/2 + end + +end + +--[[--------------------------------------------------------- + - func: CenterY() + - desc: centers the object by it's y value +--]]--------------------------------------------------------- +function newobject:CenterY() + + local base = loveframes.base + local parent = self.parent + + if parent == base then + local height = love.graphics.getHeight() + self.y = height/2 - self.height/2 + else + local height = parent.height + self.staticy = height/2 - self.height/2 + end + +end + +--[[--------------------------------------------------------- + - func: CenterWithinArea() + - desc: centers the object within the given area +--]]--------------------------------------------------------- +function newobject:CenterWithinArea(x, y, width, height) + + local selfwidth = self.width + local selfheight = self.height + + self.x = x + width/2 - selfwidth/2 + self.y = y + height/2 - selfheight/2 + +end + +--[[--------------------------------------------------------- + - func: SetSize(width, height) + - desc: sets the object's size +--]]--------------------------------------------------------- +function newobject:SetSize(width, height) + + self.width = width + self.height = height + +end + +--[[--------------------------------------------------------- + - func: SetWidth(width) + - desc: sets the object's width +--]]--------------------------------------------------------- +function newobject:SetWidth(width) + + self.width = width + +end + +--[[--------------------------------------------------------- + - func: SetHeight(height) + - desc: sets the object's height +--]]--------------------------------------------------------- +function newobject:SetHeight(height) + + self.height = height + +end + +--[[--------------------------------------------------------- + - func: GetSize() + - desc: gets the object's size +--]]--------------------------------------------------------- +function newobject:GetSize() + + return self.width, self.height + +end + +--[[--------------------------------------------------------- + - func: GetWidth() + - desc: gets the object's width +--]]--------------------------------------------------------- +function newobject:GetWidth() + + return self.width + +end + +--[[--------------------------------------------------------- + - func: GetHeight() + - desc: gets the object's height +--]]--------------------------------------------------------- +function newobject:GetHeight() + + return self.height + +end + +--[[--------------------------------------------------------- + - func: SetVisible(bool) + - desc: sets the object's visibility +--]]--------------------------------------------------------- +function newobject:SetVisible(bool) + + local children = self.children + local internals = self.internals + + self.visible = bool + + if children then + for k, v in ipairs(children) do + v:SetVisible(bool) + end + end + + if internals then + for k, v in ipairs(internals) do + v:SetVisible(bool) + end + end + +end + +--[[--------------------------------------------------------- + - func: GetVisible() + - desc: gets the object's visibility +--]]--------------------------------------------------------- +function newobject:GetVisible() + + return self.visible + +end + +--[[--------------------------------------------------------- + - func: SetParent(parent) + - desc: sets the object's parent +--]]--------------------------------------------------------- +function newobject:SetParent(parent) + + local tparent = parent + local cparent = self.parent + local ptype = tparent.type + local stype = self.type + + if ptype ~= "frame" and ptype ~= "panel" and ptype ~= "list" then + return + end + + self:Remove() + self.parent = tparent + self:SetState(tparent.state) + + table.insert(tparent.children, self) + +end + +--[[--------------------------------------------------------- + - func: GetParent() + - desc: gets the object's parent +--]]--------------------------------------------------------- +function newobject:GetParent() + + local parent = self.parent + return parent + +end + +--[[--------------------------------------------------------- + - func: Remove() + - desc: removes the object +--]]--------------------------------------------------------- +function newobject:Remove() + + local pinternals = self.parent.internals + local pchildren = self.parent.children + + if pinternals then + for k, v in ipairs(pinternals) do + if v == self then + table.remove(pinternals, k) + end + end + end + + if pchildren then + for k, v in ipairs(pchildren) do + if v == self then + table.remove(pchildren, k) + end + end + end + +end + +--[[--------------------------------------------------------- + - func: SetClickBounds(x, y, width, height) + - desc: sets a boundary box for the object's collision + detection +--]]--------------------------------------------------------- +function newobject:SetClickBounds(x, y, width, height) + + local internals = self.internals + local children = self.children + + self.clickbounds = {x = x, y = y, width = width, height = height} + + if internals then + for k, v in ipairs(internals) do + v:SetClickBounds(x, y, width, height) + end + end + + if children then + for k, v in ipairs(children) do + v:SetClickBounds(x, y, width, height) + end + end + +end + +--[[--------------------------------------------------------- + - func: GetClickBounds() + - desc: gets the boundary box for the object's collision + detection +--]]--------------------------------------------------------- +function newobject:GetClickBounds() + + return self.clickbounds + +end + +--[[--------------------------------------------------------- + - func: RemoveClickBounds() + - desc: removes the collision detection boundary for the + object +--]]--------------------------------------------------------- +function newobject:RemoveClickBounds() + + local internals = self.internals + local children = self.children + + self.clickbounds = nil + + if internals then + for k, v in ipairs(internals) do + v:RemoveClickBounds() + end + end + + if children then + for k, v in ipairs(children) do + v:RemoveClickBounds() + end + end + +end + +--[[--------------------------------------------------------- + - func: InClickBounds() + - desc: checks if the mouse is inside the object's + collision detection boundaries +--]]--------------------------------------------------------- +function newobject:InClickBounds() + + local x, y = love.mouse.getPosition() + local bounds = self.clickbounds + + if bounds then + local col = loveframes.util.BoundingBox(x, bounds.x, y, bounds.y, 1, bounds.width, 1, bounds.height) + return col + else + return false + end + +end + +--[[--------------------------------------------------------- + - func: IsTopCollision() + - desc: checks if the object the top most object in a + collision table +--]]--------------------------------------------------------- +function newobject:IsTopCollision() + + local cols = loveframes.util.GetCollisions() + local draworder = self.draworder + local found = false + local top = true + + for k, v in ipairs(cols) do + if v == self then + found = true + end + end + + if not found then + return false + end + + -- loop through the object's parent's children + for k, v in ipairs(cols) do + if v.draworder > draworder then + top = false + end + end + + return top + +end + +--[[--------------------------------------------------------- + - func: GetBaseParent(object, t) + - desc: finds the object's base parent +--]]--------------------------------------------------------- +function newobject:GetBaseParent(t) + + local t = t or {} + local base = loveframes.base + local parent = self.parent + + if parent ~= base then + table.insert(t, parent) + parent:GetBaseParent(t) + end + + return t[#t] + +end + +--[[--------------------------------------------------------- + - func: CheckHover() + - desc: checks to see if the object should be in a + hover state +--]]--------------------------------------------------------- +function newobject:CheckHover() + + local x, y = love.mouse.getPosition() + local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height) + local hoverobject = loveframes.hoverobject + local modalobject = loveframes.modalobject + local clickbounds = self.clickbounds + + -- is the mouse inside the object? + if selfcol then + local top = self:IsTopCollision() + if top then + if not hoverobject then + self.hover = true + else + if hoverobject == self then + self.hover = true + else + self.hover = false + end + end + else + self.hover = false + end + if clickbounds then + if not self:InClickBounds() then + self.hover = false + end + end + else + self.hover = false + end + + if modalobject then + if modalobject ~= self then + local baseparent = self:GetBaseParent() + if baseparent ~= modalobject and self.type ~= "multichoicerow" then + self.hover = false + if self.focus then + self.focus = false + end + end + end + end + + -- this chunk of code handles mouse enter and exit + if self.hover then + if not self.calledmousefunc then + if self.OnMouseEnter then + self.OnMouseEnter(self) + self.calledmousefunc = true + else + self.calledmousefunc = true + end + end + else + if self.calledmousefunc then + if self.OnMouseExit then + self.OnMouseExit(self) + self.calledmousefunc = false + else + self.calledmousefunc = false + end + end + end + +end + +--[[--------------------------------------------------------- + - func: GetHover() + - desc: return if the object is in a hover state or not +--]]--------------------------------------------------------- +function newobject:GetHover() + + return self.hover + +end + +--[[--------------------------------------------------------- + - func: GetChildren() + - desc: returns the object's children +--]]--------------------------------------------------------- +function newobject:GetChildren() + + local children = self.children + + if children then + return children + end + +end + +--[[--------------------------------------------------------- + - func: GetInternals() + - desc: returns the object's internals +--]]--------------------------------------------------------- +function newobject:GetChildren() + + local internals = self.internals + + if internals then + return internals + end + +end + + +--[[--------------------------------------------------------- + - func: IsTopList() + - desc: returns true if the object is the top most list + object or false if not +--]]--------------------------------------------------------- +function newobject:IsTopList() + + local cols = loveframes.util.GetCollisions() + local children = self:GetChildren() + local order = self.draworder + local top = true + local found = false + + local function IsChild(object) + local parents = object:GetParents() + for k, v in ipairs(parents) do + if v == self then + return true + end + end + return false + end + + for k, v in ipairs(cols) do + if v == self then + found = true + else + if v.draworder > order then + if IsChild(v) ~= true then + top = false + break + end + end + end + end + + if found == false then + top = false + end + + return top + +end + +--[[--------------------------------------------------------- + - func: IsTopChild() + - desc: returns true if the object is the top most child + in it's parent's children table or false if not +--]]--------------------------------------------------------- +function newobject:IsTopChild() + + local children = self.parent.children + local num = #children + + if children[num] == self then + return true + else + return false + end + +end + +--[[--------------------------------------------------------- + - func: MoveToTop() + - desc: moves the object to the top of it's parent's + children table +--]]--------------------------------------------------------- +function newobject:MoveToTop() + + local pchildren = self.parent.children + local pinternals = self.parent.internals + + local internal = false + + for k, v in ipairs(pinternals) do + if v == self then + internal = true + end + end + + self:Remove() + + if internal then + table.insert(pinternals, self) + else + table.insert(pchildren, self) + end + +end + +--[[--------------------------------------------------------- + - func: SetSkin(name) + - desc: sets the object's skin +--]]--------------------------------------------------------- +function newobject:SetSkin(name) + + local children = self.children + local internals = self.internals + + self.skin = name + + if children then + for k, v in ipairs(children) do + v:SetSkin(name) + end + end + + if internals then + for k, v in ipairs(internals) do + v:SetSkin(name) + end + end + +end + +--[[--------------------------------------------------------- + - func: GetSkin(name) + - desc: gets the object's skin +--]]--------------------------------------------------------- +function newobject:GetSkin(name) + + return self.skin + +end + +--[[--------------------------------------------------------- + - func: SetAlwaysUpdate(bool) + - desc: sets the object's skin +--]]--------------------------------------------------------- +function newobject:SetAlwaysUpdate(bool) + + self.alwaysupdate = bool + +end + +--[[--------------------------------------------------------- + - func: GetAlwaysUpdate() + - desc: gets whether or not the object will always update +--]]--------------------------------------------------------- +function newobject:GetAlwaysUpdate() + + return self.alwaysupdate + +end + +--[[--------------------------------------------------------- + - func: SetRetainSize(bool) + - desc: sets whether or not the object should retain it's + size when another object tries to resize it +--]]--------------------------------------------------------- +function newobject:SetRetainSize(bool) + + self.retainsize = bool + +end + +--[[--------------------------------------------------------- + - func: GetRetainSize() + - desc: gets whether or not the object should retain it's + size when another object tries to resize it +--]]--------------------------------------------------------- +function newobject:GetRetainSize() + + return self.retainsize + +end + +--[[--------------------------------------------------------- + - func: IsActive() + - desc: gets whether or not the object is active within + it's parent's child table +--]]--------------------------------------------------------- +function newobject:IsActive() + + local parent = self.parent + local pchildren = parent.children + local valid = false + + for k, v in ipairs(pchildren) do + if v == self then + valid = true + end + end + + return valid + +end + +--[[--------------------------------------------------------- + - func: GetParents() + - desc: returns a table of the object's parents and it's + sub-parents +--]]--------------------------------------------------------- +function newobject:GetParents() + + local function GetParents(object, t) + local t = t or {} + local type = object.type + local parent = object.parent + if type ~= "base" then + table.insert(t, parent) + GetParents(parent, t) + end + return t + end + + local parents = GetParents(self) + return parents + +end + +--[[--------------------------------------------------------- + - func: IsTopInternal() + - desc: returns true if the object is the top most + internal in it's parent's internals table or + false if not +--]]--------------------------------------------------------- +function newobject:IsTopInternal() + + local parent = self.parent + local internals = parent.internals + local topitem = internals[#internals] + + if topitem ~= self then + return false + else + return true + end + +end + +--[[--------------------------------------------------------- + - func: IsInternal() + - desc: returns true if the object is internal or + false if not +--]]--------------------------------------------------------- +function newobject:IsInternal() + + return self.internal + +end + +--[[--------------------------------------------------------- + - func: GetType() + - desc: gets the type of the object +--]]--------------------------------------------------------- +function newobject:GetType() + + return self.type + +end + +--[[--------------------------------------------------------- + - func: SetDrawOrder() + - desc: sets the object's draw order +--]]--------------------------------------------------------- +function newobject:SetDrawOrder() + + loveframes.drawcount = loveframes.drawcount + 1 + self.draworder = loveframes.drawcount + +end + +--[[--------------------------------------------------------- + - func: GetDrawOrder() + - desc: sets the object's draw order +--]]--------------------------------------------------------- +function newobject:GetDrawOrder() + + return self.draworder + +end + +--[[--------------------------------------------------------- + - func: SetProperty(name, value) + - desc: sets a property on the object +--]]--------------------------------------------------------- +function newobject:SetProperty(name, value) + + self[name] = value + +end + +--[[--------------------------------------------------------- + - func: GetProperty(name) + - desc: gets the value of an object's property +--]]--------------------------------------------------------- +function newobject:GetProperty(name) + + return self[name] + +end + +--[[--------------------------------------------------------- + - func: IsInList() + - desc: checks to see if an object is in a list +--]]--------------------------------------------------------- +function newobject:IsInList() + + local parents = self:GetParents() + + for k, v in ipairs(parents) do + if v.type == "list" then + return true, v + end + end + + return false, false + +end + +--[[--------------------------------------------------------- + - func: SetState(name) + - desc: sets the object's state +--]]--------------------------------------------------------- +function newobject:SetState(name) + + local children = self.children + local internals = self.internals + + self.state = name + + if children then + for k, v in ipairs(children) do + v:SetState(name) + end + end + + if internals then + for k, v in ipairs(internals) do + v:SetState(name) + end + end + +end + +--[[--------------------------------------------------------- + - func: GetState() + - desc: gets the object's state +--]]--------------------------------------------------------- +function newobject:GetState() + + return self.state + +end diff --git a/objects/button.lua b/objects/button.lua index aa22c69..cd006f8 100644 --- a/objects/button.lua +++ b/objects/button.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- button class @@ -30,6 +30,13 @@ end --]]--------------------------------------------------------- function newobject:update(dt) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible local alwaysupdate = self.alwaysupdate @@ -77,6 +84,13 @@ end --]]--------------------------------------------------------- function newobject:draw() + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -109,6 +123,13 @@ end --]]--------------------------------------------------------- function newobject:mousepressed(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -134,6 +155,13 @@ end --]]--------------------------------------------------------- function newobject:mousereleased(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -158,27 +186,6 @@ function newobject:mousereleased(x, y, button) end ---[[--------------------------------------------------------- - - func: keypressed(key) - - desc: called when the player presses a key ---]]--------------------------------------------------------- -function newobject:keypressed(key, unicode) - - local visible = self.visible - - if not visible then - return - end - - local selectedobject = loveframes.selectedobject - local onclick = self.OnClick - - if key == "return" and selectedobject == self then - onclick(self, 0, 0) - end - -end - --[[--------------------------------------------------------- - func: SetText(text) - desc: sets the object's text diff --git a/objects/checkbox.lua b/objects/checkbox.lua index 19fcd89..7f1c574 100644 --- a/objects/checkbox.lua +++ b/objects/checkbox.lua @@ -1,375 +1,380 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- checkbox class -local newobject = loveframes.NewObject("checkbox", "loveframes_object_checkbox", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize() - - self.type = "checkbox" - self.width = 0 - self.height = 0 - self.boxwidth = 20 - self.boxheight = 20 - self.font = loveframes.basicfont - self.checked = false - self.lastvalue = false - self.internal = false - self.down = true - self.internals = {} - self.OnChanged = nil - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - self:CheckHover() - - local hover = self.hover - local internals = self.internals - local boxwidth = self.boxwidth - local boxheight = self.boxheight - local parent = self.parent - local base = loveframes.base - local update = self.Update - - if not hover then - self.down = false - else - if loveframes.hoverobject == self then - self.down = true - end - end - - if not self.down and loveframes.hoverobject == self then - self.hover = true - end - - -- move to parent if there is a parent - if parent ~= base and parent.type ~= "list" then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - if internals[1] then - self.width = boxwidth + 5 + internals[1].width - if internals[1].height == boxheight then - self.height = boxheight - else - if internals[1].height > boxheight then - self.height = internals[1].height - else - self.height = boxheight - end - end - else - self.width = boxwidth - self.height = boxheight - end - - for k, v in ipairs(internals) do - v:update(dt) - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawCheckBox or skins[defaultskin].DrawCheckBox - local draw = self.Draw - local internals = self.internals - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - - for k, v in ipairs(internals) do - v:draw() - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - - if hover and button == "l" then - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - self.down = true - loveframes.hoverobject = self - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - local checked = self.checked - local onchanged = self.OnChanged - - if hover and button == "l" then - if checked then - self.checked = false - else - self.checked = true - end - if onchanged then - onchanged(self) - end - end - -end - ---[[--------------------------------------------------------- - - func: keypressed(key) - - desc: called when the player presses a key ---]]--------------------------------------------------------- -function newobject:keypressed(key, unicode) - - local checked = self.checked - local onchanged = self.OnChanged - local selectedobject = loveframes.selectedobject - - if key == "return" and selectedobject == self then - if checked then - self.checked = false - else - self.checked = true - end - if onchanged then - onchanged(self) - end - end - -end - ---[[--------------------------------------------------------- - - func: SetText(text) - - desc: sets the object's text ---]]--------------------------------------------------------- -function newobject:SetText(text) - - local boxwidth = self.boxwidth - local boxheight = self.boxheight - - if text ~= "" then - self.internals = {} - local textobject = loveframes.Create("text") - textobject:Remove() - textobject.parent = self - textobject.collide = false - textobject:SetFont(self.font) - textobject:SetText(text) - textobject.Update = function(object, dt) - if object.height > boxheight then - object:SetPos(boxwidth + 5, 0) - else - object:SetPos(boxwidth + 5, boxheight/2 - object.height/2) - end - end - table.insert(self.internals, textobject) - else - self.width = boxwidth - self.height = boxheight - self.internals = {} - end - -end - ---[[--------------------------------------------------------- - - func: GetText() - - desc: gets the object's text ---]]--------------------------------------------------------- -function newobject:GetText() - - local internals = self.internals - local text = internals[1] - - if text then - return text.text - else - return false - end - -end - ---[[--------------------------------------------------------- - - func: SetSize(width, height) - - desc: sets the object's size ---]]--------------------------------------------------------- -function newobject:SetSize(width, height) - - self.boxwidth = width - self.boxheight = height - -end - ---[[--------------------------------------------------------- - - func: SetWidth(width) - - desc: sets the object's width ---]]--------------------------------------------------------- -function newobject:SetWidth(width) - - self.boxwidth = width - -end - ---[[--------------------------------------------------------- - - func: SetHeight(height) - - desc: sets the object's height ---]]--------------------------------------------------------- -function newobject:SetHeight(height) - - self.boxheight = height - -end - ---[[--------------------------------------------------------- - - func: SetChecked(bool) - - desc: sets whether the object is checked or not ---]]--------------------------------------------------------- -function newobject:SetChecked(bool) - - local onchanged = self.OnChanged - - self.checked = bool - - if onchanged then - onchanged(self) - end - -end - ---[[--------------------------------------------------------- - - func: GetChecked() - - desc: gets whether the object is checked or not ---]]--------------------------------------------------------- -function newobject:GetChecked() - - return self.checked - -end - ---[[--------------------------------------------------------- - - func: SetFont(font) - - desc: sets the font of the object's text ---]]--------------------------------------------------------- -function newobject:SetFont(font) - - local internals = self.internals - local text = internals[1] - - self.font = font - - if text then - text:SetFont(font) - end - -end - ---[[--------------------------------------------------------- - - func: newobject:GetFont() - - desc: gets the font of the object's text ---]]--------------------------------------------------------- -function newobject:GetFont() - - return self.font - -end - ---[[--------------------------------------------------------- - - func: newobject:GetBoxHeight() - - desc: gets the object's box size ---]]--------------------------------------------------------- -function newobject:GetBoxSize() - - return self.boxwidth, self.boxheight - -end - ---[[--------------------------------------------------------- - - func: newobject:GetBoxWidth() - - desc: gets the object's box width ---]]--------------------------------------------------------- -function newobject:GetBoxWidth() - - return self.boxwidth - -end - ---[[--------------------------------------------------------- - - func: newobject:GetBoxHeight() - - desc: gets the object's box height ---]]--------------------------------------------------------- -function newobject:GetBoxHeight() - - return self.boxheight - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- checkbox class +local newobject = loveframes.NewObject("checkbox", "loveframes_object_checkbox", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "checkbox" + self.width = 0 + self.height = 0 + self.boxwidth = 20 + self.boxheight = 20 + self.font = loveframes.basicfont + self.checked = false + self.lastvalue = false + self.internal = false + self.down = true + self.internals = {} + self.OnChanged = nil + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + self:CheckHover() + + local hover = self.hover + local internals = self.internals + local boxwidth = self.boxwidth + local boxheight = self.boxheight + local parent = self.parent + local base = loveframes.base + local update = self.Update + + if not hover then + self.down = false + else + if loveframes.hoverobject == self then + self.down = true + end + end + + if not self.down and loveframes.hoverobject == self then + self.hover = true + end + + -- move to parent if there is a parent + if parent ~= base and parent.type ~= "list" then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + if internals[1] then + self.width = boxwidth + 5 + internals[1].width + if internals[1].height == boxheight then + self.height = boxheight + else + if internals[1].height > boxheight then + self.height = internals[1].height + else + self.height = boxheight + end + end + else + self.width = boxwidth + self.height = boxheight + end + + for k, v in ipairs(internals) do + v:update(dt) + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawCheckBox or skins[defaultskin].DrawCheckBox + local draw = self.Draw + local internals = self.internals + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + + for k, v in ipairs(internals) do + v:draw() + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + self.down = true + loveframes.hoverobject = self + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + local checked = self.checked + local onchanged = self.OnChanged + + if hover and button == "l" then + if checked then + self.checked = false + else + self.checked = true + end + if onchanged then + onchanged(self) + end + end + +end + +--[[--------------------------------------------------------- + - func: SetText(text) + - desc: sets the object's text +--]]--------------------------------------------------------- +function newobject:SetText(text) + + local boxwidth = self.boxwidth + local boxheight = self.boxheight + + if text ~= "" then + self.internals = {} + local textobject = loveframes.Create("text") + textobject:Remove() + textobject.parent = self + textobject.collide = false + textobject:SetFont(self.font) + textobject:SetText(text) + textobject.Update = function(object, dt) + if object.height > boxheight then + object:SetPos(boxwidth + 5, 0) + else + object:SetPos(boxwidth + 5, boxheight/2 - object.height/2) + end + end + table.insert(self.internals, textobject) + else + self.width = boxwidth + self.height = boxheight + self.internals = {} + end + +end + +--[[--------------------------------------------------------- + - func: GetText() + - desc: gets the object's text +--]]--------------------------------------------------------- +function newobject:GetText() + + local internals = self.internals + local text = internals[1] + + if text then + return text.text + else + return false + end + +end + +--[[--------------------------------------------------------- + - func: SetSize(width, height) + - desc: sets the object's size +--]]--------------------------------------------------------- +function newobject:SetSize(width, height) + + self.boxwidth = width + self.boxheight = height + +end + +--[[--------------------------------------------------------- + - func: SetWidth(width) + - desc: sets the object's width +--]]--------------------------------------------------------- +function newobject:SetWidth(width) + + self.boxwidth = width + +end + +--[[--------------------------------------------------------- + - func: SetHeight(height) + - desc: sets the object's height +--]]--------------------------------------------------------- +function newobject:SetHeight(height) + + self.boxheight = height + +end + +--[[--------------------------------------------------------- + - func: SetChecked(bool) + - desc: sets whether the object is checked or not +--]]--------------------------------------------------------- +function newobject:SetChecked(bool) + + local onchanged = self.OnChanged + + self.checked = bool + + if onchanged then + onchanged(self) + end + +end + +--[[--------------------------------------------------------- + - func: GetChecked() + - desc: gets whether the object is checked or not +--]]--------------------------------------------------------- +function newobject:GetChecked() + + return self.checked + +end + +--[[--------------------------------------------------------- + - func: SetFont(font) + - desc: sets the font of the object's text +--]]--------------------------------------------------------- +function newobject:SetFont(font) + + local internals = self.internals + local text = internals[1] + + self.font = font + + if text then + text:SetFont(font) + end + +end + +--[[--------------------------------------------------------- + - func: newobject:GetFont() + - desc: gets the font of the object's text +--]]--------------------------------------------------------- +function newobject:GetFont() + + return self.font + +end + +--[[--------------------------------------------------------- + - func: newobject:GetBoxHeight() + - desc: gets the object's box size +--]]--------------------------------------------------------- +function newobject:GetBoxSize() + + return self.boxwidth, self.boxheight + +end + +--[[--------------------------------------------------------- + - func: newobject:GetBoxWidth() + - desc: gets the object's box width +--]]--------------------------------------------------------- +function newobject:GetBoxWidth() + + return self.boxwidth + +end + +--[[--------------------------------------------------------- + - func: newobject:GetBoxHeight() + - desc: gets the object's box height +--]]--------------------------------------------------------- +function newobject:GetBoxHeight() + + return self.boxheight + end \ No newline at end of file diff --git a/objects/collapsiblecategory.lua b/objects/collapsiblecategory.lua index 1c171a7..ddf9d9e 100644 --- a/objects/collapsiblecategory.lua +++ b/objects/collapsiblecategory.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- collapsiblecategory class @@ -32,6 +32,13 @@ end --]]--------------------------------------------------------- function newobject:update(dt) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible local alwaysupdate = self.alwaysupdate @@ -73,6 +80,13 @@ end --]]--------------------------------------------------------- function newobject:draw() + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -112,6 +126,13 @@ end --]]--------------------------------------------------------- function newobject:mousepressed(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -147,6 +168,13 @@ end --]]--------------------------------------------------------- function newobject:mousereleased(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -213,6 +241,7 @@ function newobject:SetObject(object) object:Remove() object.parent = self + object:SetState(self.state) object:SetWidth(self.width - self.padding*2) object:SetPos(self.padding, self.closedheight + self.padding) table.insert(self.children, object) diff --git a/objects/columnlist.lua b/objects/columnlist.lua index ce6e502..25c86fe 100644 --- a/objects/columnlist.lua +++ b/objects/columnlist.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- columnlist class @@ -16,9 +16,10 @@ function newobject:initialize() self.width = 300 self.height = 100 self.columnheight = 16 - self.buttonscrollamount = 0.10 - self.mousewheelscrollamount = 5 + self.buttonscrollamount = 200 + self.mousewheelscrollamount = 1000 self.autoscroll = false + self.dtscrolling = true self.internal = false self.children = {} self.internals = {} @@ -36,6 +37,13 @@ end --]]--------------------------------------------------------- function newobject:update(dt) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible local alwaysupdate = self.alwaysupdate @@ -79,6 +87,13 @@ end --]]--------------------------------------------------------- function newobject:draw() + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -121,9 +136,16 @@ end --]]--------------------------------------------------------- function newobject:mousepressed(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible - if visible == false then + if not visible then return end @@ -131,7 +153,7 @@ function newobject:mousepressed(x, y, button) local children = self.children local internals = self.internals - if hover == true and button == "l" then + if hover and button == "l" then local baseparent = self:GetBaseParent() if baseparent and baseparent.type == "frame" then baseparent:MakeTop() @@ -154,9 +176,16 @@ end --]]--------------------------------------------------------- function newobject:mousereleased(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible - if visible == false then + if not visible then return end @@ -192,7 +221,7 @@ function newobject:AdjustColumns() local x = 0 for k, v in ipairs(children) do - if bar == true then + if bar then v:SetWidth(columnwidth) else v:SetWidth(columnwidth) @@ -417,4 +446,27 @@ function newobject:SetColumnHeight(height) list:CalculateSize() list:RedoLayout() +end + +--[[--------------------------------------------------------- + - func: SetDTScrolling(bool) + - desc: sets whether or not the object should use delta + time when scrolling +--]]--------------------------------------------------------- +function newobject:SetDTScrolling(bool) + + self.dtscrolling = bool + self.internals[1].dtscrolling = bool + +end + +--[[--------------------------------------------------------- + - func: GetDTScrolling() + - desc: gets whether or not the object should use delta + time when scrolling +--]]--------------------------------------------------------- +function newobject:GetDTScrolling() + + return self.dtscrolling + end \ No newline at end of file diff --git a/objects/frame.lua b/objects/frame.lua index 031a570..54d9b8f 100644 --- a/objects/frame.lua +++ b/objects/frame.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- frame class @@ -51,6 +51,13 @@ end --]]--------------------------------------------------------- function newobject:update(dt) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible local alwaysupdate = self.alwaysupdate @@ -173,6 +180,13 @@ end --]]--------------------------------------------------------- function newobject:draw() + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -215,7 +229,14 @@ end - desc: called when the player presses a mouse button --]]--------------------------------------------------------- function newobject:mousepressed(x, y, button) - + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -267,6 +288,13 @@ end --]]--------------------------------------------------------- function newobject:mousereleased(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then diff --git a/objects/image.lua b/objects/image.lua index 37b8c5d..0aedc38 100644 --- a/objects/image.lua +++ b/objects/image.lua @@ -1,342 +1,398 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- progressbar class -local newobject = loveframes.NewObject("image", "loveframes_object_image", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize() - - self.type = "image" - self.width = 0 - self.height = 0 - self.orientation = 0 - self.scalex = 1 - self.scaley = 1 - self.offsetx = 0 - self.offsety = 0 - self.shearx = 0 - self.sheary = 0 - self.internal = false - self.image = nil - self.imagecolor = nil - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local parent = self.parent - local base = loveframes.base - local update = self.Update - - -- move to parent if there is a parent - if parent ~= base then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawImage or skins[defaultskin].DrawImage - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - -end - ---[[--------------------------------------------------------- - - func: SetImage(image) - - desc: sets the object's image ---]]--------------------------------------------------------- -function newobject:SetImage(image) - - if type(image) == "string" then - self.image = love.graphics.newImage(image) - else - self.image = image - end - - self.width = self.image:getWidth() - self.height = self.image:getHeight() - -end - ---[[--------------------------------------------------------- - - func: GetImage() - - desc: gets the object's image ---]]--------------------------------------------------------- -function newobject:GetImage() - - return self.image - -end - ---[[--------------------------------------------------------- - - func: SetColor(table) - - desc: sets the object's color ---]]--------------------------------------------------------- -function newobject:SetColor(data) - - self.imagecolor = data - -end - ---[[--------------------------------------------------------- - - func: GetColor() - - desc: gets the object's color ---]]--------------------------------------------------------- -function newobject:GetColor() - - return self.imagecolor - -end - ---[[--------------------------------------------------------- - - func: SetOrientation(orientation) - - desc: sets the object's orientation ---]]--------------------------------------------------------- -function newobject:SetOrientation(orientation) - - self.orientation = orientation - -end - ---[[--------------------------------------------------------- - - func: GetOrientation() - - desc: gets the object's orientation ---]]--------------------------------------------------------- -function newobject:GetOrientation() - - return self.orientation - -end - ---[[--------------------------------------------------------- - - func: SetScaleX(scalex) - - desc: sets the object's x scale ---]]--------------------------------------------------------- -function newobject:SetScaleX(scalex) - - self.scalex = scalex - -end - ---[[--------------------------------------------------------- - - func: GetScaleX() - - desc: gets the object's x scale ---]]--------------------------------------------------------- -function newobject:GetScaleX() - - return self.scalex - -end - ---[[--------------------------------------------------------- - - func: SetScaleY(scaley) - - desc: sets the object's y scale ---]]--------------------------------------------------------- -function newobject:SetScaleY(scaley) - - self.scaley = scaley - -end - ---[[--------------------------------------------------------- - - func: GetScaleY() - - desc: gets the object's y scale ---]]--------------------------------------------------------- -function newobject:GetScaleY() - - return self.scaley - -end - ---[[--------------------------------------------------------- - - func: SetScale(scalex, scaley) - - desc: sets the object's x and y scale ---]]--------------------------------------------------------- -function newobject:SetScale(scalex, scaley) - - self.scalex = scalex - self.scaley = scaley - -end - ---[[--------------------------------------------------------- - - func: GetScale() - - desc: gets the object's x and y scale ---]]--------------------------------------------------------- -function newobject:GetScale() - - return self.scalex, self.scaley - -end - ---[[--------------------------------------------------------- - - func: SetOffsetX(x) - - desc: sets the object's x offset ---]]--------------------------------------------------------- -function newobject:SetOffsetX(x) - - self.offsetx = x - -end - ---[[--------------------------------------------------------- - - func: GetOffsetX() - - desc: gets the object's x offset ---]]--------------------------------------------------------- -function newobject:GetOffsetX() - - return self.offsetx - -end - ---[[--------------------------------------------------------- - - func: SetOffsetY(y) - - desc: sets the object's y offset ---]]--------------------------------------------------------- -function newobject:SetOffsetY(y) - - self.offsety = y - -end - ---[[--------------------------------------------------------- - - func: GetOffsetY() - - desc: gets the object's y offset ---]]--------------------------------------------------------- -function newobject:GetOffsetY() - - return self.offsety - -end - ---[[--------------------------------------------------------- - - func: SetOffset(x, y) - - desc: sets the object's x and y offset ---]]--------------------------------------------------------- -function newobject:SetOffset(x, y) - - self.offsetx = x - self.offsety = y - -end - ---[[--------------------------------------------------------- - - func: GetOffset() - - desc: gets the object's x and y offset ---]]--------------------------------------------------------- -function newobject:GetOffset() - - return self.offsetx, self.offsety - -end - ---[[--------------------------------------------------------- - - func: SetShearX(shearx) - - desc: sets the object's x shear ---]]--------------------------------------------------------- -function newobject:SetShearX(shearx) - - self.shearx = shearx - -end - ---[[--------------------------------------------------------- - - func: GetShearX() - - desc: gets the object's x shear ---]]--------------------------------------------------------- -function newobject:GetShearX() - - return self.shearx - -end - ---[[--------------------------------------------------------- - - func: SetShearY(sheary) - - desc: sets the object's y shear ---]]--------------------------------------------------------- -function newobject:SetShearY(sheary) - - self.sheary = sheary - -end - ---[[--------------------------------------------------------- - - func: GetShearY() - - desc: gets the object's y shear ---]]--------------------------------------------------------- -function newobject:GetShearY() - - return self.sheary - -end - ---[[--------------------------------------------------------- - - func: SetShear(shearx, sheary) - - desc: sets the object's x and y shear ---]]--------------------------------------------------------- -function newobject:SetShear(shearx, sheary) - - self.shearx = shearx - self.sheary = sheary - -end - ---[[--------------------------------------------------------- - - func: GetShear() - - desc: gets the object's x and y shear ---]]--------------------------------------------------------- -function newobject:GetShear() - - return self.shearx, self.sheary - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- progressbar class +local newobject = loveframes.NewObject("image", "loveframes_object_image", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "image" + self.width = 0 + self.height = 0 + self.orientation = 0 + self.scalex = 1 + self.scaley = 1 + self.offsetx = 0 + self.offsety = 0 + self.shearx = 0 + self.sheary = 0 + self.internal = false + self.image = nil + self.imagecolor = nil + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local parent = self.parent + local base = loveframes.base + local update = self.Update + + -- move to parent if there is a parent + if parent ~= base then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawImage or skins[defaultskin].DrawImage + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + +end + +--[[--------------------------------------------------------- + - func: SetImage(image) + - desc: sets the object's image +--]]--------------------------------------------------------- +function newobject:SetImage(image) + + if type(image) == "string" then + self.image = love.graphics.newImage(image) + else + self.image = image + end + + self.width = self.image:getWidth() + self.height = self.image:getHeight() + +end + +--[[--------------------------------------------------------- + - func: GetImage() + - desc: gets the object's image +--]]--------------------------------------------------------- +function newobject:GetImage() + + return self.image + +end + +--[[--------------------------------------------------------- + - func: SetColor(r, g, b, a) + - desc: sets the object's color +--]]--------------------------------------------------------- +function newobject:SetColor(r, g, b, a) + + self.imagecolor = {r, g, b, a} + +end + +--[[--------------------------------------------------------- + - func: GetColor() + - desc: gets the object's color +--]]--------------------------------------------------------- +function newobject:GetColor() + + return unpack(self.imagecolor) + +end + +--[[--------------------------------------------------------- + - func: SetOrientation(orientation) + - desc: sets the object's orientation +--]]--------------------------------------------------------- +function newobject:SetOrientation(orientation) + + self.orientation = orientation + +end + +--[[--------------------------------------------------------- + - func: GetOrientation() + - desc: gets the object's orientation +--]]--------------------------------------------------------- +function newobject:GetOrientation() + + return self.orientation + +end + +--[[--------------------------------------------------------- + - func: SetScaleX(scalex) + - desc: sets the object's x scale +--]]--------------------------------------------------------- +function newobject:SetScaleX(scalex) + + self.scalex = scalex + +end + +--[[--------------------------------------------------------- + - func: GetScaleX() + - desc: gets the object's x scale +--]]--------------------------------------------------------- +function newobject:GetScaleX() + + return self.scalex + +end + +--[[--------------------------------------------------------- + - func: SetScaleY(scaley) + - desc: sets the object's y scale +--]]--------------------------------------------------------- +function newobject:SetScaleY(scaley) + + self.scaley = scaley + +end + +--[[--------------------------------------------------------- + - func: GetScaleY() + - desc: gets the object's y scale +--]]--------------------------------------------------------- +function newobject:GetScaleY() + + return self.scaley + +end + +--[[--------------------------------------------------------- + - func: SetScale(scalex, scaley) + - desc: sets the object's x and y scale +--]]--------------------------------------------------------- +function newobject:SetScale(scalex, scaley) + + self.scalex = scalex + self.scaley = scaley + +end + +--[[--------------------------------------------------------- + - func: GetScale() + - desc: gets the object's x and y scale +--]]--------------------------------------------------------- +function newobject:GetScale() + + return self.scalex, self.scaley + +end + +--[[--------------------------------------------------------- + - func: SetOffsetX(x) + - desc: sets the object's x offset +--]]--------------------------------------------------------- +function newobject:SetOffsetX(x) + + self.offsetx = x + +end + +--[[--------------------------------------------------------- + - func: GetOffsetX() + - desc: gets the object's x offset +--]]--------------------------------------------------------- +function newobject:GetOffsetX() + + return self.offsetx + +end + +--[[--------------------------------------------------------- + - func: SetOffsetY(y) + - desc: sets the object's y offset +--]]--------------------------------------------------------- +function newobject:SetOffsetY(y) + + self.offsety = y + +end + +--[[--------------------------------------------------------- + - func: GetOffsetY() + - desc: gets the object's y offset +--]]--------------------------------------------------------- +function newobject:GetOffsetY() + + return self.offsety + +end + +--[[--------------------------------------------------------- + - func: SetOffset(x, y) + - desc: sets the object's x and y offset +--]]--------------------------------------------------------- +function newobject:SetOffset(x, y) + + self.offsetx = x + self.offsety = y + +end + +--[[--------------------------------------------------------- + - func: GetOffset() + - desc: gets the object's x and y offset +--]]--------------------------------------------------------- +function newobject:GetOffset() + + return self.offsetx, self.offsety + +end + +--[[--------------------------------------------------------- + - func: SetShearX(shearx) + - desc: sets the object's x shear +--]]--------------------------------------------------------- +function newobject:SetShearX(shearx) + + self.shearx = shearx + +end + +--[[--------------------------------------------------------- + - func: GetShearX() + - desc: gets the object's x shear +--]]--------------------------------------------------------- +function newobject:GetShearX() + + return self.shearx + +end + +--[[--------------------------------------------------------- + - func: SetShearY(sheary) + - desc: sets the object's y shear +--]]--------------------------------------------------------- +function newobject:SetShearY(sheary) + + self.sheary = sheary + +end + +--[[--------------------------------------------------------- + - func: GetShearY() + - desc: gets the object's y shear +--]]--------------------------------------------------------- +function newobject:GetShearY() + + return self.sheary + +end + +--[[--------------------------------------------------------- + - func: SetShear(shearx, sheary) + - desc: sets the object's x and y shear +--]]--------------------------------------------------------- +function newobject:SetShear(shearx, sheary) + + self.shearx = shearx + self.sheary = sheary + +end + +--[[--------------------------------------------------------- + - func: GetShear() + - desc: gets the object's x and y shear +--]]--------------------------------------------------------- +function newobject:GetShear() + + return self.shearx, self.sheary + +end + +--[[--------------------------------------------------------- + - func: GetImageSize() + - desc: gets the size of the object's image +--]]--------------------------------------------------------- +function newobject:GetImageSize() + + local image = self.image + + if image then + return image:getWidth(), image:getHeight() + end + +end + +--[[--------------------------------------------------------- + - func: GetImageWidth() + - desc: gets the width of the object's image +--]]--------------------------------------------------------- +function newobject:GetImageWidth() + + local image = self.image + + if image then + return image:getWidth() + end + +end + +--[[--------------------------------------------------------- + - func: GetImageWidth() + - desc: gets the height of the object's image +--]]--------------------------------------------------------- +function newobject:GetImageHeight() + + local image = self.image + + if image then + return image:getHeight() + end + end \ No newline at end of file diff --git a/objects/imagebutton.lua b/objects/imagebutton.lua index d0056e2..9f0f2d1 100644 --- a/objects/imagebutton.lua +++ b/objects/imagebutton.lua @@ -1,260 +1,330 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- imagebutton class -local newobject = loveframes.NewObject("imagebutton", "loveframes_object_imagebutton", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize() - - self.type = "imagebutton" - self.text = "Image Button" - self.width = 50 - self.height = 50 - self.internal = false - self.down = false - self.clickable = true - self.enabled = true - self.image = nil - self.OnClick = nil - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - self:CheckHover() - - local hover = self.hover - local hoverobject = loveframes.hoverobject - local down = self.down - local parent = self.parent - local base = loveframes.base - local update = self.Update - - if not hover then - self.down = false - else - if hoverobject == self then - self.down = true - end - end - - if not down and hoverobject == self then - self.hover = true - end - - -- move to parent if there is a parent - if parent ~= base then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawImageButton or skins[defaultskin].DrawImageButton - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - - if hover and button == "l" then - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - self.down = true - loveframes.hoverobject = self - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - local down = self.down - local clickable = self.clickable - local enabled = self.enabled - local onclick = self.OnClick - - if hover and down and clickable and button == "l" then - if enabled then - if onclick then - onclick(self, x, y) - end - end - end - - self.down = false - -end - ---[[--------------------------------------------------------- - - func: SetText(text) - - desc: sets the object's text ---]]--------------------------------------------------------- -function newobject:SetText(text) - - self.text = text - -end - ---[[--------------------------------------------------------- - - func: GetText() - - desc: gets the object's text ---]]--------------------------------------------------------- -function newobject:GetText() - - return self.text - -end - ---[[--------------------------------------------------------- - - func: SetClickable(bool) - - desc: sets whether the object can be clicked or not ---]]--------------------------------------------------------- -function newobject:SetClickable(bool) - - self.clickable = bool - -end - ---[[--------------------------------------------------------- - - func: GetClickable(bool) - - desc: gets whether the object can be clicked or not ---]]--------------------------------------------------------- -function newobject:GetClickable() - - return self.clickable - -end - ---[[--------------------------------------------------------- - - func: SetClickable(bool) - - desc: sets whether the object is enabled or not ---]]--------------------------------------------------------- -function newobject:SetEnabled(bool) - - self.enabled = bool - -end - ---[[--------------------------------------------------------- - - func: GetEnabled() - - desc: gets whether the object is enabled or not ---]]--------------------------------------------------------- -function newobject:GetEnabled() - - return self.enabled - -end - ---[[--------------------------------------------------------- - - func: SetImage(image) - - desc: sets the object's image ---]]--------------------------------------------------------- -function newobject:SetImage(image) - - if type(image) == "string" then - self.image = love.graphics.newImage(image) - else - self.image = image - end - -end - ---[[--------------------------------------------------------- - - func: GetImage() - - desc: gets whether the object is enabled or not ---]]--------------------------------------------------------- -function newobject:GetImage() - - return self.image - -end - ---[[--------------------------------------------------------- - - func: SizeToImage() - - desc: makes the object the same size as it's image ---]]--------------------------------------------------------- -function newobject:SizeToImage() - - local image = self.image - - if image then - self.width = image:getWidth() - self.height = image:getHeight() - end - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- imagebutton class +local newobject = loveframes.NewObject("imagebutton", "loveframes_object_imagebutton", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "imagebutton" + self.text = "Image Button" + self.width = 50 + self.height = 50 + self.internal = false + self.down = false + self.clickable = true + self.enabled = true + self.image = nil + self.OnClick = nil + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + self:CheckHover() + + local hover = self.hover + local hoverobject = loveframes.hoverobject + local down = self.down + local parent = self.parent + local base = loveframes.base + local update = self.Update + + if not hover then + self.down = false + else + if hoverobject == self then + self.down = true + end + end + + if not down and hoverobject == self then + self.hover = true + end + + -- move to parent if there is a parent + if parent ~= base then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawImageButton or skins[defaultskin].DrawImageButton + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + self.down = true + loveframes.hoverobject = self + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + local down = self.down + local clickable = self.clickable + local enabled = self.enabled + local onclick = self.OnClick + + if hover and down and clickable and button == "l" then + if enabled then + if onclick then + onclick(self, x, y) + end + end + end + + self.down = false + +end + +--[[--------------------------------------------------------- + - func: SetText(text) + - desc: sets the object's text +--]]--------------------------------------------------------- +function newobject:SetText(text) + + self.text = text + +end + +--[[--------------------------------------------------------- + - func: GetText() + - desc: gets the object's text +--]]--------------------------------------------------------- +function newobject:GetText() + + return self.text + +end + +--[[--------------------------------------------------------- + - func: SetClickable(bool) + - desc: sets whether the object can be clicked or not +--]]--------------------------------------------------------- +function newobject:SetClickable(bool) + + self.clickable = bool + +end + +--[[--------------------------------------------------------- + - func: GetClickable(bool) + - desc: gets whether the object can be clicked or not +--]]--------------------------------------------------------- +function newobject:GetClickable() + + return self.clickable + +end + +--[[--------------------------------------------------------- + - func: SetClickable(bool) + - desc: sets whether the object is enabled or not +--]]--------------------------------------------------------- +function newobject:SetEnabled(bool) + + self.enabled = bool + +end + +--[[--------------------------------------------------------- + - func: GetEnabled() + - desc: gets whether the object is enabled or not +--]]--------------------------------------------------------- +function newobject:GetEnabled() + + return self.enabled + +end + +--[[--------------------------------------------------------- + - func: SetImage(image) + - desc: sets the object's image +--]]--------------------------------------------------------- +function newobject:SetImage(image) + + if type(image) == "string" then + self.image = love.graphics.newImage(image) + else + self.image = image + end + +end + +--[[--------------------------------------------------------- + - func: GetImage() + - desc: gets whether the object is enabled or not +--]]--------------------------------------------------------- +function newobject:GetImage() + + return self.image + +end + +--[[--------------------------------------------------------- + - func: SizeToImage() + - desc: makes the object the same size as it's image +--]]--------------------------------------------------------- +function newobject:SizeToImage() + + local image = self.image + + if image then + self.width = image:getWidth() + self.height = image:getHeight() + end + +end + +--[[--------------------------------------------------------- + - func: GetImageSize() + - desc: gets the size of the object's image +--]]--------------------------------------------------------- +function newobject:GetImageSize() + + local image = self.image + + if image then + return image:getWidth(), image:getHeight() + end + +end + +--[[--------------------------------------------------------- + - func: GetImageWidth() + - desc: gets the width of the object's image +--]]--------------------------------------------------------- +function newobject:GetImageWidth() + + local image = self.image + + if image then + return image:getWidth() + end + +end + +--[[--------------------------------------------------------- + - func: GetImageWidth() + - desc: gets the height of the object's image +--]]--------------------------------------------------------- +function newobject:GetImageHeight() + + local image = self.image + + if image then + return image:getHeight() + end + end \ No newline at end of file diff --git a/objects/internal/closebutton.lua b/objects/internal/closebutton.lua index 8d270c4..0da89e3 100644 --- a/objects/internal/closebutton.lua +++ b/objects/internal/closebutton.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- closebutton class diff --git a/objects/internal/columnlist/columnlistarea.lua b/objects/internal/columnlist/columnlistarea.lua index 181b19c..f92179e 100644 --- a/objects/internal/columnlist/columnlistarea.lua +++ b/objects/internal/columnlist/columnlistarea.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- columnlistarea class @@ -28,6 +28,7 @@ function newobject:initialize(parent) self.buttonscrollamount = parent.buttonscrollamount self.mousewheelscrollamount = parent.mousewheelscrollamount self.bar = false + self.dtscrolling = parent.dtscrolling self.internal = true self.internals = {} self.children = {} @@ -160,10 +161,20 @@ function newobject:mousepressed(x, y, button) if self.bar and toplist then local bar = self:GetScrollBar() - if button == "wu" then - bar:Scroll(-scrollamount) - elseif button == "wd" then - bar:Scroll(scrollamount) + local dtscrolling = self.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + if button == "wu" then + bar:Scroll(-scrollamount * dt) + elseif button == "wd" then + bar:Scroll(scrollamount * dt) + end + else + if button == "wu" then + bar:Scroll(-scrollamount) + elseif button == "wd" then + bar:Scroll(scrollamount) + end end end diff --git a/objects/internal/columnlist/columnlistrow.lua b/objects/internal/columnlist/columnlistrow.lua index 1e57cac..39c8ebb 100644 --- a/objects/internal/columnlist/columnlistrow.lua +++ b/objects/internal/columnlist/columnlistrow.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- columnlistrow class diff --git a/objects/internal/columnlist/coulmnlistheader.lua b/objects/internal/columnlist/coulmnlistheader.lua index 8ceb98f..6a0c1c8 100644 --- a/objects/internal/columnlist/coulmnlistheader.lua +++ b/objects/internal/columnlist/coulmnlistheader.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- columnlistheader class diff --git a/objects/internal/linenumberspanel.lua b/objects/internal/linenumberspanel.lua index bd98f37..4c9f1da 100644 --- a/objects/internal/linenumberspanel.lua +++ b/objects/internal/linenumberspanel.lua @@ -1,160 +1,160 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- linenumberspanel class -local newobject = loveframes.NewObject("linenumberspanel", "loveframes_object_linenumberspanel", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize(parent) - - self.parent = parent - self.type = "linenumberspanel" - self.width = 5 - self.height = 5 - self.offsety = 0 - self.staticx = 0 - self.staticy = 0 - self.internal = true - - -- apply template properties to the object - loveframes.templates.ApplyToObject(self) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the element ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local parent = self.parent - local base = loveframes.base - local update = self.Update - local height = self.parent.height - local parentinternals = parent.internals - - self.height = height - self.offsety = self.parent.offsety - self.parent.textoffsety - - -- move to parent if there is a parent - if parent ~= base then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - if parentinternals[1] ~= self then - self:Remove() - table.insert(parentinternals, 1, self) - return - end - - self:CheckHover() - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawLineNumbersPanel or skins[defaultskin].DrawLineNumbersPanel - local draw = self.Draw - local drawcount = loveframes.drawcount - local stencilfunc = function() love.graphics.rectangle("fill", self.parent.x, self.parent.y, self.width, self.height) end - local stencil = love.graphics.newStencil(stencilfunc) - - if self.parent.hbar then - stencilfunc = function() love.graphics.rectangle("fill", self.parent.x, self.parent.y, self.width, self.parent.height - 16) end - end - - -- set the object's draw order - self:SetDrawOrder() - - love.graphics.setStencil(stencilfunc) - - if draw then - draw(self) - else - drawfunc(self) - end - - love.graphics.setStencil() - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - - if hover and button == "l" then - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - -end - ---[[--------------------------------------------------------- - - func: GetOffsetY() - - desc: gets the object's y offset ---]]--------------------------------------------------------- -function newobject:GetOffsetY() - - return self.offsety - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- linenumberspanel class +local newobject = loveframes.NewObject("linenumberspanel", "loveframes_object_linenumberspanel", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize(parent) + + self.parent = parent + self.type = "linenumberspanel" + self.width = 5 + self.height = 5 + self.offsety = 0 + self.staticx = 0 + self.staticy = 0 + self.internal = true + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the element +--]]--------------------------------------------------------- +function newobject:update(dt) + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local parent = self.parent + local base = loveframes.base + local update = self.Update + local height = self.parent.height + local parentinternals = parent.internals + + self.height = height + self.offsety = self.parent.offsety - self.parent.textoffsety + + -- move to parent if there is a parent + if parent ~= base then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + if parentinternals[1] ~= self then + self:Remove() + table.insert(parentinternals, 1, self) + return + end + + self:CheckHover() + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawLineNumbersPanel or skins[defaultskin].DrawLineNumbersPanel + local draw = self.Draw + local drawcount = loveframes.drawcount + local stencilfunc = function() love.graphics.rectangle("fill", self.parent.x, self.parent.y, self.width, self.height) end + local stencil = love.graphics.newStencil(stencilfunc) + + if self.parent.hbar then + stencilfunc = function() love.graphics.rectangle("fill", self.parent.x, self.parent.y, self.width, self.parent.height - 16) end + end + + -- set the object's draw order + self:SetDrawOrder() + + love.graphics.setStencil(stencilfunc) + + if draw then + draw(self) + else + drawfunc(self) + end + + love.graphics.setStencil() + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local visible = self.visible + + if not visible then + return + end + +end + +--[[--------------------------------------------------------- + - func: GetOffsetY() + - desc: gets the object's y offset +--]]--------------------------------------------------------- +function newobject:GetOffsetY() + + return self.offsety + end \ No newline at end of file diff --git a/objects/internal/modalbackground.lua b/objects/internal/modalbackground.lua index 796d780..52b58b7 100644 --- a/objects/internal/modalbackground.lua +++ b/objects/internal/modalbackground.lua @@ -1,101 +1,101 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- modalbackground class -local newobject = loveframes.NewObject("modalbackground", "loveframes_object_modalbackground", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize(object) - - self.type = "modalbackground" - self.width = love.graphics.getWidth() - self.height = love.graphics.getHeight() - self.x = 0 - self.y = 0 - self.internal = true - self.parent = loveframes.base - self.object = object - - table.insert(loveframes.base.children, self) - - if self.object.type ~= "frame" then - self:Remove() - end - - -- apply template properties to the object - loveframes.templates.ApplyToObject(self) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the element ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local object = self.object - local update = self.Update - local base = loveframes.base - local basechildren = base.children - - if #basechildren > 1 then - if basechildren[#basechildren - 1] ~= self then - self:Remove() - table.insert(basechildren, self) - end - end - - if not object:IsActive() then - self:Remove() - loveframes.modalobject = false - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - if not self.visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawModalBackground or skins[defaultskin].DrawModalBackground - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- modalbackground class +local newobject = loveframes.NewObject("modalbackground", "loveframes_object_modalbackground", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize(object) + + self.type = "modalbackground" + self.width = love.graphics.getWidth() + self.height = love.graphics.getHeight() + self.x = 0 + self.y = 0 + self.internal = true + self.parent = loveframes.base + self.object = object + + table.insert(loveframes.base.children, self) + + if self.object.type ~= "frame" then + self:Remove() + end + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the element +--]]--------------------------------------------------------- +function newobject:update(dt) + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local object = self.object + local update = self.Update + local base = loveframes.base + local basechildren = base.children + + if #basechildren > 1 then + if basechildren[#basechildren - 1] ~= self then + self:Remove() + table.insert(basechildren, self) + end + end + + if not object:IsActive() then + self:Remove() + loveframes.modalobject = false + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + if not self.visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawModalBackground or skins[defaultskin].DrawModalBackground + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + end \ No newline at end of file diff --git a/objects/internal/multichoice/multichoicelist.lua b/objects/internal/multichoice/multichoicelist.lua index 9a387cd..50e5ae6 100644 --- a/objects/internal/multichoice/multichoicelist.lua +++ b/objects/internal/multichoice/multichoicelist.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- multichoicelist class @@ -30,6 +30,7 @@ function newobject:initialize(object) self.extrawidth = 0 self.extraheight = 0 self.canremove = false + self.dtscrolling = self.list.dtscrolling self.internal = true self.vbar = false self.children = {} @@ -54,6 +55,13 @@ end --]]--------------------------------------------------------- function newobject:update(dt) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible local alwaysupdate = self.alwaysupdate @@ -118,6 +126,13 @@ end --]]--------------------------------------------------------- function newobject:draw() + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -174,6 +189,13 @@ end --]]--------------------------------------------------------- function newobject:mousepressed(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -191,10 +213,21 @@ function newobject:mousepressed(x, y, button) end if self.vbar and toplist then - if button == "wu" then - internals[1].internals[1].internals[1]:Scroll(-scrollamount) - elseif button == "wd" then - internals[1].internals[1].internals[1]:Scroll(scrollamount) + local bar = internals[1].internals[1].internals[1] + local dtscrolling = self.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + if button == "wu" then + bar:Scroll(-scrollamount * dt) + elseif button == "wd" then + bar:Scroll(scrollamount * dt) + end + else + if button == "wu" then + bar:Scroll(-scrollamount) + elseif button == "wd" then + bar:Scroll(scrollamount) + end end end @@ -214,6 +247,13 @@ end --]]--------------------------------------------------------- function newobject:mousereleased(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then diff --git a/objects/internal/multichoice/multichoicerow.lua b/objects/internal/multichoice/multichoicerow.lua index 877ea4c..151b604 100644 --- a/objects/internal/multichoice/multichoicerow.lua +++ b/objects/internal/multichoice/multichoicerow.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- multichoicerow class diff --git a/objects/internal/scrollable/scrollarea.lua b/objects/internal/scrollable/scrollarea.lua index b75a600..3720b9e 100644 --- a/objects/internal/scrollable/scrollarea.lua +++ b/objects/internal/scrollable/scrollarea.lua @@ -1,237 +1,237 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- scrollarea class -local newobject = loveframes.NewObject("scrollarea", "loveframes_object_scrollarea", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize(parent, bartype) - - self.type = "scroll-area" - self.bartype = bartype - self.parent = parent - self.x = 0 - self.y = 0 - self.scrolldelay = 0 - self.delayamount = 0.05 - self.down = false - self.internal = true - self.internals = {} - - table.insert(self.internals, loveframes.objects["scrollbar"]:new(self, bartype)) - - -- apply template properties to the object - loveframes.templates.ApplyToObject(self) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local parent = self.parent - local base = loveframes.base - local update = self.Update - - -- move to parent if there is a parent - if parent ~= base then - self.x = parent.x + self.staticx - self.y = parent.y + self.staticy - end - - self:CheckHover() - - local parent = self.parent - local pinternals = parent.internals - local button = pinternals[2] - local bartype = self.bartype - local time = love.timer.getTime() - local x, y = love.mouse.getPosition() - local listo = parent.parent - local down = self.down - local scrolldelay = self.scrolldelay - local delayamount = self.delayamount - local internals = self.internals - local bar = internals[1] - local hover = self.hover - - if button then - if bartype == "vertical" then - self.staticx = 0 - self.staticy = button.height - 1 - self.width = parent.width - self.height = parent.height - button.height*2 + 2 - elseif bartype == "horizontal" then - self.staticx = button.width - 1 - self.staticy = 0 - self.width = parent.width - button.width*2 + 2 - self.height = parent.height - end - end - - if down then - if scrolldelay < time then - self.scrolldelay = time + delayamount - if self.bartype == "vertical" then - if y > bar.y then - bar:Scroll(bar.height) - else - bar:Scroll(-bar.height) - end - elseif self.bartype == "horizontal" then - if x > bar.x then - bar:Scroll(bar.width) - else - bar:Scroll(-bar.width) - end - end - end - if not hover then - self.down = false - end - end - - for k, v in ipairs(internals) do - v:update(dt) - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local internals = self.internals - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawScrollArea or skins[defaultskin].DrawScrollArea - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - - for k, v in ipairs(internals) do - v:draw() - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local listo = self.parent.parent - local time = love.timer.getTime() - local internals = self.internals - local bar = internals[1] - local hover = self.hover - local delayamount = self.delayamount - - if hover and button == "l" then - self.down = true - self.scrolldelay = time + delayamount + 0.5 - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - if self.bartype == "vertical" then - if y > self.internals[1].y then - bar:Scroll(bar.height) - else - bar:Scroll(-bar.height) - end - elseif self.bartype == "horizontal" then - if x > bar.x then - bar:Scroll(bar.width) - else - bar:Scroll(-bar.width) - end - end - loveframes.hoverobject = self - end - - for k, v in ipairs(internals) do - v:mousepressed(x, y, button) - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local internals = self.internals - - if button == "l" then - self.down = false - end - - for k, v in ipairs(internals) do - v:mousereleased(x, y, button) - end - -end - ---[[--------------------------------------------------------- - - func: GetBarType() - - desc: gets the object's bar type ---]]--------------------------------------------------------- -function newobject:GetBarType() - - return self.bartype - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- scrollarea class +local newobject = loveframes.NewObject("scrollarea", "loveframes_object_scrollarea", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize(parent, bartype) + + self.type = "scroll-area" + self.bartype = bartype + self.parent = parent + self.x = 0 + self.y = 0 + self.scrolldelay = 0 + self.delayamount = 0.05 + self.down = false + self.internal = true + self.internals = {} + + table.insert(self.internals, loveframes.objects["scrollbar"]:new(self, bartype)) + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local parent = self.parent + local base = loveframes.base + local update = self.Update + + -- move to parent if there is a parent + if parent ~= base then + self.x = parent.x + self.staticx + self.y = parent.y + self.staticy + end + + self:CheckHover() + + local parent = self.parent + local pinternals = parent.internals + local button = pinternals[2] + local bartype = self.bartype + local time = love.timer.getTime() + local x, y = love.mouse.getPosition() + local listo = parent.parent + local down = self.down + local scrolldelay = self.scrolldelay + local delayamount = self.delayamount + local internals = self.internals + local bar = internals[1] + local hover = self.hover + + if button then + if bartype == "vertical" then + self.staticx = 0 + self.staticy = button.height - 1 + self.width = parent.width + self.height = parent.height - button.height*2 + 2 + elseif bartype == "horizontal" then + self.staticx = button.width - 1 + self.staticy = 0 + self.width = parent.width - button.width*2 + 2 + self.height = parent.height + end + end + + if down then + if scrolldelay < time then + self.scrolldelay = time + delayamount + if self.bartype == "vertical" then + if y > bar.y then + bar:Scroll(bar.height) + else + bar:Scroll(-bar.height) + end + elseif self.bartype == "horizontal" then + if x > bar.x then + bar:Scroll(bar.width) + else + bar:Scroll(-bar.width) + end + end + end + if not hover then + self.down = false + end + end + + for k, v in ipairs(internals) do + v:update(dt) + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local visible = self.visible + + if not visible then + return + end + + local internals = self.internals + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawScrollArea or skins[defaultskin].DrawScrollArea + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + + for k, v in ipairs(internals) do + v:draw() + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + local listo = self.parent.parent + local time = love.timer.getTime() + local internals = self.internals + local bar = internals[1] + local hover = self.hover + local delayamount = self.delayamount + + if hover and button == "l" then + self.down = true + self.scrolldelay = time + delayamount + 0.5 + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + if self.bartype == "vertical" then + if y > self.internals[1].y then + bar:Scroll(bar.height) + else + bar:Scroll(-bar.height) + end + elseif self.bartype == "horizontal" then + if x > bar.x then + bar:Scroll(bar.width) + else + bar:Scroll(-bar.width) + end + end + loveframes.hoverobject = self + end + + for k, v in ipairs(internals) do + v:mousepressed(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + local internals = self.internals + + if button == "l" then + self.down = false + end + + for k, v in ipairs(internals) do + v:mousereleased(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: GetBarType() + - desc: gets the object's bar type +--]]--------------------------------------------------------- +function newobject:GetBarType() + + return self.bartype + end \ No newline at end of file diff --git a/objects/internal/scrollable/scrollbar.lua b/objects/internal/scrollable/scrollbar.lua index 844b74b..88534ce 100644 --- a/objects/internal/scrollable/scrollbar.lua +++ b/objects/internal/scrollable/scrollbar.lua @@ -1,350 +1,350 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- scrollbar class -local newobject = loveframes.NewObject("scrollbar", "loveframes_object_scrollbar", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize(parent, bartype) - - self.type = "scrollbar" - self.bartype = bartype - self.parent = parent - self.x = 0 - self.y = 0 - self.staticx = 0 - self.staticy = 0 - self.maxx = 0 - self.maxy = 0 - self.clickx = 0 - self.clicky = 0 - self.starty = 0 - self.lastwidth = 0 - self.lastheight = 0 - self.lastx = 0 - self.lasty = 0 - self.internal = true - self.hover = false - self.dragging = false - self.autoscroll = false - self.internal = true - - if self.bartype == "vertical" then - self.width = self.parent.width - self.height = 5 - elseif self.bartype == "horizontal" then - self.width = 5 - self.height = self.parent.height - end - - -- apply template properties to the object - loveframes.templates.ApplyToObject(self) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - self:CheckHover() - - local x, y = love.mouse.getPosition() - local bartype = self.bartype - local cols = {} - local basecols = {} - local dragging = self.dragging - - if bartype == "vertical" then - self.width = self.parent.width - elseif bartype == "horizontal" then - self.height = self.parent.height - end - - if bartype == "vertical" then - local parent = self.parent - local listo = parent.parent.parent - local height = parent.height * (listo.height/listo.itemheight) - local update = self.Update - if height < 20 then - self.height = 20 - else - self.height = height - end - self.maxy = parent.y + (parent.height - self.height) - self.x = parent.x + parent.width - self.width - self.y = parent.y + self.staticy - if dragging then - if self.staticy ~= self.lasty then - if listo.OnScroll then - listo.OnScroll(listo) - end - self.lasty = self.staticy - end - self.staticy = self.starty + (y - self.clicky) - end - local space = (self.maxy - parent.y) - local remaining = (0 + self.staticy) - local percent = remaining/space - local extra = listo.extraheight * percent - local autoscroll = self.autoscroll - local lastheight = self.lastheight - listo.offsety = 0 + extra - if self.staticy > space then - self.staticy = space - listo.offsety = listo.extraheight - end - if self.staticy < 0 then - self.staticy = 0 - listo.offsety = 0 - end - if autoscroll then - if listo.itemheight > lastheight then - local type = listo.type - self.lastheight = listo.itemheight - if type == "textinput" then - local indicatory = listo.indicatory - local font = listo.font - local theight = font:getHeight("a") - local y = listo.y - local height = listo.height - local linecount = #listo.lines - local parentheight = self.parent.height - if (indicatory + theight) > (y + height) then - self:Scroll(parentheight/linecount) - end - else - local maxy = self.maxy - self:Scroll(maxy) - end - end - end - elseif bartype == "horizontal" then - local parent = self.parent - local listo = self.parent.parent.parent - local width = self.parent.width * (listo.width/listo.itemwidth) - if width < 20 then - self.width = 20 - else - self.width = width - end - self.maxx = parent.x + (parent.width) - self.width - self.x = parent.x + self.staticx - self.y = parent.y + self.staticy - if dragging then - if self.staticx ~= self.lastx then - if listo.OnScroll then - listo.OnScroll(listo) - end - self.lastx = self.staticx - end - self.staticx = self.startx + (x - self.clickx) - end - local space = (self.maxx - parent.x) - local remaining = (0 + self.staticx) - local percent = remaining/space - local extra = listo.extrawidth * percent - local autoscroll = self.autoscroll - local lastwidth = self.lastwidth - listo.offsetx = 0 + extra - if self.staticx > space then - self.staticx = space - listo.offsetx = listo.extrawidth - end - - if self.staticx < 0 then - self.staticx = 0 - listo.offsetx = 0 - end - if autoscroll then - if listo.itemwidth > lastwidth then - self.lastwidth = listo.itemwidth - self:Scroll(self.maxx) - end - end - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawScrollBar or skins[defaultskin].DrawScrollBar - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - local hover = self.hover - - if not visible then - return - end - - if not hover then - return - end - - local baseparent = self:GetBaseParent() - - if baseparent.type == "frame" then - baseparent:MakeTop() - end - - local dragging = self.dragging - - if not dragging then - if button == "l" then - self.starty = self.staticy - self.startx = self.staticx - self.clickx = x - self.clicky = y - self.dragging = true - loveframes.hoverobject = self - end - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - if self.dragging then - self.dragging = false - end - -end - ---[[--------------------------------------------------------- - - func: SetMaxX(x) - - desc: sets the object's max x position ---]]--------------------------------------------------------- -function newobject:SetMaxX(x) - - self.maxx = x - -end - ---[[--------------------------------------------------------- - - func: SetMaxY(y) - - desc: sets the object's max y position ---]]--------------------------------------------------------- -function newobject:SetMaxY(y) - - self.maxy = y - -end - ---[[--------------------------------------------------------- - - func: Scroll(amount) - - desc: scrolls the object ---]]--------------------------------------------------------- -function newobject:Scroll(amount) - - local bartype = self.bartype - local listo = self.parent.parent.parent - local onscroll = listo.OnScroll - - if bartype == "vertical" then - local newy = (self.y + amount) - if newy > self.maxy then - self.staticy = self.maxy - self.parent.y - elseif newy < self.parent.y then - self.staticy = 0 - else - self.staticy = self.staticy + amount - end - elseif bartype == "horizontal" then - local newx = (self.x + amount) - if newx > self.maxx then - self.staticx = self.maxx - self.parent.x - elseif newx < self.parent.x then - self.staticx = 0 - else - self.staticx = self.staticx + amount - end - end - - if onscroll then - onscroll(listo) - end - -end - ---[[--------------------------------------------------------- - - func: IsDragging() - - desc: gets whether the object is being dragged or not ---]]--------------------------------------------------------- -function newobject:IsDragging() - - return self.dragging - -end - ---[[--------------------------------------------------------- - - func: GetBarType() - - desc: gets the object's bartype ---]]--------------------------------------------------------- -function newobject:GetBarType() - - return self.bartype - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- scrollbar class +local newobject = loveframes.NewObject("scrollbar", "loveframes_object_scrollbar", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize(parent, bartype) + + self.type = "scrollbar" + self.bartype = bartype + self.parent = parent + self.x = 0 + self.y = 0 + self.staticx = 0 + self.staticy = 0 + self.maxx = 0 + self.maxy = 0 + self.clickx = 0 + self.clicky = 0 + self.starty = 0 + self.lastwidth = 0 + self.lastheight = 0 + self.lastx = 0 + self.lasty = 0 + self.internal = true + self.hover = false + self.dragging = false + self.autoscroll = false + self.internal = true + + if self.bartype == "vertical" then + self.width = self.parent.width + self.height = 5 + elseif self.bartype == "horizontal" then + self.width = 5 + self.height = self.parent.height + end + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + self:CheckHover() + + local x, y = love.mouse.getPosition() + local bartype = self.bartype + local cols = {} + local basecols = {} + local dragging = self.dragging + + if bartype == "vertical" then + self.width = self.parent.width + elseif bartype == "horizontal" then + self.height = self.parent.height + end + + if bartype == "vertical" then + local parent = self.parent + local listo = parent.parent.parent + local height = parent.height * (listo.height/listo.itemheight) + local update = self.Update + if height < 20 then + self.height = 20 + else + self.height = height + end + self.maxy = parent.y + (parent.height - self.height) + self.x = parent.x + parent.width - self.width + self.y = parent.y + self.staticy + if dragging then + if self.staticy ~= self.lasty then + if listo.OnScroll then + listo.OnScroll(listo) + end + self.lasty = self.staticy + end + self.staticy = self.starty + (y - self.clicky) + end + local space = (self.maxy - parent.y) + local remaining = (0 + self.staticy) + local percent = remaining/space + local extra = listo.extraheight * percent + local autoscroll = self.autoscroll + local lastheight = self.lastheight + listo.offsety = 0 + extra + if self.staticy > space then + self.staticy = space + listo.offsety = listo.extraheight + end + if self.staticy < 0 then + self.staticy = 0 + listo.offsety = 0 + end + if autoscroll then + if listo.itemheight > lastheight then + local type = listo.type + self.lastheight = listo.itemheight + if type == "textinput" then + local indicatory = listo.indicatory + local font = listo.font + local theight = font:getHeight("a") + local y = listo.y + local height = listo.height + local linecount = #listo.lines + local parentheight = self.parent.height + if (indicatory + theight) > (y + height) then + self:Scroll(parentheight/linecount) + end + else + local maxy = self.maxy + self:Scroll(maxy) + end + end + end + elseif bartype == "horizontal" then + local parent = self.parent + local listo = self.parent.parent.parent + local width = self.parent.width * (listo.width/listo.itemwidth) + if width < 20 then + self.width = 20 + else + self.width = width + end + self.maxx = parent.x + (parent.width) - self.width + self.x = parent.x + self.staticx + self.y = parent.y + self.staticy + if dragging then + if self.staticx ~= self.lastx then + if listo.OnScroll then + listo.OnScroll(listo) + end + self.lastx = self.staticx + end + self.staticx = self.startx + (x - self.clickx) + end + local space = (self.maxx - parent.x) + local remaining = (0 + self.staticx) + local percent = remaining/space + local extra = listo.extrawidth * percent + local autoscroll = self.autoscroll + local lastwidth = self.lastwidth + listo.offsetx = 0 + extra + if self.staticx > space then + self.staticx = space + listo.offsetx = listo.extrawidth + end + + if self.staticx < 0 then + self.staticx = 0 + listo.offsetx = 0 + end + if autoscroll then + if listo.itemwidth > lastwidth then + self.lastwidth = listo.itemwidth + self:Scroll(self.maxx) + end + end + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawScrollBar or skins[defaultskin].DrawScrollBar + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local visible = self.visible + local hover = self.hover + + if not visible then + return + end + + if not hover then + return + end + + local baseparent = self:GetBaseParent() + + if baseparent.type == "frame" then + baseparent:MakeTop() + end + + local dragging = self.dragging + + if not dragging then + if button == "l" then + self.starty = self.staticy + self.startx = self.staticx + self.clickx = x + self.clicky = y + self.dragging = true + loveframes.hoverobject = self + end + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + if self.dragging then + self.dragging = false + end + +end + +--[[--------------------------------------------------------- + - func: SetMaxX(x) + - desc: sets the object's max x position +--]]--------------------------------------------------------- +function newobject:SetMaxX(x) + + self.maxx = x + +end + +--[[--------------------------------------------------------- + - func: SetMaxY(y) + - desc: sets the object's max y position +--]]--------------------------------------------------------- +function newobject:SetMaxY(y) + + self.maxy = y + +end + +--[[--------------------------------------------------------- + - func: Scroll(amount) + - desc: scrolls the object +--]]--------------------------------------------------------- +function newobject:Scroll(amount) + + local bartype = self.bartype + local listo = self.parent.parent.parent + local onscroll = listo.OnScroll + + if bartype == "vertical" then + local newy = (self.y + amount) + if newy > self.maxy then + self.staticy = self.maxy - self.parent.y + elseif newy < self.parent.y then + self.staticy = 0 + else + self.staticy = self.staticy + amount + end + elseif bartype == "horizontal" then + local newx = (self.x + amount) + if newx > self.maxx then + self.staticx = self.maxx - self.parent.x + elseif newx < self.parent.x then + self.staticx = 0 + else + self.staticx = self.staticx + amount + end + end + + if onscroll then + onscroll(listo) + end + +end + +--[[--------------------------------------------------------- + - func: IsDragging() + - desc: gets whether the object is being dragged or not +--]]--------------------------------------------------------- +function newobject:IsDragging() + + return self.dragging + +end + +--[[--------------------------------------------------------- + - func: GetBarType() + - desc: gets the object's bartype +--]]--------------------------------------------------------- +function newobject:GetBarType() + + return self.bartype + end \ No newline at end of file diff --git a/objects/internal/scrollable/scrollbody.lua b/objects/internal/scrollable/scrollbody.lua index 20e7d20..c088b9c 100644 --- a/objects/internal/scrollable/scrollbody.lua +++ b/objects/internal/scrollable/scrollbody.lua @@ -1,161 +1,187 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- scrollbar class -local newobject = loveframes.NewObject("scrollbody", "loveframes_object_scrollbody", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize(parent, bartype) - - self.type = "scrollbody" - self.bartype = bartype - self.parent = parent - self.x = 0 - self.y = 0 - self.internal = true - self.internals = {} - - if self.bartype == "vertical" then - self.width = 16 - self.height = self.parent.height - self.staticx = self.parent.width - self.width - self.staticy = 0 - elseif self.bartype == "horizontal" then - self.width = self.parent.width - self.height = 16 - self.staticx = 0 - self.staticy = self.parent.height - self.height - end - - table.insert(self.internals, loveframes.objects["scrollarea"]:new(self, bartype)) - - local bar = self.internals[1].internals[1] - - if self.bartype == "vertical" then - local upbutton = loveframes.objects["scrollbutton"]:new("up") - upbutton.parent = self - upbutton.Update = function(object, dt) - upbutton.staticx = 0 + self.width - upbutton.width - upbutton.staticy = 0 - if object.down and object.hover then - bar:Scroll(-self.parent.buttonscrollamount) - end - end - local downbutton = loveframes.objects["scrollbutton"]:new("down") - downbutton.parent = self - downbutton.Update = function(object, dt) - downbutton.staticx = 0 + self.width - downbutton.width - downbutton.staticy = 0 + self.height - downbutton.height - if object.down and object.hover then - bar:Scroll(self.parent.buttonscrollamount) - end - end - table.insert(self.internals, upbutton) - table.insert(self.internals, downbutton) - elseif self.bartype == "horizontal" then - local leftbutton = loveframes.objects["scrollbutton"]:new("left") - leftbutton.parent = self - leftbutton.Update = function(object, dt) - leftbutton.staticx = 0 - leftbutton.staticy = 0 - if object.down and object.hover then - bar:Scroll(-self.parent.buttonscrollamount) - end - end - local rightbutton = loveframes.objects["scrollbutton"]:new("right") - rightbutton.parent = self - rightbutton.Update = function(object, dt) - rightbutton.staticx = 0 + self.width - rightbutton.width - rightbutton.staticy = 0 - if object.down and object.hover then - bar:Scroll(self.parent.buttonscrollamount) - end - end - table.insert(self.internals, leftbutton) - table.insert(self.internals, rightbutton) - end - - -- apply template properties to the object - loveframes.templates.ApplyToObject(self) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local parent = self.parent - local base = loveframes.base - local update = self.Update - local internals = self.internals - - -- move to parent if there is a parent - if parent ~= base then - self.x = parent.x + self.staticx - self.y = parent.y + self.staticy - end - - self:CheckHover() - - for k, v in ipairs(internals) do - v:update(dt) - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawScrollBody or skins[defaultskin].DrawScrollBody - local draw = self.Draw - local drawcount = loveframes.drawcount - local internals = self.internals - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - - for k, v in ipairs(internals) do - v:draw() - end - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- scrollbar class +local newobject = loveframes.NewObject("scrollbody", "loveframes_object_scrollbody", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize(parent, bartype) + + self.type = "scrollbody" + self.bartype = bartype + self.parent = parent + self.x = 0 + self.y = 0 + self.internal = true + self.internals = {} + + if self.bartype == "vertical" then + self.width = 16 + self.height = self.parent.height + self.staticx = self.parent.width - self.width + self.staticy = 0 + elseif self.bartype == "horizontal" then + self.width = self.parent.width + self.height = 16 + self.staticx = 0 + self.staticy = self.parent.height - self.height + end + + table.insert(self.internals, loveframes.objects["scrollarea"]:new(self, bartype)) + + local bar = self.internals[1].internals[1] + + if self.bartype == "vertical" then + local upbutton = loveframes.objects["scrollbutton"]:new("up") + upbutton.parent = self + upbutton.Update = function(object, dt) + upbutton.staticx = 0 + self.width - upbutton.width + upbutton.staticy = 0 + if object.down and object.hover then + local dtscrolling = self.parent.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + bar:Scroll(-self.parent.buttonscrollamount * dt) + else + bar:Scroll(-self.parent.buttonscrollamount) + end + end + end + local downbutton = loveframes.objects["scrollbutton"]:new("down") + downbutton.parent = self + downbutton.Update = function(object, dt) + downbutton.staticx = 0 + self.width - downbutton.width + downbutton.staticy = 0 + self.height - downbutton.height + if object.down and object.hover then + local dtscrolling = self.parent.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + bar:Scroll(self.parent.buttonscrollamount * dt) + else + bar:Scroll(self.parent.buttonscrollamount) + end + end + end + table.insert(self.internals, upbutton) + table.insert(self.internals, downbutton) + elseif self.bartype == "horizontal" then + local leftbutton = loveframes.objects["scrollbutton"]:new("left") + leftbutton.parent = self + leftbutton.Update = function(object, dt) + leftbutton.staticx = 0 + leftbutton.staticy = 0 + if object.down and object.hover then + local dtscrolling = self.parent.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + bar:Scroll(-self.parent.buttonscrollamount * dt) + else + bar:Scroll(-self.parent.buttonscrollamount) + end + end + end + local rightbutton = loveframes.objects["scrollbutton"]:new("right") + rightbutton.parent = self + rightbutton.Update = function(object, dt) + rightbutton.staticx = 0 + self.width - rightbutton.width + rightbutton.staticy = 0 + if object.down and object.hover then + local dtscrolling = self.parent.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + bar:Scroll(self.parent.buttonscrollamount * dt) + else + bar:Scroll(self.parent.buttonscrollamount) + end + end + end + table.insert(self.internals, leftbutton) + table.insert(self.internals, rightbutton) + end + + self:SetState(parent.state) + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local parent = self.parent + local base = loveframes.base + local update = self.Update + local internals = self.internals + + -- move to parent if there is a parent + if parent ~= base then + self.x = parent.x + self.staticx + self.y = parent.y + self.staticy + end + + self:CheckHover() + + for k, v in ipairs(internals) do + v:update(dt) + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawScrollBody or skins[defaultskin].DrawScrollBody + local draw = self.Draw + local drawcount = loveframes.drawcount + local internals = self.internals + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + + for k, v in ipairs(internals) do + v:draw() + end + end \ No newline at end of file diff --git a/objects/internal/scrollable/scrollbutton.lua b/objects/internal/scrollable/scrollbutton.lua index 4b32e6f..1dc6ae8 100644 --- a/objects/internal/scrollable/scrollbutton.lua +++ b/objects/internal/scrollable/scrollbutton.lua @@ -1,165 +1,165 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- scrollbutton clas -local newobject = loveframes.NewObject("scrollbutton", "loveframes_object_scrollbutton", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize(scrolltype) - - self.type = "scrollbutton" - self.scrolltype = scrolltype - self.width = 16 - self.height = 16 - self.down = false - self.internal = true - self.OnClick = function() end - - -- apply template properties to the object - loveframes.templates.ApplyToObject(self) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - self:CheckHover() - - local hover = self.hover - local parent = self.parent - local base = loveframes.base - local update = self.Update - - if not hover then - self.down = false - else - if loveframes.hoverobject == self then - self.down = true - end - end - - if not self.down and loveframes.hoverobject == self then - self.hover = true - end - - -- move to parent if there is a parent - if parent ~= base then - self.x = parent.x + self.staticx - self.y = parent.y + self.staticy - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawScrollButton or skins[defaultskin].DrawScrollButton - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - - if hover and button == "l" then - local baseparent = self:GetBaseParent() - if baseparent.type == "frame" then - baseparent:MakeTop() - end - self.down = true - loveframes.hoverobject = self - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - local down = self.down - local onclick = self.OnClick - - if hover and down then - if button == "l" then - onclick(x, y, self) - end - end - - self.down = false - -end - ---[[--------------------------------------------------------- - - func: GetScrollType() - - desc: gets the object's scroll type ---]]--------------------------------------------------------- -function newobject:GetScrollType() - - return self.scrolltype - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- scrollbutton clas +local newobject = loveframes.NewObject("scrollbutton", "loveframes_object_scrollbutton", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize(scrolltype) + + self.type = "scrollbutton" + self.scrolltype = scrolltype + self.width = 16 + self.height = 16 + self.down = false + self.internal = true + self.OnClick = function() end + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + self:CheckHover() + + local hover = self.hover + local parent = self.parent + local base = loveframes.base + local update = self.Update + + if not hover then + self.down = false + else + if loveframes.hoverobject == self then + self.down = true + end + end + + if not self.down and loveframes.hoverobject == self then + self.hover = true + end + + -- move to parent if there is a parent + if parent ~= base then + self.x = parent.x + self.staticx + self.y = parent.y + self.staticy + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawScrollButton or skins[defaultskin].DrawScrollButton + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent.type == "frame" then + baseparent:MakeTop() + end + self.down = true + loveframes.hoverobject = self + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + local down = self.down + local onclick = self.OnClick + + if hover and down then + if button == "l" then + onclick(x, y, self) + end + end + + self.down = false + +end + +--[[--------------------------------------------------------- + - func: GetScrollType() + - desc: gets the object's scroll type +--]]--------------------------------------------------------- +function newobject:GetScrollType() + + return self.scrolltype + end \ No newline at end of file diff --git a/objects/internal/sliderbutton.lua b/objects/internal/sliderbutton.lua index 0f142a4..ea9a139 100644 --- a/objects/internal/sliderbutton.lua +++ b/objects/internal/sliderbutton.lua @@ -1,244 +1,244 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- sliderbutton class -local newobject = loveframes.NewObject("sliderbutton", "loveframes_object_sliderbutton", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize(parent) - - self.type = "sliderbutton" - self.width = 10 - self.height = 20 - self.staticx = 0 - self.staticy = 0 - self.startx = 0 - self.clickx = 0 - self.starty = 0 - self.clicky = 0 - self.intervals = true - self.internal = true - self.down = false - self.dragging = false - self.parent = parent - - -- apply template properties to the object - loveframes.templates.ApplyToObject(self) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - self:CheckHover() - - local x, y = love.mouse.getPosition() - local intervals = self.intervals - local progress = 0 - local nvalue = 0 - local pvalue = self.parent.value - local hover = self.hover - local down = self.down - local hoverobject = loveframes.hoverobject - local parent = self.parent - local slidetype = parent.slidetype - local dragging = self.dragging - local parent = self.parent - local base = loveframes.base - local update = self.Update - - if not hover then - self.down = false - if hoverobject == self then - self.hover = true - end - else - if hoverobject == self then - self.down = true - end - end - - if not down and hoverobject == self then - self.hover = true - end - - -- move to parent if there is a parent - if parent ~= base then - self.x = parent.x + self.staticx - self.y = parent.y + self.staticy - end - - -- start calculations if the button is being dragged - if dragging then - -- calculations for horizontal sliders - if slidetype == "horizontal" then - self.staticx = self.startx + (x - self.clickx) - progress = self.staticx/(self.parent.width - self.width) - nvalue = self.parent.min + (self.parent.max - self.parent.min) * progress - nvalue = loveframes.util.Round(nvalue, self.parent.decimals) - -- calculations for vertical sliders - elseif slidetype == "vertical" then - self.staticy = self.starty + (y - self.clicky) - local space = self.parent.height - self.height - local remaining = (self.parent.height - self.height) - self.staticy - local percent = remaining/space - nvalue = self.parent.min + (self.parent.max - self.parent.min) * percent - nvalue = loveframes.util.Round(nvalue, self.parent.decimals) - end - if nvalue > self.parent.max then - nvalue = self.parent.max - end - if nvalue < self.parent.min then - nvalue = self.parent.min - end - self.parent.value = nvalue - if self.parent.value == -0 then - self.parent.value = math.abs(self.parent.value) - end - if nvalue ~= pvalue and nvalue >= self.parent.min and nvalue <= self.parent.max then - if self.parent.OnValueChanged then - self.parent.OnValueChanged(self.parent, self.parent.value) - end - end - loveframes.hoverobject = self - end - - if slidetype == "horizontal" then - if (self.staticx + self.width) > self.parent.width then - self.staticx = self.parent.width - self.width - end - if self.staticx < 0 then - self.staticx = 0 - end - end - - if slidetype == "vertical" then - if (self.staticy + self.height) > self.parent.height then - self.staticy = self.parent.height - self.height - end - if self.staticy < 0 then - self.staticy = 0 - end - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawSliderButton or skins[defaultskin].DrawSliderButton - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - - if hover and button == "l" then - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - self.down = true - self.dragging = true - self.startx = self.staticx - self.clickx = x - self.starty = self.staticy - self.clicky = y - loveframes.hoverobject = self - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - self.down = false - self.dragging = false - -end - ---[[--------------------------------------------------------- - - func: MoveToX(x) - - desc: moves the object to the specified x position ---]]--------------------------------------------------------- -function newobject:MoveToX(x) - - self.staticx = x - -end - ---[[--------------------------------------------------------- - - func: MoveToY(y) - - desc: moves the object to the specified y position ---]]--------------------------------------------------------- -function newobject:MoveToY(y) - - self.staticy = y - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- sliderbutton class +local newobject = loveframes.NewObject("sliderbutton", "loveframes_object_sliderbutton", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize(parent) + + self.type = "sliderbutton" + self.width = 10 + self.height = 20 + self.staticx = 0 + self.staticy = 0 + self.startx = 0 + self.clickx = 0 + self.starty = 0 + self.clicky = 0 + self.intervals = true + self.internal = true + self.down = false + self.dragging = false + self.parent = parent + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + self:CheckHover() + + local x, y = love.mouse.getPosition() + local intervals = self.intervals + local progress = 0 + local nvalue = 0 + local pvalue = self.parent.value + local hover = self.hover + local down = self.down + local hoverobject = loveframes.hoverobject + local parent = self.parent + local slidetype = parent.slidetype + local dragging = self.dragging + local parent = self.parent + local base = loveframes.base + local update = self.Update + + if not hover then + self.down = false + if hoverobject == self then + self.hover = true + end + else + if hoverobject == self then + self.down = true + end + end + + if not down and hoverobject == self then + self.hover = true + end + + -- move to parent if there is a parent + if parent ~= base then + self.x = parent.x + self.staticx + self.y = parent.y + self.staticy + end + + -- start calculations if the button is being dragged + if dragging then + -- calculations for horizontal sliders + if slidetype == "horizontal" then + self.staticx = self.startx + (x - self.clickx) + progress = self.staticx/(self.parent.width - self.width) + nvalue = self.parent.min + (self.parent.max - self.parent.min) * progress + nvalue = loveframes.util.Round(nvalue, self.parent.decimals) + -- calculations for vertical sliders + elseif slidetype == "vertical" then + self.staticy = self.starty + (y - self.clicky) + local space = self.parent.height - self.height + local remaining = (self.parent.height - self.height) - self.staticy + local percent = remaining/space + nvalue = self.parent.min + (self.parent.max - self.parent.min) * percent + nvalue = loveframes.util.Round(nvalue, self.parent.decimals) + end + if nvalue > self.parent.max then + nvalue = self.parent.max + end + if nvalue < self.parent.min then + nvalue = self.parent.min + end + self.parent.value = nvalue + if self.parent.value == -0 then + self.parent.value = math.abs(self.parent.value) + end + if nvalue ~= pvalue and nvalue >= self.parent.min and nvalue <= self.parent.max then + if self.parent.OnValueChanged then + self.parent.OnValueChanged(self.parent, self.parent.value) + end + end + loveframes.hoverobject = self + end + + if slidetype == "horizontal" then + if (self.staticx + self.width) > self.parent.width then + self.staticx = self.parent.width - self.width + end + if self.staticx < 0 then + self.staticx = 0 + end + end + + if slidetype == "vertical" then + if (self.staticy + self.height) > self.parent.height then + self.staticy = self.parent.height - self.height + end + if self.staticy < 0 then + self.staticy = 0 + end + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawSliderButton or skins[defaultskin].DrawSliderButton + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + self.down = true + self.dragging = true + self.startx = self.staticx + self.clickx = x + self.starty = self.staticy + self.clicky = y + loveframes.hoverobject = self + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + self.down = false + self.dragging = false + +end + +--[[--------------------------------------------------------- + - func: MoveToX(x) + - desc: moves the object to the specified x position +--]]--------------------------------------------------------- +function newobject:MoveToX(x) + + self.staticx = x + +end + +--[[--------------------------------------------------------- + - func: MoveToY(y) + - desc: moves the object to the specified y position +--]]--------------------------------------------------------- +function newobject:MoveToY(y) + + self.staticy = y + end \ No newline at end of file diff --git a/objects/internal/tabbutton.lua b/objects/internal/tabbutton.lua index e8c8131..80fb0d8 100644 --- a/objects/internal/tabbutton.lua +++ b/objects/internal/tabbutton.lua @@ -1,233 +1,231 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- tabbutton class -local newobject = loveframes.NewObject("tabbutton", "loveframes_object_tabbutton", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize(parent, text, tabnumber, tip, image, onopened, onclosed) - - self.type = "tabbutton" - self.font = loveframes.smallfont - self.text = text - self.tabnumber = tabnumber - self.parent = parent - self.staticx = 0 - self.staticy = 0 - self.width = 50 - self.height = 25 - self.internal = true - self.down = false - self.image = nil - self.OnOpened = nil - self.OnClosed = nil - - if tip then - self.tooltip = loveframes.objects["tooltip"]:new(self, tip) - self.tooltip:SetFollowCursor(false) - self.tooltip:SetFollowObject(true) - self.tooltip:SetOffsets(0, -(self.tooltip.text:GetHeight() + 12)) - end - - if image then - self:SetImage(image) - end - - if onopened then - self.OnOpened = onopened - end - - if onclosed then - self.OnClosed = onclosed - end - - -- apply template properties to the object - loveframes.templates.ApplyToObject(self) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local parent = self.parent - local base = loveframes.base - local update = self.Update - - self:CheckHover() - self:SetClickBounds(parent.x, parent.y, parent.width, parent.height) - - -- move to parent if there is a parent - if parent ~= base then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - if not self.visible then - return - end - - local image = self.image - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawTabButton or skins[defaultskin].DrawTabButton - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - - if hover and button == "l" then - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - self.down = true - loveframes.hoverobject = self - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - local parent = self.parent - local tabnumber = self.tabnumber - - if hover and button == "l" then - if button == "l" then - local tab = self.parent.tab - local internals = parent.internals - local onopened = self.OnOpened - local prevtab = internals[tab] - local onclosed = prevtab.OnClosed - parent:SwitchToTab(tabnumber) - if onopened then - onopened(self) - end - if onclosed then - onclosed(prevtab) - end - end - end - - self.down = false - -end - ---[[--------------------------------------------------------- - - func: SetText(text) - - desc: sets the object's text ---]]--------------------------------------------------------- -function newobject:SetText(text) - - self.text = text - -end - ---[[--------------------------------------------------------- - - func: GetText() - - desc: gets the object's text ---]]--------------------------------------------------------- -function newobject:GetText() - - return self.text - -end - ---[[--------------------------------------------------------- - - func: SetImage(image) - - desc: adds an image to the object ---]]--------------------------------------------------------- -function newobject:SetImage(image) - - if type(image) == "string" then - self.image = love.graphics.newImage(image) - else - self.image = image - end - -end - ---[[--------------------------------------------------------- - - func: GetImage() - - desc: gets the object's image ---]]--------------------------------------------------------- -function newobject:GetImage() - - return self.image - -end - ---[[--------------------------------------------------------- - - func: GetTabNumber() - - desc: gets the object's tab number ---]]--------------------------------------------------------- -function newobject:GetTabNumber() - - return self.tabnumber - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- tabbutton class +local newobject = loveframes.NewObject("tabbutton", "loveframes_object_tabbutton", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize(parent, text, tabnumber, tip, image, onopened, onclosed) + + self.type = "tabbutton" + self.font = loveframes.smallfont + self.text = text + self.tabnumber = tabnumber + self.parent = parent + self.staticx = 0 + self.staticy = 0 + self.width = 50 + self.height = 25 + self.internal = true + self.down = false + self.image = nil + self.OnOpened = nil + self.OnClosed = nil + + if tip then + self.tooltip = loveframes.objects["tooltip"]:new(self, tip) + self.tooltip:SetFollowCursor(false) + self.tooltip:SetFollowObject(true) + self.tooltip:SetOffsets(0, -(self.tooltip.text:GetHeight() + 12)) + end + + if image then + self:SetImage(image) + end + + if onopened then + self.OnOpened = onopened + end + + if onclosed then + self.OnClosed = onclosed + end + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local parent = self.parent + local base = loveframes.base + local update = self.Update + local internals = self.internals + + self:CheckHover() + self:SetClickBounds(parent.x, parent.y, parent.width, parent.height) + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + if not self.visible then + return + end + + local image = self.image + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawTabButton or skins[defaultskin].DrawTabButton + local draw = self.Draw + local drawcount = loveframes.drawcount + local internals = self.internals + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + local internals = self.internals + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + self.down = true + loveframes.hoverobject = self + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + local parent = self.parent + local tabnumber = self.tabnumber + local internals = self.internals + + if hover and button == "l" then + if button == "l" then + local tab = self.parent.tab + local internals = parent.internals + local onopened = self.OnOpened + local prevtab = internals[tab] + local onclosed = prevtab.OnClosed + parent:SwitchToTab(tabnumber) + if onopened then + onopened(self) + end + if onclosed then + onclosed(prevtab) + end + end + end + + self.down = false + +end + +--[[--------------------------------------------------------- + - func: SetText(text) + - desc: sets the object's text +--]]--------------------------------------------------------- +function newobject:SetText(text) + + self.text = text + +end + +--[[--------------------------------------------------------- + - func: GetText() + - desc: gets the object's text +--]]--------------------------------------------------------- +function newobject:GetText() + + return self.text + +end + +--[[--------------------------------------------------------- + - func: SetImage(image) + - desc: adds an image to the object +--]]--------------------------------------------------------- +function newobject:SetImage(image) + + if type(image) == "string" then + self.image = love.graphics.newImage(image) + else + self.image = image + end + +end + +--[[--------------------------------------------------------- + - func: GetImage() + - desc: gets the object's image +--]]--------------------------------------------------------- +function newobject:GetImage() + + return self.image + +end + +--[[--------------------------------------------------------- + - func: GetTabNumber() + - desc: gets the object's tab number +--]]--------------------------------------------------------- +function newobject:GetTabNumber() + + return self.tabnumber + end \ No newline at end of file diff --git a/objects/internal/tooltip.lua b/objects/internal/tooltip.lua index c593596..a94a6ee 100644 --- a/objects/internal/tooltip.lua +++ b/objects/internal/tooltip.lua @@ -1,236 +1,256 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- tooltip clas -local newobject = loveframes.NewObject("tooltip", "loveframes_object_tooltip", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize(object, text, width) - - local width = width or 0 - - self.type = "tooltip" - self.parent = loveframes.base - self.object = object or nil - self.width = width or 0 - self.height = 0 - self.padding = 5 - self.xoffset = 10 - self.yoffset = -10 - self.internal = true - self.show = false - self.followcursor = true - self.followobject = false - self.alwaysupdate = true - - -- create the object's text - self.text = loveframes.Create("text") - self.text:Remove() - self.text.parent = self - self.text:SetText(text or "") - self.text:SetWidth(width or 0) - self.text:SetPos(0, 0) - - -- apply template properties to the object - loveframes.templates.ApplyToObject(self) - - table.insert(loveframes.base.internals, self) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local text = self.text - local object = self.object - local draworder = self.draworder - local update = self.Update - - self.width = text.width + self.padding * 2 - self.height = text.height + self.padding * 2 - - if object then - if object == loveframes.base then - self:Remove() - return - end - local hover = object.hover - local odraworder = object.draworder - local ovisible = object.visible - local ohover = object.hover - self.show = ohover - self.visible = ovisible - if ohover and ovisible then - local top = self:IsTopInternal() - local followcursor = self.followcursor - local followobject = self.followobject - if followcursor then - local x, y = love.mouse.getPosition() - self.x = x + self.xoffset - self.y = y - self.height + self.yoffset - elseif followobject then - self.x = object.x + self.xoffset - self.y = object.y + self.yoffset - end - if not top then - self:MoveToTop() - end - text:SetPos(self.padding, self.padding) - end - local baseparent = object:GetBaseParent() - if baseparent then - if baseparent.removed and baseparent.removed then - self:Remove() - end - elseif object.removed then - self:Remove() - end - end - - text:update(dt) - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local show = self.show - local text = self.text - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawToolTip or skins[defaultskin].DrawToolTip - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if show then - if draw then - draw(self) - else - drawfunc(self) - end - text:draw() - end - -end - ---[[--------------------------------------------------------- - - func: SetFollowCursor(bool) - - desc: sets whether or not the tooltip should follow the - cursor ---]]--------------------------------------------------------- -function newobject:SetFollowCursor(bool) - - self.followcursor = bool - -end - ---[[--------------------------------------------------------- - - func: SetObject(object) - - desc: sets the tooltip's object ---]]--------------------------------------------------------- -function newobject:SetObject(object) - - self.object = object - self.x = object.x - self.y = object.y - -end - ---[[--------------------------------------------------------- - - func: SetText(text) - - desc: sets the tooltip's text ---]]--------------------------------------------------------- -function newobject:SetText(text) - - self.text:SetText(text) - self.text2 = text - -end - ---[[--------------------------------------------------------- - - func: SetTextMaxWidth(text) - - desc: sets the tooltip's text max width ---]]--------------------------------------------------------- -function newobject:SetTextMaxWidth(width) - - self.text:SetMaxWidth(width) - -end - ---[[--------------------------------------------------------- - - func: SetOffsets(xoffset, yoffset) - - desc: sets the tooltip's x and y offset ---]]--------------------------------------------------------- -function newobject:SetOffsets(xoffset, yoffset) - - self.xoffset = xoffset - self.yoffset = yoffset - -end - ---[[--------------------------------------------------------- - - func: SetPadding(padding) - - desc: sets the tooltip's padding ---]]--------------------------------------------------------- -function newobject:SetPadding(padding) - - self.padding = padding - -end - ---[[--------------------------------------------------------- - - func: SetFont(font) - - desc: sets the tooltip's font ---]]--------------------------------------------------------- -function newobject:SetFont(font) - - self.text:SetFont(font) - -end - ---[[--------------------------------------------------------- - - func: SetFollowObject(bool) - - desc: sets whether or not the tooltip should follow - it's assigned object ---]]--------------------------------------------------------- -function newobject:SetFollowObject(bool) - - self.followobject = bool - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- tooltip clas +local newobject = loveframes.NewObject("tooltip", "loveframes_object_tooltip", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize(object, text, width) + + local width = width or 0 + + self.type = "tooltip" + self.parent = loveframes.base + self.object = object or nil + self.width = width or 0 + self.height = 0 + self.padding = 5 + self.xoffset = 10 + self.yoffset = -10 + self.internal = true + self.show = false + self.followcursor = true + self.followobject = false + self.alwaysupdate = true + + -- create the object's text + self.text = loveframes.Create("text") + self.text:Remove() + self.text.parent = self + self.text:SetText(text or "") + self.text:SetWidth(width or 0) + self.text:SetPos(0, 0) + + -- apply template properties to the object + loveframes.templates.ApplyToObject(self) + + table.insert(loveframes.base.internals, self) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local text = self.text + local object = self.object + local draworder = self.draworder + local update = self.Update + + self.width = text.width + self.padding * 2 + self.height = text.height + self.padding * 2 + + if object then + if object == loveframes.base then + self:Remove() + return + end + local hover = object.hover + local odraworder = object.draworder + local ovisible = object.visible + local ohover = object.hover + local ostate = object.state + if ostate ~= state then + self.show = false + self.visible = false + return + end + self.show = ohover + self.visible = ovisible + if ohover and ovisible then + local top = self:IsTopInternal() + local followcursor = self.followcursor + local followobject = self.followobject + if followcursor then + local x, y = love.mouse.getPosition() + self.x = x + self.xoffset + self.y = y - self.height + self.yoffset + elseif followobject then + self.x = object.x + self.xoffset + self.y = object.y + self.yoffset + end + if not top then + self:MoveToTop() + end + text:SetPos(self.padding, self.padding) + end + local baseparent = object:GetBaseParent() + if baseparent then + if baseparent.removed and baseparent.removed then + self:Remove() + end + elseif object.removed then + self:Remove() + end + end + + text:update(dt) + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local show = self.show + local text = self.text + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawToolTip or skins[defaultskin].DrawToolTip + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if show then + if draw then + draw(self) + else + drawfunc(self) + end + text:draw() + end + +end + +--[[--------------------------------------------------------- + - func: SetFollowCursor(bool) + - desc: sets whether or not the tooltip should follow the + cursor +--]]--------------------------------------------------------- +function newobject:SetFollowCursor(bool) + + self.followcursor = bool + +end + +--[[--------------------------------------------------------- + - func: SetObject(object) + - desc: sets the tooltip's object +--]]--------------------------------------------------------- +function newobject:SetObject(object) + + self.object = object + self.x = object.x + self.y = object.y + +end + +--[[--------------------------------------------------------- + - func: SetText(text) + - desc: sets the tooltip's text +--]]--------------------------------------------------------- +function newobject:SetText(text) + + self.text:SetText(text) + self.text2 = text + +end + +--[[--------------------------------------------------------- + - func: SetTextMaxWidth(text) + - desc: sets the tooltip's text max width +--]]--------------------------------------------------------- +function newobject:SetTextMaxWidth(width) + + self.text:SetMaxWidth(width) + +end + +--[[--------------------------------------------------------- + - func: SetOffsets(xoffset, yoffset) + - desc: sets the tooltip's x and y offset +--]]--------------------------------------------------------- +function newobject:SetOffsets(xoffset, yoffset) + + self.xoffset = xoffset + self.yoffset = yoffset + +end + +--[[--------------------------------------------------------- + - func: SetPadding(padding) + - desc: sets the tooltip's padding +--]]--------------------------------------------------------- +function newobject:SetPadding(padding) + + self.padding = padding + +end + +--[[--------------------------------------------------------- + - func: SetFont(font) + - desc: sets the tooltip's font +--]]--------------------------------------------------------- +function newobject:SetFont(font) + + self.text:SetFont(font) + +end + +--[[--------------------------------------------------------- + - func: SetFollowObject(bool) + - desc: sets whether or not the tooltip should follow + it's assigned object +--]]--------------------------------------------------------- +function newobject:SetFollowObject(bool) + + self.followobject = bool + end \ No newline at end of file diff --git a/objects/list.lua b/objects/list.lua index e84445d..fe22fed 100644 --- a/objects/list.lua +++ b/objects/list.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- list class @@ -24,12 +24,14 @@ function newobject:initialize() self.offsetx = 0 self.extrawidth = 0 self.extraheight = 0 - self.buttonscrollamount = 0.10 - self.mousewheelscrollamount = 5 + self.buttonscrollamount = 200 + self.mousewheelscrollamount = 1000 self.internal = false self.hbar = false self.vbar = false self.autoscroll = false + self.horizontalstacking = false + self.dtscrolling = true self.internals = {} self.children = {} self.OnScroll = nil @@ -42,6 +44,13 @@ end --]]--------------------------------------------------------- function newobject:update(dt) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible local alwaysupdate = self.alwaysupdate @@ -55,6 +64,7 @@ function newobject:update(dt) local children = self.children local display = self.display local parent = self.parent + local horizontalstacking = self.horizontalstacking local base = loveframes.base local update = self.Update @@ -70,15 +80,23 @@ function newobject:update(dt) v:update(dt) end + local x = self.x + local y = self.y + local width = self.width + local height = self.height + local offsetx = self.offsetx + local offsety = self.offsety + for k, v in ipairs(children) do v:update(dt) - v:SetClickBounds(self.x, self.y, self.width, self.height) - v.y = (v.parent.y + v.staticy) - self.offsety - v.x = (v.parent.x + v.staticx) - self.offsetx + v:SetClickBounds(x, y, width, height) + v.x = (v.parent.x + v.staticx) - offsetx + v.y = (v.parent.y + v.staticy) - offsety if display == "vertical" then if v.lastheight ~= v.height then self:CalculateSize() self:RedoLayout() + print("!") end end end @@ -95,15 +113,26 @@ end --]]--------------------------------------------------------- function newobject:draw() + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then return end + local x = self.x + local y = self.y + local width = self.width + local height = self.height local internals = self.internals local children = self.children - local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end + local stencilfunc = function() love.graphics.rectangle("fill", x, y, width, height) end local stencil = love.graphics.newStencil(stencilfunc) local skins = loveframes.skins.available local skinindex = loveframes.config["ACTIVESKIN"] @@ -127,8 +156,8 @@ function newobject:draw() love.graphics.setStencil(stencil) for k, v in ipairs(children) do - local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height) - if col == true then + local col = loveframes.util.BoundingBox(x, v.x, y, v.y, width, v.width, height, v.height) + if col then v:draw() end end @@ -151,6 +180,13 @@ end --]]--------------------------------------------------------- function newobject:mousepressed(x, y, button) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then @@ -175,10 +211,20 @@ function newobject:mousepressed(x, y, button) if vbar or hbar then if toplist then local bar = self:GetScrollBar() - if button == "wu" then - bar:Scroll(-scrollamount) - elseif button == "wd" then - bar:Scroll(scrollamount) + local dtscrolling = self.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + if button == "wu" then + bar:Scroll(-scrollamount * dt) + elseif button == "wd" then + bar:Scroll(scrollamount * dt) + end + else + if button == "wu" then + bar:Scroll(-scrollamount) + elseif button == "wd" then + bar:Scroll(scrollamount) + end end end end @@ -208,6 +254,7 @@ function newobject:AddItem(object) -- remove the item object from it's current parent and make it's new parent the list object object:Remove() object.parent = self + object.state = self.state -- insert the item object into the list object's children table table.insert(children, object) @@ -219,14 +266,24 @@ function newobject:AddItem(object) end --[[--------------------------------------------------------- - - func: RemoveItem(object) + - func: RemoveItem(object or number) - desc: removes an item from the object --]]--------------------------------------------------------- -function newobject:RemoveItem(object) +function newobject:RemoveItem(data) - object:Remove() - self:CalculateSize() - self:RedoLayout() + local dtype = type(data) + + if dtype == "number" then + local children = self.children + local item = children[data] + if item then + item:Remove() + end + else + object:Remove() + self:CalculateSize() + self:RedoLayout() + end end @@ -248,12 +305,39 @@ function newobject:CalculateSize() local hbar = self.hbar local internals = self.internals local children = self.children + local horizontalstacking = self.horizontalstacking if display == "vertical" then - for k, v in ipairs(self.children) do - itemheight = itemheight + v.height + spacing + if horizontalstacking then + local curwidth = 0 + local maxwidth = width - padding * 2 + local prevheight = 0 + local scrollbar = self:GetScrollBar() + if scrollbar then + maxwidth = maxwidth - scrollbar.width + end + for k, v in ipairs(children) do + if v.height > prevheight then + prevheight = v.height + end + curwidth = curwidth + v.width + spacing + if children[k + 1] then + if curwidth + children[k + 1].width > maxwidth then + curwidth = padding + itemheight = itemheight + prevheight + spacing + prevheight = 0 + end + else + itemheight = itemheight + prevheight + padding + end + end + self.itemheight = itemheight + else + for k, v in ipairs(children) do + itemheight = itemheight + v.height + spacing + end + self.itemheight = (itemheight - spacing) + padding end - self.itemheight = (itemheight - spacing) + padding local itemheight = self.itemheight if itemheight > height then self.extraheight = itemheight - height @@ -303,7 +387,10 @@ end --]]--------------------------------------------------------- function newobject:RedoLayout() + local width = self.width + local height = self.height local children = self.children + local internals = self.internals local padding = self.padding local spacing = self.spacing local starty = padding @@ -311,48 +398,91 @@ function newobject:RedoLayout() local vbar = self.vbar local hbar = self.hbar local display = self.display + local horizontalstacking = self.horizontalstacking + local scrollbody, scrollbodywidth, scrollbodyheight + + if vbar or hbar then + scrollbody = internals[1] + scrollbodywidth = scrollbody.width + scrollbodyheight = scrollbody.height + end if #children > 0 then - for k, v in ipairs(children) do - if display == "vertical" then - local height = v.height - v.staticx = padding - v.staticy = starty - v.lastheight = v.height - if vbar then - if v.width + padding > (self.width - self.internals[1].width) then - v:SetWidth((self.width - self.internals[1].width) - (padding*2)) + if display == "vertical" then + if horizontalstacking then + local curwidth = padding + local curheight = padding + local maxwidth = self.width - padding * 2 + local prevheight = 0 + local scrollbar = self:GetScrollBar() + if scrollbar then + maxwidth = maxwidth - scrollbar.width + end + for k, v in ipairs(children) do + local itemheight = v.height + v.lastheight = itemheight + v.staticx = curwidth + v.staticy = curheight + if v.height > prevheight then + prevheight = v.height end - if not v.retainsize then - v:SetWidth((self.width - self.internals[1].width) - (padding*2)) - end - self.internals[1].staticx = self.width - self.internals[1].width - self.internals[1].height = self.height - else - if not v.retainsize then - v:SetWidth(self.width - (padding*2)) + if children[k + 1] then + curwidth = curwidth + v.width + spacing + if curwidth + (children[k + 1].width) > maxwidth then + curwidth = padding + curheight = curheight + prevheight + spacing + prevheight = 0 + end end end - starty = starty + v.height - starty = starty + spacing - elseif display == "horizontal" then + else + for k, v in ipairs(children) do + local itemwidth = v.width + local itemheight = v.height + local retainsize = v.retainsize + v.staticx = padding + v.staticy = starty + v.lastheight = itemheight + if vbar then + if itemwidth + padding > (width - scrollbodywidth) then + v:SetWidth((width - scrollbodywidth) - (padding * 2)) + end + if not retainsize then + v:SetWidth((width - scrollbodywidth) - (padding * 2)) + end + scrollbody.staticx = width - scrollbodywidth + scrollbody.height = height + else + if not retainsize then + v:SetWidth(width - (padding * 2)) + end + end + starty = starty + itemheight + starty = starty + spacing + end + end + elseif display == "horizontal" then + for k, v in ipairs(children) do + local itemwidth = v.width + local itemheight = v.height + local retainsize = v.retainsize v.staticx = startx v.staticy = padding if hbar then - if v.height + padding > (self.height - self.internals[1].height) then - v:SetHeight((self.height - self.internals[1].height) - (padding*2)) + if itemheight + padding > (height - scrollbodyheight) then + v:SetHeight((height - scrollbodyheight) - (padding * 2)) end - if not v.retainsize then - v:SetHeight((self.height - self.internals[1].height) - (padding*2)) + if not retainsize then + v:SetHeight((height - scrollbodyheight) - (padding * 2)) end - self.internals[1].staticy = self.height - self.internals[1].height - self.internals[1].width = self.width + scrollbody.staticy = height - scrollbodyheight + scrollbody.width = width else - if not v.retainsize then - v:SetHeight(self.height - (padding*2)) + if not retainsize then + v:SetHeight(height - (padding * 2)) end end - startx = startx + v.width + startx = startx + itemwidth startx = startx + spacing end end @@ -557,4 +687,55 @@ function newobject:GetButtonScrollAmount() return self.mousewheelscrollamount +end + +--[[--------------------------------------------------------- + - func: EnableHorizontalStacking(bool) + - desc: enables or disables horizontal stacking +--]]--------------------------------------------------------- +function newobject:EnableHorizontalStacking(bool) + + local children = self.children + local numchildren = #children + + self.horizontalstacking = bool + + if numchildren > 0 then + self:CalculateSize() + self:RedoLayout() + end + +end + +--[[--------------------------------------------------------- + - func: GetHorizontalStacking() + - desc: gets whether or not the object allows horizontal + stacking +--]]--------------------------------------------------------- +function newobject:GetHorizontalStacking() + + return self.horizontalstacking + +end + +--[[--------------------------------------------------------- + - func: SetDTScrolling(bool) + - desc: sets whether or not the object should use delta + time when scrolling +--]]--------------------------------------------------------- +function newobject:SetDTScrolling(bool) + + self.dtscrolling = bool + +end + +--[[--------------------------------------------------------- + - func: GetDTScrolling() + - desc: gets whether or not the object should use delta + time when scrolling +--]]--------------------------------------------------------- +function newobject:GetDTScrolling() + + return self.dtscrolling + end \ No newline at end of file diff --git a/objects/multichoice.lua b/objects/multichoice.lua index 70190b4..c8cb321 100644 --- a/objects/multichoice.lua +++ b/objects/multichoice.lua @@ -1,285 +1,337 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- multichoice class -local newobject = loveframes.NewObject("multichoice", "loveframes_object_multichoice", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize() - - self.type = "multichoice" - self.choice = "" - self.text = "Select an option" - self.width = 200 - self.height = 25 - self.listpadding = 0 - self.listspacing = 0 - self.buttonscrollamount = 0.10 - self.mousewheelscrollamount = 5 - self.haslist = false - self.internal = false - self.choices = {} - self.listheight = nil - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local parent = self.parent - local base = loveframes.base - local update = self.Update - - self:CheckHover() - - -- move to parent if there is a parent - if parent ~= base then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawMultiChoice or skins[defaultskin].DrawMultiChoice - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - local haslist = self.haslist - - if hover and not haslist and button == "l" then - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - self.haslist = true - self.list = loveframes.objects["multichoicelist"]:new(self) - loveframes.hoverobject = self - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - -end - ---[[--------------------------------------------------------- - - func: AddChoice(choice) - - desc: adds a choice to the current list of choices ---]]--------------------------------------------------------- -function newobject:AddChoice(choice) - - local choices = self.choices - table.insert(choices, choice) - -end - ---[[--------------------------------------------------------- - - func: SetChoice(choice) - - desc: sets the current choice ---]]--------------------------------------------------------- -function newobject:SetChoice(choice) - - self.choice = choice - -end - ---[[--------------------------------------------------------- - - func: SelectChoice(choice) - - desc: selects a choice ---]]--------------------------------------------------------- -function newobject:SelectChoice(choice) - - local onchoiceselected = self.OnChoiceSelected - - self.choice = choice - self.list:Close() - - if onchoiceselected then - onchoiceselected(self, choice) - end - -end - ---[[--------------------------------------------------------- - - func: SetListHeight(height) - - desc: sets the height of the list of choices ---]]--------------------------------------------------------- -function newobject:SetListHeight(height) - - self.listheight = height - -end - ---[[--------------------------------------------------------- - - func: SetPadding(padding) - - desc: sets the padding of the list of choices ---]]--------------------------------------------------------- -function newobject:SetPadding(padding) - - self.listpadding = padding - -end - ---[[--------------------------------------------------------- - - func: SetSpacing(spacing) - - desc: sets the spacing of the list of choices ---]]--------------------------------------------------------- -function newobject:SetSpacing(spacing) - - self.listspacing = spacing - -end - ---[[--------------------------------------------------------- - - func: GetValue() - - desc: gets the value (choice) of the object ---]]--------------------------------------------------------- -function newobject:GetValue() - - return self.choice - -end - ---[[--------------------------------------------------------- - - func: GetChoice() - - desc: gets the current choice (same as get value) ---]]--------------------------------------------------------- -function newobject:GetChoice() - - return self.choice - -end - ---[[--------------------------------------------------------- - - func: SetText(text) - - desc: sets the object's text ---]]--------------------------------------------------------- -function newobject:SetText(text) - - self.text = text - -end - ---[[--------------------------------------------------------- - - func: GetText() - - desc: gets the object's text ---]]--------------------------------------------------------- -function newobject:GetText() - - return self.text - -end - ---[[--------------------------------------------------------- - - func: SetButtonScrollAmount(speed) - - desc: sets the scroll amount of the object's scrollbar - buttons ---]]--------------------------------------------------------- -function newobject:SetButtonScrollAmount(amount) - - self.buttonscrollamount = amount - -end - ---[[--------------------------------------------------------- - - func: GetButtonScrollAmount() - - desc: gets the scroll amount of the object's scrollbar - buttons ---]]--------------------------------------------------------- -function newobject:GetButtonScrollAmount() - - return self.buttonscrollamount - -end - ---[[--------------------------------------------------------- - - func: SetMouseWheelScrollAmount(amount) - - desc: sets the scroll amount of the mouse wheel ---]]--------------------------------------------------------- -function newobject:SetMouseWheelScrollAmount(amount) - - self.mousewheelscrollamount = amount - -end - ---[[--------------------------------------------------------- - - func: GetMouseWheelScrollAmount() - - desc: gets the scroll amount of the mouse wheel ---]]--------------------------------------------------------- -function newobject:GetButtonScrollAmount() - - return self.mousewheelscrollamount - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- multichoice class +local newobject = loveframes.NewObject("multichoice", "loveframes_object_multichoice", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "multichoice" + self.choice = "" + self.text = "Select an option" + self.width = 200 + self.height = 25 + self.listpadding = 0 + self.listspacing = 0 + self.buttonscrollamount = 200 + self.mousewheelscrollamount = 1000 + self.haslist = false + self.dtscrolling = true + self.internal = false + self.choices = {} + self.listheight = nil + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local parent = self.parent + local base = loveframes.base + local update = self.Update + + self:CheckHover() + + -- move to parent if there is a parent + if parent ~= base then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawMultiChoice or skins[defaultskin].DrawMultiChoice + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + local haslist = self.haslist + + if hover and not haslist and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + self.haslist = true + self.list = loveframes.objects["multichoicelist"]:new(self) + self.list:SetState(self.state) + loveframes.hoverobject = self + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + +end + +--[[--------------------------------------------------------- + - func: AddChoice(choice) + - desc: adds a choice to the current list of choices +--]]--------------------------------------------------------- +function newobject:AddChoice(choice) + + local choices = self.choices + table.insert(choices, choice) + +end + +--[[--------------------------------------------------------- + - func: SetChoice(choice) + - desc: sets the current choice +--]]--------------------------------------------------------- +function newobject:SetChoice(choice) + + self.choice = choice + +end + +--[[--------------------------------------------------------- + - func: SelectChoice(choice) + - desc: selects a choice +--]]--------------------------------------------------------- +function newobject:SelectChoice(choice) + + local onchoiceselected = self.OnChoiceSelected + + self.choice = choice + self.list:Close() + + if onchoiceselected then + onchoiceselected(self, choice) + end + +end + +--[[--------------------------------------------------------- + - func: SetListHeight(height) + - desc: sets the height of the list of choices +--]]--------------------------------------------------------- +function newobject:SetListHeight(height) + + self.listheight = height + +end + +--[[--------------------------------------------------------- + - func: SetPadding(padding) + - desc: sets the padding of the list of choices +--]]--------------------------------------------------------- +function newobject:SetPadding(padding) + + self.listpadding = padding + +end + +--[[--------------------------------------------------------- + - func: SetSpacing(spacing) + - desc: sets the spacing of the list of choices +--]]--------------------------------------------------------- +function newobject:SetSpacing(spacing) + + self.listspacing = spacing + +end + +--[[--------------------------------------------------------- + - func: GetValue() + - desc: gets the value (choice) of the object +--]]--------------------------------------------------------- +function newobject:GetValue() + + return self.choice + +end + +--[[--------------------------------------------------------- + - func: GetChoice() + - desc: gets the current choice (same as get value) +--]]--------------------------------------------------------- +function newobject:GetChoice() + + return self.choice + +end + +--[[--------------------------------------------------------- + - func: SetText(text) + - desc: sets the object's text +--]]--------------------------------------------------------- +function newobject:SetText(text) + + self.text = text + +end + +--[[--------------------------------------------------------- + - func: GetText() + - desc: gets the object's text +--]]--------------------------------------------------------- +function newobject:GetText() + + return self.text + +end + +--[[--------------------------------------------------------- + - func: SetButtonScrollAmount(speed) + - desc: sets the scroll amount of the object's scrollbar + buttons +--]]--------------------------------------------------------- +function newobject:SetButtonScrollAmount(amount) + + self.buttonscrollamount = amount + +end + +--[[--------------------------------------------------------- + - func: GetButtonScrollAmount() + - desc: gets the scroll amount of the object's scrollbar + buttons +--]]--------------------------------------------------------- +function newobject:GetButtonScrollAmount() + + return self.buttonscrollamount + +end + +--[[--------------------------------------------------------- + - func: SetMouseWheelScrollAmount(amount) + - desc: sets the scroll amount of the mouse wheel +--]]--------------------------------------------------------- +function newobject:SetMouseWheelScrollAmount(amount) + + self.mousewheelscrollamount = amount + +end + +--[[--------------------------------------------------------- + - func: GetMouseWheelScrollAmount() + - desc: gets the scroll amount of the mouse wheel +--]]--------------------------------------------------------- +function newobject:GetButtonScrollAmount() + + return self.mousewheelscrollamount + +end + +--[[--------------------------------------------------------- + - func: SetDTScrolling(bool) + - desc: sets whether or not the object should use delta + time when scrolling +--]]--------------------------------------------------------- +function newobject:SetDTScrolling(bool) + + self.dtscrolling = bool + +end + +--[[--------------------------------------------------------- + - func: GetDTScrolling() + - desc: gets whether or not the object should use delta + time when scrolling +--]]--------------------------------------------------------- +function newobject:GetDTScrolling() + + return self.dtscrolling + end \ No newline at end of file diff --git a/objects/numberbox.lua b/objects/numberbox.lua new file mode 100644 index 0000000..427dbc4 --- /dev/null +++ b/objects/numberbox.lua @@ -0,0 +1,478 @@ +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- numberbox class +local newobject = loveframes.NewObject("numberbox", "loveframes_object_numberbox", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "numberbox" + self.width = 80 + self.height = 20 + self.value = 0 + self.increaseamount = 1 + self.descreaseamount = 1 + self.min = -100 + self.max = 100 + self.delay = 0 + self.internal = false + self.canmodify = false + self.lastbuttonclicked = false + self.internals = {} + self.OnValueChanged = nil + + local input = loveframes.objects["textinput"]:new() + input.parent = self + input:SetSize(50, 20) + input:SetUsable({"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", "-"}) + input:SetText(self.value) + input.OnTextChanged = function(object) + local value = self.value + self.value = tonumber(object.lines[1]) + if not self.value then + return + end + if self.value > self.max then + self.value = self.max + object:SetText(self.value) + end + if self.value < self.min then + self.value = self.min + object:SetText(self.value) + end + if value ~= self.value then + if self.OnValueChanged then + self.OnValueChanged(self, self.value) + end + end + end + input.Update = function(object) + object:SetSize(object.parent.width - 20, object.parent.height) + end + + local increasebutton = loveframes.objects["button"]:new() + increasebutton.parent = self + increasebutton:SetWidth(21) + increasebutton:SetText("+") + increasebutton.OnClick = function() + local canmodify = self.canmodify + if not canmodify then + self:ModifyValue("add") + else + self.canmodify = false + end + end + increasebutton.Update = function(object) + local time = love.timer.getMicroTime() + local delay = self.delay + local down = object.down + local canmodify = self.canmodify + local lastbuttonclicked = self.lastbuttonclicked + object:SetPos(object.parent.width - 21, 0) + object:SetHeight(object.parent.height/2 + 1) + if down and not canmodify then + self:ModifyValue("add") + self.canmodify = true + self.delay = time + 0.80 + self.lastbuttonclicked = object + elseif down and canmodify and delay < time then + self:ModifyValue("add") + self.delay = time + 0.02 + elseif not down and canmodify and lastbuttonclicked == object then + self.canmodify = false + self.delay = time + 0.80 + end + end + + local decreasesbutton = loveframes.objects["button"]:new() + decreasesbutton.parent = self + decreasesbutton:SetWidth(21) + decreasesbutton:SetText("-") + decreasesbutton.OnClick = function() + local canmodify = self.canmodify + if not canmodify then + self:ModifyValue("subtract") + else + self.canmodify = false + end + end + decreasesbutton.Update = function(object) + local time = love.timer.getMicroTime() + local delay = self.delay + local down = object.down + local canmodify = self.canmodify + local lastbuttonclicked = self.lastbuttonclicked + object:SetPos(object.parent.width - 21, object.parent.height/2) + object:SetHeight(object.parent.height/2) + if down and not canmodify then + self:ModifyValue("subtract") + self.canmodify = true + self.delay = time + 0.80 + self.lastbuttonclicked = object + elseif down and canmodify and delay < time then + self:ModifyValue("subtract") + self.delay = time + 0.02 + elseif not down and canmodify and lastbuttonclicked == object then + self.canmodify = false + self.delay = time + 0.80 + end + end + + table.insert(self.internals, input) + table.insert(self.internals, increasebutton) + table.insert(self.internals, decreasesbutton) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the element +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local internals = self.internals + local parent = self.parent + local base = loveframes.base + local update = self.Update + + -- move to parent if there is a parent + if parent ~= base and parent.type ~= "list" then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + self:CheckHover() + + for k, v in ipairs(internals) do + v:update(dt) + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local internals = self.internals + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawNumberBox or skins[defaultskin].DrawNumberBox + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + + -- loop through the object's internals and draw them + for k, v in ipairs(internals) do + v:draw() + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local internals = self.internals + local hover = self.hover + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + end + + for k, v in ipairs(internals) do + v:mousepressed(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: SetValue(value) + - desc: sets the object's value +--]]--------------------------------------------------------- +function newobject:SetValue(value) + + local min = self.min + local curvalue = self.value + local value = tonumber(value) or min + local internals = self.internals + local input = internals[1] + local onvaluechanged = self.OnValueChanged + + self.value = value + input:SetValue(value) + + if value ~= curvalue then + onvaluechanged(self, value) + end + +end + +--[[--------------------------------------------------------- + - func: GetValue() + - desc: gets the object's value +--]]--------------------------------------------------------- +function newobject:GetValue() + + return self.value + +end + +--[[--------------------------------------------------------- + - func: SetIncreaseAmount(amount) + - desc: sets the object's increase amount +--]]--------------------------------------------------------- +function newobject:SetIncreaseAmount(amount) + + self.increaseamount = amount + +end + +--[[--------------------------------------------------------- + - func: GetIncreaseAmount() + - desc: gets the object's increase amount +--]]--------------------------------------------------------- +function newobject:GetIncreaseAmount() + + return self.increaseamount + +end + +--[[--------------------------------------------------------- + - func: SetDescreaseAmount(amount) + - desc: sets the object's decrease amount +--]]--------------------------------------------------------- +function newobject:SetDescreaseAmount(amount) + + self.decreaseamount = amount + +end + +--[[--------------------------------------------------------- + - func: GetDescreaseAmount() + - desc: gets the object's decrease amount +--]]--------------------------------------------------------- +function newobject:GetDescreaseAmount() + + return self.decreaseamount + +end + +--[[--------------------------------------------------------- + - func: SetMax(max) + - desc: sets the object's maximum value +--]]--------------------------------------------------------- +function newobject:SetMax(max) + + local internals = self.internals + local input = internals[1] + local onvaluechanged = self.OnValueChanged + + self.max = max + + if self.value > max then + self.value = max + input:SetValue(max) + if onvaluechanged then + onvaluechanged(self, max) + end + end + +end + +--[[--------------------------------------------------------- + - func: GetMax() + - desc: gets the object's maximum value +--]]--------------------------------------------------------- +function newobject:GetMax() + + return self.max + +end + +--[[--------------------------------------------------------- + - func: SetMin(min) + - desc: sets the object's minimum value +--]]--------------------------------------------------------- +function newobject:SetMin(min) + + local internals = self.internals + local input = internals[1] + local onvaluechanged = self.OnValueChanged + + self.min = min + + if self.value < min then + self.value = min + input:SetValue(min) + if onvaluechanged then + onvaluechanged(self, min) + end + end + +end + +--[[--------------------------------------------------------- + - func: GetMin() + - desc: gets the object's minimum value +--]]--------------------------------------------------------- +function newobject:GetMin() + + return self.min + +end + +--[[--------------------------------------------------------- + - func: SetMinMax() + - desc: sets the object's minimum and maximum values +--]]--------------------------------------------------------- +function newobject:SetMinMax(min, max) + + local internals = self.internals + local input = internals[1] + local onvaluechanged = self.OnValueChanged + + self.min = min + self.max = max + + if self.value > max then + self.value = max + input:SetValue(max) + if onvaluechanged then + onvaluechanged(self, max) + end + end + + if self.value < min then + self.value = min + input:SetValue(min) + if onvaluechanged then + onvaluechanged(self, min) + end + end + +end + +--[[--------------------------------------------------------- + - func: GetMinMax() + - desc: gets the object's minimum and maximum values +--]]--------------------------------------------------------- +function newobject:GetMinMax() + + return self.min, self.max + +end + +--[[--------------------------------------------------------- + - func: ModifyValue(type) + - desc: modifies the object's value +--]]--------------------------------------------------------- +function newobject:ModifyValue(type) + + local value = self.value + local internals = self.internals + local input = internals[1] + local onvaluechanged = self.OnValueChanged + + if not value then + return + end + + if type == "add" then + local increaseamount = self.increaseamount + local max = self.max + self.value = value + increaseamount + if self.value > max then + self.value = max + end + input:SetText(self.value) + if value ~= self.value then + if onvaluechanged then + onvaluechanged(self, self.value) + end + end + elseif type == "subtract" then + local descreaseamount = self.descreaseamount + local min = self.min + self.value = value - descreaseamount + if self.value < min then + self.value = min + end + input:SetText(self.value) + if value ~= self.value then + if onvaluechanged then + onvaluechanged(self, self.value) + end + end + end + +end \ No newline at end of file diff --git a/objects/panel.lua b/objects/panel.lua index d03d0e4..48f3922 100644 --- a/objects/panel.lua +++ b/objects/panel.lua @@ -1,144 +1,172 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- panel class -local newobject = loveframes.NewObject("panel", "loveframes_object_panel", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize() - - self.type = "panel" - self.width = 200 - self.height = 50 - self.internal = false - self.children = {} - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the element ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local children = self.children - local parent = self.parent - local base = loveframes.base - local update = self.Update - - -- move to parent if there is a parent - if parent ~= base and parent.type ~= "list" then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - self:CheckHover() - - for k, v in ipairs(children) do - v:update(dt) - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local children = self.children - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawPanel or skins[defaultskin].DrawPanel - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - - -- loop through the object's children and draw them - for k, v in ipairs(children) do - v:draw() - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local children = self.children - local hover = self.hover - - if hover and button == "l" then - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - end - - for k, v in ipairs(children) do - v:mousepressed(x, y, button) - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - local children = self.children - - if not visible then - return - end - - for k, v in ipairs(children) do - v:mousereleased(x, y, button) - end - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- panel class +local newobject = loveframes.NewObject("panel", "loveframes_object_panel", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "panel" + self.width = 200 + self.height = 50 + self.internal = false + self.children = {} + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the element +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local children = self.children + local parent = self.parent + local base = loveframes.base + local update = self.Update + + -- move to parent if there is a parent + if parent ~= base and parent.type ~= "list" then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + self:CheckHover() + + for k, v in ipairs(children) do + v:update(dt) + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local children = self.children + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawPanel or skins[defaultskin].DrawPanel + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + + -- loop through the object's children and draw them + for k, v in ipairs(children) do + v:draw() + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local children = self.children + local hover = self.hover + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + end + + for k, v in ipairs(children) do + v:mousepressed(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local children = self.children + + if not visible then + return + end + + for k, v in ipairs(children) do + v:mousereleased(x, y, button) + end + end \ No newline at end of file diff --git a/objects/progressbar.lua b/objects/progressbar.lua index 6363270..6d4e400 100644 --- a/objects/progressbar.lua +++ b/objects/progressbar.lua @@ -1,6 +1,6 @@ --[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- + -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ -- progressbar class @@ -36,6 +36,13 @@ end --]]--------------------------------------------------------- function newobject:update(dt) + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible local alwaysupdate = self.alwaysupdate @@ -123,6 +130,13 @@ end --]]--------------------------------------------------------- function newobject:draw() + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + local visible = self.visible if not visible then diff --git a/objects/slider.lua b/objects/slider.lua index 8dc663d..2c1aabc 100644 --- a/objects/slider.lua +++ b/objects/slider.lua @@ -1,388 +1,409 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- slider class -local newobject = loveframes.NewObject("slider", "loveframes_object_slider", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize() - - self.type = "slider" - self.text = "Slider" - self.slidetype = "horizontal" - self.width = 5 - self.height = 5 - self.max = 10 - self.min = 0 - self.value = 0 - self.decimals = 5 - self.internal = false - self.internals = {} - self.OnValueChanged = nil - - -- create the slider button - table.insert(self.internals, loveframes.objects["sliderbutton"]:new(self)) - - -- set initial value to minimum - self:SetValue(self.min) - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local internals = self.internals - local sliderbutton = internals[1] - local parent = self.parent - local base = loveframes.base - local update = self.Update - - self:CheckHover() - - -- move to parent if there is a parent - if parent ~= base and parent.type ~= "list" then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - if sliderbutton then - if self.slidetype == "horizontal" then - self.height = sliderbutton.height - elseif self.slidetype == "vertical" then - self.width = sliderbutton.width - end - end - - -- update internals - for k, v in ipairs(self.internals) do - v:update(dt) - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local internals = self.internals - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawSlider or skins[defaultskin].DrawSlider - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - - -- draw internals - for k, v in ipairs(internals) do - v:draw() - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local internals = self.internals - - if self.hover and button == "l" then - if self.slidetype == "horizontal" then - local xpos = x - self.x - local button = internals[1] - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - button:MoveToX(xpos) - button.down = true - button.dragging = true - button.startx = button.staticx - button.clickx = x - elseif self.slidetype == "vertical" then - local ypos = y - self.y - local button = internals[1] - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - button:MoveToY(ypos) - button.down = true - button.dragging = true - button.starty = button.staticy - button.clicky = y - end - end - - for k, v in ipairs(internals) do - v:mousepressed(x, y, button) - end - -end - ---[[--------------------------------------------------------- - - func: SetValue(value) - - desc: sets the object's value ---]]--------------------------------------------------------- -function newobject:SetValue(value) - - if value > self.max then - return - end - - if value < self.min then - return - end - - local decimals = self.decimals - local newval = loveframes.util.Round(value, decimals) - local internals = self.internals - local onvaluechanged = self.OnValueChanged - - -- set the new value - self.value = newval - - -- slider button object - local sliderbutton = internals[1] - local slidetype = self.slidetype - local width = self.width - local height = self.height - local min = self.min - local max = self.max - - -- move the slider button to the new position - if slidetype == "horizontal" then - local xpos = width * ((newval - min) / (max - min)) - sliderbutton:MoveToX(xpos) - elseif slidetype == "vertical" then - local ypos = height - height * ((newval - min) / (max - min)) - sliderbutton:MoveToY(ypos) - end - - -- call OnValueChanged - if onvaluechanged then - onvaluechanged(self) - end - -end - ---[[--------------------------------------------------------- - - func: GetValue() - - desc: gets the object's value ---]]--------------------------------------------------------- -function newobject:GetValue() - - return self.value - -end - ---[[--------------------------------------------------------- - - func: SetMax(max) - - desc: sets the object's maximum value ---]]--------------------------------------------------------- -function newobject:SetMax(max) - - self.max = max - - if self.value > self.max then - self.value = self.max - end - -end - ---[[--------------------------------------------------------- - - func: GetMax() - - desc: gets the object's maximum value ---]]--------------------------------------------------------- -function newobject:GetMax() - - return self.max - -end - ---[[--------------------------------------------------------- - - func: SetMin(min) - - desc: sets the object's minimum value ---]]--------------------------------------------------------- -function newobject:SetMin(min) - - self.min = min - - if self.value < self.min then - self.value = self.min - end - -end - ---[[--------------------------------------------------------- - - func: GetMin() - - desc: gets the object's minimum value ---]]--------------------------------------------------------- -function newobject:GetMin() - - return self.min - -end - ---[[--------------------------------------------------------- - - func: SetMinMax() - - desc: sets the object's minimum and maximum values ---]]--------------------------------------------------------- -function newobject:SetMinMax(min, max) - - self.min = min - self.max = max - - if self.value > self.max then - self.value = self.max - end - - if self.value < self.min then - self.value = self.min - end - -end - ---[[--------------------------------------------------------- - - func: GetMinMax() - - desc: gets the object's minimum and maximum values ---]]--------------------------------------------------------- -function newobject:GetMinMax() - - return self.min, self.max - -end - ---[[--------------------------------------------------------- - - func: SetText(name) - - desc: sets the objects's text ---]]--------------------------------------------------------- -function newobject:SetText(text) - - self.text = text - -end - ---[[--------------------------------------------------------- - - func: GetText() - - desc: gets the objects's text ---]]--------------------------------------------------------- -function newobject:GetText() - - return self.text - -end - ---[[--------------------------------------------------------- - - func: SetDecimals(decimals) - - desc: sets the objects's decimals ---]]--------------------------------------------------------- -function newobject:SetDecimals(decimals) - - self.decimals = decimals - -end - ---[[--------------------------------------------------------- - - func: SetButtonSize(width, height) - - desc: sets the objects's button size ---]]--------------------------------------------------------- -function newobject:SetButtonSize(width, height) - - local internals = self.internals - local sliderbutton = internals[1] - - if sliderbutton then - sliderbutton.width = width - sliderbutton.height = height - end - -end - ---[[--------------------------------------------------------- - - func: GetButtonSize() - - desc: gets the objects's button size ---]]--------------------------------------------------------- -function newobject:GetButtonSize() - - local internals = self.internals - local sliderbutton = internals[1] - - if sliderbutton then - return sliderbutton.width, sliderbutton.height - else - return false - end - -end - ---[[--------------------------------------------------------- - - func: SetSlideType(slidetype) - - desc: sets the objects's slide type ---]]--------------------------------------------------------- -function newobject:SetSlideType(slidetype) - - self.slidetype = slidetype - - if slidetype == "vertical" then - self:SetValue(self.min) - end - -end - ---[[--------------------------------------------------------- - - func: GetSlideType() - - desc: gets the objects's slide type ---]]--------------------------------------------------------- -function newobject:GetSlideType() - - return self.slidetype - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- slider class +local newobject = loveframes.NewObject("slider", "loveframes_object_slider", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "slider" + self.text = "Slider" + self.slidetype = "horizontal" + self.width = 5 + self.height = 5 + self.max = 10 + self.min = 0 + self.value = 0 + self.decimals = 5 + self.internal = false + self.internals = {} + self.OnValueChanged = nil + + -- create the slider button + local sliderbutton = loveframes.objects["sliderbutton"]:new(self) + sliderbutton.state = self.state + table.insert(self.internals, sliderbutton) + + -- set initial value to minimum + self:SetValue(self.min) + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local internals = self.internals + local sliderbutton = internals[1] + local parent = self.parent + local base = loveframes.base + local update = self.Update + + self:CheckHover() + + -- move to parent if there is a parent + if parent ~= base and parent.type ~= "list" then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + if sliderbutton then + if self.slidetype == "horizontal" then + self.height = sliderbutton.height + elseif self.slidetype == "vertical" then + self.width = sliderbutton.width + end + end + + -- update internals + for k, v in ipairs(self.internals) do + v:update(dt) + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local internals = self.internals + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawSlider or skins[defaultskin].DrawSlider + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + + -- draw internals + for k, v in ipairs(internals) do + v:draw() + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local internals = self.internals + + if self.hover and button == "l" then + if self.slidetype == "horizontal" then + local xpos = x - self.x + local button = internals[1] + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + button:MoveToX(xpos) + button.down = true + button.dragging = true + button.startx = button.staticx + button.clickx = x + elseif self.slidetype == "vertical" then + local ypos = y - self.y + local button = internals[1] + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + button:MoveToY(ypos) + button.down = true + button.dragging = true + button.starty = button.staticy + button.clicky = y + end + end + + for k, v in ipairs(internals) do + v:mousepressed(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: SetValue(value) + - desc: sets the object's value +--]]--------------------------------------------------------- +function newobject:SetValue(value) + + if value > self.max then + return + end + + if value < self.min then + return + end + + local decimals = self.decimals + local newval = loveframes.util.Round(value, decimals) + local internals = self.internals + local onvaluechanged = self.OnValueChanged + + -- set the new value + self.value = newval + + -- slider button object + local sliderbutton = internals[1] + local slidetype = self.slidetype + local width = self.width + local height = self.height + local min = self.min + local max = self.max + + -- move the slider button to the new position + if slidetype == "horizontal" then + local xpos = width * ((newval - min) / (max - min)) + sliderbutton:MoveToX(xpos) + elseif slidetype == "vertical" then + local ypos = height - height * ((newval - min) / (max - min)) + sliderbutton:MoveToY(ypos) + end + + -- call OnValueChanged + if onvaluechanged then + onvaluechanged(self) + end + +end + +--[[--------------------------------------------------------- + - func: GetValue() + - desc: gets the object's value +--]]--------------------------------------------------------- +function newobject:GetValue() + + return self.value + +end + +--[[--------------------------------------------------------- + - func: SetMax(max) + - desc: sets the object's maximum value +--]]--------------------------------------------------------- +function newobject:SetMax(max) + + self.max = max + + if self.value > self.max then + self.value = self.max + end + +end + +--[[--------------------------------------------------------- + - func: GetMax() + - desc: gets the object's maximum value +--]]--------------------------------------------------------- +function newobject:GetMax() + + return self.max + +end + +--[[--------------------------------------------------------- + - func: SetMin(min) + - desc: sets the object's minimum value +--]]--------------------------------------------------------- +function newobject:SetMin(min) + + self.min = min + + if self.value < self.min then + self.value = self.min + end + +end + +--[[--------------------------------------------------------- + - func: GetMin() + - desc: gets the object's minimum value +--]]--------------------------------------------------------- +function newobject:GetMin() + + return self.min + +end + +--[[--------------------------------------------------------- + - func: SetMinMax() + - desc: sets the object's minimum and maximum values +--]]--------------------------------------------------------- +function newobject:SetMinMax(min, max) + + self.min = min + self.max = max + + if self.value > self.max then + self.value = self.max + end + + if self.value < self.min then + self.value = self.min + end + +end + +--[[--------------------------------------------------------- + - func: GetMinMax() + - desc: gets the object's minimum and maximum values +--]]--------------------------------------------------------- +function newobject:GetMinMax() + + return self.min, self.max + +end + +--[[--------------------------------------------------------- + - func: SetText(name) + - desc: sets the objects's text +--]]--------------------------------------------------------- +function newobject:SetText(text) + + self.text = text + +end + +--[[--------------------------------------------------------- + - func: GetText() + - desc: gets the objects's text +--]]--------------------------------------------------------- +function newobject:GetText() + + return self.text + +end + +--[[--------------------------------------------------------- + - func: SetDecimals(decimals) + - desc: sets the objects's decimals +--]]--------------------------------------------------------- +function newobject:SetDecimals(decimals) + + self.decimals = decimals + +end + +--[[--------------------------------------------------------- + - func: SetButtonSize(width, height) + - desc: sets the objects's button size +--]]--------------------------------------------------------- +function newobject:SetButtonSize(width, height) + + local internals = self.internals + local sliderbutton = internals[1] + + if sliderbutton then + sliderbutton.width = width + sliderbutton.height = height + end + +end + +--[[--------------------------------------------------------- + - func: GetButtonSize() + - desc: gets the objects's button size +--]]--------------------------------------------------------- +function newobject:GetButtonSize() + + local internals = self.internals + local sliderbutton = internals[1] + + if sliderbutton then + return sliderbutton.width, sliderbutton.height + end + +end + +--[[--------------------------------------------------------- + - func: SetSlideType(slidetype) + - desc: sets the objects's slide type +--]]--------------------------------------------------------- +function newobject:SetSlideType(slidetype) + + self.slidetype = slidetype + + if slidetype == "vertical" then + self:SetValue(self.min) + end + +end + +--[[--------------------------------------------------------- + - func: GetSlideType() + - desc: gets the objects's slide type +--]]--------------------------------------------------------- +function newobject:GetSlideType() + + return self.slidetype + end \ No newline at end of file diff --git a/objects/tabs.lua b/objects/tabs.lua index dca593d..e98125f 100644 --- a/objects/tabs.lua +++ b/objects/tabs.lua @@ -1,474 +1,628 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- tabs class -local newobject = loveframes.NewObject("tabs", "loveframes_object_tabs", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize() - - self.type = "tabs" - self.width = 100 - self.height = 50 - self.clickx = 0 - self.clicky = 0 - self.offsetx = 0 - self.tab = 1 - self.tabnumber = 1 - self.padding = 5 - self.tabheight = 25 - self.previoustabheight = 25 - self.autosize = true - self.internal = false - self.tooltipfont = loveframes.basicfontsmall - self.internals = {} - self.children = {} - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the element ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - local x, y = love.mouse.getPosition() - local tabheight = self.tabheight - local padding = self.padding - local autosize = self.autosize - local padding = self.padding - local autosize = self.autosize - local children = self.children - local numchildren = #children - local internals = self.internals - local tab = self.tab - local parent = self.parent - local autosize = self.autosize - local base = loveframes.base - local update = self.Update - - -- move to parent if there is a parent - if parent ~= base then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - self:CheckHover() - - if numchildren > 0 and tab == 0 then - self.tab = 1 - end - - local pos = 0 - - for k, v in ipairs(internals) do - v:update(dt) - if v.type == "tabbutton" then - v.y = (v.parent.y + v.staticy) - v.x = (v.parent.x + v.staticx) + pos + self.offsetx - pos = pos + v.width - 1 - end - end - - for k, v in ipairs(children) do - v:update(dt) - v:SetPos(padding, tabheight + padding) - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local internals = self.internals - local tabheight = self:GetHeightOfButtons() - local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, tabheight) end - local stencil = love.graphics.newStencil(stencilfunc) - local internals = self.internals - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawTabPanel or skins[defaultskin].DrawTabPanel - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - - love.graphics.setStencil(stencil) - - for k, v in ipairs(internals) do - v:draw() - end - - love.graphics.setStencil() - - if #self.children > 0 then - self.children[self.tab]:draw() - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local children = self.children - local numchildren = #children - local tab = self.tab - local internals = self.internals - local numinternals = #internals - local hover = self.hover - - if hover then - if button == "l" then - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - end - end - - if button == "wu" then - local buttonheight = self:GetHeightOfButtons() - local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1) - local visible = internals[numinternals - 1]:GetVisible() - if col and visible then - self.offsetx = self.offsetx + 5 - if self.offsetx > 0 then - self.offsetx = 0 - end - end - end - - if button == "wd" then - local buttonheight = self:GetHeightOfButtons() - local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1) - local visible = internals[numinternals]:GetVisible() - if col and visible then - local bwidth = self:GetWidthOfButtons() - if (self.offsetx + bwidth) < self.width then - self.offsetx = bwidth - self.width - else - self.offsetx = self.offsetx - 5 - end - end - end - - for k, v in ipairs(internals) do - v:mousepressed(x, y, button) - end - - if numchildren > 0 then - children[tab]:mousepressed(x, y, button) - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - local children = self.children - local numchildren = #children - local tab = self.tab - local internals = self.internals - - if not visible then - return - end - - for k, v in ipairs(internals) do - v:mousereleased(x, y, button) - end - - if numchildren > 0 then - children[tab]:mousereleased(x, y, button) - end - -end - ---[[--------------------------------------------------------- - - func: AddTab(name, object, tip, image) - - desc: adds a new tab to the tab panel ---]]--------------------------------------------------------- -function newobject:AddTab(name, object, tip, image, onopened, onclosed) - - local padding = self.padding - local autosize = self.autosize - local tabnumber = self.tabnumber - local tabheight = self.tabheight - local internals = self.internals - - object:Remove() - object.parent = self - object.staticx = 0 - object.staticy = 0 - - table.insert(self.children, object) - internals[tabnumber] = loveframes.objects["tabbutton"]:new(self, name, tabnumber, tip, image, onopened, onclosed) - self.tabnumber = tabnumber + 1 - - for k, v in ipairs(internals) do - self:SwitchToTab(k) - break - end - - self:AddScrollButtons() - - if autosize and not retainsize then - object:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2) - end - -end - ---[[--------------------------------------------------------- - - func: AddScrollButtons() - - desc: creates scroll buttons fot the tab panel - - note: for internal use only ---]]--------------------------------------------------------- -function newobject:AddScrollButtons() - - local internals = self.internals - - for k, v in ipairs(internals) do - if v.type == "scrollbutton" then - table.remove(internals, k) - end - end - - local leftbutton = loveframes.objects["scrollbutton"]:new("left") - leftbutton.parent = self - leftbutton:SetPos(0, 0) - leftbutton:SetSize(15, 25) - leftbutton:SetAlwaysUpdate(true) - leftbutton.Update = function(object, dt) - if self.offsetx ~= 0 then - object.visible = true - else - object.visible = false - object.down = false - object.hover = false - end - - if object.down == true then - if self.offsetx ~= 0 then - self.offsetx = self.offsetx + 1 - end - end - end - - local rightbutton = loveframes.objects["scrollbutton"]:new("right") - rightbutton.parent = self - rightbutton:SetPos(self.width - 15, 0) - rightbutton:SetSize(15, 25) - rightbutton:SetAlwaysUpdate(true) - rightbutton.Update = function(object, dt) - local bwidth = self:GetWidthOfButtons() - if (self.offsetx + bwidth) > self.width then - object.visible = true - else - object.visible = false - object.down = false - object.hover = false - end - - if object.down == true then - if ((self.x + self.offsetx) + bwidth) ~= (self.x + self.width) then - self.offsetx = self.offsetx - 1 - end - end - end - - table.insert(internals, leftbutton) - table.insert(internals, rightbutton) - -end - ---[[--------------------------------------------------------- - - func: GetWidthOfButtons() - - desc: gets the total width of all of the tab buttons ---]]--------------------------------------------------------- -function newobject:GetWidthOfButtons() - - local width = 0 - local internals = self.internals - - for k, v in ipairs(internals) do - if v.type == "tabbutton" then - width = width + v.width - end - end - - return width - -end - ---[[--------------------------------------------------------- - - func: GetHeightOfButtons() - - desc: gets the height of one tab button ---]]--------------------------------------------------------- -function newobject:GetHeightOfButtons() - - return self.tabheight - -end - ---[[--------------------------------------------------------- - - func: SwitchToTab(tabnumber) - - desc: makes the specified tab the active tab ---]]--------------------------------------------------------- -function newobject:SwitchToTab(tabnumber) - - local children = self.children - - for k, v in ipairs(children) do - v.visible = false - end - - self.tab = tabnumber - self.children[tabnumber].visible = true - -end - ---[[--------------------------------------------------------- - - func: SetScrollButtonSize(width, height) - - desc: sets the size of the scroll buttons ---]]--------------------------------------------------------- -function newobject:SetScrollButtonSize(width, height) - - local internals = self.internals - - for k, v in ipairs(internals) do - if v.type == "scrollbutton" then - v:SetSize(width, height) - end - end - -end - ---[[--------------------------------------------------------- - - func: SetPadding(paddint) - - desc: sets the padding for the tab panel ---]]--------------------------------------------------------- -function newobject:SetPadding(padding) - - self.padding = padding - -end - ---[[--------------------------------------------------------- - - func: SetPadding(paddint) - - desc: gets the padding of the tab panel ---]]--------------------------------------------------------- -function newobject:GetPadding() - - return self.padding - -end - ---[[--------------------------------------------------------- - - func: SetTabHeight(height) - - desc: sets the height of the tab buttons ---]]--------------------------------------------------------- -function newobject:SetTabHeight(height) - - local autosize = self.autosize - local padding = self.padding - local previoustabheight = self.previoustabheight - local children = self.children - local internals = self.internals - - self.tabheight = height - - local tabheight = self.tabheight - - if tabheight ~= previoustabheight then - for k, v in ipairs(children) do - local retainsize = v.retainsize - if autosize and not retainsize then - v:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2) - end - end - self.previoustabheight = tabheight - end - - for k, v in ipairs(internals) do - if v.type == "tabbutton" then - v:SetHeight(self.tabheight) - end - end - -end - ---[[--------------------------------------------------------- - - func: SetToolTipFont(font) - - desc: sets the height of the tab buttons ---]]--------------------------------------------------------- -function newobject:SetToolTipFont(font) - - local internals = self.internals - - for k, v in ipairs(internals) do - if v.type == "tabbutton" and v.tooltip then - v.tooltip:SetFont(font) - end - end - -end - ---[[--------------------------------------------------------- - - func: GetTabNumber() - - desc: gets the object's tab number ---]]--------------------------------------------------------- -function newobject:GetTabNumber() - - return self.tab - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- tabs class +local newobject = loveframes.NewObject("tabs", "loveframes_object_tabs", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "tabs" + self.width = 100 + self.height = 50 + self.clickx = 0 + self.clicky = 0 + self.offsetx = 0 + self.tab = 1 + self.tabnumber = 1 + self.padding = 5 + self.tabheight = 25 + self.previoustabheight = 25 + self.buttonscrollamount = 200 + self.mousewheelscrollamount = 5 + self.autosize = true + self.dtscrolling = true + self.internal = false + self.tooltipfont = loveframes.basicfontsmall + self.internals = {} + self.children = {} + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the element +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local x, y = love.mouse.getPosition() + local tabheight = self.tabheight + local padding = self.padding + local autosize = self.autosize + local padding = self.padding + local autosize = self.autosize + local children = self.children + local numchildren = #children + local internals = self.internals + local tab = self.tab + local parent = self.parent + local autosize = self.autosize + local base = loveframes.base + local update = self.Update + + -- move to parent if there is a parent + if parent ~= base then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + self:CheckHover() + + if numchildren > 0 and tab == 0 then + self.tab = 1 + end + + local pos = 0 + + for k, v in ipairs(internals) do + v:update(dt) + if v.type == "tabbutton" then + v.x = (v.parent.x + v.staticx) + pos + self.offsetx + v.y = (v.parent.y + v.staticy) + pos = pos + v.width - 1 + end + end + + for k, v in ipairs(children) do + v:update(dt) + v:SetPos(padding, tabheight + padding) + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local internals = self.internals + local tabheight = self:GetHeightOfButtons() + local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, tabheight) end + local stencil = love.graphics.newStencil(stencilfunc) + local internals = self.internals + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawTabPanel or skins[defaultskin].DrawTabPanel + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + + love.graphics.setStencil(stencil) + + for k, v in ipairs(internals) do + v:draw() + end + + love.graphics.setStencil() + + if #self.children > 0 then + self.children[self.tab]:draw() + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local children = self.children + local numchildren = #children + local tab = self.tab + local internals = self.internals + local numinternals = #internals + local hover = self.hover + + if hover then + if button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + end + end + + if button == "wu" then + local buttonheight = self:GetHeightOfButtons() + local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1) + local visible = internals[numinternals - 1]:GetVisible() + if col and visible then + local scrollamount = self.mousewheelscrollamount + local dtscrolling = self.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + self.offsetx = self.offsetx + scrollamount * dt + else + self.offsetx = self.offsetx + scrollamount + end + if self.offsetx > 0 then + self.offsetx = 0 + end + end + end + + if button == "wd" then + local buttonheight = self:GetHeightOfButtons() + local col = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, buttonheight, 1) + local visible = internals[numinternals]:GetVisible() + if col and visible then + local bwidth = self:GetWidthOfButtons() + if (self.offsetx + bwidth) < self.width then + self.offsetx = bwidth - self.width + else + local scrollamount = self.mousewheelscrollamount + local dtscrolling = self.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + self.offsetx = self.offsetx - scrollamount * dt + else + self.offsetx = self.offsetx - scrollamount + end + end + end + end + + for k, v in ipairs(internals) do + v:mousepressed(x, y, button) + end + + if numchildren > 0 then + children[tab]:mousepressed(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local children = self.children + local numchildren = #children + local tab = self.tab + local internals = self.internals + + if not visible then + return + end + + for k, v in ipairs(internals) do + v:mousereleased(x, y, button) + end + + if numchildren > 0 then + children[tab]:mousereleased(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: AddTab(name, object, tip, image) + - desc: adds a new tab to the tab panel +--]]--------------------------------------------------------- +function newobject:AddTab(name, object, tip, image, onopened, onclosed) + + local padding = self.padding + local autosize = self.autosize + local tabnumber = self.tabnumber + local tabheight = self.tabheight + local internals = self.internals + + object:Remove() + object.parent = self + object:SetState(self.state) + object.staticx = 0 + object.staticy = 0 + + table.insert(self.children, object) + internals[tabnumber] = loveframes.objects["tabbutton"]:new(self, name, tabnumber, tip, image, showclose, onopened, onclosed) + self.tabnumber = tabnumber + 1 + self:AddScrollButtons() + + if autosize and not retainsize then + object:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2) + end + +end + +--[[--------------------------------------------------------- + - func: AddScrollButtons() + - desc: creates scroll buttons fot the tab panel + - note: for internal use only +--]]--------------------------------------------------------- +function newobject:AddScrollButtons() + + local internals = self.internals + + for k, v in ipairs(internals) do + if v.type == "scrollbutton" then + table.remove(internals, k) + end + end + + local leftbutton = loveframes.objects["scrollbutton"]:new("left") + leftbutton.parent = self + leftbutton:SetPos(0, 0) + leftbutton:SetSize(15, 25) + leftbutton:SetAlwaysUpdate(true) + leftbutton.Update = function(object, dt) + if self.offsetx ~= 0 then + object.visible = true + else + object.visible = false + object.down = false + object.hover = false + end + if object.down then + if self.offsetx > 0 then + self.offsetx = 0 + else + local scrollamount = self.buttonscrollamount + local dtscrolling = self.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + self.offsetx = self.offsetx + scrollamount * dt + else + self.offsetx = self.offsetx + scrollamount + end + end + end + end + + local rightbutton = loveframes.objects["scrollbutton"]:new("right") + rightbutton.parent = self + rightbutton:SetPos(self.width - 15, 0) + rightbutton:SetSize(15, 25) + rightbutton:SetAlwaysUpdate(true) + rightbutton.Update = function(object, dt) + local bwidth = self:GetWidthOfButtons() + if (self.offsetx + bwidth) > self.width then + object.visible = true + else + object.visible = false + object.down = false + object.hover = false + end + if object.down then + if ((self.x + self.offsetx) + bwidth) ~= (self.x + self.width) then + local scrollamount = self.buttonscrollamount + local dtscrolling = self.dtscrolling + if dtscrolling then + local dt = love.timer.getDelta() + self.offsetx = self.offsetx - scrollamount * dt + else + self.offsetx = self.offsetx - scrollamount + end + end + end + end + + table.insert(internals, leftbutton) + table.insert(internals, rightbutton) + +end + +--[[--------------------------------------------------------- + - func: GetWidthOfButtons() + - desc: gets the total width of all of the tab buttons +--]]--------------------------------------------------------- +function newobject:GetWidthOfButtons() + + local width = 0 + local internals = self.internals + + for k, v in ipairs(internals) do + if v.type == "tabbutton" then + width = width + v.width + end + end + + return width + +end + +--[[--------------------------------------------------------- + - func: GetHeightOfButtons() + - desc: gets the height of one tab button +--]]--------------------------------------------------------- +function newobject:GetHeightOfButtons() + + return self.tabheight + +end + +--[[--------------------------------------------------------- + - func: SwitchToTab(tabnumber) + - desc: makes the specified tab the active tab +--]]--------------------------------------------------------- +function newobject:SwitchToTab(tabnumber) + + local children = self.children + + for k, v in ipairs(children) do + v.visible = false + end + + self.tab = tabnumber + self.children[tabnumber].visible = true + +end + +--[[--------------------------------------------------------- + - func: SetScrollButtonSize(width, height) + - desc: sets the size of the scroll buttons +--]]--------------------------------------------------------- +function newobject:SetScrollButtonSize(width, height) + + local internals = self.internals + + for k, v in ipairs(internals) do + if v.type == "scrollbutton" then + v:SetSize(width, height) + end + end + +end + +--[[--------------------------------------------------------- + - func: SetPadding(paddint) + - desc: sets the padding for the tab panel +--]]--------------------------------------------------------- +function newobject:SetPadding(padding) + + self.padding = padding + +end + +--[[--------------------------------------------------------- + - func: SetPadding(paddint) + - desc: gets the padding of the tab panel +--]]--------------------------------------------------------- +function newobject:GetPadding() + + return self.padding + +end + +--[[--------------------------------------------------------- + - func: SetTabHeight(height) + - desc: sets the height of the tab buttons +--]]--------------------------------------------------------- +function newobject:SetTabHeight(height) + + local autosize = self.autosize + local padding = self.padding + local previoustabheight = self.previoustabheight + local children = self.children + local internals = self.internals + + self.tabheight = height + + local tabheight = self.tabheight + + if tabheight ~= previoustabheight then + for k, v in ipairs(children) do + local retainsize = v.retainsize + if autosize and not retainsize then + v:SetSize(self.width - padding*2, (self.height - tabheight) - padding*2) + end + end + self.previoustabheight = tabheight + end + + for k, v in ipairs(internals) do + if v.type == "tabbutton" then + v:SetHeight(self.tabheight) + end + end + +end + +--[[--------------------------------------------------------- + - func: SetToolTipFont(font) + - desc: sets the height of the tab buttons +--]]--------------------------------------------------------- +function newobject:SetToolTipFont(font) + + local internals = self.internals + + for k, v in ipairs(internals) do + if v.type == "tabbutton" and v.tooltip then + v.tooltip:SetFont(font) + end + end + +end + +--[[--------------------------------------------------------- + - func: GetTabNumber() + - desc: gets the object's tab number +--]]--------------------------------------------------------- +function newobject:GetTabNumber() + + return self.tab + +end + +--[[--------------------------------------------------------- + - func: RemoveTab(id) + - desc: removes a tab from the object +--]]--------------------------------------------------------- +function newobject:RemoveTab(id) + + local children = self.children + local internals = self.internals + local tab = children[id] + + if tab then + tab:Remove() + end + + for k, v in ipairs(internals) do + if v.type == "tabbutton" then + if v.tabnumber == id then + v:Remove() + end + end + end + + local tabnumber = 1 + + for k, v in ipairs(internals) do + if v.type == "tabbutton" then + v.tabnumber = tabnumber + tabnumber = tabnumber + 1 + end + end + + self.tabnumber = tabnumber + self:AddScrollButtons() + +end + +--[[--------------------------------------------------------- + - func: SetButtonScrollAmount(speed) + - desc: sets the scroll amount of the object's scrollbar + buttons +--]]--------------------------------------------------------- +function newobject:SetButtonScrollAmount(amount) + + self.buttonscrollamount = amount + +end + +--[[--------------------------------------------------------- + - func: GetButtonScrollAmount() + - desc: gets the scroll amount of the object's scrollbar + buttons +--]]--------------------------------------------------------- +function newobject:GetButtonScrollAmount() + + return self.buttonscrollamount + +end + +--[[--------------------------------------------------------- + - func: SetMouseWheelScrollAmount(amount) + - desc: sets the scroll amount of the mouse wheel +--]]--------------------------------------------------------- +function newobject:SetMouseWheelScrollAmount(amount) + + self.mousewheelscrollamount = amount + +end + +--[[--------------------------------------------------------- + - func: GetMouseWheelScrollAmount() + - desc: gets the scroll amount of the mouse wheel +--]]--------------------------------------------------------- +function newobject:GetButtonScrollAmount() + + return self.mousewheelscrollamount + +end + +--[[--------------------------------------------------------- + - func: SetDTScrolling(bool) + - desc: sets whether or not the object should use delta + time when scrolling +--]]--------------------------------------------------------- +function newobject:SetDTScrolling(bool) + + self.dtscrolling = bool + +end + +--[[--------------------------------------------------------- + - func: GetDTScrolling() + - desc: gets whether or not the object should use delta + time when scrolling +--]]--------------------------------------------------------- +function newobject:GetDTScrolling() + + return self.dtscrolling + end \ No newline at end of file diff --git a/objects/text.lua b/objects/text.lua index e4432a4..737dc1f 100644 --- a/objects/text.lua +++ b/objects/text.lua @@ -1,522 +1,545 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - ---[[------------------------------------------------ - -- note: the text wrapping of this object is - experimental and not final ---]]------------------------------------------------ - --- text class -local newobject = loveframes.NewObject("text", "loveframes_object_text", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- -function newobject:initialize() - - self.type = "text" - self.text = "" - self.font = loveframes.basicfont - self.width = 5 - self.height = 5 - self.maxw = 0 - self.lines = 1 - self.shadowxoffset = 1 - self.shadowyoffset = 1 - self.formattedtext = {} - self.original = {} - self.shadowcolor = {0, 0, 0, 255} - self.ignorenewlines = false - self.shadow = false - self.internal = false - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - if not self.visible then - if not self.alwaysupdate then - return - end - end - - local parent = self.parent - local base = loveframes.base - local update = self.Update - - self:CheckHover() - - -- move to parent if there is a parent - if parent ~= base then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - if not self.visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawText or skins[defaultskin].DrawText - local draw = self.Draw - local drawcount = loveframes.drawcount - - -- set the object's draw order - self:SetDrawOrder() - - if draw then - draw(self) - else - drawfunc(self) - end - - self:DrawText() - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - - if hover and button == "l" then - local baseparent = self:GetBaseParent() - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - end - -end - ---[[--------------------------------------------------------- - - func: SetText(text) - - desc: sets the object's text ---]]--------------------------------------------------------- -function newobject:SetText(t) - - local dtype = type(t) - local maxw = self.maxw - local font = self.font - local inserts = {} - local tdata, prevcolor - - self.text = "" - self.formattedtext = {} - - if dtype == "string" then - tdata = {t} - self.original = {t} - elseif dtype == "number" then - tdata = {tostring(t)} - self.original = {tostring(t)} - elseif dtype == "table" then - tdata = t - self.original = t - else - return - end - - for k, v in ipairs(tdata) do - local dtype = type(v) - if k == 1 and dtype ~= "table" then - prevcolor = {0, 0, 0, 255} - end - if dtype == "table" then - prevcolor = v - elseif dtype == "number" then - table.insert(self.formattedtext, {color = prevcolor, text = tostring(v)}) - elseif dtype == "string" then - if self.ignorenewlines then - v = v:gsub(" \n ", " ") - v = v:gsub("\n", "") - end - v = v:gsub(string.char(9), " ") - local parts = loveframes.util.SplitString(v, " ") - for i, j in ipairs(parts) do - table.insert(self.formattedtext, {color = prevcolor, text = j}) - end - end - end - - if maxw > 0 then - for k, v in ipairs(self.formattedtext) do - local data = v.text - local width = font:getWidth(data) - local curw = 0 - local new = "" - local key = k - if width > maxw then - table.remove(self.formattedtext, k) - for n=1, #data do - local item = data:sub(n, n) - local itemw = font:getWidth(item) - if n ~= #data then - if (curw + itemw) > maxw then - table.insert(inserts, {key = key, color = v.color, text = new}) - new = item - curw = 0 + itemw - key = key + 1 - else - new = new .. item - curw = curw + itemw - end - else - new = new .. item - table.insert(inserts, {key = key, color = v.color, text = new}) - end - end - end - end - end - - for k, v in ipairs(inserts) do - table.insert(self.formattedtext, v.key, {color = v.color, text = v.text}) - end - - local textdata = self.formattedtext - local maxw = self.maxw - local font = self.font - local height = font:getHeight("a") - local twidth = 0 - local drawx = 0 - local drawy = 0 - local lines = 0 - local textwidth = 0 - local lastwidth = 0 - local totalwidth = 0 - local x = self.x - local y = self.y - local prevtextwidth = 0 - - for k, v in ipairs(textdata) do - local text = v.text - local color = v.color - if type(text) == "string" then - self.text = self.text .. text - local width = font:getWidth(text) - totalwidth = totalwidth + width - if maxw > 0 then - if k ~= 1 then - if string.byte(text) == 10 then - twidth = 0 - drawx = 0 - width = 0 - drawy = drawy + height - text = "" - elseif (twidth + width) > maxw then - twidth = 0 + width - drawx = 0 - drawy = drawy + height - else - twidth = twidth + width - drawx = drawx + prevtextwidth - end - else - twidth = twidth + width - end - prevtextwidth = width - v.x = drawx - v.y = drawy - else - if k ~= 1 then - if string.byte(text) == 10 then - twidth = 0 - drawx = 0 - width = 0 - drawy = drawy + height - text = "" - if lastwidth < textwidth then - lastwidth = textwidth - end - textwidth = 0 - else - drawx = drawx + prevtextwidth - textwidth = textwidth + width - end - end - prevtextwidth = width - v.x = drawx - v.y = drawy - end - end - end - - if lastwidth == 0 then - textwidth = totalwidth - end - - if maxw > 0 then - self.width = maxw - else - self.width = textwidth - end - - self.height = drawy + height - -end - ---[[--------------------------------------------------------- - - func: GetText() - - desc: gets the object's text ---]]--------------------------------------------------------- -function newobject:GetText() - - return self.text - -end - ---[[--------------------------------------------------------- - - func: GetFormattedText() - - desc: gets the object's formatted text ---]]--------------------------------------------------------- -function newobject:GetFormattedText() - - return self.formattedtext - -end - ---[[--------------------------------------------------------- - - func: Format() - - desc: formats the text ---]]--------------------------------------------------------- -function newobject:DrawText() - - local textdata = self.formattedtext - local font = self.font - local theight = font:getHeight("a") - local x = self.x - local y = self.y - local shadow = self.shadow - local shadowxoffset = self.shadowxoffset - local shadowyoffset = self.shadowyoffset - local shadowcolor = self.shadowcolor - local inlist, list = self:IsInList() - - for k, v in ipairs(textdata) do - local text = v.text - local color = v.color - if inlist then - if (y + v.y) <= (list.y + list.height) and self.y + ((v.y + theight)) >= list.y then - love.graphics.setFont(font) - if shadow then - love.graphics.setColor(unpack(shadowcolor)) - love.graphics.print(text, x + v.x + shadowxoffset, y + v.y + shadowyoffset) - end - love.graphics.setColor(unpack(color)) - love.graphics.print(text, x + v.x, y + v.y) - end - else - love.graphics.setFont(font) - if shadow then - love.graphics.setColor(unpack(shadowcolor)) - love.graphics.print(text, x + v.x + shadowxoffset, y + v.y + shadowyoffset) - end - love.graphics.setColor(unpack(color)) - love.graphics.print(text, x + v.x, y + v.y) - end - end - -end - ---[[--------------------------------------------------------- - - func: SetMaxWidth(width) - - desc: sets the object's maximum width ---]]--------------------------------------------------------- -function newobject:SetMaxWidth(width) - - self.maxw = width - self:SetText(self.original) - -end - ---[[--------------------------------------------------------- - - func: GetMaxWidth() - - desc: gets the object's maximum width ---]]--------------------------------------------------------- -function newobject:GetMaxWidth() - - return self.maxw - -end - ---[[--------------------------------------------------------- - - func: SetWidth(width) - - desc: sets the object's width ---]]--------------------------------------------------------- -function newobject:SetWidth(width) - - self:SetMaxWidth(width) - -end - ---[[--------------------------------------------------------- - - func: SetHeight() - - desc: sets the object's height ---]]--------------------------------------------------------- -function newobject:SetHeight(height) - - return - -end - ---[[--------------------------------------------------------- - - func: SetSize() - - desc: sets the object's size ---]]--------------------------------------------------------- -function newobject:SetSize(width, height) - - self:SetMaxWidth(width) - -end - ---[[--------------------------------------------------------- - - func: SetFont(font) - - desc: sets the object's font - - note: font argument must be a font object ---]]--------------------------------------------------------- -function newobject:SetFont(font) - - local original = self.original - - self.font = font - - if original then - self:SetText(original) - end - -end - ---[[--------------------------------------------------------- - - func: GetFont() - - desc: gets the object's font ---]]--------------------------------------------------------- -function newobject:GetFont() - - return self.font - -end - ---[[--------------------------------------------------------- - - func: GetLines() - - desc: gets the number of lines the object's text uses ---]]--------------------------------------------------------- -function newobject:GetLines() - - return self.lines - -end - ---[[--------------------------------------------------------- - - func: SetIgnoreNewlines(bool) - - desc: sets whether the object should ignore \n or not ---]]--------------------------------------------------------- -function newobject:SetIgnoreNewlines(bool) - - self.ignorenewlines = bool - -end - ---[[--------------------------------------------------------- - - func: GetIgnoreNewlines() - - desc: gets whether the object should ignore \n or not ---]]--------------------------------------------------------- -function newobject:GetIgnoreNewlines() - - return self.ignorenewlines - -end - ---[[--------------------------------------------------------- - - func: SetShadow(bool) - - desc: sets whether or not the object should draw a - shadow behind it's text ---]]--------------------------------------------------------- -function newobject:SetShadow(bool) - - self.shadow = bool - -end - ---[[--------------------------------------------------------- - - func: GetShadow() - - desc: gets whether or not the object should draw a - shadow behind it's text ---]]--------------------------------------------------------- -function newobject:GetShadow() - - return self.shadow - -end - ---[[--------------------------------------------------------- - - func: SetShadowOffsets(offsetx, offsety) - - desc: sets the object's x and y shadow offsets ---]]--------------------------------------------------------- -function newobject:SetShadowOffsets(offsetx, offsety) - - self.shadowxoffset = offsetx - self.shadowyoffset = offsety - -end - ---[[--------------------------------------------------------- - - func: GetShadowOffsets() - - desc: gets the object's x and y shadow offsets ---]]--------------------------------------------------------- -function newobject:GetShadowOffsets() - - return self.shadowxoffset, self.shadowyoffset - -end - ---[[--------------------------------------------------------- - - func: SetShadowColor(r, g, b, a) - - desc: sets the object's shadow color ---]]--------------------------------------------------------- -function newobject:SetShadowColor(r, g, b, a) - - self.shadowcolor = {r, g, b, a} - -end - ---[[--------------------------------------------------------- - - func: GetShadowColor() - - desc: gets the object's shadow color ---]]--------------------------------------------------------- -function newobject:GetShadowColor() - - return self.shadowcolor - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +--[[------------------------------------------------ + -- note: the text wrapping of this object is + experimental and not final +--]]------------------------------------------------ + +-- text class +local newobject = loveframes.NewObject("text", "loveframes_object_text", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function newobject:initialize() + + self.type = "text" + self.text = "" + self.font = loveframes.basicfont + self.width = 5 + self.height = 5 + self.maxw = 0 + self.shadowxoffset = 1 + self.shadowyoffset = 1 + self.formattedtext = {} + self.original = {} + self.shadowcolor = {0, 0, 0, 255} + self.ignorenewlines = false + self.shadow = false + self.internal = false + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + local parent = self.parent + local base = loveframes.base + local update = self.Update + + self:CheckHover() + + -- move to parent if there is a parent + if parent ~= base then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + if not self.visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawText or skins[defaultskin].DrawText + local draw = self.Draw + local drawcount = loveframes.drawcount + + -- set the object's draw order + self:SetDrawOrder() + + if draw then + draw(self) + else + drawfunc(self) + end + + self:DrawText() + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + + if hover and button == "l" then + local baseparent = self:GetBaseParent() + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + end + +end + +--[[--------------------------------------------------------- + - func: SetText(text) + - desc: sets the object's text +--]]--------------------------------------------------------- +function newobject:SetText(t) + + local dtype = type(t) + local maxw = self.maxw + local font = self.font + local inserts = {} + local tdata, prevcolor + + self.text = "" + self.formattedtext = {} + + if dtype == "string" then + tdata = {t} + self.original = {t} + elseif dtype == "number" then + tdata = {tostring(t)} + self.original = {tostring(t)} + elseif dtype == "table" then + tdata = t + self.original = t + else + return + end + + for k, v in ipairs(tdata) do + local dtype = type(v) + if k == 1 and dtype ~= "table" then + prevcolor = {0, 0, 0, 255} + end + if dtype == "table" then + prevcolor = v + elseif dtype == "number" then + table.insert(self.formattedtext, {color = prevcolor, text = tostring(v)}) + elseif dtype == "string" then + if self.ignorenewlines then + v = v:gsub(" \n ", " ") + v = v:gsub("\n", "") + end + v = v:gsub(string.char(9), " ") + local parts = loveframes.util.SplitString(v, " ") + for i, j in ipairs(parts) do + table.insert(self.formattedtext, {color = prevcolor, text = j}) + end + end + end + + if maxw > 0 then + for k, v in ipairs(self.formattedtext) do + local data = v.text + local width = font:getWidth(data) + local curw = 0 + local new = "" + local key = k + if width > maxw then + table.remove(self.formattedtext, k) + for n=1, #data do + local item = data:sub(n, n) + local itemw = font:getWidth(item) + if n ~= #data then + if (curw + itemw) > maxw then + table.insert(inserts, {key = key, color = v.color, text = new}) + new = item + curw = 0 + itemw + key = key + 1 + else + new = new .. item + curw = curw + itemw + end + else + new = new .. item + table.insert(inserts, {key = key, color = v.color, text = new}) + end + end + end + end + end + + for k, v in ipairs(inserts) do + table.insert(self.formattedtext, v.key, {color = v.color, text = v.text}) + end + + local textdata = self.formattedtext + local maxw = self.maxw + local font = self.font + local height = font:getHeight("a") + local twidth = 0 + local drawx = 0 + local drawy = 0 + local lines = 0 + local textwidth = 0 + local lastwidth = 0 + local totalwidth = 0 + local x = self.x + local y = self.y + local prevtextwidth = 0 + + for k, v in ipairs(textdata) do + local text = v.text + local color = v.color + if type(text) == "string" then + self.text = self.text .. text + local width = font:getWidth(text) + totalwidth = totalwidth + width + if maxw > 0 then + if k ~= 1 then + if string.byte(text) == 10 then + twidth = 0 + drawx = 0 + width = 0 + drawy = drawy + height + text = "" + elseif (twidth + width) > maxw then + twidth = 0 + width + drawx = 0 + drawy = drawy + height + else + twidth = twidth + width + drawx = drawx + prevtextwidth + end + else + twidth = twidth + width + end + prevtextwidth = width + v.x = drawx + v.y = drawy + else + if k ~= 1 then + if string.byte(text) == 10 then + twidth = 0 + drawx = 0 + width = 0 + drawy = drawy + height + text = "" + if lastwidth < textwidth then + lastwidth = textwidth + end + textwidth = 0 + else + drawx = drawx + prevtextwidth + textwidth = textwidth + width + end + end + prevtextwidth = width + v.x = drawx + v.y = drawy + end + end + end + + if lastwidth == 0 then + textwidth = totalwidth + end + + if maxw > 0 then + self.width = maxw + else + self.width = textwidth + end + + self.height = drawy + height + +end + +--[[--------------------------------------------------------- + - func: GetText() + - desc: gets the object's text +--]]--------------------------------------------------------- +function newobject:GetText() + + return self.text + +end + +--[[--------------------------------------------------------- + - func: GetFormattedText() + - desc: gets the object's formatted text +--]]--------------------------------------------------------- +function newobject:GetFormattedText() + + return self.formattedtext + +end + +--[[--------------------------------------------------------- + - func: Format() + - desc: formats the text +--]]--------------------------------------------------------- +function newobject:DrawText() + + local textdata = self.formattedtext + local font = self.font + local theight = font:getHeight("a") + local x = self.x + local y = self.y + local shadow = self.shadow + local shadowxoffset = self.shadowxoffset + local shadowyoffset = self.shadowyoffset + local shadowcolor = self.shadowcolor + local inlist, list = self:IsInList() + + for k, v in ipairs(textdata) do + local text = v.text + local color = v.color + if inlist then + if (y + v.y) <= (list.y + list.height) and self.y + ((v.y + theight)) >= list.y then + love.graphics.setFont(font) + if shadow then + love.graphics.setColor(unpack(shadowcolor)) + love.graphics.print(text, x + v.x + shadowxoffset, y + v.y + shadowyoffset) + end + love.graphics.setColor(unpack(color)) + love.graphics.print(text, x + v.x, y + v.y) + end + else + love.graphics.setFont(font) + if shadow then + love.graphics.setColor(unpack(shadowcolor)) + love.graphics.print(text, x + v.x + shadowxoffset, y + v.y + shadowyoffset) + end + love.graphics.setColor(unpack(color)) + love.graphics.print(text, x + v.x, y + v.y) + end + end + +end + +--[[--------------------------------------------------------- + - func: SetMaxWidth(width) + - desc: sets the object's maximum width +--]]--------------------------------------------------------- +function newobject:SetMaxWidth(width) + + self.maxw = width + self:SetText(self.original) + +end + +--[[--------------------------------------------------------- + - func: GetMaxWidth() + - desc: gets the object's maximum width +--]]--------------------------------------------------------- +function newobject:GetMaxWidth() + + return self.maxw + +end + +--[[--------------------------------------------------------- + - func: SetWidth(width) + - desc: sets the object's width +--]]--------------------------------------------------------- +function newobject:SetWidth(width) + + self:SetMaxWidth(width) + +end + +--[[--------------------------------------------------------- + - func: SetHeight() + - desc: sets the object's height +--]]--------------------------------------------------------- +function newobject:SetHeight(height) + + return + +end + +--[[--------------------------------------------------------- + - func: SetSize() + - desc: sets the object's size +--]]--------------------------------------------------------- +function newobject:SetSize(width, height) + + self:SetMaxWidth(width) + +end + +--[[--------------------------------------------------------- + - func: SetFont(font) + - desc: sets the object's font + - note: font argument must be a font object +--]]--------------------------------------------------------- +function newobject:SetFont(font) + + local original = self.original + + self.font = font + + if original then + self:SetText(original) + end + +end + +--[[--------------------------------------------------------- + - func: GetFont() + - desc: gets the object's font +--]]--------------------------------------------------------- +function newobject:GetFont() + + return self.font + +end + +--[[--------------------------------------------------------- + - func: GetLines() + - desc: gets the number of lines the object's text uses +--]]--------------------------------------------------------- +function newobject:GetLines() + + return self.lines + +end + +--[[--------------------------------------------------------- + - func: SetIgnoreNewlines(bool) + - desc: sets whether the object should ignore \n or not +--]]--------------------------------------------------------- +function newobject:SetIgnoreNewlines(bool) + + self.ignorenewlines = bool + +end + +--[[--------------------------------------------------------- + - func: GetIgnoreNewlines() + - desc: gets whether the object should ignore \n or not +--]]--------------------------------------------------------- +function newobject:GetIgnoreNewlines() + + return self.ignorenewlines + +end + +--[[--------------------------------------------------------- + - func: SetShadow(bool) + - desc: sets whether or not the object should draw a + shadow behind it's text +--]]--------------------------------------------------------- +function newobject:SetShadow(bool) + + self.shadow = bool + +end + +--[[--------------------------------------------------------- + - func: GetShadow() + - desc: gets whether or not the object should draw a + shadow behind it's text +--]]--------------------------------------------------------- +function newobject:GetShadow() + + return self.shadow + +end + +--[[--------------------------------------------------------- + - func: SetShadowOffsets(offsetx, offsety) + - desc: sets the object's x and y shadow offsets +--]]--------------------------------------------------------- +function newobject:SetShadowOffsets(offsetx, offsety) + + self.shadowxoffset = offsetx + self.shadowyoffset = offsety + +end + +--[[--------------------------------------------------------- + - func: GetShadowOffsets() + - desc: gets the object's x and y shadow offsets +--]]--------------------------------------------------------- +function newobject:GetShadowOffsets() + + return self.shadowxoffset, self.shadowyoffset + +end + +--[[--------------------------------------------------------- + - func: SetShadowColor(r, g, b, a) + - desc: sets the object's shadow color +--]]--------------------------------------------------------- +function newobject:SetShadowColor(r, g, b, a) + + self.shadowcolor = {r, g, b, a} + +end + +--[[--------------------------------------------------------- + - func: GetShadowColor() + - desc: gets the object's shadow color +--]]--------------------------------------------------------- +function newobject:GetShadowColor() + + return self.shadowcolor + end \ No newline at end of file diff --git a/objects/textinput.lua b/objects/textinput.lua index 5baa1f6..1daac8e 100644 --- a/objects/textinput.lua +++ b/objects/textinput.lua @@ -1,1525 +1,1570 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- textinput class -local newobject = loveframes.NewObject("textinput", "loveframes_object_textinput", true) - ---[[--------------------------------------------------------- - - func: initialize() - - desc: initializes the object ---]]--------------------------------------------------------- - -function newobject:initialize() - - self.type = "textinput" - self.keydown = "none" - self.tabreplacement = " " - self.font = loveframes.basicfont - self.width = 200 - self.height = 25 - self.delay = 0 - self.offsetx = 0 - self.offsety = 0 - self.indincatortime = 0 - self.indicatornum = 0 - self.indicatorx = 0 - self.indicatory = 0 - self.textx = 0 - self.texty = 0 - self.textoffsetx = 5 - self.textoffsety = 5 - self.unicode = 0 - self.limit = 0 - self.line = 1 - self.itemwidth = 0 - self.itemheight = 0 - self.extrawidth = 0 - self.extraheight = 0 - self.rightpadding = 0 - self.bottompadding = 0 - self.lastclicktime = 0 - self.maxx = 0 - self.buttonscrollamount = 0.10 - self.mousewheelscrollamount = 5 - self.usable = {} - self.unusable = {} - self.lines = {""} - self.internals = {} - self.showindicator = true - self.focus = false - self.multiline = false - self.vbar = false - self.hbar = false - self.alltextselected = false - self.linenumbers = true - self.linenumberspanel = false - self.editable = true - self.internal = false - self.autoscroll = false - self.OnEnter = nil - self.OnTextChanged = nil - self.OnFocusGained = nil - self.OnFocusLost = nil - -end - ---[[--------------------------------------------------------- - - func: update(deltatime) - - desc: updates the object ---]]--------------------------------------------------------- -function newobject:update(dt) - - local visible = self.visible - local alwaysupdate = self.alwaysupdate - - if not visible then - if not alwaysupdate then - return - end - end - - -- check to see if the object is being hovered over - self:CheckHover() +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- textinput class +local newobject = loveframes.NewObject("textinput", "loveframes_object_textinput", true) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- + +function newobject:initialize() + + self.type = "textinput" + self.keydown = "none" + self.tabreplacement = " " + self.font = loveframes.basicfont + self.width = 200 + self.height = 25 + self.delay = 0 + self.offsetx = 0 + self.offsety = 0 + self.indincatortime = 0 + self.indicatornum = 0 + self.indicatorx = 0 + self.indicatory = 0 + self.textx = 0 + self.texty = 0 + self.textoffsetx = 5 + self.textoffsety = 5 + self.unicode = 0 + self.limit = 0 + self.line = 1 + self.itemwidth = 0 + self.itemheight = 0 + self.extrawidth = 0 + self.extraheight = 0 + self.rightpadding = 0 + self.bottompadding = 0 + self.lastclicktime = 0 + self.maxx = 0 + self.buttonscrollamount = 0.10 + self.mousewheelscrollamount = 5 + self.usable = {} + self.unusable = {} + self.lines = {""} + self.internals = {} + self.showindicator = true + self.focus = false + self.multiline = false + self.vbar = false + self.hbar = false + self.alltextselected = false + self.linenumbers = true + self.linenumberspanel = false + self.editable = true + self.internal = false + self.autoscroll = false + self.OnEnter = nil + self.OnTextChanged = nil + self.OnFocusGained = nil + self.OnFocusLost = nil + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the object +--]]--------------------------------------------------------- +function newobject:update(dt) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + local alwaysupdate = self.alwaysupdate + + if not visible then + if not alwaysupdate then + return + end + end + + -- check to see if the object is being hovered over + self:CheckHover() + + local time = love.timer.getTime() + local keydown = self.keydown + local unicode = self.unicode + local parent = self.parent + local base = loveframes.base + local update = self.Update + local theight = self.font:getHeight("a") + local delay = self.delay + local lines = self.lines + local numlines = #lines + local multiline = self.multiline + local width = self.width + local height = self.height + local vbar = self.vbar + local hbar = self.hbar + local inputobject = loveframes.inputobject + local internals = self.internals + + -- move to parent if there is a parent + if parent ~= base then + self.x = self.parent.x + self.staticx + self.y = self.parent.y + self.staticy + end + + if inputobject ~= self then + self.focus = false + self.alltextselected = false + end + + -- keydown check + if keydown ~= "none" then + if time > delay then + self:RunKey(keydown, unicode) + self.delay = time + 0.02 + end + end + + -- psotion the object's text + self:PositionText() + + -- update the object's text insertion positon indicator + self:UpdateIndicator() + + -- calculations for multiline mode + if multiline then + local twidth = 0 + local panel = self:GetLineNumbersPanel() + -- get the longest line of text + for k, v in ipairs(lines) do + local linewidth = self.font:getWidth(v) + if linewidth > twidth then + twidth = linewidth + end + end + -- item width calculation + if vbar then + self.itemwidth = twidth + 16 + self.textoffsetx * 2 + else + self.itemwidth = twidth + end + if panel then + self.itemwidth = self.itemwidth + panel.width + end + -- item height calculation + if hbar then + self.itemheight = theight * numlines + 16 + self.textoffsety * 2 + else + self.itemheight = theight * numlines + end + -- extra width and height calculations + self.extrawidth = self.itemwidth - self.width + self.extraheight = self.itemheight - self.height + local itemwidth = self.itemwidth + local itemheight = self.itemheight + if itemheight > height then + if not vbar then + local scrollbody = loveframes.objects["scrollbody"]:new(self, "vertical") + scrollbody.internals[1].internals[1].autoscroll = self.autoscroll + table.insert(self.internals, scrollbody) + self.vbar = true + if hbar then + local vbody = self:GetVerticalScrollBody() + local hbody = self:GetHorizontalScrollBody() + vbody:SetHeight(vbody:GetHeight() - 15) + hbody:SetWidth(hbody:GetWidth() - 15) + end + end + else + if vbar then + self:GetVerticalScrollBody():Remove() + self.vbar = false + self.offsety = 0 + if self.hbar then + local hbody = self:GetHorizontalScrollBody() + hbody:SetWidth(hbody:GetWidth() + 15) + end + end + end + + if itemwidth > width then + if not hbar then + local scrollbody = loveframes.objects["scrollbody"]:new(self, "horizontal") + scrollbody.internals[1].internals[1].autoscroll = self.autoscroll + table.insert(self.internals, scrollbody) + self.hbar = true + if self.vbar then + local vbody = self:GetVerticalScrollBody() + local hbody = self:GetHorizontalScrollBody() + vbody:SetHeight(vbody:GetHeight() - 15) + hbody:SetWidth(hbody:GetWidth() - 15) + end + end + else + if hbar then + self:GetHorizontalScrollBody():Remove() + self.hbar = false + self.offsetx = 0 + if vbar then + local vbody = self:GetVerticalScrollBody() + if vbody then + vbody:SetHeight(vbody:GetHeight() + 15) + end + end + end + end + if self.linenumbers then + if not self.linenumberspanel then + local linenumberspanel = loveframes.objects["linenumberspanel"]:new(self) + table.insert(self.internals, linenumberspanel) + self.linenumberspanel = true + end + else + if self.linenumberspanel then + table.remove(self.internals, 1) + self.linenumberspanel = false + end + end + end + + for k, v in ipairs(internals) do + v:update(dt) + end + + if update then + update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function newobject:draw() + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local skins = loveframes.skins.available + local skinindex = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end + local stencil = love.graphics.newStencil(stencilfunc) + local selfskin = self.skin + local skin = skins[selfskin] or skins[skinindex] + local drawfunc = skin.DrawTextInput or skins[defaultskin].DrawTextInput + local drawoverfunc = skin.DrawOverTextInput or skins[defaultskin].DrawOverTextInput + local draw = self.Draw + local drawcount = loveframes.drawcount + local internals = self.internals + local vbar = self.vbar + local hbar = self.hbar + + -- set the object's draw order + self:SetDrawOrder() + + if vbar and hbar then + stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width - 16, self.height - 16) end + end + + love.graphics.setStencil(stencilfunc) + + if draw then + draw(self) + else + drawfunc(self) + end + + love.graphics.setStencil() + + for k, v in ipairs(internals) do + v:draw() + end + + if not draw then + drawoverfunc(self) + end + +end + +--[[--------------------------------------------------------- + - func: mousepressed(x, y, button) + - desc: called when the player presses a mouse button +--]]--------------------------------------------------------- +function newobject:mousepressed(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local hover = self.hover + local internals = self.internals + local vbar = self.vbar + local hbar = self.hbar + local scrollamount = self.mousewheelscrollamount + local focus = self.focus + local onfocusgained = self.OnFocusGained + local onfocuslost = self.OnFocusLost + local time = love.timer.getTime() + local inputobject = loveframes.inputobject + + if hover then + if button == "l" then + if inputobject ~= self then + loveframes.inputobject = self + end + if not self.alltextselected then + if time > self.lastclicktime and time < (self.lastclicktime + 0.25) then + self.alltextselected = true + end + else + self.alltextselected = false + end + self.focus = true + self.lastclicktime = time + self:GetTextCollisions(x, y) + if onfocusgained and not focus then + onfocusgained(self) + end + local baseparent = self:GetBaseParent() + + if baseparent and baseparent.type == "frame" then + baseparent:MakeTop() + end + elseif button == "wu" then + if vbar and not hbar then + local vbar = self:GetVerticalScrollBody().internals[1].internals[1] + vbar:Scroll(-scrollamount) + elseif vbar and hbar then + local vbar = self:GetVerticalScrollBody().internals[1].internals[1] + vbar:Scroll(-scrollamount) + elseif not vbar and hbar then + local hbar = self:GetHorizontalScrollBody().internals[1].internals[1] + hbar:Scroll(-scrollamount) + end + elseif button == "wd" then + if vbar and not hbar then + local vbar = self:GetVerticalScrollBody().internals[1].internals[1] + vbar:Scroll(scrollamount) + elseif vbar and hbar then + local vbar = self:GetVerticalScrollBody().internals[1].internals[1] + vbar:Scroll(scrollamount) + elseif not vbar and hbar then + local hbar = self:GetHorizontalScrollBody().internals[1].internals[1] + hbar:Scroll(scrollamount) + end + end + else + if inputobject == self then + loveframes.inputobject = false + if onfocuslost then + onfocuslost(self) + end + end + end + + for k, v in ipairs(internals) do + v:mousepressed(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: mousereleased(x, y, button) + - desc: called when the player releases a mouse button +--]]--------------------------------------------------------- +function newobject:mousereleased(x, y, button) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local internals = self.internals + + for k, v in ipairs(internals) do + v:mousereleased(x, y, button) + end + +end + +--[[--------------------------------------------------------- + - func: keypressed(key) + - desc: called when the player presses a key +--]]--------------------------------------------------------- +function newobject:keypressed(key, unicode) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + local time = love.timer.getTime() + local lctrl = love.keyboard.isDown("lctrl") + local rctrl = love.keyboard.isDown("rctrl") + local focus = self.focus + + self.delay = time + 0.80 + self.keydown = key + + if (lctrl or rctrl) and focus then + if key == "a" then + self.alltextselected = true + end + end + + self:RunKey(key, unicode) + +end + +--[[--------------------------------------------------------- + - func: keyreleased(key) + - desc: called when the player releases a key +--]]--------------------------------------------------------- +function newobject:keyreleased(key) + + local state = loveframes.state + local selfstate = self.state + + if state ~= selfstate then + return + end + + local visible = self.visible + + if not visible then + return + end + + self.keydown = "none" + +end + +--[[--------------------------------------------------------- + - func: RunKey(key, unicode) + - desc: runs a key event on the object +--]]--------------------------------------------------------- +function newobject:RunKey(key, unicode) + + local visible = self.visible + local focus = self.focus + + if not visible then + return + end + + if not focus then + return + end + + local lines = self.lines + local line = self.line + local numlines = #lines + local curline = lines[line] + local text = curline + local ckey = "" + local font = self.font + local swidth = self.width + local textoffsetx = self.textoffsetx + local indicatornum = self.indicatornum + local multiline = self.multiline + local alltextselected = self.alltextselected + local editable = self.editable + local initialtext = self:GetText() + local ontextchanged = self.OnTextChanged + local onenter = self.OnEnter + + self.unicode = unicode + + if key == "left" then + local indicatorx = self.indicatorx + indicatornum = self.indicatornum + if not multiline then + self:MoveIndicator(-1) + if indicatorx <= self.x and indicatornum ~= 0 then + local width = self.font:getWidth(text:sub(indicatornum, indicatornum + 1)) + self.offsetx = self.offsetx - width + elseif indicatornum == 0 and self.offsetx ~= 0 then + self.offsetx = 0 + end + else + if indicatornum == 0 then + if line > 1 then + self.line = line - 1 + local numchars = #lines[self.line] + self:MoveIndicator(numchars) + end + else + self:MoveIndicator(-1) + end + end + elseif key == "right" then + local indicatorx = self.indicatorx + indicatornum = self.indicatornum + if not multiline then + self:MoveIndicator(1) + if indicatorx >= (self.x + swidth) and indicatornum ~= #text then + local width = self.font:getWidth(text:sub(indicatornum, indicatornum)) + self.offsetx = self.offsetx + width + elseif indicatornum == #text and self.offsetx ~= ((0 - font:getWidth(text)) + swidth) and font:getWidth(text) + self.textoffsetx > self.width then + self.offsetx = ((0 - font:getWidth(text)) + swidth) + end + else + if indicatornum == #text then + if line < numlines then + self.line = line + 1 + self:MoveIndicator(0, true) + end + else + self:MoveIndicator(1) + end + end + elseif key == "up" then + if multiline then + if line > 1 then + self.line = line - 1 + if indicatornum > #lines[self.line] then + self.indicatornum = #lines[self.line] + end + end + end + elseif key == "down" then + if multiline then + if line < #lines then + self.line = line + 1 + if indicatornum > #lines[self.line] then + self.indicatornum = #lines[self.line] + end + end + end + end + + if not editable then + return + end + + -- key input checking system + if key == "backspace" then + ckey = key + if alltextselected then + self:Clear() + self.alltextselected = false + indicatornum = self.indicatornum + else + if text ~= "" and indicatornum ~= 0 then + text = self:RemoveFromeText(indicatornum) + self:MoveIndicator(-1) + lines[line] = text + end + if multiline then + if line > 1 and indicatornum == 0 then + local newindicatornum = 0 + local oldtext = lines[line] + table.remove(lines, line) + self.line = line - 1 + if #oldtext > 0 then + newindicatornum = #lines[self.line] + lines[self.line] = lines[self.line] .. oldtext + self:MoveIndicator(newindicatornum) + else + self:MoveIndicator(#lines[self.line]) + end + end + end + local cwidth = font:getWidth(text:sub(#text)) + if self.offsetx ~= 0 then + self.offsetx = self.offsetx - cwidth + end + end + elseif key == "delete" then + if not editable then + return + end + ckey = key + if alltextselected then + self:Clear() + self.alltextselected = false + indicatornum = self.indicatornum + else + if text ~= "" and indicatornum < #text then + text = self:RemoveFromeText(indicatornum + 1) + lines[line] = text + elseif indicatornum == #text and line < #lines then + local oldtext = lines[line + 1] + if #oldtext > 0 then + newindicatornum = #lines[self.line] + lines[self.line] = lines[self.line] .. oldtext + end + table.remove(lines, line + 1) + end + end + elseif key == "return" or key == "kpenter" then + ckey = key + -- call onenter if it exists + if onenter then + onenter(self, text) + end + -- newline calculations for multiline mode + if multiline then + if alltextselected then + self.alltextselected = false + self:Clear() + indicatornum = self.indicatornum + line = self.line + end + local newtext = "" + if indicatornum == 0 then + newtext = self.lines[line] + self.lines[line] = "" + elseif indicatornum > 0 and indicatornum < #self.lines[line] then + newtext = self.lines[line]:sub(indicatornum + 1, #self.lines[line]) + self.lines[line] = self.lines[line]:sub(1, indicatornum) + end + if line ~= #lines then + table.insert(self.lines, line + 1, newtext) + self.line = line + 1 + else + table.insert(self.lines, newtext) + self.line = line + 1 + end + self.indicatornum = 0 + end + elseif key == "tab" then + ckey = key + for i=1, #self.tabreplacement do + local number = string.byte(self.tabreplacement:sub(i, i)) + self.lines[self.line] = self:AddIntoText(number, self.indicatornum) + self:MoveIndicator(1) + end + else + if unicode > 31 and unicode < 127 then + -- do not continue if the text limit has been reached or exceeded + if #text >= self.limit and self.limit ~= 0 then + return + end + -- set the current key + ckey = string.char(unicode) + -- check for unusable characters + if #self.usable > 0 then + local found = false + for k, v in ipairs(self.usable) do + if v == ckey then + found = true + end + end + if not found then + return + end + end + -- check for usable characters + if #self.unusable > 0 then + local found = false + for k, v in ipairs(self.unusable) do + if v == ckey then + found = true + end + end + if found then + return + end + end + if alltextselected then + self.alltextselected = false + self:Clear() + indicatornum = self.indicatornum + text = "" + lines = self.lines + line = self.line + end + if indicatornum ~= 0 and indicatornum ~= #text then + text = self:AddIntoText(unicode, indicatornum) + lines[line] = text + self:MoveIndicator(1) + elseif indicatornum == #text then + text = text .. ckey + lines[line] = text + self:MoveIndicator(1) + elseif indicatornum == 0 then + text = self:AddIntoText(unicode, indicatornum) + lines[line] = text + self:MoveIndicator(1) + end + lines = self.lines + line = self.line + curline = lines[line] + text = curline + if not multiline then + local twidth = font:getWidth(text) + local cwidth = font:getWidth(ckey) + + -- swidth - 1 is for the "-" character + if (twidth + textoffsetx) >= (swidth - 1) then + self.offsetx = self.offsetx + cwidth + end + end + end + end + + local curtext = self:GetText() + + if ontextchanged and initialtext ~= curtext then + ontextchanged(self, ckey) + end + +end + +--[[--------------------------------------------------------- + - func: MoveIndicator(num, exact) + - desc: moves the object's indicator +--]]--------------------------------------------------------- +function newobject:MoveIndicator(num, exact) + + local lines = self.lines + local line = self.line + local curline = lines[line] + local text = curline + local indicatornum = self.indicatornum + + if not exact then + self.indicatornum = indicatornum + num + else + self.indicatornum = num + end + + if self.indicatornum > #text then + self.indicatornum = #text + elseif self.indicatornum < 0 then + self.indicatornum = 0 + end + + self.showindicator = true + + self:UpdateIndicator() + +end + +--[[--------------------------------------------------------- + - func: UpdateIndicator() + - desc: updates the object's text insertion position + indicator +--]]--------------------------------------------------------- +function newobject:UpdateIndicator() + + local time = love.timer.getTime() + local indincatortime = self.indincatortime + local indicatornum = self.indicatornum + local lines = self.lines + local line = self.line + local curline = lines[line] + local text = curline + local theight = self.font:getHeight("a") + local offsetx = self.offsetx + local multiline = self.multiline + + if indincatortime < time then + if self.showindicator then + self.showindicator = false + else + self.showindicator = true + end + self.indincatortime = time + 0.50 + end + + if self.alltextselected then + self.showindicator = false + end + + local width = 0 + + for i=1, indicatornum do + width = width + self.font:getWidth(text:sub(i, i)) + end + + if multiline then + self.indicatorx = self.textx + width + self.indicatory = self.texty + theight * line - theight + else + self.indicatorx = self.textx + width + self.indicatory = self.texty + end + +end + +--[[--------------------------------------------------------- + - func: AddIntoText(t, p) + - desc: adds text into the object's text a given + position +--]]--------------------------------------------------------- +function newobject:AddIntoText(t, p) + + local lines = self.lines + local line = self.line + local curline = lines[line] + local text = curline + local part1 = text:sub(1, p) + local part2 = text:sub(p + 1) + local new = part1 .. string.char(t) .. part2 + + return new + +end + +--[[--------------------------------------------------------- + - func: RemoveFromeText(p) + - desc: removes text from the object's text a given + position +--]]--------------------------------------------------------- +function newobject:RemoveFromeText(p) + + local lines = self.lines + local line = self.line + local curline = lines[line] + local text = curline + local indicatornum = self.indicatornum + + local part1 = text:sub(1, p - 1) + local part2 = text:sub(p + 1) + local new = part1 .. part2 + return new + +end + +--[[--------------------------------------------------------- + - func: GetTextCollisions(x, y) + - desc: gets text collisions with the mouse +--]]--------------------------------------------------------- +function newobject:GetTextCollisions(x, y) + + local font = self.font + local lines = self.lines + local numlines = #lines + local line = self.line + local curline = lines[line] + local text = curline + local xpos = 0 + local line = 0 + local vbar = self.vbar + local hbar = self.hbar + local multiline = self.multiline + + if multiline then + local theight = self.font:getHeight("a") + local liney = 0 + local selfcol + if vbar and not hbar then + selfcol = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width - 16, 1, self.height, 1) + elseif hbar and not vbar then + selfcol = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.height - 16, 1) + elseif not vbar and not hbar then + selfcol = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.height, 1) + elseif vbar and hbar then + selfcol = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width - 16, 1, self.height - 16, 1) + end + if selfcol then + for i=1, numlines do + local linecol = loveframes.util.BoundingBox(self.x, x, (self.y - self.offsety) + self.textoffsety + (theight * i) - theight, y, self.width, 1, theight, 1) + if linecol then + liney = (self.y - self.offsety) + self.textoffsety + (theight * i) - theight + self.line = i + end + end + local line = self.line + local curline = lines[line] + for i=1, #curline do + local width = font:getWidth(curline:sub(i, i)) + local height = font:getHeight(curline:sub(i, i)) + local tx = self.textx + xpos + local ty = self.texty + local col = loveframes.util.BoundingBox(tx, x, liney, y, width, 1, height, 1) + + xpos = xpos + width + + if col then + self:MoveIndicator(i - 1, true) + break + else + self.indicatornum = #curline + end + + if x < tx then + self:MoveIndicator(0, true) + end + + if x > (tx + width) then + self:MoveIndicator(#curline, true) + end + end + + if #curline == 0 then + self.indicatornum = 0 + end + end + else + for i=1, #text do + local width = font:getWidth(text:sub(i, i)) + local height = font:getHeight(text:sub(i, i)) + local tx = self.textx + xpos + local ty = self.texty + local col = loveframes.util.BoundingBox(tx, x, ty, y, width, 1, height, 1) + xpos = xpos + width + if col then + self:MoveIndicator(i - 1, true) + break + end + if x < tx then + self:MoveIndicator(0, true) + end + if x > (tx + width) then + self:MoveIndicator(#text, true) + end + end + end + +end + +--[[--------------------------------------------------------- + - func: PositionText() + - desc: positions the object's text +--]]--------------------------------------------------------- +function newobject:PositionText() + + local multiline = self.multiline + local x = self.x + local y = self.y + local offsetx = self.offsetx + local offsety = self.offsety + local textoffsetx = self.textoffsetx + local textoffsety = self.textoffsety + local linenumberspanel = self.linenumberspanel + + if multiline then + if linenumberspanel then + local panel = self:GetLineNumbersPanel() + self.textx = ((x + panel.width) - offsetx) + textoffsetx + self.texty = (y - offsety) + textoffsety + else + self.textx = (x - offsetx) + textoffsetx + self.texty = (y - offsety) + textoffsety + end + else + self.textx = (x - offsetx) + textoffsetx + self.texty = (y - offsety) + textoffsety + end + +end + +--[[--------------------------------------------------------- + - func: SetTextOffsetX(num) + - desc: sets the object's text x offset +--]]--------------------------------------------------------- +function newobject:SetTextOffsetX(num) + + self.textoffsetx = num + +end + +--[[--------------------------------------------------------- + - func: SetTextOffsetY(num) + - desc: sets the object's text y offset +--]]--------------------------------------------------------- +function newobject:SetTextOffsetY(num) + + self.textoffsety = num + +end + +--[[--------------------------------------------------------- + - func: SetFont(font) + - desc: sets the object's font +--]]--------------------------------------------------------- +function newobject:SetFont(font) + + self.font = font + +end + +--[[--------------------------------------------------------- + - func: GetFont() + - desc: gets the object's font +--]]--------------------------------------------------------- +function newobject:GetFont() + + return self.font + +end + +--[[--------------------------------------------------------- + - func: SetFocus(focus) + - desc: sets the object's focus +--]]--------------------------------------------------------- +function newobject:SetFocus(focus) + + local inputobject = loveframes.inputobject + local onfocusgained = self.OnFocusGained + local onfocuslost = self.OnFocusLost + + self.focus = focus + + if focus then + loveframes.inputobject = self + if onfocusgained then + onfocusgained(self) + end + else + if inputobject == self then + loveframes.inputobject = false + end + if onfocuslost then + onfocuslost(self) + end + end + +end + +--[[--------------------------------------------------------- + - func: GetFocus() + - desc: gets the object's focus +--]]--------------------------------------------------------- +function newobject:GetFocus() + + return self.focus + +end + +--[[--------------------------------------------------------- + - func: GetIndicatorVisibility() + - desc: gets the object's indicator visibility +--]]--------------------------------------------------------- +function newobject:GetIndicatorVisibility() + + return self.showindicator + +end + +--[[--------------------------------------------------------- + - func: SetLimit(limit) + - desc: sets the object's text limit +--]]--------------------------------------------------------- +function newobject:SetLimit(limit) + + self.limit = limit + +end + +--[[--------------------------------------------------------- + - func: SetUsable(usable) + - desc: sets what characters can be used for the + object's text +--]]--------------------------------------------------------- +function newobject:SetUsable(usable) + + self.usable = usable + +end + +--[[--------------------------------------------------------- + - func: GetUsable() + - desc: gets what characters can be used for the + object's text +--]]--------------------------------------------------------- +function newobject:GetUsable() + + return self.usable + +end + +--[[--------------------------------------------------------- + - func: SetUnusable(unusable) + - desc: sets what characters can not be used for the + object's text +--]]--------------------------------------------------------- +function newobject:SetUnusable(unusable) + + self.unusable = unusable + +end + +--[[--------------------------------------------------------- + - func: GetUnusable() + - desc: gets what characters can not be used for the + object's text +--]]--------------------------------------------------------- +function newobject:GetUnusable() + + return self.unusable + +end + +--[[--------------------------------------------------------- + - func: Clear() + - desc: clears the object's text +--]]--------------------------------------------------------- +function newobject:Clear() + + self.lines = {""} + self.line = 1 + self.offsetx = 0 + self.offsety = 0 + self.indicatornum = 0 + +end + +--[[--------------------------------------------------------- + - func: SetText(text) + - desc: sets the object's text +--]]--------------------------------------------------------- +function newobject:SetText(text) + + local tabreplacement = self.tabreplacement + local multiline = self.multiline + + -- make sure the text is a string + text = tostring(text) + + -- replace any tabs character with spaces + text = text:gsub(string.char(9), tabreplacement) + + -- remove any carriage returns + text = text:gsub(string.char(13), "") + + if multiline then + text = text:gsub(string.char(92) .. string.char(110), string.char(10)) + local t = loveframes.util.SplitString(text, string.char(10)) + if #t > 0 then + self.lines = t + else + self.lines = {""} + end + else + text = text:gsub(string.char(92) .. string.char(110), "") + text = text:gsub(string.char(10), "") + self.lines = {text} + self.line = 1 + end + +end + +--[[--------------------------------------------------------- + - func: GetText() + - desc: gets the object's text +--]]--------------------------------------------------------- +function newobject:GetText() + + local multiline = self.multiline + local lines = self.lines + local text = "" + + if multiline then + for k, v in ipairs(lines) do + text = text .. v .. "\n" + end + else + text = lines[1] + end + + return text + +end + +--[[--------------------------------------------------------- + - func: SetMultiline(bool) + - desc: enables or disables allowing multiple lines for + text entry +--]]--------------------------------------------------------- +function newobject:SetMultiline(bool) + + local text = "" + local lines = self.lines + + self.multiline = bool + + if bool then + self:Clear() + else + for k, v in ipairs(lines) do + text = text .. v + end + self:SetText(text) + self.internals = {} + self.vbar = false + self.hbar = false + self.linenumberspanel = false + end + +end + +--[[--------------------------------------------------------- + - func: GetMultiLine() + - desc: gets whether or not the object is using multiple + lines +--]]--------------------------------------------------------- +function newobject:GetMultiLine() + + return self.multiline + +end + +--[[--------------------------------------------------------- + - func: GetVerticalScrollBody() + - desc: gets the object's vertical scroll body +--]]--------------------------------------------------------- +function newobject:GetVerticalScrollBody() + + local vbar = self.vbar + local internals = self.internals + local item = false + + if vbar then + for k, v in ipairs(internals) do + if v.type == "scrollbody" and v.bartype == "vertical" then + item = v + end + end + end + + return item + +end + +--[[--------------------------------------------------------- + - func: GetHorizontalScrollBody() + - desc: gets the object's horizontal scroll body +--]]--------------------------------------------------------- +function newobject:GetHorizontalScrollBody() + + local hbar = self.hbar + local internals = self.internals + local item = false + + if hbar then + for k, v in ipairs(internals) do + if v.type == "scrollbody" and v.bartype == "horizontal" then + item = v + end + end + end + + return item + +end + +--[[--------------------------------------------------------- + - func: HasVerticalScrollBar() + - desc: gets whether or not the object has a vertical + scroll bar +--]]--------------------------------------------------------- +function newobject:HasVerticalScrollBar() + + return self.vbar + +end + +--[[--------------------------------------------------------- + - func: HasHorizontalScrollBar() + - desc: gets whether or not the object has a horizontal + scroll bar +--]]--------------------------------------------------------- +function newobject:HasHorizontalScrollBar() + + return self.hbar + +end + +--[[--------------------------------------------------------- + - func: GetLineNumbersPanel() + - desc: gets the object's line numbers panel +--]]--------------------------------------------------------- +function newobject:GetLineNumbersPanel() + + local panel = self.linenumberspanel + local internals = self.internals + local item = false + + if panel then + for k, v in ipairs(internals) do + if v.type == "linenumberspanel" then + item = v + end + end + end + + return item + +end + +--[[--------------------------------------------------------- + - func: ShowLineNumbers(bool) + - desc: sets whether or not to show line numbers when + using multiple lines +--]]--------------------------------------------------------- +function newobject:ShowLineNumbers(bool) + + local multiline = self.multiline + + if multiline then + self.linenumbers = bool + end + +end + +--[[--------------------------------------------------------- + - func: GetTextX() + - desc: gets the object's text x +--]]--------------------------------------------------------- +function newobject:GetTextX() + + return self.textx + +end + +--[[--------------------------------------------------------- + - func: GetTextY() + - desc: gets the object's text y +--]]--------------------------------------------------------- +function newobject:GetTextY() + + return self.texty + +end + +--[[--------------------------------------------------------- + - func: IsAllTextSelected() + - desc: gets whether or not all of the object's text is + selected +--]]--------------------------------------------------------- +function newobject:IsAllTextSelected() + + return self.alltextselected + +end + +--[[--------------------------------------------------------- + - func: GetLines() + - desc: gets the object's lines +--]]--------------------------------------------------------- +function newobject:GetLines() + + return self.lines + +end + +--[[--------------------------------------------------------- + - func: GetOffsetX() + - desc: gets the object's x offset +--]]--------------------------------------------------------- +function newobject:GetOffsetX() + + return self.offsetx + +end + +--[[--------------------------------------------------------- + - func: GetOffsetY() + - desc: gets the object's y offset +--]]--------------------------------------------------------- +function newobject:GetOffsetY() + + return self.offsety + +end + +--[[--------------------------------------------------------- + - func: GetIndicatorX() + - desc: gets the object's indicator's xpos +--]]--------------------------------------------------------- +function newobject:GetIndicatorX() + + return self.indicatorx + +end + +--[[--------------------------------------------------------- + - func: GetIndicatorY() + - desc: gets the object's indicator's ypos +--]]--------------------------------------------------------- +function newobject:GetIndicatorY() + + return self.indicatory + +end + +--[[--------------------------------------------------------- + - func: GetLineNumbersEnabled() + - desc: gets whether line numbers are enabled on the + object or not +--]]--------------------------------------------------------- +function newobject:GetLineNumbersEnabled() + + return self.linenumbers + +end + +--[[--------------------------------------------------------- + - func: GetItemWidth() + - desc: gets the object's item width +--]]--------------------------------------------------------- +function newobject:GetItemWidth() + + return self.itemwidth + +end + +--[[--------------------------------------------------------- + - func: GetItemHeight() + - desc: gets the object's item height +--]]--------------------------------------------------------- +function newobject:GetItemHeight() + + return self.itemheight + +end + +--[[--------------------------------------------------------- + - func: SetTabReplacement(tabreplacement) + - desc: sets a string to replace tabs with +--]]--------------------------------------------------------- +function newobject:SetTabReplacement(tabreplacement) + + self.tabreplacement = tabreplacement + +end + +--[[--------------------------------------------------------- + - func: GetTabReplacement() + - desc: gets the object's tab replacement +--]]--------------------------------------------------------- +function newobject:GetTabReplacement() + + return self.tabreplacement + +end + +--[[--------------------------------------------------------- + - func: SetEditable(bool) + - desc: sets whether or not the user can edit the + object's text +--]]--------------------------------------------------------- +function newobject:SetEditable(bool) + + self.editable = bool + +end + +--[[--------------------------------------------------------- + - func: GetEditable + - desc: gets whether or not the user can edit the + object's text +--]]--------------------------------------------------------- +function newobject:GetEditable() + + return self.editable + +end + +--[[--------------------------------------------------------- + - func: SetButtonScrollAmount(speed) + - desc: sets the scroll amount of the object's scrollbar + buttons +--]]--------------------------------------------------------- +function newobject:SetButtonScrollAmount(amount) + + self.buttonscrollamount = amount + +end + +--[[--------------------------------------------------------- + - func: GetButtonScrollAmount() + - desc: gets the scroll amount of the object's scrollbar + buttons +--]]--------------------------------------------------------- +function newobject:GetButtonScrollAmount() + + return self.buttonscrollamount + +end + +--[[--------------------------------------------------------- + - func: SetMouseWheelScrollAmount(amount) + - desc: sets the scroll amount of the mouse wheel +--]]--------------------------------------------------------- +function newobject:SetMouseWheelScrollAmount(amount) + + self.mousewheelscrollamount = amount + +end + +--[[--------------------------------------------------------- + - func: GetMouseWheelScrollAmount() + - desc: gets the scroll amount of the mouse wheel +--]]--------------------------------------------------------- +function newobject:GetButtonScrollAmount() + + return self.mousewheelscrollamount + +end + +--[[--------------------------------------------------------- + - func: SetAutoScroll(bool) + - desc: sets whether or not the object should autoscroll + when in multiline mode +--]]--------------------------------------------------------- +function newobject:SetAutoScroll(bool) + + local internals = self.internals + + self.autoscroll = bool + + if internals[2] then + internals[2].internals[1].internals[1].autoscroll = bool + end + +end + +--[[--------------------------------------------------------- + - func: GetAutoScroll() + - desc: gets whether or not the object should autoscroll + when in multiline mode +--]]--------------------------------------------------------- +function newobject:GetAutoScroll() + + return self.autoscroll - local time = love.timer.getTime() - local keydown = self.keydown - local unicode = self.unicode - local parent = self.parent - local base = loveframes.base - local update = self.Update - local theight = self.font:getHeight("a") - local delay = self.delay - local lines = self.lines - local numlines = #lines - local multiline = self.multiline - local width = self.width - local height = self.height - local vbar = self.vbar - local hbar = self.hbar - local inputobject = loveframes.inputobject - local internals = self.internals - - -- move to parent if there is a parent - if parent ~= base then - self.x = self.parent.x + self.staticx - self.y = self.parent.y + self.staticy - end - - if inputobject ~= self then - self.focus = false - self.alltextselected = false - end - - -- keydown check - if keydown ~= "none" then - if time > delay then - self:RunKey(keydown, unicode) - self.delay = time + 0.02 - end - end - - -- psotion the object's text - self:PositionText() - - -- update the object's text insertion positon indicator - self:UpdateIndicator() - - -- calculations for multiline mode - if multiline then - local twidth = 0 - local panel = self:GetLineNumbersPanel() - -- get the longest line of text - for k, v in ipairs(lines) do - local linewidth = self.font:getWidth(v) - if linewidth > twidth then - twidth = linewidth - end - end - -- item width calculation - if vbar then - self.itemwidth = twidth + 16 + self.textoffsetx * 2 - else - self.itemwidth = twidth - end - if panel then - self.itemwidth = self.itemwidth + panel.width - end - -- item height calculation - if hbar then - self.itemheight = theight * numlines + 16 + self.textoffsety * 2 - else - self.itemheight = theight * numlines - end - -- extra width and height calculations - self.extrawidth = self.itemwidth - self.width - self.extraheight = self.itemheight - self.height - local itemwidth = self.itemwidth - local itemheight = self.itemheight - if itemheight > height then - if not vbar then - local scrollbody = loveframes.objects["scrollbody"]:new(self, "vertical") - scrollbody.internals[1].internals[1].autoscroll = self.autoscroll - table.insert(self.internals, scrollbody) - self.vbar = true - if hbar then - local vbody = self:GetVerticalScrollBody() - local hbody = self:GetHorizontalScrollBody() - vbody:SetHeight(vbody:GetHeight() - 15) - hbody:SetWidth(hbody:GetWidth() - 15) - end - end - else - if vbar then - self:GetVerticalScrollBody():Remove() - self.vbar = false - self.offsety = 0 - if self.hbar then - local hbody = self:GetHorizontalScrollBody() - hbody:SetWidth(hbody:GetWidth() + 15) - end - end - end - - if itemwidth > width then - if not hbar then - local scrollbody = loveframes.objects["scrollbody"]:new(self, "horizontal") - scrollbody.internals[1].internals[1].autoscroll = self.autoscroll - table.insert(self.internals, scrollbody) - self.hbar = true - if self.vbar then - local vbody = self:GetVerticalScrollBody() - local hbody = self:GetHorizontalScrollBody() - vbody:SetHeight(vbody:GetHeight() - 15) - hbody:SetWidth(hbody:GetWidth() - 15) - end - end - else - if hbar then - self:GetHorizontalScrollBody():Remove() - self.hbar = false - self.offsetx = 0 - if vbar then - local vbody = self:GetVerticalScrollBody() - if vbody then - vbody:SetHeight(vbody:GetHeight() + 15) - end - end - end - end - if self.linenumbers then - if not self.linenumberspanel then - local linenumberspanel = loveframes.objects["linenumberspanel"]:new(self) - table.insert(self.internals, linenumberspanel) - self.linenumberspanel = true - end - else - if self.linenumberspanel then - table.remove(self.internals, 1) - self.linenumberspanel = false - end - end - end - - for k, v in ipairs(internals) do - v:update(dt) - end - - if update then - update(self, dt) - end - -end - ---[[--------------------------------------------------------- - - func: draw() - - desc: draws the object ---]]--------------------------------------------------------- -function newobject:draw() - - local visible = self.visible - - if not visible then - return - end - - local skins = loveframes.skins.available - local skinindex = loveframes.config["ACTIVESKIN"] - local defaultskin = loveframes.config["DEFAULTSKIN"] - local stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width, self.height) end - local stencil = love.graphics.newStencil(stencilfunc) - local selfskin = self.skin - local skin = skins[selfskin] or skins[skinindex] - local drawfunc = skin.DrawTextInput or skins[defaultskin].DrawTextInput - local drawoverfunc = skin.DrawOverTextInput or skins[defaultskin].DrawOverTextInput - local draw = self.Draw - local drawcount = loveframes.drawcount - local internals = self.internals - local vbar = self.vbar - local hbar = self.hbar - - -- set the object's draw order - self:SetDrawOrder() - - if vbar and hbar then - stencilfunc = function() love.graphics.rectangle("fill", self.x, self.y, self.width - 16, self.height - 16) end - end - - love.graphics.setStencil(stencilfunc) - - if draw then - draw(self) - else - drawfunc(self) - end - - love.graphics.setStencil() - - for k, v in ipairs(internals) do - v:draw() - end - - if not draw then - drawoverfunc(self) - end - -end - ---[[--------------------------------------------------------- - - func: mousepressed(x, y, button) - - desc: called when the player presses a mouse button ---]]--------------------------------------------------------- -function newobject:mousepressed(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local hover = self.hover - local internals = self.internals - local vbar = self.vbar - local hbar = self.hbar - local scrollamount = self.mousewheelscrollamount - local focus = self.focus - local onfocusgained = self.OnFocusGained - local onfocuslost = self.OnFocusLost - local time = love.timer.getTime() - local inputobject = loveframes.inputobject - - if hover then - if button == "l" then - if inputobject ~= self then - loveframes.inputobject = self - end - if not self.alltextselected then - if time > self.lastclicktime and time < (self.lastclicktime + 0.25) then - self.alltextselected = true - end - else - self.alltextselected = false - end - self.focus = true - self.lastclicktime = time - self:GetTextCollisions(x, y) - if onfocusgained and not focus then - onfocusgained(self) - end - local baseparent = self:GetBaseParent() - - if baseparent and baseparent.type == "frame" then - baseparent:MakeTop() - end - elseif button == "wu" then - if vbar and not hbar then - local vbar = self:GetVerticalScrollBody().internals[1].internals[1] - vbar:Scroll(-scrollamount) - elseif vbar and hbar then - local vbar = self:GetVerticalScrollBody().internals[1].internals[1] - vbar:Scroll(-scrollamount) - elseif not vbar and hbar then - local hbar = self:GetHorizontalScrollBody().internals[1].internals[1] - hbar:Scroll(-scrollamount) - end - elseif button == "wd" then - if vbar and not hbar then - local vbar = self:GetVerticalScrollBody().internals[1].internals[1] - vbar:Scroll(scrollamount) - elseif vbar and hbar then - local vbar = self:GetVerticalScrollBody().internals[1].internals[1] - vbar:Scroll(scrollamount) - elseif not vbar and hbar then - local hbar = self:GetHorizontalScrollBody().internals[1].internals[1] - hbar:Scroll(scrollamount) - end - end - else - if inputobject == self then - loveframes.inputobject = false - if onfocuslost then - onfocuslost(self) - end - end - end - - for k, v in ipairs(internals) do - v:mousepressed(x, y, button) - end - -end - ---[[--------------------------------------------------------- - - func: mousereleased(x, y, button) - - desc: called when the player releases a mouse button ---]]--------------------------------------------------------- -function newobject:mousereleased(x, y, button) - - local visible = self.visible - - if not visible then - return - end - - local internals = self.internals - - for k, v in ipairs(internals) do - v:mousereleased(x, y, button) - end - -end - ---[[--------------------------------------------------------- - - func: keypressed(key) - - desc: called when the player presses a key ---]]--------------------------------------------------------- -function newobject:keypressed(key, unicode) - - local visible = self.visible - - if not visible then - return - end - - local time = love.timer.getTime() - local lctrl = love.keyboard.isDown("lctrl") - local rctrl = love.keyboard.isDown("rctrl") - local focus = self.focus - - self.delay = time + 0.80 - self.keydown = key - - if (lctrl or rctrl) and focus then - if key == "a" then - self.alltextselected = true - end - end - - self:RunKey(key, unicode) - -end - ---[[--------------------------------------------------------- - - func: keyreleased(key) - - desc: called when the player releases a key ---]]--------------------------------------------------------- -function newobject:keyreleased(key) - - local visible = self.visible - - if not visible then - return - end - - self.keydown = "none" - -end - ---[[--------------------------------------------------------- - - func: RunKey(key, unicode) - - desc: runs a key event on the object ---]]--------------------------------------------------------- -function newobject:RunKey(key, unicode) - - local visible = self.visible - local focus = self.focus - - if not visible then - return - end - - if not focus then - return - end - - local lines = self.lines - local line = self.line - local numlines = #lines - local curline = lines[line] - local text = curline - local ckey = "" - local font = self.font - local swidth = self.width - local textoffsetx = self.textoffsetx - local indicatornum = self.indicatornum - local multiline = self.multiline - local alltextselected = self.alltextselected - local editable = self.editable - local initialtext = self:GetText() - local ontextchanged = self.OnTextChanged - local onenter = self.OnEnter - - self.unicode = unicode - - if key == "left" then - local indicatorx = self.indicatorx - indicatornum = self.indicatornum - if not multiline then - self:MoveIndicator(-1) - if indicatorx <= self.x and indicatornum ~= 0 then - local width = self.font:getWidth(text:sub(indicatornum, indicatornum + 1)) - self.offsetx = self.offsetx - width - elseif indicatornum == 0 and self.offsetx ~= 0 then - self.offsetx = 0 - end - else - if indicatornum == 0 then - if line > 1 then - self.line = line - 1 - local numchars = #lines[self.line] - self:MoveIndicator(numchars) - end - else - self:MoveIndicator(-1) - end - end - elseif key == "right" then - local indicatorx = self.indicatorx - indicatornum = self.indicatornum - if not multiline then - self:MoveIndicator(1) - if indicatorx >= (self.x + swidth) and indicatornum ~= #text then - local width = self.font:getWidth(text:sub(indicatornum, indicatornum)) - self.offsetx = self.offsetx + width - elseif indicatornum == #text and self.offsetx ~= ((0 - font:getWidth(text)) + swidth) and font:getWidth(text) + self.textoffsetx > self.width then - self.offsetx = ((0 - font:getWidth(text)) + swidth) - end - else - if indicatornum == #text then - if line < numlines then - self.line = line + 1 - self:MoveIndicator(0, true) - end - else - self:MoveIndicator(1) - end - end - elseif key == "up" then - if multiline then - if line > 1 then - self.line = line - 1 - if indicatornum > #lines[self.line] then - self.indicatornum = #lines[self.line] - end - end - end - elseif key == "down" then - if multiline then - if line < #lines then - self.line = line + 1 - if indicatornum > #lines[self.line] then - self.indicatornum = #lines[self.line] - end - end - end - end - - if not editable then - return - end - - -- key input checking system - if key == "backspace" then - ckey = key - if alltextselected then - self:Clear() - self.alltextselected = false - indicatornum = self.indicatornum - else - if text ~= "" and indicatornum ~= 0 then - text = self:RemoveFromeText(indicatornum) - self:MoveIndicator(-1) - lines[line] = text - end - if multiline then - if line > 1 and indicatornum == 0 then - local newindicatornum = 0 - local oldtext = lines[line] - table.remove(lines, line) - self.line = line - 1 - if #oldtext > 0 then - newindicatornum = #lines[self.line] - lines[self.line] = lines[self.line] .. oldtext - self:MoveIndicator(newindicatornum) - else - self:MoveIndicator(#lines[self.line]) - end - end - end - local cwidth = font:getWidth(text:sub(#text)) - if self.offsetx ~= 0 then - self.offsetx = self.offsetx - cwidth - end - end - elseif key == "delete" then - if not editable then - return - end - ckey = key - if alltextselected then - self:Clear() - self.alltextselected = false - indicatornum = self.indicatornum - else - if text ~= "" and indicatornum < #text then - text = self:RemoveFromeText(indicatornum + 1) - lines[line] = text - elseif indicatornum == #text and line < #lines then - local oldtext = lines[line + 1] - if #oldtext > 0 then - newindicatornum = #lines[self.line] - lines[self.line] = lines[self.line] .. oldtext - end - table.remove(lines, line + 1) - end - end - elseif key == "return" or key == "kpenter" then - ckey = key - -- call onenter if it exists - if onenter then - onenter(self, text) - end - -- newline calculations for multiline mode - if multiline then - if alltextselected then - self.alltextselected = false - self:Clear() - indicatornum = self.indicatornum - line = self.line - end - local newtext = "" - if indicatornum == 0 then - newtext = self.lines[line] - self.lines[line] = "" - elseif indicatornum > 0 and indicatornum < #self.lines[line] then - newtext = self.lines[line]:sub(indicatornum + 1, #self.lines[line]) - self.lines[line] = self.lines[line]:sub(1, indicatornum) - end - if line ~= #lines then - table.insert(self.lines, line + 1, newtext) - self.line = line + 1 - else - table.insert(self.lines, newtext) - self.line = line + 1 - end - self.indicatornum = 0 - end - elseif key == "tab" then - ckey = key - for i=1, #self.tabreplacement do - local number = string.byte(self.tabreplacement:sub(i, i)) - self.lines[self.line] = self:AddIntoText(number, self.indicatornum) - self:MoveIndicator(1) - end - else - if unicode > 31 and unicode < 127 then - if alltextselected then - self.alltextselected = false - self:Clear() - indicatornum = self.indicatornum - text = "" - lines = self.lines - line = self.line - end - -- do not continue if the text limit has been reached or exceeded - if #text >= self.limit and self.limit ~= 0 then - return - end - -- set the current key - ckey = string.char(unicode) - -- check for unusable characters - if #self.usable > 0 then - local found = false - for k, v in ipairs(self.usable) do - if v == ckey then - found = true - end - end - if found == false then - return - end - end - -- check for usable characters - if #self.unusable > 0 then - local found = false - for k, v in ipairs(self.unusable) do - if v == ckey then - found = true - end - end - if found == true then - return - end - end - if indicatornum ~= 0 and indicatornum ~= #text then - text = self:AddIntoText(unicode, indicatornum) - lines[line] = text - self:MoveIndicator(1) - elseif indicatornum == #text then - text = text .. ckey - lines[line] = text - self:MoveIndicator(1) - elseif indicatornum == 0 then - text = self:AddIntoText(unicode, indicatornum) - lines[line] = text - self:MoveIndicator(1) - end - lines = self.lines - line = self.line - curline = lines[line] - text = curline - if not multiline then - local twidth = font:getWidth(text) - local cwidth = font:getWidth(ckey) - - -- swidth - 1 is for the "-" character - if (twidth + textoffsetx) >= (swidth - 1) then - self.offsetx = self.offsetx + cwidth - end - end - end - end - - local curtext = self:GetText() - - if ontextchanged and initialtext ~= curtext then - ontextchanged(self, ckey) - end - -end - ---[[--------------------------------------------------------- - - func: MoveIndicator(num, exact) - - desc: moves the object's indicator ---]]--------------------------------------------------------- -function newobject:MoveIndicator(num, exact) - - local lines = self.lines - local line = self.line - local curline = lines[line] - local text = curline - local indicatornum = self.indicatornum - - if not exact then - self.indicatornum = indicatornum + num - else - self.indicatornum = num - end - - if self.indicatornum > #text then - self.indicatornum = #text - elseif self.indicatornum < 0 then - self.indicatornum = 0 - end - - self.showindicator = true - - self:UpdateIndicator() - -end - ---[[--------------------------------------------------------- - - func: UpdateIndicator() - - desc: updates the object's text insertion position - indicator ---]]--------------------------------------------------------- -function newobject:UpdateIndicator() - - local time = love.timer.getTime() - local indincatortime = self.indincatortime - local indicatornum = self.indicatornum - local lines = self.lines - local line = self.line - local curline = lines[line] - local text = curline - local theight = self.font:getHeight("a") - local offsetx = self.offsetx - local multiline = self.multiline - - if indincatortime < time then - if self.showindicator then - self.showindicator = false - else - self.showindicator = true - end - self.indincatortime = time + 0.50 - end - - if self.alltextselected then - self.showindicator = false - end - - local width = 0 - - for i=1, indicatornum do - width = width + self.font:getWidth(text:sub(i, i)) - end - - if multiline then - self.indicatorx = self.textx + width - self.indicatory = self.texty + theight * line - theight - else - self.indicatorx = self.textx + width - self.indicatory = self.texty - end - -end - ---[[--------------------------------------------------------- - - func: AddIntoText(t, p) - - desc: adds text into the object's text a given - position ---]]--------------------------------------------------------- -function newobject:AddIntoText(t, p) - - local lines = self.lines - local line = self.line - local curline = lines[line] - local text = curline - local part1 = text:sub(1, p) - local part2 = text:sub(p + 1) - local new = part1 .. string.char(t) .. part2 - - return new - -end - ---[[--------------------------------------------------------- - - func: RemoveFromeText(p) - - desc: removes text from the object's text a given - position ---]]--------------------------------------------------------- -function newobject:RemoveFromeText(p) - - local lines = self.lines - local line = self.line - local curline = lines[line] - local text = curline - local indicatornum = self.indicatornum - - local part1 = text:sub(1, p - 1) - local part2 = text:sub(p + 1) - local new = part1 .. part2 - return new - -end - ---[[--------------------------------------------------------- - - func: GetTextCollisions(x, y) - - desc: gets text collisions with the mouse ---]]--------------------------------------------------------- -function newobject:GetTextCollisions(x, y) - - local font = self.font - local lines = self.lines - local numlines = #lines - local line = self.line - local curline = lines[line] - local text = curline - local xpos = 0 - local line = 0 - local vbar = self.vbar - local hbar = self.hbar - local multiline = self.multiline - - if multiline then - local theight = self.font:getHeight("a") - local liney = 0 - local selfcol - if vbar and not hbar then - selfcol = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width - 16, 1, self.height, 1) - elseif hbar and not vbar then - selfcol = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.height - 16, 1) - elseif not vbar and not hbar then - selfcol = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width, 1, self.height, 1) - elseif vbar and hbar then - selfcol = loveframes.util.BoundingBox(self.x, x, self.y, y, self.width - 16, 1, self.height - 16, 1) - end - if selfcol then - for i=1, numlines do - local linecol = loveframes.util.BoundingBox(self.x, x, (self.y - self.offsety) + self.textoffsety + (theight * i) - theight, y, self.width, 1, theight, 1) - if linecol then - liney = (self.y - self.offsety) + self.textoffsety + (theight * i) - theight - self.line = i - end - end - local line = self.line - local curline = lines[line] - for i=1, #curline do - local width = font:getWidth(curline:sub(i, i)) - local height = font:getHeight(curline:sub(i, i)) - local tx = self.textx + xpos - local ty = self.texty - local col = loveframes.util.BoundingBox(tx, x, liney, y, width, 1, height, 1) - - xpos = xpos + width - - if col then - self:MoveIndicator(i - 1, true) - break - else - self.indicatornum = #curline - end - - if x < tx then - self:MoveIndicator(0, true) - end - - if x > (tx + width) then - self:MoveIndicator(#curline, true) - end - end - - if #curline == 0 then - self.indicatornum = 0 - end - end - else - for i=1, #text do - local width = font:getWidth(text:sub(i, i)) - local height = font:getHeight(text:sub(i, i)) - local tx = self.textx + xpos - local ty = self.texty - local col = loveframes.util.BoundingBox(tx, x, ty, y, width, 1, height, 1) - xpos = xpos + width - if col then - self:MoveIndicator(i - 1, true) - break - end - if x < tx then - self:MoveIndicator(0, true) - end - if x > (tx + width) then - self:MoveIndicator(#text, true) - end - end - end - -end - ---[[--------------------------------------------------------- - - func: PositionText() - - desc: positions the object's text ---]]--------------------------------------------------------- -function newobject:PositionText() - - local multiline = self.multiline - local x = self.x - local y = self.y - local offsetx = self.offsetx - local offsety = self.offsety - local textoffsetx = self.textoffsetx - local textoffsety = self.textoffsety - local linenumberspanel = self.linenumberspanel - - if multiline then - if linenumberspanel then - local panel = self:GetLineNumbersPanel() - self.textx = ((x + panel.width) - offsetx) + textoffsetx - self.texty = (y - offsety) + textoffsety - else - self.textx = (x - offsetx) + textoffsetx - self.texty = (y - offsety) + textoffsety - end - else - self.textx = (x - offsetx) + textoffsetx - self.texty = (y - offsety) + textoffsety - end - -end - ---[[--------------------------------------------------------- - - func: SetTextOffsetX(num) - - desc: sets the object's text x offset ---]]--------------------------------------------------------- -function newobject:SetTextOffsetX(num) - - self.textoffsetx = num - -end - ---[[--------------------------------------------------------- - - func: SetTextOffsetY(num) - - desc: sets the object's text y offset ---]]--------------------------------------------------------- -function newobject:SetTextOffsetY(num) - - self.textoffsety = num - -end - ---[[--------------------------------------------------------- - - func: SetFont(font) - - desc: sets the object's font ---]]--------------------------------------------------------- -function newobject:SetFont(font) - - self.font = font - -end - ---[[--------------------------------------------------------- - - func: GetFont() - - desc: gets the object's font ---]]--------------------------------------------------------- -function newobject:GetFont() - - return self.font - -end - ---[[--------------------------------------------------------- - - func: SetFocus(focus) - - desc: sets the object's focus ---]]--------------------------------------------------------- -function newobject:SetFocus(focus) - - local inputobject = loveframes.inputobject - local onfocusgained = self.OnFocusGained - local onfocuslost = self.OnFocusLost - - self.focus = focus - - if focus then - loveframes.inputobject = self - if onfocusgained then - onfocusgained(self) - end - else - if inputobject == self then - loveframes.inputobject = false - end - if onfocuslost then - onfocuslost(self) - end - end - -end - ---[[--------------------------------------------------------- - - func: GetFocus() - - desc: gets the object's focus ---]]--------------------------------------------------------- -function newobject:GetFocus() - - return self.focus - -end - ---[[--------------------------------------------------------- - - func: GetIndicatorVisibility() - - desc: gets the object's indicator visibility ---]]--------------------------------------------------------- -function newobject:GetIndicatorVisibility() - - return self.showindicator - -end - ---[[--------------------------------------------------------- - - func: SetLimit(limit) - - desc: sets the object's text limit ---]]--------------------------------------------------------- -function newobject:SetLimit(limit) - - self.limit = limit - -end - ---[[--------------------------------------------------------- - - func: SetUsable(usable) - - desc: sets what characters can be used for the - object's text ---]]--------------------------------------------------------- -function newobject:SetUsable(usable) - - self.usable = usable - -end - ---[[--------------------------------------------------------- - - func: GetUsable() - - desc: gets what characters can be used for the - object's text ---]]--------------------------------------------------------- -function newobject:GetUsable() - - return self.usable - -end - ---[[--------------------------------------------------------- - - func: SetUnusable(unusable) - - desc: sets what characters can not be used for the - object's text ---]]--------------------------------------------------------- -function newobject:SetUnusable(unusable) - - self.unusable = unusable - -end - ---[[--------------------------------------------------------- - - func: GetUnusable() - - desc: gets what characters can not be used for the - object's text ---]]--------------------------------------------------------- -function newobject:GetUnusable() - - return self.unusable - -end - ---[[--------------------------------------------------------- - - func: Clear() - - desc: clears the object's text ---]]--------------------------------------------------------- -function newobject:Clear() - - self.lines = {""} - self.line = 1 - self.offsetx = 0 - self.offsety = 0 - self.indicatornum = 0 - -end - ---[[--------------------------------------------------------- - - func: SetText(text) - - desc: sets the object's text ---]]--------------------------------------------------------- -function newobject:SetText(text) - - local tabreplacement = self.tabreplacement - local multiline = self.multiline - - -- replace any tabs character with spaces - text = text:gsub(string.char(9), tabreplacement) - - -- remove any carriage returns - text = text:gsub(string.char(13), "") - - if multiline then - text = text:gsub(string.char(92) .. string.char(110), string.char(10)) - local t = loveframes.util.SplitString(text, string.char(10)) - if #t > 0 then - self.lines = t - else - self.lines = {""} - end - else - text = text:gsub(string.char(92) .. string.char(110), "") - text = text:gsub(string.char(10), "") - self.lines = {text} - self.line = 1 - end - -end - ---[[--------------------------------------------------------- - - func: GetText() - - desc: gets the object's text ---]]--------------------------------------------------------- -function newobject:GetText() - - local multiline = self.multiline - local lines = self.lines - local text = "" - - if multiline then - for k, v in ipairs(lines) do - text = text .. v .. "\n" - end - else - text = lines[1] - end - - return text - -end - ---[[--------------------------------------------------------- - - func: SetMultiline(bool) - - desc: enables or disables allowing multiple lines for - text entry ---]]--------------------------------------------------------- -function newobject:SetMultiline(bool) - - local text = "" - local lines = self.lines - - self.multiline = bool - - if bool then - self:Clear() - else - for k, v in ipairs(lines) do - text = text .. v - end - self:SetText(text) - self.internals = {} - self.vbar = false - self.hbar = false - self.linenumberspanel = false - end - -end - ---[[--------------------------------------------------------- - - func: GetMultiLine() - - desc: gets whether or not the object is using multiple - lines ---]]--------------------------------------------------------- -function newobject:GetMultiLine() - - return self.multiline - -end - ---[[--------------------------------------------------------- - - func: GetVerticalScrollBody() - - desc: gets the object's vertical scroll body ---]]--------------------------------------------------------- -function newobject:GetVerticalScrollBody() - - local vbar = self.vbar - local internals = self.internals - local item = false - - if vbar then - for k, v in ipairs(internals) do - if v.type == "scrollbody" and v.bartype == "vertical" then - item = v - end - end - end - - return item - -end - ---[[--------------------------------------------------------- - - func: GetHorizontalScrollBody() - - desc: gets the object's horizontal scroll body ---]]--------------------------------------------------------- -function newobject:GetHorizontalScrollBody() - - local hbar = self.hbar - local internals = self.internals - local item = false - - if hbar then - for k, v in ipairs(internals) do - if v.type == "scrollbody" and v.bartype == "horizontal" then - item = v - end - end - end - - return item - -end - ---[[--------------------------------------------------------- - - func: HasVerticalScrollBar() - - desc: gets whether or not the object has a vertical - scroll bar ---]]--------------------------------------------------------- -function newobject:HasVerticalScrollBar() - - return self.vbar - -end - ---[[--------------------------------------------------------- - - func: HasHorizontalScrollBar() - - desc: gets whether or not the object has a horizontal - scroll bar ---]]--------------------------------------------------------- -function newobject:HasHorizontalScrollBar() - - return self.hbar - -end - ---[[--------------------------------------------------------- - - func: GetLineNumbersPanel() - - desc: gets the object's line numbers panel ---]]--------------------------------------------------------- -function newobject:GetLineNumbersPanel() - - local panel = self.linenumberspanel - local internals = self.internals - local item = false - - if panel then - for k, v in ipairs(internals) do - if v.type == "linenumberspanel" then - item = v - end - end - end - - return item - -end - ---[[--------------------------------------------------------- - - func: ShowLineNumbers(bool) - - desc: sets whether or not to show line numbers when - using multiple lines ---]]--------------------------------------------------------- -function newobject:ShowLineNumbers(bool) - - local multiline = self.multiline - - if multiline then - self.linenumbers = bool - end - -end - ---[[--------------------------------------------------------- - - func: GetTextX() - - desc: gets the object's text x ---]]--------------------------------------------------------- -function newobject:GetTextX() - - return self.textx - -end - ---[[--------------------------------------------------------- - - func: GetTextY() - - desc: gets the object's text y ---]]--------------------------------------------------------- -function newobject:GetTextY() - - return self.texty - -end - ---[[--------------------------------------------------------- - - func: IsAllTextSelected() - - desc: gets whether or not all of the object's text is - selected ---]]--------------------------------------------------------- -function newobject:IsAllTextSelected() - - return self.alltextselected - -end - ---[[--------------------------------------------------------- - - func: GetLines() - - desc: gets the object's lines ---]]--------------------------------------------------------- -function newobject:GetLines() - - return self.lines - -end - ---[[--------------------------------------------------------- - - func: GetOffsetX() - - desc: gets the object's x offset ---]]--------------------------------------------------------- -function newobject:GetOffsetX() - - return self.offsetx - -end - ---[[--------------------------------------------------------- - - func: GetOffsetY() - - desc: gets the object's y offset ---]]--------------------------------------------------------- -function newobject:GetOffsetY() - - return self.offsety - -end - ---[[--------------------------------------------------------- - - func: GetIndicatorX() - - desc: gets the object's indicator's xpos ---]]--------------------------------------------------------- -function newobject:GetIndicatorX() - - return self.indicatorx - -end - ---[[--------------------------------------------------------- - - func: GetIndicatorY() - - desc: gets the object's indicator's ypos ---]]--------------------------------------------------------- -function newobject:GetIndicatorY() - - return self.indicatory - -end - ---[[--------------------------------------------------------- - - func: GetLineNumbersEnabled() - - desc: gets whether line numbers are enabled on the - object or not ---]]--------------------------------------------------------- -function newobject:GetLineNumbersEnabled() - - return self.linenumbers - -end - ---[[--------------------------------------------------------- - - func: GetItemWidth() - - desc: gets the object's item width ---]]--------------------------------------------------------- -function newobject:GetItemWidth() - - return self.itemwidth - -end - ---[[--------------------------------------------------------- - - func: GetItemHeight() - - desc: gets the object's item height ---]]--------------------------------------------------------- -function newobject:GetItemHeight() - - return self.itemheight - -end - ---[[--------------------------------------------------------- - - func: SetTabReplacement(tabreplacement) - - desc: sets a string to replace tabs with ---]]--------------------------------------------------------- -function newobject:SetTabReplacement(tabreplacement) - - self.tabreplacement = tabreplacement - -end - ---[[--------------------------------------------------------- - - func: GetTabReplacement() - - desc: gets the object's tab replacement ---]]--------------------------------------------------------- -function newobject:GetTabReplacement() - - return self.tabreplacement - -end - ---[[--------------------------------------------------------- - - func: SetEditable(bool) - - desc: sets whether or not the user can edit the - object's text ---]]--------------------------------------------------------- -function newobject:SetEditable(bool) - - self.editable = bool - -end - ---[[--------------------------------------------------------- - - func: GetEditable - - desc: gets whether or not the user can edit the - object's text ---]]--------------------------------------------------------- -function newobject:GetEditable() - - return self.editable - -end - ---[[--------------------------------------------------------- - - func: SetButtonScrollAmount(speed) - - desc: sets the scroll amount of the object's scrollbar - buttons ---]]--------------------------------------------------------- -function newobject:SetButtonScrollAmount(amount) - - self.buttonscrollamount = amount - -end - ---[[--------------------------------------------------------- - - func: GetButtonScrollAmount() - - desc: gets the scroll amount of the object's scrollbar - buttons ---]]--------------------------------------------------------- -function newobject:GetButtonScrollAmount() - - return self.buttonscrollamount - -end - ---[[--------------------------------------------------------- - - func: SetMouseWheelScrollAmount(amount) - - desc: sets the scroll amount of the mouse wheel ---]]--------------------------------------------------------- -function newobject:SetMouseWheelScrollAmount(amount) - - self.mousewheelscrollamount = amount - -end - ---[[--------------------------------------------------------- - - func: GetMouseWheelScrollAmount() - - desc: gets the scroll amount of the mouse wheel ---]]--------------------------------------------------------- -function newobject:GetButtonScrollAmount() - - return self.mousewheelscrollamount - -end - ---[[--------------------------------------------------------- - - func: SetAutoScroll(bool) - - desc: sets whether or not the object should autoscroll - when in multiline mode ---]]--------------------------------------------------------- -function newobject:SetAutoScroll(bool) - - local internals = self.internals - - self.autoscroll = bool - - if internals[2] then - internals[2].internals[1].internals[1].autoscroll = bool - end - -end - ---[[--------------------------------------------------------- - - func: GetAutoScroll() - - desc: gets whether or not the object should autoscroll - when in multiline mode ---]]--------------------------------------------------------- -function newobject:GetAutoScroll() - - return self.autoscroll - end \ No newline at end of file diff --git a/readme.md b/readme.md index f501e49..cc28031 100644 --- a/readme.md +++ b/readme.md @@ -1,18 +1,18 @@ -# Love Frames - -## Information - -Love Frames is a GUI library for [LOVE](https://love2d.org/). For information on installation and usage, please visit the [wiki](https://github.com/NikolaiResokav/LoveFrames/wiki). A demo of the library can be found at: http://nikolairesokav.com/projects/loveframes/ - -## License - -Love Frames is licensed under the Creative Commons Attribution 3.0 Unported (CC BY 3.0) license. -For more information on this license, please read license.txt or visit this web page: http://creativecommons.org/licenses/by/3.0/ - -## Credits - -Created by Kenny Shields - -**Third-Party Libraries** - +# Love Frames + +## Information + +Love Frames is a GUI library for [LOVE](https://love2d.org/). For information on installation and usage, please visit the [wiki](http://nikolairesokav.com/documents/?page=loveframes/main). A demo of the library can be found at: http://nikolairesokav.com/projects/loveframes/ + +## License + +Love Frames is licensed under the Creative Commons Attribution 3.0 Unported (CC BY 3.0) license. +For more information on this license, please read license.txt or visit this web page: http://creativecommons.org/licenses/by/3.0/ + +## Credits + +Created by Kenny Shields + +**Third-Party Libraries** + - middleclass by kikito - https://github.com/kikito/middleclass \ No newline at end of file diff --git a/skins.lua b/skins.lua index aa6590e..1b66145 100644 --- a/skins.lua +++ b/skins.lua @@ -1,70 +1,70 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- skins library -loveframes.skins = {} - --- available skins -loveframes.skins.available = {} - ---[[--------------------------------------------------------- - - func: Register(skin) - - desc: registers a skin ---]]--------------------------------------------------------- -function loveframes.skins.Register(skin) - - local name = skin.name - local author = skin.author - local version = skin.version - local namecheck = loveframes.skins.available[name] - local dir = loveframes.config["DIRECTORY"] .. "/skins/" ..name - local dircheck = love.filesystem.isDirectory(dir) - local images = loveframes.util.GetDirectoryContents(dir .. "/images") - local indeximages = loveframes.config["INDEXSKINIMAGES"] - - if name == "" or not name then - loveframes.util.Error("Could not register skin: Invalid or missing name data.") - end - - if author == "" or not author then - loveframes.util.Error("Could not register skin: Invalid or missing author data.") - end - - if version == "" or version == nil then - loveframes.util.Error("Could not register skin: Invalid or missing version data.") - end - - if namecheck then - loveframes.util.Error("Could not register skin: A skin with the name '" ..name.. "' already exists.") - end - - if not dircheck then - loveframes.util.Error("Could not register skin: Could not find a directory for skin '" ..name.. "'.") - end - - loveframes.skins.available[name] = skin - loveframes.skins.available[name].dir = dir - loveframes.skins.available[name].images = {} - - if #images > 0 and indeximages == true then - - for k, v in ipairs(images) do - loveframes.skins.available[name].images[v.name .. "." .. v.extension] = love.graphics.newImage(v.fullpath) - end - - end - -end - ---[[--------------------------------------------------------- - - func: GetAvailable() - - desc: gets all available skins ---]]--------------------------------------------------------- -function loveframes.skins.GetAvailable() - - local available = loveframes.skins.available - return available - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- skins library +loveframes.skins = {} + +-- available skins +loveframes.skins.available = {} + +--[[--------------------------------------------------------- + - func: Register(skin) + - desc: registers a skin +--]]--------------------------------------------------------- +function loveframes.skins.Register(skin) + + local name = skin.name + local author = skin.author + local version = skin.version + local namecheck = loveframes.skins.available[name] + local dir = loveframes.config["DIRECTORY"] .. "/skins/" ..name + local dircheck = love.filesystem.isDirectory(dir) + local images = loveframes.util.GetDirectoryContents(dir .. "/images") + local indeximages = loveframes.config["INDEXSKINIMAGES"] + + if name == "" or not name then + loveframes.util.Error("Could not register skin: Invalid or missing name data.") + end + + if author == "" or not author then + loveframes.util.Error("Could not register skin: Invalid or missing author data.") + end + + if version == "" or version == nil then + loveframes.util.Error("Could not register skin: Invalid or missing version data.") + end + + if namecheck then + loveframes.util.Error("Could not register skin: A skin with the name '" ..name.. "' already exists.") + end + + if not dircheck then + loveframes.util.Error("Could not register skin: Could not find a directory for skin '" ..name.. "'.") + end + + loveframes.skins.available[name] = skin + loveframes.skins.available[name].dir = dir + loveframes.skins.available[name].images = {} + + if #images > 0 and indeximages == true then + + for k, v in ipairs(images) do + loveframes.skins.available[name].images[v.name .. "." .. v.extension] = love.graphics.newImage(v.fullpath) + end + + end + +end + +--[[--------------------------------------------------------- + - func: GetAvailable() + - desc: gets all available skins +--]]--------------------------------------------------------- +function loveframes.skins.GetAvailable() + + local available = loveframes.skins.available + return available + end \ No newline at end of file diff --git a/skins/Blue (basic)/images/arrow-down.png b/skins/Blue (basic)/images/arrow-down.png index 14e39181a536a2a53513f343b3908411a4a6d406..37d805800fd4b840d58fc637925316b0a4c697a1 100644 GIT binary patch delta 290 zcmV+-0p0$z0oVc|iBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;PNkliBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;INklzN}+9AOw)vUp3(O`%CZcQB!J0X*I^h2 ztm_Kz{T_590w;i6(00=_7{?LYw(W`UJI~_gnd>>hBYS7XeYLcA2>Bwi%hgXAI!A9m~0U&M#^_Rg$o|w6XvI002ovPDHLkV1mSDcYFW< delta 133 zcmcb}w1-i#Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{K?VlCgN!>SX1|^2 zrs-?p>Ealo5uBW`fGr~<;|KpCma|NnOpHxkiCmmoZebnahP#|z&E)xPdNI%Kx`Tnq h1XF>v645CP4E5?c>rZc52Q-a=!PC{xWt~$(6976eC^`TD diff --git a/skins/Blue (basic)/images/arrow-right.png b/skins/Blue (basic)/images/arrow-right.png index 159cd41e72ab30068f715cc4871a45b57d3a0b6b..89b4818627737201d05713540777e2d19c06f43d 100644 GIT binary patch delta 282 zcmV+#0p=iBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;HNkl(Dd}wAM(|^gDzz zps0P{W1eS>zV9c5GVzw<12AM+77W9Hs;b=m2mu%p4WM2`m%z?ZO(f^P$4EkA9YhJ~wv=fa gx0cDZ(xEMU0H$wJHGrC-$^ZZW07*qoM6N<$f*huHYybcN delta 130 zcmcb>w3AV>Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{K?VlCgN!>SX1|^2 zrs-ws>Ealo5uBW$AZ}t}@`pWf(U)eCCWb(%gs#p@4QpmBU@JLVVLBn#$kBh2j1-Hn eik47A7sIT1IqQu&B&2}GGI+ZBxvXycm@&iD7$=N5;8cm zE&~&2ZMv(ft2NR$P7nlo75|!LiD4MZ4_m(#0SK`yOVxF4f}9$?x5rLMl0>h@*2$9_-!{`AoacXO$Q&y|@3IbLtQAF}rfIY+ zi;m-PWTWs9p$7)6UB~Q{WtqCJGn4myzmRcc7k0000< LMNUMnLSO-cDrSHw delta 133 zcmaFIw1-i#Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{0R{%X1B_YMIyoo0 zY5H1tx;Tbt1Scmf(9X!n_~AdLRiRbEA%NLOF~Zc2_XSsB)`6u0&ddRd%pQhdl h$nXi_n7EXK;cI+@{*#rgXMiR%c)I$ztaD0e0sz<7CDQ-^ diff --git a/skins/Blue (basic)/images/multichoice-arrow.png b/skins/Blue (basic)/images/multichoice-arrow.png index c7294cb988d550ae37b61de17bd99f60cc984151..165121c956329680f817fdc62358e736bfebea59 100644 GIT binary patch delta 230 zcmV&Y z4#EKyC`y2lMk#-oNkl)lw(yN3ek#+n$V=8p?B1z z5Q!M4fn>^>+wcAYr4;?i1T!;M{*ZJKETZPv4qFA@`_e^=0WcV_>7liz7-N$JFlxah z0Rk_^m`6#5QCr|V6j>5NsCEJvdsTQZvDT85WEgv=ljSa0qCiR@Y=Y(QIOhm?+xFGP gkkk3k0Tv)+O`Ywc{{R3007*qoM6N<$f-8<#R{#J2 delta 176 zcmbQk^qf(#Gr-TCmrII^fq{Y7)59eQNb`d*2OE&IzBbisqM|g{VFm`i!;HuCSENjI z)2vALba4!^@J~)Sz~t4JZqQ&5$*^LgU`yw8Fr9Z6-lD0PvyA@j theight then - parent:SetTabHeight(imageheight + 5) - object.height = imageheight + 5 - else - parent:SetTabHeight(theight + 5) - object.height = theight + 5 - end - else - object.width = 10 + twidth - parent:SetTabHeight(theight + 5) - object.height = theight + 5 - end - - local width = object:GetWidth() - local height = object:GetHeight() - - if tabnumber == ptabnumber then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if image then - -- button image - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) - else - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + 5, y + height/2 - theight/2) - end - - else - - -- button body - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if image then - -- button image - love.graphics.setColor(255, 255, 255, 150) - love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(object.text, x + imagewidth + 10, y + height/2 - theight/2) - else - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(object.text, x + 5, y + height/2 - theight/2) - end - - end - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoice(object) - - desc: draws the multi choice object ---]]--------------------------------------------------------- -function skin.DrawMultiChoice(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local choice = object:GetChoice() - local image = skin.images["multichoice-arrow.png"] - local font = skin.controls.multichoice_text_font - local theight = font:getHeight("a") - local bodycolor = skin.controls.multichoice_body_color - local textcolor = skin.controls.multichoice_text_color - local bordercolor = skin.controls.multichoice_border_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - love.graphics.setColor(unpack(textcolor)) - love.graphics.setFont(font) - - if choice == "" then - love.graphics.print(text, x + 5, y + height/2 - theight/2) - else - love.graphics.print(choice, x + 5, y + height/2 - theight/2) - end - - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(image, x + width - 20, y + 5) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoiceList(object) - - desc: draws the multi choice list object ---]]--------------------------------------------------------- -function skin.DrawMultiChoiceList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.multichoicelist_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawOverMultiChoiceList(object) - - desc: draws over the multi choice list object ---]]--------------------------------------------------------- -function skin.DrawOverMultiChoiceList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.multichoicelist_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y - 1, width, height + 1) - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoiceRow(object) - - desc: draws the multi choice row object ---]]--------------------------------------------------------- -function skin.DrawMultiChoiceRow(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local font = skin.controls.multichoicerow_text_font - local bodyhovecolor = skin.controls.multichoicerow_body_hover_color - local texthovercolor = skin.controls.multichoicerow_text_hover_color - local bodynohovercolor = skin.controls.multichoicerow_body_nohover_color - local textnohovercolor = skin.controls.multichoicerow_text_nohover_color - - love.graphics.setFont(font) - - if object.hover then - love.graphics.setColor(unpack(bodyhovecolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + 5, y + 5) - else - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(text, x + 5, y + 5) - end - -end - ---[[--------------------------------------------------------- - - func: DrawToolTip(object) - - desc: draws the tool tip object ---]]--------------------------------------------------------- -function skin.DrawToolTip(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.tooltip_body_color - local bordercolor = skin.controls.tooltip_border_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawText(object) - - desc: draws the text object ---]]--------------------------------------------------------- -function skin.DrawText(object) - -end - ---[[--------------------------------------------------------- - - func: DrawTextInput(object) - - desc: draws the text input object ---]]--------------------------------------------------------- -function skin.DrawTextInput(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local font = object:GetFont() - local focus = object:GetFocus() - local showindicator = object:GetIndicatorVisibility() - local alltextselected = object:IsAllTextSelected() - local textx = object:GetTextX() - local texty = object:GetTextY() - local text = object:GetText() - local multiline = object:GetMultiLine() - local lines = object:GetLines() - local offsetx = object:GetOffsetX() - local offsety = object:GetOffsetY() - local indicatorx = object:GetIndicatorX() - local indicatory = object:GetIndicatorY() - local vbar = object:HasVerticalScrollBar() - local hbar = object:HasHorizontalScrollBar() - local linenumbers = object:GetLineNumbersEnabled() - local itemwidth = object:GetItemWidth() - local theight = font:getHeight("a") - local bodycolor = skin.controls.textinput_body_color - local textnormalcolor = skin.controls.textinput_text_normal_color - local textselectedcolor = skin.controls.textinput_text_selected_color - local highlightbarcolor = skin.controls.textinput_highlight_bar_color - local indicatorcolor = skin.controls.textinput_indicator_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - if alltextselected then - local bary = 0 - if multiline then - for i=1, #lines do - local twidth = font:getWidth(lines[i]) - love.graphics.setColor(unpack(highlightbarcolor)) - love.graphics.rectangle("fill", textx, texty + bary, twidth, theight) - bary = bary + theight - end - else - local twidth = font:getWidth(text) - love.graphics.setColor(unpack(highlightbarcolor)) - love.graphics.rectangle("fill", textx, texty, twidth, theight) - end - end - - if showindicator and focus then - love.graphics.setColor(unpack(indicatorcolor)) - love.graphics.rectangle("fill", indicatorx, indicatory, 1, theight) - end - - if not multiline then - object:SetTextOffsetY(height/2 - theight/2) - if offsetx ~= 0 then - object:SetTextOffsetX(0) - else - object:SetTextOffsetX(5) - end - else - if vbar then - if offsety ~= 0 then - if hbar then - object:SetTextOffsetY(5) - else - object:SetTextOffsetY(-5) - end - else - object:SetTextOffsetY(5) - end - else - object:SetTextOffsetY(5) - end - - if hbar then - if offsety ~= 0 then - if linenumbers then - local panel = object:GetLineNumbersPanel() - if vbar then - object:SetTextOffsetX(5) - else - object:SetTextOffsetX(-5) - end - else - if vbar then - object:SetTextOffsetX(5) - else - object:SetTextOffsetX(-5) - end - end - else - object:SetTextOffsetX(5) - end - else - object:SetTextOffsetX(5) - end - - end - - textx = object:GetTextX() - texty = object:GetTextY() - - love.graphics.setFont(font) - - if alltextselected then - love.graphics.setColor(unpack(textselectedcolor)) - else - love.graphics.setColor(unpack(textnormalcolor)) - end - - if multiline then - for i=1, #lines do - love.graphics.print(lines[i], textx, texty + theight * i - theight) - end - else - love.graphics.print(lines[1], textx, texty) - end - -end - ---[[--------------------------------------------------------- - - func: DrawOverTextInput(object) - - desc: draws over the text input object ---]]--------------------------------------------------------- -function skin.DrawOverTextInput(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.textinput_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawScrollButton(object) - - desc: draws the scroll button object ---]]--------------------------------------------------------- -function skin.DrawScrollButton(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local scrolltype = object:GetScrollType() - local down = object.down - local bodydowncolor = skin.controls.button_body_down_color - local borderdowncolor = skin.controls.button_border_down_color - local bodyhovercolor = skin.controls.button_body_hover_color - local borderhovercolor = skin.controls.button_border_hover_color - local bodynohovercolor = skin.controls.button_body_nohover_color - local bordernohovercolor = skin.controls.button_border_nohover_color - - if down then - - -- button body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height) - - elseif hover then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(borderhovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - else - - -- button body - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - end - - if scrolltype == "up" then - local image = skin.images["arrow-up.png"] - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) - elseif scrolltype == "down" then - local image = skin.images["arrow-down.png"] - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) - elseif scrolltype == "left" then - local image = skin.images["arrow-left.png"] - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) - elseif scrolltype == "right" then - local image = skin.images["arrow-right.png"] - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawSlider(object) - - desc: draws the slider object ---]]--------------------------------------------------------- -function skin.DrawSlider(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local slidtype = object:GetSlideType() - local baroutlinecolor = skin.controls.slider_bar_outline_color - local barcolor = skin.controls.slider_bar_color - - if slidtype == "horizontal" then - - love.graphics.setColor(unpack(baroutlinecolor)) - love.graphics.rectangle("fill", x, y + height/2 - 5, width, 10) - - love.graphics.setColor(unpack(barcolor)) - love.graphics.rectangle("fill", x + 5, y + height/2, width - 10, 1) - - elseif slidtype == "vertical" then - - love.graphics.setColor(unpack(baroutlinecolor)) - love.graphics.rectangle("fill", x + width/2 - 5, y, 10, height) - - love.graphics.setColor(unpack(barcolor)) - love.graphics.rectangle("fill", x + width/2, y + 5, 1, height - 10) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawSliderButton(object) - - desc: draws the slider button object ---]]--------------------------------------------------------- -function skin.DrawSliderButton(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local down = object.down - local bodydowncolor = skin.controls.button_body_down_color - local borderdowncolor = skin.controls.button_border_down_color - local bodyhovercolor = skin.controls.button_body_hover_color - local borderhovercolor = skin.controls.button_border_down_color - local bodynohvercolor = skin.controls.button_body_nohover_color - local bordernohovercolor = skin.controls.button_border_down_color - - if down then - - -- button body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height) - - elseif hover then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(borderhovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - else - - -- button body - love.graphics.setColor(unpack(bodynohvercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawCheckBox(object) - - desc: draws the check box object ---]]--------------------------------------------------------- -function skin.DrawCheckBox(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetBoxWidth() - local height = object:GetBoxHeight() - local checked = object:GetChecked() - - love.graphics.setColor(unpack(skin.controls.checkbox_body_color)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(skin.controls.checkbox_border_color)) - skin.OutlinedRectangle(x, y, width, height) - - if checked then - love.graphics.setColor(unpack(skin.controls.checkbox_check_color)) - love.graphics.rectangle("fill", x + 4, y + 4, width - 8, height - 8) - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawCollapsibleCategory(object) - - desc: draws the collapsible category object ---]]--------------------------------------------------------- -function skin.DrawCollapsibleCategory(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local bodycolor = skin.controls.collapsiblecategory_body_color - local textcolor = skin.controls.collapsiblecategory_text_color - local bordercolor = skin.controls.collapsiblecategory_border_color - local font = smallfont - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setFont(font) - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(text, x + 5, y + 5) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnList(object) - - desc: draws the column list object ---]]--------------------------------------------------------- -function skin.DrawColumnList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.columnlist_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListHeader(object) - - desc: draws the column list header object ---]]--------------------------------------------------------- -function skin.DrawColumnListHeader(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local name = object:GetName() - local down = object.down - local font = skin.controls.columnlistheader_text_font - local twidth = font:getWidth(object.name) - local theight = font:getHeight(object.name) - local bodydowncolor = skin.controls.columnlistheader_body_down_color - local textdowncolor = skin.controls.columnlistheader_text_down_color - local borderdowncolor = skin.controls.columnlistheader_border_down_color - local bodyhovercolor = skin.controls.columnlistheader_body_hover_color - local textdowncolor = skin.controls.columnlistheader_text_hover_color - local borderdowncolor = skin.controls.columnlistheader_border_down_color - local nohovercolor = skin.controls.columnlistheader_body_nohover_color - local textnohovercolor = skin.controls.columnlistheader_text_nohover_color - local bordernohovercolor = skin.controls.columnlistheader_border_down_color - - if down then - - -- header body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textdowncolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - elseif hover then - - -- header body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textdowncolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - else - - -- header body - love.graphics.setColor(unpack(nohovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListArea(object) - - desc: draws the column list area object ---]]--------------------------------------------------------- -function skin.DrawColumnListArea(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.columnlistarea_body_color - - love.graphics.setColor(unpack(skin.controls.columnlistarea_body_color)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawOverColumnListArea(object) - - desc: draws over the column list area object ---]]--------------------------------------------------------- -function skin.DrawOverColumnListArea(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.columnlist_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListRow(object) - - desc: draws the column list row object ---]]--------------------------------------------------------- -function skin.DrawColumnListRow(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local colorindex = object:GetColorIndex() - local font = object:GetFont() - local columndata = object:GetColumnData() - local textx = object:GetTextX() - local texty = object:GetTextY() - local parent = object:GetParent() - local cwidth, cheight = parent:GetParent():GetColumnSize() - local theight = font:getHeight("a") - local body1color = skin.controls.columnlistrow_body1_color - local border1color = skin.controls.columnlistrow_border1_color - local body2color = skin.controls.columnlistrow_body2_color - local border2color = skin.controls.columnlistrow_border2_color - local textcolor = skin.controls.columnlistrow_text_color - - object:SetTextPos(5, height/2 - theight/2) - - if colorindex == 1 then - - love.graphics.setColor(unpack(body1color)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - love.graphics.setColor(unpack(skin.controls.columnlistrow_border1_color)) - skin.OutlinedRectangle(x, y, width, height, true, false, true, true) - - else - - love.graphics.setColor(unpack(body2color)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(border2color)) - skin.OutlinedRectangle(x, y, width, height, true, false, true, true) - - end - - for k, v in ipairs(columndata) do - love.graphics.setFont(font) - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(v, x + textx, y + texty) - x = x + cwidth - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawModalBackground(object) - - desc: draws the modal background object ---]]--------------------------------------------------------- -function skin.DrawModalBackground(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.modalbackground_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawLineNumbersPanel(object) - - desc: draws the line numbers panel object ---]]--------------------------------------------------------- -function skin.DrawLineNumbersPanel(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local offsety = object:GetOffsetY() - local parent = object:GetParent() - local lines = parent:GetLines() - local font = parent:GetFont() - local theight = font:getHeight("a") - local bordercolor = skin.controls.linenumberspanel_border_color - local textcolor = skin.controls.linenumberspanel_text_color - local mody = y - - object:SetWidth(10 + font:getWidth(#lines)) - love.graphics.setFont(font) - - love.graphics.setColor(200, 200, 200, 255) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height, true, true, true, false) - - for i=1, #lines do - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(i, object.x + 5, mody - offsety) - mody = mody + theight - end - -end - --- register the skin +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- skin table +local skin = {} + +-- skin info (you always need this in a skin) +skin.name = "Blue (basic)" +skin.author = "Nikolai Resokav" +skin.version = "1.0" + +local smallfont = love.graphics.newFont(10) +local imagebuttonfont = love.graphics.newFont(15) +local bordercolor = {143, 143, 143, 255} + +-- controls +skin.controls = {} + +-- frame +skin.controls.frame_border_color = bordercolor +skin.controls.frame_body_color = {232, 232, 232, 255} +skin.controls.frame_top_color = {102, 194, 255, 255} +skin.controls.frame_name_color = {255, 255, 255, 255} +skin.controls.frame_name_font = smallfont + +-- button +skin.controls.button_border_down_color = bordercolor +skin.controls.button_border_nohover_color = bordercolor +skin.controls.button_border_hover_color = bordercolor +skin.controls.button_body_down_color = {128, 204, 255, 255} +skin.controls.button_body_nohover_color = {255, 255, 255, 255} +skin.controls.button_body_hover_color = {153, 214, 255, 255} +skin.controls.button_text_down_color = {255, 255, 255, 255} +skin.controls.button_text_nohover_color = {0, 0, 0, 200} +skin.controls.button_text_hover_color = {255, 255, 255, 255} +skin.controls.button_body_nonclickable_color = {220, 220, 220, 255} +skin.controls.button_text_nonclickable_color = {0, 0, 0, 100} +skin.controls.button_text_font = smallfont + +-- image button +skin.controls.imagebutton_text_down_color = {255, 255, 255, 255} +skin.controls.imagebutton_text_nohover_color = {255, 255, 255, 200} +skin.controls.imagebutton_text_hover_color = {255, 255, 255, 255} +skin.controls.imagebutton_text_font = imagebuttonfont + +-- close button +skin.controls.closebutton_body_down_color = {255, 255, 255, 255} +skin.controls.closebutton_body_nohover_color = {255, 255, 255, 255} +skin.controls.closebutton_body_hover_color = {255, 255, 255, 255} + +-- progress bar +skin.controls.progressbar_border_color = bordercolor +skin.controls.progressbar_body_color = {255, 255, 255, 255} +skin.controls.progressbar_bar_color = {0, 255, 0, 255} +skin.controls.progressbar_text_color = {0, 0, 0, 255} +skin.controls.progressbar_text_font = smallfont + +-- list +skin.controls.list_border_color = bordercolor +skin.controls.list_body_color = {232, 232, 232, 255} + +-- scrollbar +skin.controls.scrollbar_border_down_color = bordercolor +skin.controls.scrollbar_border_hover_color = bordercolor +skin.controls.scrollbar_border_nohover_color = bordercolor +skin.controls.scrollbar_body_down_color = {128, 204, 255, 255} +skin.controls.scrollbar_body_nohover_color = {255, 255, 255, 255} +skin.controls.scrollbar_body_hover_color = {153, 214, 255, 255} + +-- scrollarea +skin.controls.scrollarea_body_color = {200, 200, 200, 255} +skin.controls.scrollarea_border_color = bordercolor + +-- scrollbody +skin.controls.scrollbody_body_color = {0, 0, 0, 0} + +-- panel +skin.controls.panel_body_color = {232, 232, 232, 255} +skin.controls.panel_border_color = bordercolor + +-- tab panel +skin.controls.tabpanel_body_color = {232, 232, 232, 255} +skin.controls.tabpanel_border_color = bordercolor + +-- tab button +skin.controls.tab_border_nohover_color = bordercolor +skin.controls.tab_border_hover_color = bordercolor +skin.controls.tab_body_nohover_color = {255, 255, 255, 255} +skin.controls.tab_body_hover_color = {153, 214, 255, 255} +skin.controls.tab_text_nohover_color = {0, 0, 0, 200} +skin.controls.tab_text_hover_color = {255, 255, 255, 255} +skin.controls.tab_text_font = smallfont + +-- multichoice +skin.controls.multichoice_body_color = {240, 240, 240, 255} +skin.controls.multichoice_border_color = bordercolor +skin.controls.multichoice_text_color = {0, 0, 0, 255} +skin.controls.multichoice_text_font = smallfont + +-- multichoicelist +skin.controls.multichoicelist_body_color = {240, 240, 240, 200} +skin.controls.multichoicelist_border_color = bordercolor + +-- multichoicerow +skin.controls.multichoicerow_body_nohover_color = {240, 240, 240, 255} +skin.controls.multichoicerow_body_hover_color = {51, 204, 255, 255} +skin.controls.multichoicerow_border_color = {50, 50, 50, 255} +skin.controls.multichoicerow_text_nohover_color = {0, 0, 0, 150} +skin.controls.multichoicerow_text_hover_color = {255, 255, 255, 255} +skin.controls.multichoicerow_text_font = smallfont + +-- tooltip +skin.controls.tooltip_border_color = bordercolor +skin.controls.tooltip_body_color = {255, 255, 255, 255} + +-- text input +skin.controls.textinput_border_color = bordercolor +skin.controls.textinput_body_color = {240, 240, 240, 255} +skin.controls.textinput_indicator_color = {0, 0, 0, 255} +skin.controls.textinput_text_normal_color = {0, 0, 0, 255} +skin.controls.textinput_text_selected_color = {255, 255, 255, 255} +skin.controls.textinput_highlight_bar_color = {51, 204, 255, 255} + +-- slider +skin.controls.slider_bar_color = bordercolor +skin.controls.slider_bar_outline_color = {220, 220, 220, 255} + +-- checkbox +skin.controls.checkbox_border_color = bordercolor +skin.controls.checkbox_body_color = {255, 255, 255, 255} +skin.controls.checkbox_check_color = {128, 204, 255, 255} +skin.controls.checkbox_text_color = {0, 0, 0, 255} +skin.controls.checkbox_text_font = smallfont + +-- collapsiblecategory +skin.controls.collapsiblecategory_text_color = {0, 0, 0, 255} +skin.controls.collapsiblecategory_body_color = {255, 255, 255, 255} +skin.controls.collapsiblecategory_border_color = bordercolor + +-- columnlist +skin.controls.columnlist_border_color = bordercolor +skin.controls.columnlist_body_color = {232, 232, 232, 255} + +-- columlistarea +skin.controls.columnlistarea_border_color = bordercolor +skin.controls.columnlistarea_body_color = {232, 232, 232, 255} + +-- columnlistheader +skin.controls.columnlistheader_border_down_color = bordercolor +skin.controls.columnlistheader_border_nohover_color = bordercolor +skin.controls.columnlistheader_border_hover_color = bordercolor +skin.controls.columnlistheader_body_down_color = {128, 204, 255, 255} +skin.controls.columnlistheader_body_nohover_color = {255, 255, 255, 255} +skin.controls.columnlistheader_body_hover_color = {153, 214, 255, 255} +skin.controls.columnlistheader_text_down_color = {255, 255, 255, 255} +skin.controls.columnlistheader_text_nohover_color = {0, 0, 0, 200} +skin.controls.columnlistheader_text_hover_color = {255, 255, 255, 255} +skin.controls.columnlistheader_text_font = smallfont + +-- columnlistrow +skin.controls.columnlistrow_border1_color = bordercolor +skin.controls.columnlistrow_body1_color = {232, 232, 232, 255} +skin.controls.columnlistrow_border2_color = bordercolor +skin.controls.columnlistrow_body2_color = {200, 200, 200, 255} +skin.controls.columnlistrow_text_color = {100, 100, 100, 255} + +-- modalbackground +skin.controls.modalbackground_body_color = {255, 255, 255, 100} + +-- linenumberspanel +skin.controls.linenumberspanel_border_color = bordercolor +skin.controls.linenumberspanel_text_color = {100, 100, 100, 255} + +--[[--------------------------------------------------------- + - func: OutlinedRectangle(object) + - desc: creates and outlined rectangle +--]]--------------------------------------------------------- +function skin.OutlinedRectangle(x, y, width, height, ovt, ovb, ovl, ovr) + + local ovt = ovt or false + local ovb = ovb or false + local ovl = ovl or false + local ovr = ovr or false + + -- top + if not ovt then + love.graphics.rectangle("fill", x, y, width, 1) + end + + -- bottom + if not ovb then + love.graphics.rectangle("fill", x, y + height - 1, width, 1) + end + + -- left + if not ovl then + love.graphics.rectangle("fill", x, y, 1, height) + end + + -- right + if not ovr then + love.graphics.rectangle("fill", x + width - 1, y, 1, height) + end + +end + +--[[--------------------------------------------------------- + - func: DrawFrame(object) + - desc: draws the frame object +--]]--------------------------------------------------------- +function skin.DrawFrame(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local name = object:GetName() + local bodycolor = skin.controls.frame_body_color + local topcolor = skin.controls.frame_top_color + local bordercolor = skin.controls.frame_border_color + local namecolor = skin.controls.frame_name_color + local font = skin.controls.frame_name_font + + -- frame body + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + -- frame top bar + love.graphics.setColor(topcolor) + love.graphics.rectangle("fill", x, y, width, 25) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y + 25, width, 1) + + -- frame name section + love.graphics.setFont(font) + love.graphics.setColor(namecolor) + love.graphics.print(name, x + 5, y + 5) + + -- frame border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawButton(object) + - desc: draws the button object +--]]--------------------------------------------------------- +function skin.DrawButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local text = object:GetText() + local font = skin.controls.button_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local down = object.down + local enabled = object:GetEnabled() + local clickable = object:GetClickable() + local bodydowncolor = skin.controls.button_body_down_color + local textdowncolor = skin.controls.button_text_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local texthovercolor = skin.controls.button_text_hover_color + local borderhovercolor = skin.controls.button_border_down_color + local bodynohvercolor = skin.controls.button_body_nohover_color + local textnohovercolor = skin.controls.button_text_nohover_color + local bordernohovercolor = skin.controls.button_border_down_color + local bodynonclickablecolor = skin.controls.button_body_nonclickable_color + local textnonclickablecolor = skin.controls.button_text_nonclickable_color + + if not enabled or not clickable then + -- button body + love.graphics.setColor(bodynonclickablecolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnonclickablecolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + return + end + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + +end + +--[[--------------------------------------------------------- + - func: DrawCloseButton(object) + - desc: draws the close button object +--]]--------------------------------------------------------- +function skin.DrawCloseButton(object) + + local x = object:GetX() + local y = object:GetY() + local staticx = object:GetStaticX() + local width = object:GetWidth() + local height = object:GetHeight() + local parentwidth = object.parent:GetWidth() + local hover = object:GetHover() + local down = object.down + local image = skin.images["close.png"] + local bodydowncolor = skin.controls.closebutton_body_down_color + local bodyhovercolor = skin.controls.closebutton_body_hover_color + local bodynohovercolor = skin.controls.closebutton_body_nohover_color + + image:setFilter("nearest", "nearest") + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.draw(image, x, y) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.draw(image, x, y) + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.draw(image, x, y) + end + + if staticx ~= (parentwidth - 20) then + object:SetPos(parentwidth - 20, 4) + end + +end + +--[[--------------------------------------------------------- + - func: DrawImage(object) + - desc: draws the image object +--]]--------------------------------------------------------- +function skin.DrawImage(object) + + local x = object:GetX() + local y = object:GetY() + local orientation = object:GetOrientation() + local scalex = object:GetScaleX() + local scaley = object:GetScaleY() + local offsetx = object:GetOffsetX() + local offsety = object:GetOffsetY() + local shearx = object:GetShearX() + local sheary = object:GetShearY() + local image = object.image + local color = object.imagecolor + + if color then + love.graphics.setColor(color) + love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary) + else + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary) + end + +end + +--[[--------------------------------------------------------- + - func: DrawImageButton(object) + - desc: draws the image button object +--]]--------------------------------------------------------- +function skin.DrawImageButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local hover = object:GetHover() + local image = object:GetImage() + local down = object.down + local font = skin.controls.imagebutton_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local textdowncolor = skin.controls.imagebutton_text_down_color + local texthovercolor = skin.controls.imagebutton_text_hover_color + local textnohovercolor = skin.controls.imagebutton_text_nohover_color + + if down then + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + 1, y + 1) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2 + 1, y + height - theight - 5 + 1) + love.graphics.setColor(textdowncolor) + love.graphics.print(text, x + width/2 - twidth/2 + 1, y + height - theight - 6 + 1) + elseif hover then + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 5) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6) + else + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 5) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6) + end + +end + +--[[--------------------------------------------------------- + - func: DrawProgressBar(object) + - desc: draws the progress bar object +--]]--------------------------------------------------------- +function skin.DrawProgressBar(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local value = object:GetValue() + local max = object:GetMax() + local barwidth = object:GetBarWidth() + local font = skin.controls.progressbar_text_font + local text = value .. "/" ..max + local twidth = font:getWidth(text) + local theight = font:getHeight("a") + local bodycolor = skin.controls.progressbar_body_color + local barcolor = skin.controls.progressbar_bar_color + local textcolor = skin.controls.progressbar_text_color + local bordercolor = skin.controls.progressbar_border_color + + -- progress bar body + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x, y, barwidth, height) + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + + -- progress bar border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawScrollArea(object) + - desc: draws the scroll area object +--]]--------------------------------------------------------- +function skin.DrawScrollArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bartype = object:GetBarType() + local bodycolor = skin.controls.scrollarea_body_color + local bordercolor = skin.controls.scrollarea_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + + if bartype == "vertical" then + skin.OutlinedRectangle(x, y, width, height, true, true) + elseif bartype == "horizontal" then + skin.OutlinedRectangle(x, y, width, height, false, false, true, true) + end + +end + +--[[--------------------------------------------------------- + - func: DrawScrollBar(object) + - desc: draws the scroll bar object +--]]--------------------------------------------------------- +function skin.DrawScrollBar(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local dragging = object:IsDragging() + local hover = object:GetHover() + local bartype = object:GetBarType() + local bodydowncolor = skin.controls.scrollbar_body_down_color + local borderdowncolor = skin.controls.scrollbar_border_down_color + local bodyhovercolor = skin.controls.scrollbar_body_hover_color + local borderhovercolor = skin.controls.scrollbar_border_hover_color + local bodynohvercolor = skin.controls.scrollbar_body_nohover_color + local bordernohovercolor = skin.controls.scrollbar_border_nohover_color + + if dragging then + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + + if bartype == "vertical" then + love.graphics.setColor(bordernohovercolor) + love.graphics.rectangle("fill", x + 3, y + height/2 - 3, width - 6, 1) + love.graphics.rectangle("fill", x + 3, y + height/2, width - 6, 1) + love.graphics.rectangle("fill", x + 3, y + height/2 + 3, width - 6, 1) + else + love.graphics.setColor(bordernohovercolor) + love.graphics.rectangle("fill", x + width/2 - 3, y + 3, 1, height - 6) + love.graphics.rectangle("fill", x + width/2, y + 3, 1, height - 6) + love.graphics.rectangle("fill", x + width/2 + 3, y + 3, 1, height - 6) + end + +end + +--[[--------------------------------------------------------- + - func: DrawScrollBody(object) + - desc: draws the scroll body object +--]]--------------------------------------------------------- +function skin.DrawScrollBody(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.scrollbody_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawPanel(object) + - desc: draws the panel object +--]]--------------------------------------------------------- +function skin.DrawPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.panel_body_color + local bordercolor = skin.controls.panel_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawList(object) + - desc: draws the list object +--]]--------------------------------------------------------- +function skin.DrawList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.list_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawList(object) + - desc: used to draw over the object and it's children +--]]--------------------------------------------------------- +function skin.DrawOverList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordrcolor = skin.controls.list_border_color + + love.graphics.setColor(bordrcolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawTabPanel(object) + - desc: draws the tab panel object +--]]--------------------------------------------------------- +function skin.DrawTabPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local buttonheight = object:GetHeightOfButtons() + local bodycolor = skin.controls.tabpanel_body_color + local bordercolor = skin.controls.tabpanel_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y + buttonheight, width, height - buttonheight) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y + buttonheight - 1, width, height - buttonheight + 2) + + object:SetScrollButtonSize(15, buttonheight) + +end + +--[[--------------------------------------------------------- + - func: DrawTabButton(object) + - desc: draws the tab button object +--]]--------------------------------------------------------- +function skin.DrawTabButton(object) + + local x = object:GetX() + local y = object:GetY() + local hover = object:GetHover() + local text = object:GetText() + local image = object:GetImage() + local tabnumber = object:GetTabNumber() + local parent = object:GetParent() + local ptabnumber = parent:GetTabNumber() + local font = skin.controls.tab_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local imagewidth = 0 + local imageheight = 0 + local bordercolor = skin.controls.tabpanel_border_color + local bodyhovercolor = skin.controls.button_body_hover_color + local texthovercolor = skin.controls.button_text_hover_color + local bodynohovercolor = skin.controls.button_body_nohover_color + local textnohovercolor = skin.controls.button_text_nohover_color + + if image then + imagewidth = image:getWidth() + imageheight = image:getHeight() + object.width = imagewidth + 15 + twidth + if imageheight > theight then + parent:SetTabHeight(imageheight + 5) + object.height = imageheight + 5 + else + parent:SetTabHeight(theight + 5) + object.height = theight + 5 + end + else + object.width = 10 + twidth + parent:SetTabHeight(theight + 5) + object.height = theight + 5 + end + + local width = object:GetWidth() + local height = object:GetHeight() + + if tabnumber == ptabnumber then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x, y, width, height) + -- button border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + if image then + image:setFilter("nearest", "nearest") + -- button image + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) + else + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + 5, y + height/2 - theight/2) + end + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x, y, width, height) + -- button border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + if image then + image:setFilter("nearest", "nearest") + -- button image + love.graphics.setColor(255, 255, 255, 150) + love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) + else + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + 5, y + height/2 - theight/2) + end + end + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoice(object) + - desc: draws the multi choice object +--]]--------------------------------------------------------- +function skin.DrawMultiChoice(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local choice = object:GetChoice() + local image = skin.images["multichoice-arrow.png"] + local font = skin.controls.multichoice_text_font + local theight = font:getHeight("a") + local bodycolor = skin.controls.multichoice_body_color + local textcolor = skin.controls.multichoice_text_color + local bordercolor = skin.controls.multichoice_border_color + + image:setFilter("nearest", "nearest") + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + + love.graphics.setColor(textcolor) + love.graphics.setFont(font) + + if choice == "" then + love.graphics.print(text, x + 5, y + height/2 - theight/2) + else + love.graphics.print(choice, x + 5, y + height/2 - theight/2) + end + + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + width - 20, y + 5) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoiceList(object) + - desc: draws the multi choice list object +--]]--------------------------------------------------------- +function skin.DrawMultiChoiceList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.multichoicelist_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawOverMultiChoiceList(object) + - desc: draws over the multi choice list object +--]]--------------------------------------------------------- +function skin.DrawOverMultiChoiceList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.multichoicelist_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y - 1, width, height + 1) + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoiceRow(object) + - desc: draws the multi choice row object +--]]--------------------------------------------------------- +function skin.DrawMultiChoiceRow(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local font = skin.controls.multichoicerow_text_font + local bodyhovecolor = skin.controls.multichoicerow_body_hover_color + local texthovercolor = skin.controls.multichoicerow_text_hover_color + local bodynohovercolor = skin.controls.multichoicerow_body_nohover_color + local textnohovercolor = skin.controls.multichoicerow_text_nohover_color + + love.graphics.setFont(font) + + if object.hover then + love.graphics.setColor(bodyhovecolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + 5, y + 5) + else + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + 5, y + 5) + end + +end + +--[[--------------------------------------------------------- + - func: DrawToolTip(object) + - desc: draws the tool tip object +--]]--------------------------------------------------------- +function skin.DrawToolTip(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.tooltip_body_color + local bordercolor = skin.controls.tooltip_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawText(object) + - desc: draws the text object +--]]--------------------------------------------------------- +function skin.DrawText(object) + +end + +--[[--------------------------------------------------------- + - func: DrawTextInput(object) + - desc: draws the text input object +--]]--------------------------------------------------------- +function skin.DrawTextInput(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local font = object:GetFont() + local focus = object:GetFocus() + local showindicator = object:GetIndicatorVisibility() + local alltextselected = object:IsAllTextSelected() + local textx = object:GetTextX() + local texty = object:GetTextY() + local text = object:GetText() + local multiline = object:GetMultiLine() + local lines = object:GetLines() + local offsetx = object:GetOffsetX() + local offsety = object:GetOffsetY() + local indicatorx = object:GetIndicatorX() + local indicatory = object:GetIndicatorY() + local vbar = object:HasVerticalScrollBar() + local hbar = object:HasHorizontalScrollBar() + local linenumbers = object:GetLineNumbersEnabled() + local itemwidth = object:GetItemWidth() + local theight = font:getHeight("a") + local bodycolor = skin.controls.textinput_body_color + local textnormalcolor = skin.controls.textinput_text_normal_color + local textselectedcolor = skin.controls.textinput_text_selected_color + local highlightbarcolor = skin.controls.textinput_highlight_bar_color + local indicatorcolor = skin.controls.textinput_indicator_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + if alltextselected then + local bary = 0 + if multiline then + for i=1, #lines do + local twidth = font:getWidth(lines[i]) + love.graphics.setColor(highlightbarcolor) + love.graphics.rectangle("fill", textx, texty + bary, twidth, theight) + bary = bary + theight + end + else + local twidth = font:getWidth(text) + love.graphics.setColor(highlightbarcolor) + love.graphics.rectangle("fill", textx, texty, twidth, theight) + end + end + + if showindicator and focus then + love.graphics.setColor(indicatorcolor) + love.graphics.rectangle("fill", indicatorx, indicatory, 1, theight) + end + + if not multiline then + object:SetTextOffsetY(height/2 - theight/2) + if offsetx ~= 0 then + object:SetTextOffsetX(0) + else + object:SetTextOffsetX(5) + end + else + if vbar then + if offsety ~= 0 then + if hbar then + object:SetTextOffsetY(5) + else + object:SetTextOffsetY(-5) + end + else + object:SetTextOffsetY(5) + end + else + object:SetTextOffsetY(5) + end + + if hbar then + if offsety ~= 0 then + if linenumbers then + local panel = object:GetLineNumbersPanel() + if vbar then + object:SetTextOffsetX(5) + else + object:SetTextOffsetX(-5) + end + else + if vbar then + object:SetTextOffsetX(5) + else + object:SetTextOffsetX(-5) + end + end + else + object:SetTextOffsetX(5) + end + else + object:SetTextOffsetX(5) + end + + end + + textx = object:GetTextX() + texty = object:GetTextY() + + love.graphics.setFont(font) + + if alltextselected then + love.graphics.setColor(textselectedcolor) + else + love.graphics.setColor(textnormalcolor) + end + + if multiline then + for i=1, #lines do + love.graphics.print(lines[i], textx, texty + theight * i - theight) + end + else + love.graphics.print(lines[1], textx, texty) + end + +end + +--[[--------------------------------------------------------- + - func: DrawOverTextInput(object) + - desc: draws over the text input object +--]]--------------------------------------------------------- +function skin.DrawOverTextInput(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.textinput_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawScrollButton(object) + - desc: draws the scroll button object +--]]--------------------------------------------------------- +function skin.DrawScrollButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local scrolltype = object:GetScrollType() + local down = object.down + local bodydowncolor = skin.controls.button_body_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local borderhovercolor = skin.controls.button_border_hover_color + local bodynohovercolor = skin.controls.button_body_nohover_color + local bordernohovercolor = skin.controls.button_border_nohover_color + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + + if scrolltype == "up" then + local image = skin.images["arrow-up.png"] + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) + elseif scrolltype == "down" then + local image = skin.images["arrow-down.png"] + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) + elseif scrolltype == "left" then + local image = skin.images["arrow-left.png"] + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) + elseif scrolltype == "right" then + local image = skin.images["arrow-right.png"] + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawSlider(object) + - desc: draws the slider object +--]]--------------------------------------------------------- +function skin.DrawSlider(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local slidtype = object:GetSlideType() + local baroutlinecolor = skin.controls.slider_bar_outline_color + local barcolor = skin.controls.slider_bar_color + + if slidtype == "horizontal" then + love.graphics.setColor(baroutlinecolor) + love.graphics.rectangle("fill", x, y + height/2 - 5, width, 10) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x + 5, y + height/2, width - 10, 1) + elseif slidtype == "vertical" then + love.graphics.setColor(baroutlinecolor) + love.graphics.rectangle("fill", x + width/2 - 5, y, 10, height) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x + width/2, y + 5, 1, height - 10) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawSliderButton(object) + - desc: draws the slider button object +--]]--------------------------------------------------------- +function skin.DrawSliderButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local down = object.down + local bodydowncolor = skin.controls.button_body_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local borderhovercolor = skin.controls.button_border_down_color + local bodynohvercolor = skin.controls.button_body_nohover_color + local bordernohovercolor = skin.controls.button_border_down_color + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawCheckBox(object) + - desc: draws the check box object +--]]--------------------------------------------------------- +function skin.DrawCheckBox(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetBoxWidth() + local height = object:GetBoxHeight() + local checked = object:GetChecked() + local hover = object:GetHover() + local bodycolor = skin.controls.checkbox_body_color + local bordercolor = skin.controls.checkbox_border_color + local checkcolor = skin.controls.checkbox_check_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + + if checked then + love.graphics.setColor(checkcolor) + love.graphics.rectangle("fill", x + 4, y + 4, width - 8, height - 8) + end + + if hover then + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x + 4, y + 4, width - 8, height - 8) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawCollapsibleCategory(object) + - desc: draws the collapsible category object +--]]--------------------------------------------------------- +function skin.DrawCollapsibleCategory(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local bodycolor = skin.controls.collapsiblecategory_body_color + local textcolor = skin.controls.collapsiblecategory_text_color + local bordercolor = skin.controls.collapsiblecategory_border_color + local font = smallfont + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(text, x + 5, y + 5) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnList(object) + - desc: draws the column list object +--]]--------------------------------------------------------- +function skin.DrawColumnList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.columnlist_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListHeader(object) + - desc: draws the column list header object +--]]--------------------------------------------------------- +function skin.DrawColumnListHeader(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local name = object:GetName() + local down = object.down + local font = skin.controls.columnlistheader_text_font + local twidth = font:getWidth(object.name) + local theight = font:getHeight(object.name) + local bodydowncolor = skin.controls.columnlistheader_body_down_color + local textdowncolor = skin.controls.columnlistheader_text_down_color + local borderdowncolor = skin.controls.columnlistheader_border_down_color + local bodyhovercolor = skin.controls.columnlistheader_body_hover_color + local textdowncolor = skin.controls.columnlistheader_text_hover_color + local borderdowncolor = skin.controls.columnlistheader_border_down_color + local nohovercolor = skin.controls.columnlistheader_body_nohover_color + local textnohovercolor = skin.controls.columnlistheader_text_nohover_color + local bordernohovercolor = skin.controls.columnlistheader_border_down_color + + if down then + -- header body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + elseif hover then + -- header body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + else + -- header body + love.graphics.setColor(nohovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListArea(object) + - desc: draws the column list area object +--]]--------------------------------------------------------- +function skin.DrawColumnListArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.columnlistarea_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawOverColumnListArea(object) + - desc: draws over the column list area object +--]]--------------------------------------------------------- +function skin.DrawOverColumnListArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.columnlist_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListRow(object) + - desc: draws the column list row object +--]]--------------------------------------------------------- +function skin.DrawColumnListRow(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local colorindex = object:GetColorIndex() + local font = object:GetFont() + local columndata = object:GetColumnData() + local textx = object:GetTextX() + local texty = object:GetTextY() + local parent = object:GetParent() + local cwidth, cheight = parent:GetParent():GetColumnSize() + local theight = font:getHeight("a") + local body1color = skin.controls.columnlistrow_body1_color + local border1color = skin.controls.columnlistrow_border1_color + local body2color = skin.controls.columnlistrow_body2_color + local border2color = skin.controls.columnlistrow_border2_color + local textcolor = skin.controls.columnlistrow_text_color + + object:SetTextPos(5, height/2 - theight/2) + + if colorindex == 1 then + love.graphics.setColor(body1color) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(border1color) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + else + love.graphics.setColor(body2color) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(border2color) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + end + + for k, v in ipairs(columndata) do + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(v, x + textx, y + texty) + x = x + cwidth + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawModalBackground(object) + - desc: draws the modal background object +--]]--------------------------------------------------------- +function skin.DrawModalBackground(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.modalbackground_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawLineNumbersPanel(object) + - desc: draws the line numbers panel object +--]]--------------------------------------------------------- +function skin.DrawLineNumbersPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local offsety = object:GetOffsetY() + local parent = object:GetParent() + local lines = parent:GetLines() + local font = parent:GetFont() + local theight = font:getHeight("a") + local bordercolor = skin.controls.linenumberspanel_border_color + local textcolor = skin.controls.linenumberspanel_text_color + local mody = y + + object:SetWidth(10 + font:getWidth(#lines)) + love.graphics.setFont(font) + + love.graphics.setColor(200, 200, 200, 255) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height, true, true, true, false) + + for i=1, #lines do + love.graphics.setColor(textcolor) + love.graphics.print(i, object.x + 5, mody - offsety) + mody = mody + theight + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawNumberBox(object) + - desc: draws the numberbox object +--]]--------------------------------------------------------- +function skin.DrawNumberBox(object) + +end + +-- register the skin loveframes.skins.Register(skin) \ No newline at end of file diff --git a/skins/Blue/images/arrow-down.png b/skins/Blue/images/arrow-down.png index 14e39181a536a2a53513f343b3908411a4a6d406..37d805800fd4b840d58fc637925316b0a4c697a1 100644 GIT binary patch delta 290 zcmV+-0p0$z0oVc|iBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;PNkliBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;INklzN}+9AOw)vUp3(O`%CZcQB!J0X*I^h2 ztm_Kz{T_590w;i6(00=_7{?LYw(W`UJI~_gnd>>hBYS7XeYLcA2>Bwi%hgXAI!A9m~0U&M#^_Rg$o|w6XvI002ovPDHLkV1mSDcYFW< delta 133 zcmcb}w1-i#Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{K?VlCgN!>SX1|^2 zrs-?p>Ealo5uBW`fGr~<;|KpCma|NnOpHxkiCmmoZebnahP#|z&E)xPdNI%Kx`Tnq h1XF>v645CP4E5?c>rZc52Q-a=!PC{xWt~$(6976eC^`TD diff --git a/skins/Blue/images/arrow-right.png b/skins/Blue/images/arrow-right.png index 159cd41e72ab30068f715cc4871a45b57d3a0b6b..89b4818627737201d05713540777e2d19c06f43d 100644 GIT binary patch delta 282 zcmV+#0p=iBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;HNkl(Dd}wAM(|^gDzz zps0P{W1eS>zV9c5GVzw<12AM+77W9Hs;b=m2mu%p4WM2`m%z?ZO(f^P$4EkA9YhJ~wv=fa gx0cDZ(xEMU0H$wJHGrC-$^ZZW07*qoM6N<$f*huHYybcN delta 130 zcmcb>w3AV>Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{K?VlCgN!>SX1|^2 zrs-ws>Ealo5uBW$AZ}t}@`pWf(U)eCCWb(%gs#p@4QpmBU@JLVVLBn#$kBh2j1-Hn eik47A7sIT1IqQu&B&2}GGI+ZBxvXycm@&iD7$=N5;8cm zE&~&2ZMv(ft2NR$P7nlo75|!LiD4MZ4_m(#0SK`yOVxF4f}9$?x5rLMl0>h@*2$9_-!{`AoacXO$Q&y|@3IbLtQAF}rfIY+ zi;m-PWTWs9p$7)6UB~Q{WtqCJGn4myzmRcc7k0000< LMNUMnLSO-cDrSHw delta 133 zcmaFIw1-i#Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{0R{%X1B_YMIyoo0 zY5H1tx;Tbt1Scmf(9X!n_~AdLRiRbEA%NLOF~Zc2_XSsB)`6u0&ddRd%pQhdl h$nXi_n7EXK;cI+@{*#rgXMiR%c)I$ztaD0e0sz<7CDQ-^ diff --git a/skins/Blue/images/multichoice-arrow.png b/skins/Blue/images/multichoice-arrow.png index c7294cb988d550ae37b61de17bd99f60cc984151..165121c956329680f817fdc62358e736bfebea59 100644 GIT binary patch delta 230 zcmV&Y z4#EKyC`y2lMk#-oNkl)lw(yN3ek#+n$V=8p?B1z z5Q!M4fn>^>+wcAYr4;?i1T!;M{*ZJKETZPv4qFA@`_e^=0WcV_>7liz7-N$JFlxah z0Rk_^m`6#5QCr|V6j>5NsCEJvdsTQZvDT85WEgv=ljSa0qCiR@Y=Y(QIOhm?+xFGP gkkk3k0Tv)+O`Ywc{{R3007*qoM6N<$f-8<#R{#J2 delta 176 zcmbQk^qf(#Gr-TCmrII^fq{Y7)59eQNb`d*2OE&IzBbisqM|g{VFm`i!;HuCSENjI z)2vALba4!^@J~)Sz~t4JZqQ&5$*^LgU`yw8Fr9Z6-lD0PvyA@j theight then - parent:SetTabHeight(imageheight + 5) - object.height = imageheight + 5 - else - parent:SetTabHeight(theight + 5) - object.height = theight + 5 - end - else - object.width = 10 + twidth - parent:SetTabHeight(theight + 5) - object.height = theight + 5 - end - - local width = object:GetWidth() - local height = object:GetHeight() - - if tabnumber == ptabnumber then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - - gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if image then - -- button image - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) - else - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + 5, y + height/2 - theight/2) - end - - else - - -- button body - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - - gradientcolor = {bodynohovercolor[1] - 20, bodynohovercolor[2] - 20, bodynohovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if image then - -- button image - love.graphics.setColor(255, 255, 255, 150) - love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(object.text, x + imagewidth + 10, y + height/2 - theight/2) - else - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(object.text, x + 5, y + height/2 - theight/2) - end - - end - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoice(object) - - desc: draws the multi choice object ---]]--------------------------------------------------------- -function skin.DrawMultiChoice(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local choice = object:GetChoice() - local image = skin.images["multichoice-arrow.png"] - local font = skin.controls.multichoice_text_font - local theight = font:getHeight("a") - local bodycolor = skin.controls.multichoice_body_color - local textcolor = skin.controls.multichoice_text_color - local bordercolor = skin.controls.multichoice_border_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - love.graphics.setColor(unpack(textcolor)) - love.graphics.setFont(font) - - if choice == "" then - love.graphics.print(text, x + 5, y + height/2 - theight/2) - else - love.graphics.print(choice, x + 5, y + height/2 - theight/2) - end - - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(image, x + width - 20, y + 5) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoiceList(object) - - desc: draws the multi choice list object ---]]--------------------------------------------------------- -function skin.DrawMultiChoiceList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.multichoicelist_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawOverMultiChoiceList(object) - - desc: draws over the multi choice list object ---]]--------------------------------------------------------- -function skin.DrawOverMultiChoiceList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.multichoicelist_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y - 1, width, height + 1) - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoiceRow(object) - - desc: draws the multi choice row object ---]]--------------------------------------------------------- -function skin.DrawMultiChoiceRow(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local font = skin.controls.multichoicerow_text_font - local bodyhovecolor = skin.controls.multichoicerow_body_hover_color - local texthovercolor = skin.controls.multichoicerow_text_hover_color - local bodynohovercolor = skin.controls.multichoicerow_body_nohover_color - local textnohovercolor = skin.controls.multichoicerow_text_nohover_color - - love.graphics.setFont(font) - - if object.hover then - love.graphics.setColor(unpack(bodyhovecolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + 5, y + 5) - else - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(text, x + 5, y + 5) - end - -end - ---[[--------------------------------------------------------- - - func: DrawToolTip(object) - - desc: draws the tool tip object ---]]--------------------------------------------------------- -function skin.DrawToolTip(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.tooltip_body_color - local bordercolor = skin.controls.tooltip_border_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawText(object) - - desc: draws the text object ---]]--------------------------------------------------------- -function skin.DrawText(object) - -end - ---[[--------------------------------------------------------- - - func: DrawTextInput(object) - - desc: draws the text input object ---]]--------------------------------------------------------- -function skin.DrawTextInput(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local font = object:GetFont() - local focus = object:GetFocus() - local showindicator = object:GetIndicatorVisibility() - local alltextselected = object:IsAllTextSelected() - local textx = object:GetTextX() - local texty = object:GetTextY() - local text = object:GetText() - local multiline = object:GetMultiLine() - local lines = object:GetLines() - local offsetx = object:GetOffsetX() - local offsety = object:GetOffsetY() - local indicatorx = object:GetIndicatorX() - local indicatory = object:GetIndicatorY() - local vbar = object:HasVerticalScrollBar() - local hbar = object:HasHorizontalScrollBar() - local linenumbers = object:GetLineNumbersEnabled() - local itemwidth = object:GetItemWidth() - local theight = font:getHeight("a") - local bodycolor = skin.controls.textinput_body_color - local textnormalcolor = skin.controls.textinput_text_normal_color - local textselectedcolor = skin.controls.textinput_text_selected_color - local highlightbarcolor = skin.controls.textinput_highlight_bar_color - local indicatorcolor = skin.controls.textinput_indicator_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - if alltextselected then - local bary = 0 - if multiline then - for i=1, #lines do - local twidth = font:getWidth(lines[i]) - love.graphics.setColor(unpack(highlightbarcolor)) - love.graphics.rectangle("fill", textx, texty + bary, twidth, theight) - bary = bary + theight - end - else - local twidth = font:getWidth(text) - love.graphics.setColor(unpack(highlightbarcolor)) - love.graphics.rectangle("fill", textx, texty, twidth, theight) - end - end - - if showindicator and focus then - love.graphics.setColor(unpack(indicatorcolor)) - love.graphics.rectangle("fill", indicatorx, indicatory, 1, theight) - end - - if not multiline then - object:SetTextOffsetY(height/2 - theight/2) - if offsetx ~= 0 then - object:SetTextOffsetX(0) - else - object:SetTextOffsetX(5) - end - else - if vbar then - if offsety ~= 0 then - if hbar then - object:SetTextOffsetY(5) - else - object:SetTextOffsetY(-5) - end - else - object:SetTextOffsetY(5) - end - else - object:SetTextOffsetY(5) - end - - if hbar then - if offsety ~= 0 then - if linenumbers then - local panel = object:GetLineNumbersPanel() - if vbar then - object:SetTextOffsetX(5) - else - object:SetTextOffsetX(-5) - end - else - if vbar then - object:SetTextOffsetX(5) - else - object:SetTextOffsetX(-5) - end - end - else - object:SetTextOffsetX(5) - end - else - object:SetTextOffsetX(5) - end - - end - - textx = object:GetTextX() - texty = object:GetTextY() - - love.graphics.setFont(font) - - if alltextselected then - love.graphics.setColor(unpack(textselectedcolor)) - else - love.graphics.setColor(unpack(textnormalcolor)) - end - - if multiline then - for i=1, #lines do - love.graphics.print(lines[i], textx, texty + theight * i - theight) - end - else - love.graphics.print(lines[1], textx, texty) - end - -end - ---[[--------------------------------------------------------- - - func: DrawOverTextInput(object) - - desc: draws over the text input object ---]]--------------------------------------------------------- -function skin.DrawOverTextInput(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.textinput_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawScrollButton(object) - - desc: draws the scroll button object ---]]--------------------------------------------------------- -function skin.DrawScrollButton(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local scrolltype = object:GetScrollType() - local down = object.down - local bodydowncolor = skin.controls.button_body_down_color - local borderdowncolor = skin.controls.button_border_down_color - local bodyhovercolor = skin.controls.button_body_hover_color - local borderhovercolor = skin.controls.button_border_hover_color - local bodynohovercolor = skin.controls.button_body_nohover_color - local bordernohovercolor = skin.controls.button_border_nohover_color - local gradientcolor = {} - - if down then - - -- button body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height) - - elseif hover then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(borderhovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - else - - -- button body - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodynohovercolor[1] - 20, bodynohovercolor[2] - 20, bodynohovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - end - - if scrolltype == "up" then - local image = skin.images["arrow-up.png"] - local imagewidth = image:getWidth() - local imageheight = image:getHeight() - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) - elseif scrolltype == "down" then - local image = skin.images["arrow-down.png"] - local imagewidth = image:getWidth() - local imageheight = image:getHeight() - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) - elseif scrolltype == "left" then - local image = skin.images["arrow-left.png"] - local imagewidth = image:getWidth() - local imageheight = image:getHeight() - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) - elseif scrolltype == "right" then - local image = skin.images["arrow-right.png"] - local imagewidth = image:getWidth() - local imageheight = image:getHeight() - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawSlider(object) - - desc: draws the slider object ---]]--------------------------------------------------------- -function skin.DrawSlider(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local slidtype = object:GetSlideType() - local baroutlinecolor = skin.controls.slider_bar_outline_color - local barcolor = skin.controls.slider_bar_color - - if slidtype == "horizontal" then - - love.graphics.setColor(unpack(baroutlinecolor)) - love.graphics.rectangle("fill", x, y + height/2 - 5, width, 10) - - love.graphics.setColor(unpack(barcolor)) - love.graphics.rectangle("fill", x + 5, y + height/2, width - 10, 1) - - elseif slidtype == "vertical" then - - love.graphics.setColor(unpack(baroutlinecolor)) - love.graphics.rectangle("fill", x + width/2 - 5, y, 10, height) - - love.graphics.setColor(unpack(barcolor)) - love.graphics.rectangle("fill", x + width/2, y + 5, 1, height - 10) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawSliderButton(object) - - desc: draws the slider button object ---]]--------------------------------------------------------- -function skin.DrawSliderButton(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local down = object.down - local bodydowncolor = skin.controls.button_body_down_color - local borderdowncolor = skin.controls.button_border_down_color - local bodyhovercolor = skin.controls.button_body_hover_color - local borderhovercolor = skin.controls.button_border_down_color - local bodynohvercolor = skin.controls.button_body_nohover_color - local bordernohovercolor = skin.controls.button_border_down_color - local gradientcolor = {} - - if down then - - -- button body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height) - - elseif hover then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(borderhovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - else - - -- button body - love.graphics.setColor(unpack(bodynohvercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodynohvercolor[1] - 20, bodynohvercolor[2] - 20, bodynohvercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawCheckBox(object) - - desc: draws the check box object ---]]--------------------------------------------------------- -function skin.DrawCheckBox(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetBoxWidth() - local height = object:GetBoxHeight() - local checked = object:GetChecked() - local hover = object:GetHover() - local bodycolor = skin.controls.checkbox_body_color - local bordercolor = skin.controls.checkbox_border_color - local checkcolor = skin.controls.checkbox_check_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if checked then - love.graphics.setColor(unpack(checkcolor)) - love.graphics.rectangle("fill", x + 4, y + 4, width - 8, height - 8) - end - - if hover then - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x + 4, y + 4, width - 8, height - 8) - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawCollapsibleCategory(object) - - desc: draws the collapsible category object ---]]--------------------------------------------------------- -function skin.DrawCollapsibleCategory(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local bodycolor = skin.controls.collapsiblecategory_body_color - local textcolor = skin.controls.collapsiblecategory_text_color - local bordercolor = skin.controls.collapsiblecategory_border_color - local font = smallfont - local gradientcolor = {bodycolor[1] - 20, bodycolor[2] - 20, bodycolor[3] - 20, 255} - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(gradientcolor)) - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - love.graphics.setFont(font) - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(text, x + 5, y + 5) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnList(object) - - desc: draws the column list object ---]]--------------------------------------------------------- -function skin.DrawColumnList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.columnlist_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListHeader(object) - - desc: draws the column list header object ---]]--------------------------------------------------------- -function skin.DrawColumnListHeader(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local name = object:GetName() - local down = object.down - local font = skin.controls.columnlistheader_text_font - local twidth = font:getWidth(object.name) - local theight = font:getHeight(object.name) - local bodydowncolor = skin.controls.columnlistheader_body_down_color - local textdowncolor = skin.controls.columnlistheader_text_down_color - local borderdowncolor = skin.controls.columnlistheader_border_down_color - local bodyhovercolor = skin.controls.columnlistheader_body_hover_color - local textdowncolor = skin.controls.columnlistheader_text_hover_color - local borderdowncolor = skin.controls.columnlistheader_border_down_color - local nohovercolor = skin.controls.columnlistheader_body_nohover_color - local textnohovercolor = skin.controls.columnlistheader_text_nohover_color - local bordernohovercolor = skin.controls.columnlistheader_border_down_color - local gradientcolor = {} - - if down then - - -- header body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textdowncolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - elseif hover then - - -- header body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textdowncolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - else - - -- header body - love.graphics.setColor(unpack(nohovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {nohovercolor[1] - 20, nohovercolor[2] - 20, nohovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListArea(object) - - desc: draws the column list area object ---]]--------------------------------------------------------- -function skin.DrawColumnListArea(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.columnlistarea_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawOverColumnListArea(object) - - desc: draws over the column list area object ---]]--------------------------------------------------------- -function skin.DrawOverColumnListArea(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.columnlist_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListRow(object) - - desc: draws the column list row object ---]]--------------------------------------------------------- -function skin.DrawColumnListRow(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local colorindex = object:GetColorIndex() - local font = object:GetFont() - local columndata = object:GetColumnData() - local textx = object:GetTextX() - local texty = object:GetTextY() - local parent = object:GetParent() - local cwidth, cheight = parent:GetParent():GetColumnSize() - local theight = font:getHeight("a") - local body1color = skin.controls.columnlistrow_body1_color - local border1color = skin.controls.columnlistrow_border1_color - local body2color = skin.controls.columnlistrow_body2_color - local border2color = skin.controls.columnlistrow_border2_color - local textcolor = skin.controls.columnlistrow_text_color - - object:SetTextPos(5, height/2 - theight/2) - - if colorindex == 1 then - - love.graphics.setColor(unpack(body1color)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - love.graphics.setColor(unpack(skin.controls.columnlistrow_border1_color)) - skin.OutlinedRectangle(x, y, width, height, true, false, true, true) - - else - - love.graphics.setColor(unpack(body2color)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(border2color)) - skin.OutlinedRectangle(x, y, width, height, true, false, true, true) - - end - - for k, v in ipairs(columndata) do - love.graphics.setFont(font) - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(v, x + textx, y + texty) - x = x + cwidth - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawModalBackground(object) - - desc: draws the modal background object ---]]--------------------------------------------------------- -function skin.DrawModalBackground(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.modalbackground_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawLineNumbersPanel(object) - - desc: draws the line numbers panel object ---]]--------------------------------------------------------- -function skin.DrawLineNumbersPanel(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local offsety = object:GetOffsetY() - local parent = object:GetParent() - local lines = parent:GetLines() - local font = parent:GetFont() - local theight = font:getHeight("a") - local bordercolor = skin.controls.linenumberspanel_border_color - local textcolor = skin.controls.linenumberspanel_text_color - local mody = y - - object:SetWidth(10 + font:getWidth(#lines)) - love.graphics.setFont(font) - - love.graphics.setColor(200, 200, 200, 255) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height, true, true, true, false) - - for i=1, #lines do - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(i, object.x + 5, mody - offsety) - mody = mody + theight - end - -end - --- register the skin +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- skin table +local skin = {} + +-- skin info (you always need this in a skin) +skin.name = "Blue" +skin.author = "Nikolai Resokav" +skin.version = "1.0" + +local smallfont = love.graphics.newFont(10) +local imagebuttonfont = love.graphics.newFont(15) +local bordercolor = {143, 143, 143, 255} + +-- controls +skin.controls = {} + +-- frame +skin.controls.frame_border_color = bordercolor +skin.controls.frame_body_color = {232, 232, 232, 255} +skin.controls.frame_top_color = {102, 194, 255, 255} +skin.controls.frame_name_color = {255, 255, 255, 255} +skin.controls.frame_name_font = smallfont + +-- button +skin.controls.button_border_down_color = bordercolor +skin.controls.button_border_nohover_color = bordercolor +skin.controls.button_border_hover_color = bordercolor +skin.controls.button_body_down_color = {128, 204, 255, 255} +skin.controls.button_body_nohover_color = {255, 255, 255, 255} +skin.controls.button_body_hover_color = {153, 214, 255, 255} +skin.controls.button_text_down_color = {255, 255, 255, 255} +skin.controls.button_text_nohover_color = {0, 0, 0, 200} +skin.controls.button_text_hover_color = {255, 255, 255, 255} +skin.controls.button_body_nonclickable_color = {220, 220, 220, 255} +skin.controls.button_text_nonclickable_color = {0, 0, 0, 100} +skin.controls.button_text_font = smallfont + +-- image button +skin.controls.imagebutton_text_down_color = {255, 255, 255, 255} +skin.controls.imagebutton_text_nohover_color = {255, 255, 255, 200} +skin.controls.imagebutton_text_hover_color = {255, 255, 255, 255} +skin.controls.imagebutton_text_font = imagebuttonfont + +-- close button +skin.controls.closebutton_body_down_color = {255, 255, 255, 255} +skin.controls.closebutton_body_nohover_color = {255, 255, 255, 255} +skin.controls.closebutton_body_hover_color = {255, 255, 255, 255} + +-- progress bar +skin.controls.progressbar_border_color = bordercolor +skin.controls.progressbar_body_color = {255, 255, 255, 255} +skin.controls.progressbar_bar_color = {0, 255, 0, 255} +skin.controls.progressbar_text_color = {0, 0, 0, 255} +skin.controls.progressbar_text_font = smallfont + +-- list +skin.controls.list_border_color = bordercolor +skin.controls.list_body_color = {232, 232, 232, 255} + +-- scrollbar +skin.controls.scrollbar_border_down_color = bordercolor +skin.controls.scrollbar_border_hover_color = bordercolor +skin.controls.scrollbar_border_nohover_color = bordercolor +skin.controls.scrollbar_body_down_color = {128, 204, 255, 255} +skin.controls.scrollbar_body_nohover_color = {255, 255, 255, 255} +skin.controls.scrollbar_body_hover_color = {153, 214, 255, 255} + +-- scrollarea +skin.controls.scrollarea_body_color = {200, 200, 200, 255} +skin.controls.scrollarea_border_color = bordercolor + +-- scrollbody +skin.controls.scrollbody_body_color = {0, 0, 0, 0} + +-- panel +skin.controls.panel_body_color = {232, 232, 232, 255} +skin.controls.panel_border_color = bordercolor + +-- tab panel +skin.controls.tabpanel_body_color = {232, 232, 232, 255} +skin.controls.tabpanel_border_color = bordercolor + +-- tab button +skin.controls.tab_border_nohover_color = bordercolor +skin.controls.tab_border_hover_color = bordercolor +skin.controls.tab_body_nohover_color = {255, 255, 255, 255} +skin.controls.tab_body_hover_color = {153, 214, 255, 255} +skin.controls.tab_text_nohover_color = {0, 0, 0, 200} +skin.controls.tab_text_hover_color = {255, 255, 255, 255} +skin.controls.tab_text_font = smallfont + +-- multichoice +skin.controls.multichoice_body_color = {240, 240, 240, 255} +skin.controls.multichoice_border_color = bordercolor +skin.controls.multichoice_text_color = {0, 0, 0, 255} +skin.controls.multichoice_text_font = smallfont + +-- multichoicelist +skin.controls.multichoicelist_body_color = {240, 240, 240, 200} +skin.controls.multichoicelist_border_color = bordercolor + +-- multichoicerow +skin.controls.multichoicerow_body_nohover_color = {240, 240, 240, 255} +skin.controls.multichoicerow_body_hover_color = {51, 204, 255, 255} +skin.controls.multichoicerow_border_color = {50, 50, 50, 255} +skin.controls.multichoicerow_text_nohover_color = {0, 0, 0, 150} +skin.controls.multichoicerow_text_hover_color = {255, 255, 255, 255} +skin.controls.multichoicerow_text_font = smallfont + +-- tooltip +skin.controls.tooltip_border_color = bordercolor +skin.controls.tooltip_body_color = {255, 255, 255, 255} + +-- text input +skin.controls.textinput_border_color = bordercolor +skin.controls.textinput_body_color = {240, 240, 240, 255} +skin.controls.textinput_indicator_color = {0, 0, 0, 255} +skin.controls.textinput_text_normal_color = {0, 0, 0, 255} +skin.controls.textinput_text_selected_color = {255, 255, 255, 255} +skin.controls.textinput_highlight_bar_color = {51, 204, 255, 255} + +-- slider +skin.controls.slider_bar_color = bordercolor +skin.controls.slider_bar_outline_color = {220, 220, 220, 255} + +-- checkbox +skin.controls.checkbox_border_color = bordercolor +skin.controls.checkbox_body_color = {255, 255, 255, 255} +skin.controls.checkbox_check_color = {128, 204, 255, 255} +skin.controls.checkbox_text_color = {0, 0, 0, 255} +skin.controls.checkbox_text_font = smallfont + +-- collapsiblecategory +skin.controls.collapsiblecategory_text_color = {0, 0, 0, 255} +skin.controls.collapsiblecategory_body_color = {255, 255, 255, 255} +skin.controls.collapsiblecategory_border_color = bordercolor + +-- columnlist +skin.controls.columnlist_border_color = bordercolor +skin.controls.columnlist_body_color = {232, 232, 232, 255} + +-- columlistarea +skin.controls.columnlistarea_border_color = bordercolor +skin.controls.columnlistarea_body_color = {232, 232, 232, 255} + +-- columnlistheader +skin.controls.columnlistheader_border_down_color = bordercolor +skin.controls.columnlistheader_border_nohover_color = bordercolor +skin.controls.columnlistheader_border_hover_color = bordercolor +skin.controls.columnlistheader_body_down_color = {128, 204, 255, 255} +skin.controls.columnlistheader_body_nohover_color = {255, 255, 255, 255} +skin.controls.columnlistheader_body_hover_color = {153, 214, 255, 255} +skin.controls.columnlistheader_text_down_color = {255, 255, 255, 255} +skin.controls.columnlistheader_text_nohover_color = {0, 0, 0, 200} +skin.controls.columnlistheader_text_hover_color = {255, 255, 255, 255} +skin.controls.columnlistheader_text_font = smallfont + +-- columnlistrow +skin.controls.columnlistrow_border1_color = bordercolor +skin.controls.columnlistrow_body1_color = {232, 232, 232, 255} +skin.controls.columnlistrow_border2_color = bordercolor +skin.controls.columnlistrow_body2_color = {200, 200, 200, 255} +skin.controls.columnlistrow_text_color = {100, 100, 100, 255} + +-- modalbackground +skin.controls.modalbackground_body_color = {255, 255, 255, 100} + +-- linenumberspanel +skin.controls.linenumberspanel_border_color = bordercolor +skin.controls.linenumberspanel_text_color = {100, 100, 100, 255} + +--[[--------------------------------------------------------- + - func: OutlinedRectangle(object) + - desc: creates and outlined rectangle +--]]--------------------------------------------------------- +function skin.OutlinedRectangle(x, y, width, height, ovt, ovb, ovl, ovr) + + local ovt = ovt or false + local ovb = ovb or false + local ovl = ovl or false + local ovr = ovr or false + + -- top + if not ovt then + love.graphics.rectangle("fill", x, y, width, 1) + end + + -- bottom + if not ovb then + love.graphics.rectangle("fill", x, y + height - 1, width, 1) + end + + -- left + if not ovl then + love.graphics.rectangle("fill", x, y, 1, height) + end + + -- right + if not ovr then + love.graphics.rectangle("fill", x + width - 1, y, 1, height) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawGradient(x, y, width, height, color) + - desc: draws a gradient +--]]--------------------------------------------------------- +function skin.DrawGradient(x, y, width, height, color) + + local color = color + local percent = 0 + + for i=1, (height - 1) do + percent = i/height * 255 + color[4] = loveframes.util.Round(percent) + love.graphics.setColor(unpack(color)) + love.graphics.rectangle("fill", x, y + i, width, 1) + end + +end + +--[[--------------------------------------------------------- + - func: DrawFrame(object) + - desc: draws the frame object +--]]--------------------------------------------------------- +function skin.DrawFrame(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local name = object:GetName() + local bodycolor = skin.controls.frame_body_color + local topcolor = skin.controls.frame_top_color + local bordercolor = skin.controls.frame_border_color + local namecolor = skin.controls.frame_name_color + local font = skin.controls.frame_name_font + local gradientcolor = {topcolor[1] - 20, topcolor[2] - 20, topcolor[3] - 20, 255} + + -- frame body + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + -- frame top bar + love.graphics.setColor(topcolor) + love.graphics.rectangle("fill", x, y, width, 25) + skin.DrawGradient(x, y, width, 25, gradientcolor) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y + 25, width, 1) + + -- frame name section + love.graphics.setFont(font) + love.graphics.setColor(namecolor) + love.graphics.print(name, x + 5, y + 5) + + -- frame border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawButton(object) + - desc: draws the button object +--]]--------------------------------------------------------- +function skin.DrawButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local text = object:GetText() + local font = skin.controls.button_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local down = object.down + local enabled = object:GetEnabled() + local clickable = object:GetClickable() + local bodydowncolor = skin.controls.button_body_down_color + local textdowncolor = skin.controls.button_text_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local texthovercolor = skin.controls.button_text_hover_color + local borderhovercolor = skin.controls.button_border_down_color + local bodynohvercolor = skin.controls.button_body_nohover_color + local textnohovercolor = skin.controls.button_text_nohover_color + local bordernohovercolor = skin.controls.button_border_down_color + local bodynonclickablecolor = skin.controls.button_body_nonclickable_color + local textnonclickablecolor = skin.controls.button_text_nonclickable_color + local gradientcolor = {} + + if not enabled or not clickable then + -- button body + love.graphics.setColor(bodynonclickablecolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynonclickablecolor[1] - 20, bodynonclickablecolor[2] - 20, bodynonclickablecolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnonclickablecolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + return + end + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynohvercolor[1] - 20, bodynohvercolor[2] - 20, bodynohvercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + +end + +--[[--------------------------------------------------------- + - func: DrawCloseButton(object) + - desc: draws the close button object +--]]--------------------------------------------------------- +function skin.DrawCloseButton(object) + + local x = object:GetX() + local y = object:GetY() + local staticx = object:GetStaticX() + local parent = object.parent + local parentwidth = parent:GetWidth() + local hover = object:GetHover() + local down = object.down + local image = skin.images["close.png"] + local bodydowncolor = skin.controls.closebutton_body_down_color + local bodyhovercolor = skin.controls.closebutton_body_hover_color + local bodynohovercolor = skin.controls.closebutton_body_nohover_color + + image:setFilter("nearest", "nearest") + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.draw(image, x, y) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.draw(image, x, y) + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.draw(image, x, y) + end + + if staticx ~= (parentwidth - 20) then + object:SetPos(parentwidth - 20, 4) + end + +end + +--[[--------------------------------------------------------- + - func: DrawImage(object) + - desc: draws the image object +--]]--------------------------------------------------------- +function skin.DrawImage(object) + + local x = object:GetX() + local y = object:GetY() + local orientation = object:GetOrientation() + local scalex = object:GetScaleX() + local scaley = object:GetScaleY() + local offsetx = object:GetOffsetX() + local offsety = object:GetOffsetY() + local shearx = object:GetShearX() + local sheary = object:GetShearY() + local image = object.image + local color = object.imagecolor + + if color then + love.graphics.setColor(color) + love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary) + else + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary) + end + +end + +--[[--------------------------------------------------------- + - func: DrawImageButton(object) + - desc: draws the image button object +--]]--------------------------------------------------------- +function skin.DrawImageButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local hover = object:GetHover() + local image = object:GetImage() + local down = object.down + local font = skin.controls.imagebutton_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local textdowncolor = skin.controls.imagebutton_text_down_color + local texthovercolor = skin.controls.imagebutton_text_hover_color + local textnohovercolor = skin.controls.imagebutton_text_nohover_color + + if down then + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + 1, y + 1) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2 + 1, y + height - theight - 5 + 1) + love.graphics.setColor(textdowncolor) + love.graphics.print(text, x + width/2 - twidth/2 + 1, y + height - theight - 6 + 1) + elseif hover then + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 5) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6) + else + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 5) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6) + end + +end + +--[[--------------------------------------------------------- + - func: DrawProgressBar(object) + - desc: draws the progress bar object +--]]--------------------------------------------------------- +function skin.DrawProgressBar(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local value = object:GetValue() + local max = object:GetMax() + local barwidth = object:GetBarWidth() + local font = skin.controls.progressbar_text_font + local text = value .. "/" ..max + local twidth = font:getWidth(text) + local theight = font:getHeight("a") + local bodycolor = skin.controls.progressbar_body_color + local barcolor = skin.controls.progressbar_bar_color + local textcolor = skin.controls.progressbar_text_color + local bordercolor = skin.controls.progressbar_border_color + local gradientcolor = {barcolor[1], barcolor[2] - 20, barcolor[3], 255} + + -- progress bar body + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x, y, barwidth, height) + skin.DrawGradient(x, y, barwidth, height, gradientcolor) + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + + -- progress bar border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawScrollArea(object) + - desc: draws the scroll area object +--]]--------------------------------------------------------- +function skin.DrawScrollArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bartype = object:GetBarType() + local bodycolor = skin.controls.scrollarea_body_color + local bordercolor = skin.controls.scrollarea_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + + if bartype == "vertical" then + skin.OutlinedRectangle(x, y, width, height, true, true) + elseif bartype == "horizontal" then + skin.OutlinedRectangle(x, y, width, height, false, false, true, true) + end + +end + +--[[--------------------------------------------------------- + - func: DrawScrollBar(object) + - desc: draws the scroll bar object +--]]--------------------------------------------------------- +function skin.DrawScrollBar(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local dragging = object:IsDragging() + local hover = object:GetHover() + local bartype = object:GetBarType() + local bodydowncolor = skin.controls.scrollbar_body_down_color + local borderdowncolor = skin.controls.scrollbar_border_down_color + local bodyhovercolor = skin.controls.scrollbar_body_hover_color + local borderhovercolor = skin.controls.scrollbar_border_hover_color + local bodynohvercolor = skin.controls.scrollbar_body_nohover_color + local bordernohovercolor = skin.controls.scrollbar_border_nohover_color + local gradientcolor = {} + + if dragging then + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y, width, height, gradientcolor) + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y, width, height, gradientcolor) + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynohvercolor[1] - 20, bodynohvercolor[2] - 20, bodynohvercolor[3] - 20, 255} + skin.DrawGradient(x, y, width, height, gradientcolor) + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + + if bartype == "vertical" then + love.graphics.setColor(bordernohovercolor) + love.graphics.rectangle("fill", x + 3, y + height/2 - 3, width - 6, 1) + love.graphics.rectangle("fill", x + 3, y + height/2, width - 6, 1) + love.graphics.rectangle("fill", x + 3, y + height/2 + 3, width - 6, 1) + else + love.graphics.setColor(bordernohovercolor) + love.graphics.rectangle("fill", x + width/2 - 3, y + 3, 1, height - 6) + love.graphics.rectangle("fill", x + width/2, y + 3, 1, height - 6) + love.graphics.rectangle("fill", x + width/2 + 3, y + 3, 1, height - 6) + end + +end + +--[[--------------------------------------------------------- + - func: DrawScrollBody(object) + - desc: draws the scroll body object +--]]--------------------------------------------------------- +function skin.DrawScrollBody(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.scrollbody_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawPanel(object) + - desc: draws the panel object +--]]--------------------------------------------------------- +function skin.DrawPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.panel_body_color + local bordercolor = skin.controls.panel_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawList(object) + - desc: draws the list object +--]]--------------------------------------------------------- +function skin.DrawList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.list_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawList(object) + - desc: used to draw over the object and it's children +--]]--------------------------------------------------------- +function skin.DrawOverList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordrcolor = skin.controls.list_border_color + + love.graphics.setColor(bordrcolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawTabPanel(object) + - desc: draws the tab panel object +--]]--------------------------------------------------------- +function skin.DrawTabPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local buttonheight = object:GetHeightOfButtons() + local bodycolor = skin.controls.tabpanel_body_color + local bordercolor = skin.controls.tabpanel_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y + buttonheight, width, height - buttonheight) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y + buttonheight - 1, width, height - buttonheight + 2) + + object:SetScrollButtonSize(15, buttonheight) + +end + +--[[--------------------------------------------------------- + - func: DrawTabButton(object) + - desc: draws the tab button object +--]]--------------------------------------------------------- +function skin.DrawTabButton(object) + + local x = object:GetX() + local y = object:GetY() + local hover = object:GetHover() + local text = object:GetText() + local image = object:GetImage() + local tabnumber = object:GetTabNumber() + local parent = object:GetParent() + local ptabnumber = parent:GetTabNumber() + local font = skin.controls.tab_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local imagewidth = 0 + local imageheight = 0 + local bordercolor = skin.controls.tabpanel_border_color + local bodyhovercolor = skin.controls.button_body_hover_color + local texthovercolor = skin.controls.button_text_hover_color + local bodynohovercolor = skin.controls.button_body_nohover_color + local textnohovercolor = skin.controls.button_text_nohover_color + local gradientcolor = {} + + if image then + image:setFilter("nearest", "nearest") + imagewidth = image:getWidth() + imageheight = image:getHeight() + object.width = imagewidth + 15 + twidth + if imageheight > theight then + parent:SetTabHeight(imageheight + 5) + object.height = imageheight + 5 + else + parent:SetTabHeight(theight + 5) + object.height = theight + 5 + end + else + object.width = 10 + twidth + parent:SetTabHeight(theight + 5) + object.height = theight + 5 + end + + local width = object:GetWidth() + local height = object:GetHeight() + + if tabnumber == ptabnumber then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x, y, width, height) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + if image then + -- button image + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) + else + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + 5, y + height/2 - theight/2) + end + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x, y, width, height) + gradientcolor = {bodynohovercolor[1] - 20, bodynohovercolor[2] - 20, bodynohovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + if image then + -- button image + love.graphics.setColor(255, 255, 255, 150) + love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) + else + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + 5, y + height/2 - theight/2) + end + end + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoice(object) + - desc: draws the multi choice object +--]]--------------------------------------------------------- +function skin.DrawMultiChoice(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local choice = object:GetChoice() + local image = skin.images["multichoice-arrow.png"] + local font = skin.controls.multichoice_text_font + local theight = font:getHeight("a") + local bodycolor = skin.controls.multichoice_body_color + local textcolor = skin.controls.multichoice_text_color + local bordercolor = skin.controls.multichoice_border_color + + image:setFilter("nearest", "nearest") + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + + love.graphics.setColor(textcolor) + love.graphics.setFont(font) + + if choice == "" then + love.graphics.print(text, x + 5, y + height/2 - theight/2) + else + love.graphics.print(choice, x + 5, y + height/2 - theight/2) + end + + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + width - 20, y + 5) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoiceList(object) + - desc: draws the multi choice list object +--]]--------------------------------------------------------- +function skin.DrawMultiChoiceList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.multichoicelist_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawOverMultiChoiceList(object) + - desc: draws over the multi choice list object +--]]--------------------------------------------------------- +function skin.DrawOverMultiChoiceList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.multichoicelist_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y - 1, width, height + 1) + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoiceRow(object) + - desc: draws the multi choice row object +--]]--------------------------------------------------------- +function skin.DrawMultiChoiceRow(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local font = skin.controls.multichoicerow_text_font + local bodyhovecolor = skin.controls.multichoicerow_body_hover_color + local texthovercolor = skin.controls.multichoicerow_text_hover_color + local bodynohovercolor = skin.controls.multichoicerow_body_nohover_color + local textnohovercolor = skin.controls.multichoicerow_text_nohover_color + + love.graphics.setFont(font) + + if object.hover then + love.graphics.setColor(bodyhovecolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + 5, y + 5) + else + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + 5, y + 5) + end + +end + +--[[--------------------------------------------------------- + - func: DrawToolTip(object) + - desc: draws the tool tip object +--]]--------------------------------------------------------- +function skin.DrawToolTip(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.tooltip_body_color + local bordercolor = skin.controls.tooltip_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawText(object) + - desc: draws the text object +--]]--------------------------------------------------------- +function skin.DrawText(object) + +end + +--[[--------------------------------------------------------- + - func: DrawTextInput(object) + - desc: draws the text input object +--]]--------------------------------------------------------- +function skin.DrawTextInput(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local font = object:GetFont() + local focus = object:GetFocus() + local showindicator = object:GetIndicatorVisibility() + local alltextselected = object:IsAllTextSelected() + local textx = object:GetTextX() + local texty = object:GetTextY() + local text = object:GetText() + local multiline = object:GetMultiLine() + local lines = object:GetLines() + local offsetx = object:GetOffsetX() + local offsety = object:GetOffsetY() + local indicatorx = object:GetIndicatorX() + local indicatory = object:GetIndicatorY() + local vbar = object:HasVerticalScrollBar() + local hbar = object:HasHorizontalScrollBar() + local linenumbers = object:GetLineNumbersEnabled() + local itemwidth = object:GetItemWidth() + local theight = font:getHeight("a") + local bodycolor = skin.controls.textinput_body_color + local textnormalcolor = skin.controls.textinput_text_normal_color + local textselectedcolor = skin.controls.textinput_text_selected_color + local highlightbarcolor = skin.controls.textinput_highlight_bar_color + local indicatorcolor = skin.controls.textinput_indicator_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + if alltextselected then + local bary = 0 + if multiline then + for i=1, #lines do + local twidth = font:getWidth(lines[i]) + love.graphics.setColor(highlightbarcolor) + love.graphics.rectangle("fill", textx, texty + bary, twidth, theight) + bary = bary + theight + end + else + local twidth = font:getWidth(text) + love.graphics.setColor(highlightbarcolor) + love.graphics.rectangle("fill", textx, texty, twidth, theight) + end + end + + if showindicator and focus then + love.graphics.setColor(indicatorcolor) + love.graphics.rectangle("fill", indicatorx, indicatory, 1, theight) + end + + if not multiline then + object:SetTextOffsetY(height/2 - theight/2) + if offsetx ~= 0 then + object:SetTextOffsetX(0) + else + object:SetTextOffsetX(5) + end + else + if vbar then + if offsety ~= 0 then + if hbar then + object:SetTextOffsetY(5) + else + object:SetTextOffsetY(-5) + end + else + object:SetTextOffsetY(5) + end + else + object:SetTextOffsetY(5) + end + + if hbar then + if offsety ~= 0 then + if linenumbers then + local panel = object:GetLineNumbersPanel() + if vbar then + object:SetTextOffsetX(5) + else + object:SetTextOffsetX(-5) + end + else + if vbar then + object:SetTextOffsetX(5) + else + object:SetTextOffsetX(-5) + end + end + else + object:SetTextOffsetX(5) + end + else + object:SetTextOffsetX(5) + end + + end + + textx = object:GetTextX() + texty = object:GetTextY() + + love.graphics.setFont(font) + + if alltextselected then + love.graphics.setColor(textselectedcolor) + else + love.graphics.setColor(textnormalcolor) + end + + if multiline then + for i=1, #lines do + love.graphics.print(lines[i], textx, texty + theight * i - theight) + end + else + love.graphics.print(lines[1], textx, texty) + end + +end + +--[[--------------------------------------------------------- + - func: DrawOverTextInput(object) + - desc: draws over the text input object +--]]--------------------------------------------------------- +function skin.DrawOverTextInput(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.textinput_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawScrollButton(object) + - desc: draws the scroll button object +--]]--------------------------------------------------------- +function skin.DrawScrollButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local scrolltype = object:GetScrollType() + local down = object.down + local bodydowncolor = skin.controls.button_body_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local borderhovercolor = skin.controls.button_border_hover_color + local bodynohovercolor = skin.controls.button_body_nohover_color + local bordernohovercolor = skin.controls.button_border_nohover_color + local gradientcolor = {} + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynohovercolor[1] - 20, bodynohovercolor[2] - 20, bodynohovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + + if scrolltype == "up" then + local image = skin.images["arrow-up.png"] + local imagewidth = image:getWidth() + local imageheight = image:getHeight() + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) + elseif scrolltype == "down" then + local image = skin.images["arrow-down.png"] + local imagewidth = image:getWidth() + local imageheight = image:getHeight() + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) + elseif scrolltype == "left" then + local image = skin.images["arrow-left.png"] + local imagewidth = image:getWidth() + local imageheight = image:getHeight() + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) + elseif scrolltype == "right" then + local image = skin.images["arrow-right.png"] + local imagewidth = image:getWidth() + local imageheight = image:getHeight() + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawSlider(object) + - desc: draws the slider object +--]]--------------------------------------------------------- +function skin.DrawSlider(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local slidtype = object:GetSlideType() + local baroutlinecolor = skin.controls.slider_bar_outline_color + local barcolor = skin.controls.slider_bar_color + + if slidtype == "horizontal" then + love.graphics.setColor(baroutlinecolor) + love.graphics.rectangle("fill", x, y + height/2 - 5, width, 10) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x + 5, y + height/2, width - 10, 1) + elseif slidtype == "vertical" then + love.graphics.setColor(baroutlinecolor) + love.graphics.rectangle("fill", x + width/2 - 5, y, 10, height) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x + width/2, y + 5, 1, height - 10) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawSliderButton(object) + - desc: draws the slider button object +--]]--------------------------------------------------------- +function skin.DrawSliderButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local down = object.down + local bodydowncolor = skin.controls.button_body_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local borderhovercolor = skin.controls.button_border_down_color + local bodynohvercolor = skin.controls.button_body_nohover_color + local bordernohovercolor = skin.controls.button_border_down_color + local gradientcolor = {} + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynohvercolor[1] - 20, bodynohvercolor[2] - 20, bodynohvercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawCheckBox(object) + - desc: draws the check box object +--]]--------------------------------------------------------- +function skin.DrawCheckBox(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetBoxWidth() + local height = object:GetBoxHeight() + local checked = object:GetChecked() + local hover = object:GetHover() + local bodycolor = skin.controls.checkbox_body_color + local bordercolor = skin.controls.checkbox_border_color + local checkcolor = skin.controls.checkbox_check_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + + if checked then + love.graphics.setColor(checkcolor) + love.graphics.rectangle("fill", x + 4, y + 4, width - 8, height - 8) + end + + if hover then + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x + 4, y + 4, width - 8, height - 8) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawCollapsibleCategory(object) + - desc: draws the collapsible category object +--]]--------------------------------------------------------- +function skin.DrawCollapsibleCategory(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local bodycolor = skin.controls.collapsiblecategory_body_color + local textcolor = skin.controls.collapsiblecategory_text_color + local bordercolor = skin.controls.collapsiblecategory_border_color + local font = smallfont + local gradientcolor = {bodycolor[1] - 20, bodycolor[2] - 20, bodycolor[3] - 20, 255} + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(gradientcolor) + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(text, x + 5, y + 5) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnList(object) + - desc: draws the column list object +--]]--------------------------------------------------------- +function skin.DrawColumnList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.columnlist_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListHeader(object) + - desc: draws the column list header object +--]]--------------------------------------------------------- +function skin.DrawColumnListHeader(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local name = object:GetName() + local down = object.down + local font = skin.controls.columnlistheader_text_font + local twidth = font:getWidth(object.name) + local theight = font:getHeight(object.name) + local bodydowncolor = skin.controls.columnlistheader_body_down_color + local textdowncolor = skin.controls.columnlistheader_text_down_color + local borderdowncolor = skin.controls.columnlistheader_border_down_color + local bodyhovercolor = skin.controls.columnlistheader_body_hover_color + local textdowncolor = skin.controls.columnlistheader_text_hover_color + local borderdowncolor = skin.controls.columnlistheader_border_down_color + local nohovercolor = skin.controls.columnlistheader_body_nohover_color + local textnohovercolor = skin.controls.columnlistheader_text_nohover_color + local bordernohovercolor = skin.controls.columnlistheader_border_down_color + local gradientcolor = {} + + if down then + -- header body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + elseif hover then + -- header body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + else + -- header body + love.graphics.setColor(nohovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + gradientcolor = {nohovercolor[1] - 20, nohovercolor[2] - 20, nohovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListArea(object) + - desc: draws the column list area object +--]]--------------------------------------------------------- +function skin.DrawColumnListArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.columnlistarea_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawOverColumnListArea(object) + - desc: draws over the column list area object +--]]--------------------------------------------------------- +function skin.DrawOverColumnListArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.columnlist_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListRow(object) + - desc: draws the column list row object +--]]--------------------------------------------------------- +function skin.DrawColumnListRow(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local colorindex = object:GetColorIndex() + local font = object:GetFont() + local columndata = object:GetColumnData() + local textx = object:GetTextX() + local texty = object:GetTextY() + local parent = object:GetParent() + local cwidth, cheight = parent:GetParent():GetColumnSize() + local theight = font:getHeight("a") + local body1color = skin.controls.columnlistrow_body1_color + local border1color = skin.controls.columnlistrow_border1_color + local body2color = skin.controls.columnlistrow_body2_color + local border2color = skin.controls.columnlistrow_border2_color + local textcolor = skin.controls.columnlistrow_text_color + + object:SetTextPos(5, height/2 - theight/2) + + if colorindex == 1 then + love.graphics.setColor(body1color) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(border1color) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + else + love.graphics.setColor(body2color) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(border2color) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + end + + for k, v in ipairs(columndata) do + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(v, x + textx, y + texty) + x = x + cwidth + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawModalBackground(object) + - desc: draws the modal background object +--]]--------------------------------------------------------- +function skin.DrawModalBackground(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.modalbackground_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawLineNumbersPanel(object) + - desc: draws the line numbers panel object +--]]--------------------------------------------------------- +function skin.DrawLineNumbersPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local offsety = object:GetOffsetY() + local parent = object:GetParent() + local lines = parent:GetLines() + local font = parent:GetFont() + local theight = font:getHeight("a") + local bordercolor = skin.controls.linenumberspanel_border_color + local textcolor = skin.controls.linenumberspanel_text_color + local mody = y + + object:SetWidth(10 + font:getWidth(#lines)) + love.graphics.setFont(font) + + love.graphics.setColor(200, 200, 200, 255) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height, true, true, true, false) + + for i=1, #lines do + love.graphics.setColor(textcolor) + love.graphics.print(i, object.x + 5, mody - offsety) + mody = mody + theight + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawNumberBox(object) + - desc: draws the numberbox object +--]]--------------------------------------------------------- +function skin.DrawNumberBox(object) + +end + +-- register the skin loveframes.skins.Register(skin) \ No newline at end of file diff --git a/skins/Orange (basic)/images/arrow-down.png b/skins/Orange (basic)/images/arrow-down.png index 14e39181a536a2a53513f343b3908411a4a6d406..37d805800fd4b840d58fc637925316b0a4c697a1 100644 GIT binary patch delta 290 zcmV+-0p0$z0oVc|iBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;PNkliBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;INklzN}+9AOw)vUp3(O`%CZcQB!J0X*I^h2 ztm_Kz{T_590w;i6(00=_7{?LYw(W`UJI~_gnd>>hBYS7XeYLcA2>Bwi%hgXAI!A9m~0U&M#^_Rg$o|w6XvI002ovPDHLkV1mSDcYFW< delta 133 zcmcb}w1-i#Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{K?VlCgN!>SX1|^2 zrs-?p>Ealo5uBW`fGr~<;|KpCma|NnOpHxkiCmmoZebnahP#|z&E)xPdNI%Kx`Tnq h1XF>v645CP4E5?c>rZc52Q-a=!PC{xWt~$(6976eC^`TD diff --git a/skins/Orange (basic)/images/arrow-right.png b/skins/Orange (basic)/images/arrow-right.png index 159cd41e72ab30068f715cc4871a45b57d3a0b6b..89b4818627737201d05713540777e2d19c06f43d 100644 GIT binary patch delta 282 zcmV+#0p=iBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;HNkl(Dd}wAM(|^gDzz zps0P{W1eS>zV9c5GVzw<12AM+77W9Hs;b=m2mu%p4WM2`m%z?ZO(f^P$4EkA9YhJ~wv=fa gx0cDZ(xEMU0H$wJHGrC-$^ZZW07*qoM6N<$f*huHYybcN delta 130 zcmcb>w3AV>Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{K?VlCgN!>SX1|^2 zrs-ws>Ealo5uBW$AZ}t}@`pWf(U)eCCWb(%gs#p@4QpmBU@JLVVLBn#$kBh2j1-Hn eik47A7sIT1IqQu&B&2}GGI+ZBxvXycm@&iD7$=N5;8cm zE&~&2ZMv(ft2NR$P7nlo75|!LiD4MZ4_m(#0SK`yOVxF4f}9$?x5rLMl0>h@*2$9_-!{`AoacXO$Q&y|@3IbLtQAF}rfIY+ zi;m-PWTWs9p$7)6UB~Q{WtqCJGn4myzmRcc7k0000< LMNUMnLSO-cDrSHw delta 133 zcmaFIw1-i#Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{0R{%X1B_YMIyoo0 zY5H1tx;Tbt1Scmf(9X!n_~AdLRiRbEA%NLOF~Zc2_XSsB)`6u0&ddRd%pQhdl h$nXi_n7EXK;cI+@{*#rgXMiR%c)I$ztaD0e0sz<7CDQ-^ diff --git a/skins/Orange (basic)/images/multichoice-arrow.png b/skins/Orange (basic)/images/multichoice-arrow.png index c7294cb988d550ae37b61de17bd99f60cc984151..165121c956329680f817fdc62358e736bfebea59 100644 GIT binary patch delta 230 zcmV&Y z4#EKyC`y2lMk#-oNkl)lw(yN3ek#+n$V=8p?B1z z5Q!M4fn>^>+wcAYr4;?i1T!;M{*ZJKETZPv4qFA@`_e^=0WcV_>7liz7-N$JFlxah z0Rk_^m`6#5QCr|V6j>5NsCEJvdsTQZvDT85WEgv=ljSa0qCiR@Y=Y(QIOhm?+xFGP gkkk3k0Tv)+O`Ywc{{R3007*qoM6N<$f-8<#R{#J2 delta 176 zcmbQk^qf(#Gr-TCmrII^fq{Y7)59eQNb`d*2OE&IzBbisqM|g{VFm`i!;HuCSENjI z)2vALba4!^@J~)Sz~t4JZqQ&5$*^LgU`yw8Fr9Z6-lD0PvyA@j theight then - parent:SetTabHeight(imageheight + 5) - object.height = imageheight + 5 - else - parent:SetTabHeight(theight + 5) - object.height = theight + 5 - end - else - object.width = 10 + twidth - parent:SetTabHeight(theight + 5) - object.height = theight + 5 - end - - local width = object:GetWidth() - local height = object:GetHeight() - - if tabnumber == ptabnumber then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if image then - -- button image - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) - else - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + 5, y + height/2 - theight/2) - end - - else - - -- button body - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if image then - -- button image - love.graphics.setColor(255, 255, 255, 150) - love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(object.text, x + imagewidth + 10, y + height/2 - theight/2) - else - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(object.text, x + 5, y + height/2 - theight/2) - end - - end - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoice(object) - - desc: draws the multi choice object ---]]--------------------------------------------------------- -function skin.DrawMultiChoice(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local choice = object:GetChoice() - local image = skin.images["multichoice-arrow.png"] - local font = skin.controls.multichoice_text_font - local theight = font:getHeight("a") - local bodycolor = skin.controls.multichoice_body_color - local textcolor = skin.controls.multichoice_text_color - local bordercolor = skin.controls.multichoice_border_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - love.graphics.setColor(unpack(textcolor)) - love.graphics.setFont(font) - - if choice == "" then - love.graphics.print(text, x + 5, y + height/2 - theight/2) - else - love.graphics.print(choice, x + 5, y + height/2 - theight/2) - end - - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(image, x + width - 20, y + 5) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoiceList(object) - - desc: draws the multi choice list object ---]]--------------------------------------------------------- -function skin.DrawMultiChoiceList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.multichoicelist_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawOverMultiChoiceList(object) - - desc: draws over the multi choice list object ---]]--------------------------------------------------------- -function skin.DrawOverMultiChoiceList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.multichoicelist_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y - 1, width, height + 1) - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoiceRow(object) - - desc: draws the multi choice row object ---]]--------------------------------------------------------- -function skin.DrawMultiChoiceRow(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local font = skin.controls.multichoicerow_text_font - local bodyhovecolor = skin.controls.multichoicerow_body_hover_color - local texthovercolor = skin.controls.multichoicerow_text_hover_color - local bodynohovercolor = skin.controls.multichoicerow_body_nohover_color - local textnohovercolor = skin.controls.multichoicerow_text_nohover_color - - love.graphics.setFont(font) - - if object.hover then - love.graphics.setColor(unpack(bodyhovecolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + 5, y + 5) - else - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(text, x + 5, y + 5) - end - -end - ---[[--------------------------------------------------------- - - func: DrawToolTip(object) - - desc: draws the tool tip object ---]]--------------------------------------------------------- -function skin.DrawToolTip(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.tooltip_body_color - local bordercolor = skin.controls.tooltip_border_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawText(object) - - desc: draws the text object ---]]--------------------------------------------------------- -function skin.DrawText(object) - -end - ---[[--------------------------------------------------------- - - func: DrawTextInput(object) - - desc: draws the text input object ---]]--------------------------------------------------------- -function skin.DrawTextInput(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local font = object:GetFont() - local focus = object:GetFocus() - local showindicator = object:GetIndicatorVisibility() - local alltextselected = object:IsAllTextSelected() - local textx = object:GetTextX() - local texty = object:GetTextY() - local text = object:GetText() - local multiline = object:GetMultiLine() - local lines = object:GetLines() - local offsetx = object:GetOffsetX() - local offsety = object:GetOffsetY() - local indicatorx = object:GetIndicatorX() - local indicatory = object:GetIndicatorY() - local vbar = object:HasVerticalScrollBar() - local hbar = object:HasHorizontalScrollBar() - local linenumbers = object:GetLineNumbersEnabled() - local itemwidth = object:GetItemWidth() - local theight = font:getHeight("a") - local bodycolor = skin.controls.textinput_body_color - local textnormalcolor = skin.controls.textinput_text_normal_color - local textselectedcolor = skin.controls.textinput_text_selected_color - local highlightbarcolor = skin.controls.textinput_highlight_bar_color - local indicatorcolor = skin.controls.textinput_indicator_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - if alltextselected then - local bary = 0 - if multiline then - for i=1, #lines do - local twidth = font:getWidth(lines[i]) - love.graphics.setColor(unpack(highlightbarcolor)) - love.graphics.rectangle("fill", textx, texty + bary, twidth, theight) - bary = bary + theight - end - else - local twidth = font:getWidth(text) - love.graphics.setColor(unpack(highlightbarcolor)) - love.graphics.rectangle("fill", textx, texty, twidth, theight) - end - end - - if showindicator and focus then - love.graphics.setColor(unpack(indicatorcolor)) - love.graphics.rectangle("fill", indicatorx, indicatory, 1, theight) - end - - if not multiline then - object:SetTextOffsetY(height/2 - theight/2) - if offsetx ~= 0 then - object:SetTextOffsetX(0) - else - object:SetTextOffsetX(5) - end - else - if vbar then - if offsety ~= 0 then - if hbar then - object:SetTextOffsetY(5) - else - object:SetTextOffsetY(-5) - end - else - object:SetTextOffsetY(5) - end - else - object:SetTextOffsetY(5) - end - - if hbar then - if offsety ~= 0 then - if linenumbers then - local panel = object:GetLineNumbersPanel() - if vbar then - object:SetTextOffsetX(5) - else - object:SetTextOffsetX(-5) - end - else - if vbar then - object:SetTextOffsetX(5) - else - object:SetTextOffsetX(-5) - end - end - else - object:SetTextOffsetX(5) - end - else - object:SetTextOffsetX(5) - end - - end - - textx = object:GetTextX() - texty = object:GetTextY() - - love.graphics.setFont(font) - - if alltextselected then - love.graphics.setColor(unpack(textselectedcolor)) - else - love.graphics.setColor(unpack(textnormalcolor)) - end - - if multiline then - for i=1, #lines do - love.graphics.print(lines[i], textx, texty + theight * i - theight) - end - else - love.graphics.print(lines[1], textx, texty) - end - -end - ---[[--------------------------------------------------------- - - func: DrawOverTextInput(object) - - desc: draws over the text input object ---]]--------------------------------------------------------- -function skin.DrawOverTextInput(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.textinput_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawScrollButton(object) - - desc: draws the scroll button object ---]]--------------------------------------------------------- -function skin.DrawScrollButton(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local scrolltype = object:GetScrollType() - local down = object.down - local bodydowncolor = skin.controls.button_body_down_color - local borderdowncolor = skin.controls.button_border_down_color - local bodyhovercolor = skin.controls.button_body_hover_color - local borderhovercolor = skin.controls.button_border_hover_color - local bodynohovercolor = skin.controls.button_body_nohover_color - local bordernohovercolor = skin.controls.button_border_nohover_color - - if down then - - -- button body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height) - - elseif hover then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(borderhovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - else - - -- button body - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - end - - if scrolltype == "up" then - local image = skin.images["arrow-up.png"] - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) - elseif scrolltype == "down" then - local image = skin.images["arrow-down.png"] - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) - elseif scrolltype == "left" then - local image = skin.images["arrow-left.png"] - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) - elseif scrolltype == "right" then - local image = skin.images["arrow-right.png"] - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawSlider(object) - - desc: draws the slider object ---]]--------------------------------------------------------- -function skin.DrawSlider(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local slidtype = object:GetSlideType() - local baroutlinecolor = skin.controls.slider_bar_outline_color - local barcolor = skin.controls.slider_bar_color - - if slidtype == "horizontal" then - - love.graphics.setColor(unpack(baroutlinecolor)) - love.graphics.rectangle("fill", x, y + height/2 - 5, width, 10) - - love.graphics.setColor(unpack(barcolor)) - love.graphics.rectangle("fill", x + 5, y + height/2, width - 10, 1) - - elseif slidtype == "vertical" then - - love.graphics.setColor(unpack(baroutlinecolor)) - love.graphics.rectangle("fill", x + width/2 - 5, y, 10, height) - - love.graphics.setColor(unpack(barcolor)) - love.graphics.rectangle("fill", x + width/2, y + 5, 1, height - 10) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawSliderButton(object) - - desc: draws the slider button object ---]]--------------------------------------------------------- -function skin.DrawSliderButton(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local down = object.down - local bodydowncolor = skin.controls.button_body_down_color - local borderdowncolor = skin.controls.button_border_down_color - local bodyhovercolor = skin.controls.button_body_hover_color - local borderhovercolor = skin.controls.button_border_down_color - local bodynohvercolor = skin.controls.button_body_nohover_color - local bordernohovercolor = skin.controls.button_border_down_color - - if down then - - -- button body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height) - - elseif hover then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(borderhovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - else - - -- button body - love.graphics.setColor(unpack(bodynohvercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- button border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawCheckBox(object) - - desc: draws the check box object ---]]--------------------------------------------------------- -function skin.DrawCheckBox(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetBoxWidth() - local height = object:GetBoxHeight() - local checked = object:GetChecked() - - love.graphics.setColor(unpack(skin.controls.checkbox_body_color)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(skin.controls.checkbox_border_color)) - skin.OutlinedRectangle(x, y, width, height) - - if checked then - love.graphics.setColor(unpack(skin.controls.checkbox_check_color)) - love.graphics.rectangle("fill", x + 4, y + 4, width - 8, height - 8) - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawCollapsibleCategory(object) - - desc: draws the collapsible category object ---]]--------------------------------------------------------- -function skin.DrawCollapsibleCategory(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local bodycolor = skin.controls.collapsiblecategory_body_color - local textcolor = skin.controls.collapsiblecategory_text_color - local bordercolor = skin.controls.collapsiblecategory_border_color - local font = smallfont - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setFont(font) - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(text, x + 5, y + 5) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnList(object) - - desc: draws the column list object ---]]--------------------------------------------------------- -function skin.DrawColumnList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.columnlist_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListHeader(object) - - desc: draws the column list header object ---]]--------------------------------------------------------- -function skin.DrawColumnListHeader(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local name = object:GetName() - local down = object.down - local font = skin.controls.columnlistheader_text_font - local twidth = font:getWidth(object.name) - local theight = font:getHeight(object.name) - local bodydowncolor = skin.controls.columnlistheader_body_down_color - local textdowncolor = skin.controls.columnlistheader_text_down_color - local borderdowncolor = skin.controls.columnlistheader_border_down_color - local bodyhovercolor = skin.controls.columnlistheader_body_hover_color - local textdowncolor = skin.controls.columnlistheader_text_hover_color - local borderdowncolor = skin.controls.columnlistheader_border_down_color - local nohovercolor = skin.controls.columnlistheader_body_nohover_color - local textnohovercolor = skin.controls.columnlistheader_text_nohover_color - local bordernohovercolor = skin.controls.columnlistheader_border_down_color - - if down then - - -- header body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textdowncolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - elseif hover then - - -- header body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textdowncolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - else - - -- header body - love.graphics.setColor(unpack(nohovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListArea(object) - - desc: draws the column list area object ---]]--------------------------------------------------------- -function skin.DrawColumnListArea(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.columnlistarea_body_color - - love.graphics.setColor(unpack(skin.controls.columnlistarea_body_color)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawOverColumnListArea(object) - - desc: draws over the column list area object ---]]--------------------------------------------------------- -function skin.DrawOverColumnListArea(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.columnlist_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListRow(object) - - desc: draws the column list row object ---]]--------------------------------------------------------- -function skin.DrawColumnListRow(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local colorindex = object:GetColorIndex() - local font = object:GetFont() - local columndata = object:GetColumnData() - local textx = object:GetTextX() - local texty = object:GetTextY() - local parent = object:GetParent() - local cwidth, cheight = parent:GetParent():GetColumnSize() - local theight = font:getHeight("a") - local body1color = skin.controls.columnlistrow_body1_color - local border1color = skin.controls.columnlistrow_border1_color - local body2color = skin.controls.columnlistrow_body2_color - local border2color = skin.controls.columnlistrow_border2_color - local textcolor = skin.controls.columnlistrow_text_color - - object:SetTextPos(5, height/2 - theight/2) - - if colorindex == 1 then - - love.graphics.setColor(unpack(body1color)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - love.graphics.setColor(unpack(skin.controls.columnlistrow_border1_color)) - skin.OutlinedRectangle(x, y, width, height, true, false, true, true) - - else - - love.graphics.setColor(unpack(body2color)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(border2color)) - skin.OutlinedRectangle(x, y, width, height, true, false, true, true) - - end - - for k, v in ipairs(columndata) do - love.graphics.setFont(font) - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(v, x + textx, y + texty) - x = x + cwidth - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawModalBackground(object) - - desc: draws the modal background object ---]]--------------------------------------------------------- -function skin.DrawModalBackground(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.modalbackground_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawLineNumbersPanel(object) - - desc: draws the line numbers panel object ---]]--------------------------------------------------------- -function skin.DrawLineNumbersPanel(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local offsety = object:GetOffsetY() - local parent = object:GetParent() - local lines = parent:GetLines() - local font = parent:GetFont() - local theight = font:getHeight("a") - local bordercolor = skin.controls.linenumberspanel_border_color - local textcolor = skin.controls.linenumberspanel_text_color - local mody = y - - object:SetWidth(10 + font:getWidth(#lines)) - love.graphics.setFont(font) - - love.graphics.setColor(200, 200, 200, 255) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height, true, true, true, false) - - for i=1, #lines do - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(i, object.x + 5, mody - offsety) - mody = mody + theight - end - -end - --- register the skin +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- skin table +local skin = {} + +-- skin info (you always need this in a skin) +skin.name = "Orange (basic)" +skin.author = "Nikolai Resokav" +skin.version = "1.0" + +local smallfont = love.graphics.newFont(10) +local imagebuttonfont = love.graphics.newFont(15) +local bordercolor = {143, 143, 143, 255} + +-- controls +skin.controls = {} + +-- frame +skin.controls.frame_border_color = bordercolor +skin.controls.frame_body_color = {232, 232, 232, 255} +skin.controls.frame_top_color = {255, 153, 0, 255} +skin.controls.frame_name_color = {255, 255, 255, 255} +skin.controls.frame_name_font = smallfont + +-- button +skin.controls.button_border_down_color = bordercolor +skin.controls.button_border_nohover_color = bordercolor +skin.controls.button_border_hover_color = bordercolor +skin.controls.button_body_down_color = {255, 173, 51, 255} +skin.controls.button_body_nohover_color = {255, 255, 255, 255} +skin.controls.button_body_hover_color = {255, 184, 77, 255} +skin.controls.button_text_down_color = {255, 255, 255, 255} +skin.controls.button_text_nohover_color = {0, 0, 0, 200} +skin.controls.button_text_hover_color = {255, 255, 255, 255} +skin.controls.button_body_nonclickable_color = {220, 220, 220, 255} +skin.controls.button_text_nonclickable_color = {0, 0, 0, 100} +skin.controls.button_text_font = smallfont + +-- image button +skin.controls.imagebutton_text_down_color = {255, 255, 255, 255} +skin.controls.imagebutton_text_nohover_color = {255, 255, 255, 200} +skin.controls.imagebutton_text_hover_color = {255, 255, 255, 255} +skin.controls.imagebutton_text_font = imagebuttonfont + +-- close button +skin.controls.closebutton_body_down_color = {255, 255, 255, 255} +skin.controls.closebutton_body_nohover_color = {255, 255, 255, 255} +skin.controls.closebutton_body_hover_color = {255, 255, 255, 255} + +-- progress bar +skin.controls.progressbar_border_color = bordercolor +skin.controls.progressbar_body_color = {255, 255, 255, 255} +skin.controls.progressbar_bar_color = {0, 255, 0, 255} +skin.controls.progressbar_text_color = {0, 0, 0, 255} +skin.controls.progressbar_text_font = smallfont + +-- list +skin.controls.list_border_color = bordercolor +skin.controls.list_body_color = {232, 232, 232, 255} + +-- scrollbar +skin.controls.scrollbar_border_down_color = bordercolor +skin.controls.scrollbar_border_hover_color = bordercolor +skin.controls.scrollbar_border_nohover_color = bordercolor +skin.controls.scrollbar_body_down_color = {255, 173, 51, 255} +skin.controls.scrollbar_body_nohover_color = {255, 255, 255, 255} +skin.controls.scrollbar_body_hover_color = {255, 184, 77, 255} + +-- scrollarea +skin.controls.scrollarea_body_color = {200, 200, 200, 255} +skin.controls.scrollarea_border_color = bordercolor + +-- scrollbody +skin.controls.scrollbody_body_color = {0, 0, 0, 0} + +-- panel +skin.controls.panel_body_color = {232, 232, 232, 255} +skin.controls.panel_border_color = bordercolor + +-- tab panel +skin.controls.tabpanel_body_color = {232, 232, 232, 255} +skin.controls.tabpanel_border_color = bordercolor + +-- tab button +skin.controls.tab_border_nohover_color = bordercolor +skin.controls.tab_border_hover_color = bordercolor +skin.controls.tab_body_nohover_color = {255, 255, 255, 255} +skin.controls.tab_body_hover_color = {255, 173, 51, 255} +skin.controls.tab_text_nohover_color = {0, 0, 0, 200} +skin.controls.tab_text_hover_color = {255, 255, 255, 255} +skin.controls.tab_text_font = smallfont + +-- multichoice +skin.controls.multichoice_body_color = {240, 240, 240, 255} +skin.controls.multichoice_border_color = bordercolor +skin.controls.multichoice_text_color = {0, 0, 0, 255} +skin.controls.multichoice_text_font = smallfont + +-- multichoicelist +skin.controls.multichoicelist_body_color = {240, 240, 240, 200} +skin.controls.multichoicelist_border_color = bordercolor + +-- multichoicerow +skin.controls.multichoicerow_body_nohover_color = {240, 240, 240, 255} +skin.controls.multichoicerow_body_hover_color = {255, 117, 26, 255} +skin.controls.multichoicerow_border_color = {50, 50, 50, 255} +skin.controls.multichoicerow_text_nohover_color = {0, 0, 0, 150} +skin.controls.multichoicerow_text_hover_color = {255, 255, 255, 255} +skin.controls.multichoicerow_text_font = smallfont + +-- tooltip +skin.controls.tooltip_border_color = bordercolor +skin.controls.tooltip_body_color = {255, 255, 255, 255} + +-- text input +skin.controls.textinput_border_color = bordercolor +skin.controls.textinput_body_color = {240, 240, 240, 255} +skin.controls.textinput_indicator_color = {0, 0, 0, 255} +skin.controls.textinput_text_normal_color = {0, 0, 0, 255} +skin.controls.textinput_text_selected_color = {255, 255, 255, 255} +skin.controls.textinput_highlight_bar_color = {51, 204, 255, 255} + +-- slider +skin.controls.slider_bar_color = bordercolor +skin.controls.slider_bar_outline_color = {220, 220, 220, 255} + +-- checkbox +skin.controls.checkbox_border_color = bordercolor +skin.controls.checkbox_body_color = {255, 255, 255, 255} +skin.controls.checkbox_check_color = {255, 173, 51, 255} +skin.controls.checkbox_text_color = {0, 0, 0, 255} +skin.controls.checkbox_text_font = smallfont + +-- collapsiblecategory +skin.controls.collapsiblecategory_text_color = {0, 0, 0, 255} +skin.controls.collapsiblecategory_body_color = {255, 255, 255, 255} +skin.controls.collapsiblecategory_border_color = bordercolor + +-- columnlist +skin.controls.columnlist_border_color = bordercolor +skin.controls.columnlist_body_color = {232, 232, 232, 255} + +-- columlistarea +skin.controls.columnlistarea_border_color = bordercolor +skin.controls.columnlistarea_body_color = {232, 232, 232, 255} + +-- columnlistheader +skin.controls.columnlistheader_border_down_color = bordercolor +skin.controls.columnlistheader_border_nohover_color = bordercolor +skin.controls.columnlistheader_border_hover_color = bordercolor +skin.controls.columnlistheader_body_down_color = {255, 173, 51, 255} +skin.controls.columnlistheader_body_nohover_color = {255, 255, 255, 255} +skin.controls.columnlistheader_body_hover_color = {255, 184, 77, 255} +skin.controls.columnlistheader_text_down_color = {255, 255, 255, 255} +skin.controls.columnlistheader_text_nohover_color = {0, 0, 0, 200} +skin.controls.columnlistheader_text_hover_color = {255, 255, 255, 255} +skin.controls.columnlistheader_text_font = smallfont + +-- columnlistrow +skin.controls.columnlistrow_border1_color = bordercolor +skin.controls.columnlistrow_body1_color = {232, 232, 232, 255} +skin.controls.columnlistrow_border2_color = bordercolor +skin.controls.columnlistrow_body2_color = {200, 200, 200, 255} +skin.controls.columnlistrow_text_color = {100, 100, 100, 255} + +-- modalbackground +skin.controls.modalbackground_body_color = {255, 255, 255, 100} + +-- linenumberspanel +skin.controls.linenumberspanel_border_color = bordercolor +skin.controls.linenumberspanel_text_color = {100, 100, 100, 255} + +--[[--------------------------------------------------------- + - func: OutlinedRectangle(object) + - desc: creates and outlined rectangle +--]]--------------------------------------------------------- +function skin.OutlinedRectangle(x, y, width, height, ovt, ovb, ovl, ovr) + + local ovt = ovt or false + local ovb = ovb or false + local ovl = ovl or false + local ovr = ovr or false + + -- top + if not ovt then + love.graphics.rectangle("fill", x, y, width, 1) + end + + -- bottom + if not ovb then + love.graphics.rectangle("fill", x, y + height - 1, width, 1) + end + + -- left + if not ovl then + love.graphics.rectangle("fill", x, y, 1, height) + end + + -- right + if not ovr then + love.graphics.rectangle("fill", x + width - 1, y, 1, height) + end + +end + +--[[--------------------------------------------------------- + - func: DrawFrame(object) + - desc: draws the frame object +--]]--------------------------------------------------------- +function skin.DrawFrame(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local name = object:GetName() + local bodycolor = skin.controls.frame_body_color + local topcolor = skin.controls.frame_top_color + local bordercolor = skin.controls.frame_border_color + local namecolor = skin.controls.frame_name_color + local font = skin.controls.frame_name_font + + -- frame body + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + -- frame top bar + love.graphics.setColor(topcolor) + love.graphics.rectangle("fill", x, y, width, 25) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y + 25, width, 1) + + -- frame name section + love.graphics.setFont(font) + love.graphics.setColor(namecolor) + love.graphics.print(name, x + 5, y + 5) + + -- frame border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawButton(object) + - desc: draws the button object +--]]--------------------------------------------------------- +function skin.DrawButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local text = object:GetText() + local font = skin.controls.button_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local down = object.down + local enabled = object:GetEnabled() + local clickable = object:GetClickable() + local bodydowncolor = skin.controls.button_body_down_color + local textdowncolor = skin.controls.button_text_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local texthovercolor = skin.controls.button_text_hover_color + local borderhovercolor = skin.controls.button_border_down_color + local bodynohvercolor = skin.controls.button_body_nohover_color + local textnohovercolor = skin.controls.button_text_nohover_color + local bordernohovercolor = skin.controls.button_border_down_color + local bodynonclickablecolor = skin.controls.button_body_nonclickable_color + local textnonclickablecolor = skin.controls.button_text_nonclickable_color + + if not enabled or not clickable then + -- button body + love.graphics.setColor(bodynonclickablecolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnonclickablecolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + return + end + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + +end + +--[[--------------------------------------------------------- + - func: DrawCloseButton(object) + - desc: draws the close button object +--]]--------------------------------------------------------- +function skin.DrawCloseButton(object) + + local x = object:GetX() + local y = object:GetY() + local staticx = object:GetStaticX() + local width = object:GetWidth() + local height = object:GetHeight() + local parentwidth = object.parent:GetWidth() + local hover = object:GetHover() + local down = object.down + local image = skin.images["close.png"] + local bodydowncolor = skin.controls.closebutton_body_down_color + local bodyhovercolor = skin.controls.closebutton_body_hover_color + local bodynohovercolor = skin.controls.closebutton_body_nohover_color + + image:setFilter("nearest", "nearest") + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.draw(image, x, y) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.draw(image, x, y) + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.draw(image, x, y) + end + + if staticx ~= (parentwidth - 20) then + object:SetPos(parentwidth - 20, 4) + end + +end + +--[[--------------------------------------------------------- + - func: DrawImage(object) + - desc: draws the image object +--]]--------------------------------------------------------- +function skin.DrawImage(object) + + local x = object:GetX() + local y = object:GetY() + local orientation = object:GetOrientation() + local scalex = object:GetScaleX() + local scaley = object:GetScaleY() + local offsetx = object:GetOffsetX() + local offsety = object:GetOffsetY() + local shearx = object:GetShearX() + local sheary = object:GetShearY() + local image = object.image + local color = object.imagecolor + + if color then + love.graphics.setColor(color) + love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary) + else + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary) + end + +end + +--[[--------------------------------------------------------- + - func: DrawImageButton(object) + - desc: draws the image button object +--]]--------------------------------------------------------- +function skin.DrawImageButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local hover = object:GetHover() + local image = object:GetImage() + local down = object.down + local font = skin.controls.imagebutton_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local textdowncolor = skin.controls.imagebutton_text_down_color + local texthovercolor = skin.controls.imagebutton_text_hover_color + local textnohovercolor = skin.controls.imagebutton_text_nohover_color + + if down then + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + 1, y + 1) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2 + 1, y + height - theight - 5 + 1) + love.graphics.setColor(textdowncolor) + love.graphics.print(text, x + width/2 - twidth/2 + 1, y + height - theight - 6 + 1) + elseif hover then + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 5) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6) + else + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 5) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6) + end + +end + +--[[--------------------------------------------------------- + - func: DrawProgressBar(object) + - desc: draws the progress bar object +--]]--------------------------------------------------------- +function skin.DrawProgressBar(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local value = object:GetValue() + local max = object:GetMax() + local barwidth = object:GetBarWidth() + local font = skin.controls.progressbar_text_font + local text = value .. "/" ..max + local twidth = font:getWidth(text) + local theight = font:getHeight("a") + local bodycolor = skin.controls.progressbar_body_color + local barcolor = skin.controls.progressbar_bar_color + local textcolor = skin.controls.progressbar_text_color + local bordercolor = skin.controls.progressbar_border_color + + -- progress bar body + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x, y, barwidth, height) + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + + -- progress bar border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawScrollArea(object) + - desc: draws the scroll area object +--]]--------------------------------------------------------- +function skin.DrawScrollArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bartype = object:GetBarType() + local bodycolor = skin.controls.scrollarea_body_color + local bordercolor = skin.controls.scrollarea_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + + if bartype == "vertical" then + skin.OutlinedRectangle(x, y, width, height, true, true) + elseif bartype == "horizontal" then + skin.OutlinedRectangle(x, y, width, height, false, false, true, true) + end + +end + +--[[--------------------------------------------------------- + - func: DrawScrollBar(object) + - desc: draws the scroll bar object +--]]--------------------------------------------------------- +function skin.DrawScrollBar(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local dragging = object:IsDragging() + local hover = object:GetHover() + local bartype = object:GetBarType() + local bodydowncolor = skin.controls.scrollbar_body_down_color + local borderdowncolor = skin.controls.scrollbar_border_down_color + local bodyhovercolor = skin.controls.scrollbar_body_hover_color + local borderhovercolor = skin.controls.scrollbar_border_hover_color + local bodynohvercolor = skin.controls.scrollbar_body_nohover_color + local bordernohovercolor = skin.controls.scrollbar_border_nohover_color + + if dragging then + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + + if bartype == "vertical" then + love.graphics.setColor(bordernohovercolor) + love.graphics.rectangle("fill", x + 3, y + height/2 - 3, width - 6, 1) + love.graphics.rectangle("fill", x + 3, y + height/2, width - 6, 1) + love.graphics.rectangle("fill", x + 3, y + height/2 + 3, width - 6, 1) + else + love.graphics.setColor(bordernohovercolor) + love.graphics.rectangle("fill", x + width/2 - 3, y + 3, 1, height - 6) + love.graphics.rectangle("fill", x + width/2, y + 3, 1, height - 6) + love.graphics.rectangle("fill", x + width/2 + 3, y + 3, 1, height - 6) + end + +end + +--[[--------------------------------------------------------- + - func: DrawScrollBody(object) + - desc: draws the scroll body object +--]]--------------------------------------------------------- +function skin.DrawScrollBody(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.scrollbody_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawPanel(object) + - desc: draws the panel object +--]]--------------------------------------------------------- +function skin.DrawPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.panel_body_color + local bordercolor = skin.controls.panel_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawList(object) + - desc: draws the list object +--]]--------------------------------------------------------- +function skin.DrawList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.list_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawList(object) + - desc: used to draw over the object and it's children +--]]--------------------------------------------------------- +function skin.DrawOverList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordrcolor = skin.controls.list_border_color + + love.graphics.setColor(bordrcolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawTabPanel(object) + - desc: draws the tab panel object +--]]--------------------------------------------------------- +function skin.DrawTabPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local buttonheight = object:GetHeightOfButtons() + local bodycolor = skin.controls.tabpanel_body_color + local bordercolor = skin.controls.tabpanel_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y + buttonheight, width, height - buttonheight) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y + buttonheight - 1, width, height - buttonheight + 2) + + object:SetScrollButtonSize(15, buttonheight) + +end + +--[[--------------------------------------------------------- + - func: DrawTabButton(object) + - desc: draws the tab button object +--]]--------------------------------------------------------- +function skin.DrawTabButton(object) + + local x = object:GetX() + local y = object:GetY() + local hover = object:GetHover() + local text = object:GetText() + local image = object:GetImage() + local tabnumber = object:GetTabNumber() + local parent = object:GetParent() + local ptabnumber = parent:GetTabNumber() + local font = skin.controls.tab_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local imagewidth = 0 + local imageheight = 0 + local bordercolor = skin.controls.tabpanel_border_color + local bodyhovercolor = skin.controls.button_body_hover_color + local texthovercolor = skin.controls.button_text_hover_color + local bodynohovercolor = skin.controls.button_body_nohover_color + local textnohovercolor = skin.controls.button_text_nohover_color + + if image then + imagewidth = image:getWidth() + imageheight = image:getHeight() + object.width = imagewidth + 15 + twidth + if imageheight > theight then + parent:SetTabHeight(imageheight + 5) + object.height = imageheight + 5 + else + parent:SetTabHeight(theight + 5) + object.height = theight + 5 + end + else + object.width = 10 + twidth + parent:SetTabHeight(theight + 5) + object.height = theight + 5 + end + + local width = object:GetWidth() + local height = object:GetHeight() + + if tabnumber == ptabnumber then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x, y, width, height) + -- button border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + if image then + image:setFilter("nearest", "nearest") + -- button image + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) + else + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + 5, y + height/2 - theight/2) + end + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x, y, width, height) + -- button border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + if image then + image:setFilter("nearest", "nearest") + -- button image + love.graphics.setColor(255, 255, 255, 150) + love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) + else + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + 5, y + height/2 - theight/2) + end + end + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoice(object) + - desc: draws the multi choice object +--]]--------------------------------------------------------- +function skin.DrawMultiChoice(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local choice = object:GetChoice() + local image = skin.images["multichoice-arrow.png"] + local font = skin.controls.multichoice_text_font + local theight = font:getHeight("a") + local bodycolor = skin.controls.multichoice_body_color + local textcolor = skin.controls.multichoice_text_color + local bordercolor = skin.controls.multichoice_border_color + + image:setFilter("nearest", "nearest") + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + + love.graphics.setColor(textcolor) + love.graphics.setFont(font) + + if choice == "" then + love.graphics.print(text, x + 5, y + height/2 - theight/2) + else + love.graphics.print(choice, x + 5, y + height/2 - theight/2) + end + + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + width - 20, y + 5) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoiceList(object) + - desc: draws the multi choice list object +--]]--------------------------------------------------------- +function skin.DrawMultiChoiceList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.multichoicelist_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawOverMultiChoiceList(object) + - desc: draws over the multi choice list object +--]]--------------------------------------------------------- +function skin.DrawOverMultiChoiceList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.multichoicelist_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y - 1, width, height + 1) + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoiceRow(object) + - desc: draws the multi choice row object +--]]--------------------------------------------------------- +function skin.DrawMultiChoiceRow(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local font = skin.controls.multichoicerow_text_font + local bodyhovecolor = skin.controls.multichoicerow_body_hover_color + local texthovercolor = skin.controls.multichoicerow_text_hover_color + local bodynohovercolor = skin.controls.multichoicerow_body_nohover_color + local textnohovercolor = skin.controls.multichoicerow_text_nohover_color + + love.graphics.setFont(font) + + if object.hover then + love.graphics.setColor(bodyhovecolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + 5, y + 5) + else + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + 5, y + 5) + end + +end + +--[[--------------------------------------------------------- + - func: DrawToolTip(object) + - desc: draws the tool tip object +--]]--------------------------------------------------------- +function skin.DrawToolTip(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.tooltip_body_color + local bordercolor = skin.controls.tooltip_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawText(object) + - desc: draws the text object +--]]--------------------------------------------------------- +function skin.DrawText(object) + +end + +--[[--------------------------------------------------------- + - func: DrawTextInput(object) + - desc: draws the text input object +--]]--------------------------------------------------------- +function skin.DrawTextInput(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local font = object:GetFont() + local focus = object:GetFocus() + local showindicator = object:GetIndicatorVisibility() + local alltextselected = object:IsAllTextSelected() + local textx = object:GetTextX() + local texty = object:GetTextY() + local text = object:GetText() + local multiline = object:GetMultiLine() + local lines = object:GetLines() + local offsetx = object:GetOffsetX() + local offsety = object:GetOffsetY() + local indicatorx = object:GetIndicatorX() + local indicatory = object:GetIndicatorY() + local vbar = object:HasVerticalScrollBar() + local hbar = object:HasHorizontalScrollBar() + local linenumbers = object:GetLineNumbersEnabled() + local itemwidth = object:GetItemWidth() + local theight = font:getHeight("a") + local bodycolor = skin.controls.textinput_body_color + local textnormalcolor = skin.controls.textinput_text_normal_color + local textselectedcolor = skin.controls.textinput_text_selected_color + local highlightbarcolor = skin.controls.textinput_highlight_bar_color + local indicatorcolor = skin.controls.textinput_indicator_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + if alltextselected then + local bary = 0 + if multiline then + for i=1, #lines do + local twidth = font:getWidth(lines[i]) + love.graphics.setColor(highlightbarcolor) + love.graphics.rectangle("fill", textx, texty + bary, twidth, theight) + bary = bary + theight + end + else + local twidth = font:getWidth(text) + love.graphics.setColor(highlightbarcolor) + love.graphics.rectangle("fill", textx, texty, twidth, theight) + end + end + + if showindicator and focus then + love.graphics.setColor(indicatorcolor) + love.graphics.rectangle("fill", indicatorx, indicatory, 1, theight) + end + + if not multiline then + object:SetTextOffsetY(height/2 - theight/2) + if offsetx ~= 0 then + object:SetTextOffsetX(0) + else + object:SetTextOffsetX(5) + end + else + if vbar then + if offsety ~= 0 then + if hbar then + object:SetTextOffsetY(5) + else + object:SetTextOffsetY(-5) + end + else + object:SetTextOffsetY(5) + end + else + object:SetTextOffsetY(5) + end + + if hbar then + if offsety ~= 0 then + if linenumbers then + local panel = object:GetLineNumbersPanel() + if vbar then + object:SetTextOffsetX(5) + else + object:SetTextOffsetX(-5) + end + else + if vbar then + object:SetTextOffsetX(5) + else + object:SetTextOffsetX(-5) + end + end + else + object:SetTextOffsetX(5) + end + else + object:SetTextOffsetX(5) + end + + end + + textx = object:GetTextX() + texty = object:GetTextY() + + love.graphics.setFont(font) + + if alltextselected then + love.graphics.setColor(textselectedcolor) + else + love.graphics.setColor(textnormalcolor) + end + + if multiline then + for i=1, #lines do + love.graphics.print(lines[i], textx, texty + theight * i - theight) + end + else + love.graphics.print(lines[1], textx, texty) + end + +end + +--[[--------------------------------------------------------- + - func: DrawOverTextInput(object) + - desc: draws over the text input object +--]]--------------------------------------------------------- +function skin.DrawOverTextInput(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.textinput_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawScrollButton(object) + - desc: draws the scroll button object +--]]--------------------------------------------------------- +function skin.DrawScrollButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local scrolltype = object:GetScrollType() + local down = object.down + local bodydowncolor = skin.controls.button_body_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local borderhovercolor = skin.controls.button_border_hover_color + local bodynohovercolor = skin.controls.button_body_nohover_color + local bordernohovercolor = skin.controls.button_border_nohover_color + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + + if scrolltype == "up" then + local image = skin.images["arrow-up.png"] + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) + elseif scrolltype == "down" then + local image = skin.images["arrow-down.png"] + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) + elseif scrolltype == "left" then + local image = skin.images["arrow-left.png"] + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) + elseif scrolltype == "right" then + local image = skin.images["arrow-right.png"] + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - image:getWidth()/2, y + height/2 - image:getHeight()/2) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawSlider(object) + - desc: draws the slider object +--]]--------------------------------------------------------- +function skin.DrawSlider(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local slidtype = object:GetSlideType() + local baroutlinecolor = skin.controls.slider_bar_outline_color + local barcolor = skin.controls.slider_bar_color + + if slidtype == "horizontal" then + love.graphics.setColor(baroutlinecolor) + love.graphics.rectangle("fill", x, y + height/2 - 5, width, 10) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x + 5, y + height/2, width - 10, 1) + elseif slidtype == "vertical" then + love.graphics.setColor(baroutlinecolor) + love.graphics.rectangle("fill", x + width/2 - 5, y, 10, height) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x + width/2, y + 5, 1, height - 10) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawSliderButton(object) + - desc: draws the slider button object +--]]--------------------------------------------------------- +function skin.DrawSliderButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local down = object.down + local bodydowncolor = skin.controls.button_body_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local borderhovercolor = skin.controls.button_border_down_color + local bodynohvercolor = skin.controls.button_body_nohover_color + local bordernohovercolor = skin.controls.button_border_down_color + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawCheckBox(object) + - desc: draws the check box object +--]]--------------------------------------------------------- +function skin.DrawCheckBox(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetBoxWidth() + local height = object:GetBoxHeight() + local checked = object:GetChecked() + local hover = object:GetHover() + local bodycolor = skin.controls.checkbox_body_color + local bordercolor = skin.controls.checkbox_border_color + local checkcolor = skin.controls.checkbox_check_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + + if checked then + love.graphics.setColor(checkcolor) + love.graphics.rectangle("fill", x + 4, y + 4, width - 8, height - 8) + end + + if hover then + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x + 4, y + 4, width - 8, height - 8) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawCollapsibleCategory(object) + - desc: draws the collapsible category object +--]]--------------------------------------------------------- +function skin.DrawCollapsibleCategory(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local bodycolor = skin.controls.collapsiblecategory_body_color + local textcolor = skin.controls.collapsiblecategory_text_color + local bordercolor = skin.controls.collapsiblecategory_border_color + local font = smallfont + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(text, x + 5, y + 5) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnList(object) + - desc: draws the column list object +--]]--------------------------------------------------------- +function skin.DrawColumnList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.columnlist_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListHeader(object) + - desc: draws the column list header object +--]]--------------------------------------------------------- +function skin.DrawColumnListHeader(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local name = object:GetName() + local down = object.down + local font = skin.controls.columnlistheader_text_font + local twidth = font:getWidth(object.name) + local theight = font:getHeight(object.name) + local bodydowncolor = skin.controls.columnlistheader_body_down_color + local textdowncolor = skin.controls.columnlistheader_text_down_color + local borderdowncolor = skin.controls.columnlistheader_border_down_color + local bodyhovercolor = skin.controls.columnlistheader_body_hover_color + local textdowncolor = skin.controls.columnlistheader_text_hover_color + local borderdowncolor = skin.controls.columnlistheader_border_down_color + local nohovercolor = skin.controls.columnlistheader_body_nohover_color + local textnohovercolor = skin.controls.columnlistheader_text_nohover_color + local bordernohovercolor = skin.controls.columnlistheader_border_down_color + + if down then + -- header body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + elseif hover then + -- header body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + else + -- header body + love.graphics.setColor(nohovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListArea(object) + - desc: draws the column list area object +--]]--------------------------------------------------------- +function skin.DrawColumnListArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.columnlistarea_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawOverColumnListArea(object) + - desc: draws over the column list area object +--]]--------------------------------------------------------- +function skin.DrawOverColumnListArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.columnlist_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListRow(object) + - desc: draws the column list row object +--]]--------------------------------------------------------- +function skin.DrawColumnListRow(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local colorindex = object:GetColorIndex() + local font = object:GetFont() + local columndata = object:GetColumnData() + local textx = object:GetTextX() + local texty = object:GetTextY() + local parent = object:GetParent() + local cwidth, cheight = parent:GetParent():GetColumnSize() + local theight = font:getHeight("a") + local body1color = skin.controls.columnlistrow_body1_color + local border1color = skin.controls.columnlistrow_border1_color + local body2color = skin.controls.columnlistrow_body2_color + local border2color = skin.controls.columnlistrow_border2_color + local textcolor = skin.controls.columnlistrow_text_color + + object:SetTextPos(5, height/2 - theight/2) + + if colorindex == 1 then + love.graphics.setColor(body1color) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(border1color) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + else + love.graphics.setColor(body2color) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(border2color) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + end + + for k, v in ipairs(columndata) do + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(v, x + textx, y + texty) + x = x + cwidth + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawModalBackground(object) + - desc: draws the modal background object +--]]--------------------------------------------------------- +function skin.DrawModalBackground(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.modalbackground_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawLineNumbersPanel(object) + - desc: draws the line numbers panel object +--]]--------------------------------------------------------- +function skin.DrawLineNumbersPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local offsety = object:GetOffsetY() + local parent = object:GetParent() + local lines = parent:GetLines() + local font = parent:GetFont() + local theight = font:getHeight("a") + local bordercolor = skin.controls.linenumberspanel_border_color + local textcolor = skin.controls.linenumberspanel_text_color + local mody = y + + object:SetWidth(10 + font:getWidth(#lines)) + love.graphics.setFont(font) + + love.graphics.setColor(200, 200, 200, 255) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height, true, true, true, false) + + for i=1, #lines do + love.graphics.setColor(textcolor) + love.graphics.print(i, object.x + 5, mody - offsety) + mody = mody + theight + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawNumberBox(object) + - desc: draws the numberbox object +--]]--------------------------------------------------------- +function skin.DrawNumberBox(object) + +end + +-- register the skin loveframes.skins.Register(skin) \ No newline at end of file diff --git a/skins/Orange/images/arrow-down.png b/skins/Orange/images/arrow-down.png index 14e39181a536a2a53513f343b3908411a4a6d406..37d805800fd4b840d58fc637925316b0a4c697a1 100644 GIT binary patch delta 290 zcmV+-0p0$z0oVc|iBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;PNkliBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;INklzN}+9AOw)vUp3(O`%CZcQB!J0X*I^h2 ztm_Kz{T_590w;i6(00=_7{?LYw(W`UJI~_gnd>>hBYS7XeYLcA2>Bwi%hgXAI!A9m~0U&M#^_Rg$o|w6XvI002ovPDHLkV1mSDcYFW< delta 133 zcmcb}w1-i#Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{K?VlCgN!>SX1|^2 zrs-?p>Ealo5uBW`fGr~<;|KpCma|NnOpHxkiCmmoZebnahP#|z&E)xPdNI%Kx`Tnq h1XF>v645CP4E5?c>rZc52Q-a=!PC{xWt~$(6976eC^`TD diff --git a/skins/Orange/images/arrow-right.png b/skins/Orange/images/arrow-right.png index 159cd41e72ab30068f715cc4871a45b57d3a0b6b..89b4818627737201d05713540777e2d19c06f43d 100644 GIT binary patch delta 282 zcmV+#0p=iBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZyl3cmmV z4!;371ydxEMk#;HNkl(Dd}wAM(|^gDzz zps0P{W1eS>zV9c5GVzw<12AM+77W9Hs;b=m2mu%p4WM2`m%z?ZO(f^P$4EkA9YhJ~wv=fa gx0cDZ(xEMU0H$wJHGrC-$^ZZW07*qoM6N<$f*huHYybcN delta 130 zcmcb>w3AV>Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{K?VlCgN!>SX1|^2 zrs-ws>Ealo5uBW$AZ}t}@`pWf(U)eCCWb(%gs#p@4QpmBU@JLVVLBn#$kBh2j1-Hn eik47A7sIT1IqQu&B&2}GGI+ZBxvXycm@&iD7$=N5;8cm zE&~&2ZMv(ft2NR$P7nlo75|!LiD4MZ4_m(#0SK`yOVxF4f}9$?x5rLMl0>h@*2$9_-!{`AoacXO$Q&y|@3IbLtQAF}rfIY+ zi;m-PWTWs9p$7)6UB~Q{WtqCJGn4myzmRcc7k0000< LMNUMnLSO-cDrSHw delta 133 zcmaFIw1-i#Gr-TCmrII^fq{Y7)59eQNOOZQ2OE%Fxu#rgqM|g{0R{%X1B_YMIyoo0 zY5H1tx;Tbt1Scmf(9X!n_~AdLRiRbEA%NLOF~Zc2_XSsB)`6u0&ddRd%pQhdl h$nXi_n7EXK;cI+@{*#rgXMiR%c)I$ztaD0e0sz<7CDQ-^ diff --git a/skins/Orange/images/multichoice-arrow.png b/skins/Orange/images/multichoice-arrow.png index c7294cb988d550ae37b61de17bd99f60cc984151..165121c956329680f817fdc62358e736bfebea59 100644 GIT binary patch delta 230 zcmV&Y z4#EKyC`y2lMk#-oNkl)lw(yN3ek#+n$V=8p?B1z z5Q!M4fn>^>+wcAYr4;?i1T!;M{*ZJKETZPv4qFA@`_e^=0WcV_>7liz7-N$JFlxah z0Rk_^m`6#5QCr|V6j>5NsCEJvdsTQZvDT85WEgv=ljSa0qCiR@Y=Y(QIOhm?+xFGP gkkk3k0Tv)+O`Ywc{{R3007*qoM6N<$f-8<#R{#J2 delta 176 zcmbQk^qf(#Gr-TCmrII^fq{Y7)59eQNb`d*2OE&IzBbisqM|g{VFm`i!;HuCSENjI z)2vALba4!^@J~)Sz~t4JZqQ&5$*^LgU`yw8Fr9Z6-lD0PvyA@j theight then - parent:SetTabHeight(imageheight + 5) - object.height = imageheight + 5 - else - parent:SetTabHeight(theight + 5) - object.height = theight + 5 - end - else - object.width = 10 + twidth - parent:SetTabHeight(theight + 5) - object.height = theight + 5 - end - - local width = object:GetWidth() - local height = object:GetHeight() - - if tabnumber == ptabnumber then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - - gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if image then - -- button image - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) - else - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + 5, y + height/2 - theight/2) - end - - else - - -- button body - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - - gradientcolor = {bodynohovercolor[1] - 20, bodynohovercolor[2] - 20, bodynohovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if image then - -- button image - love.graphics.setColor(255, 255, 255, 150) - love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(object.text, x + imagewidth + 10, y + height/2 - theight/2) - else - -- button text - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(object.text, x + 5, y + height/2 - theight/2) - end - - end - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoice(object) - - desc: draws the multi choice object ---]]--------------------------------------------------------- -function skin.DrawMultiChoice(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local choice = object:GetChoice() - local image = skin.images["multichoice-arrow.png"] - local font = skin.controls.multichoice_text_font - local theight = font:getHeight("a") - local bodycolor = skin.controls.multichoice_body_color - local textcolor = skin.controls.multichoice_text_color - local bordercolor = skin.controls.multichoice_border_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - love.graphics.setColor(unpack(textcolor)) - love.graphics.setFont(font) - - if choice == "" then - love.graphics.print(text, x + 5, y + height/2 - theight/2) - else - love.graphics.print(choice, x + 5, y + height/2 - theight/2) - end - - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(image, x + width - 20, y + 5) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoiceList(object) - - desc: draws the multi choice list object ---]]--------------------------------------------------------- -function skin.DrawMultiChoiceList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.multichoicelist_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawOverMultiChoiceList(object) - - desc: draws over the multi choice list object ---]]--------------------------------------------------------- -function skin.DrawOverMultiChoiceList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.multichoicelist_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y - 1, width, height + 1) - -end - ---[[--------------------------------------------------------- - - func: DrawMultiChoiceRow(object) - - desc: draws the multi choice row object ---]]--------------------------------------------------------- -function skin.DrawMultiChoiceRow(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local font = skin.controls.multichoicerow_text_font - local bodyhovecolor = skin.controls.multichoicerow_body_hover_color - local texthovercolor = skin.controls.multichoicerow_text_hover_color - local bodynohovercolor = skin.controls.multichoicerow_body_nohover_color - local textnohovercolor = skin.controls.multichoicerow_text_nohover_color - - love.graphics.setFont(font) - - if object.hover then - love.graphics.setColor(unpack(bodyhovecolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(texthovercolor)) - love.graphics.print(text, x + 5, y + 5) - else - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(text, x + 5, y + 5) - end - -end - ---[[--------------------------------------------------------- - - func: DrawToolTip(object) - - desc: draws the tool tip object ---]]--------------------------------------------------------- -function skin.DrawToolTip(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.tooltip_body_color - local bordercolor = skin.controls.tooltip_border_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawText(object) - - desc: draws the text object ---]]--------------------------------------------------------- -function skin.DrawText(object) - -end - ---[[--------------------------------------------------------- - - func: DrawTextInput(object) - - desc: draws the text input object ---]]--------------------------------------------------------- -function skin.DrawTextInput(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local font = object:GetFont() - local focus = object:GetFocus() - local showindicator = object:GetIndicatorVisibility() - local alltextselected = object:IsAllTextSelected() - local textx = object:GetTextX() - local texty = object:GetTextY() - local text = object:GetText() - local multiline = object:GetMultiLine() - local lines = object:GetLines() - local offsetx = object:GetOffsetX() - local offsety = object:GetOffsetY() - local indicatorx = object:GetIndicatorX() - local indicatory = object:GetIndicatorY() - local vbar = object:HasVerticalScrollBar() - local hbar = object:HasHorizontalScrollBar() - local linenumbers = object:GetLineNumbersEnabled() - local itemwidth = object:GetItemWidth() - local theight = font:getHeight("a") - local bodycolor = skin.controls.textinput_body_color - local textnormalcolor = skin.controls.textinput_text_normal_color - local textselectedcolor = skin.controls.textinput_text_selected_color - local highlightbarcolor = skin.controls.textinput_highlight_bar_color - local indicatorcolor = skin.controls.textinput_indicator_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - if alltextselected then - local bary = 0 - if multiline then - for i=1, #lines do - local twidth = font:getWidth(lines[i]) - love.graphics.setColor(unpack(highlightbarcolor)) - love.graphics.rectangle("fill", textx, texty + bary, twidth, theight) - bary = bary + theight - end - else - local twidth = font:getWidth(text) - love.graphics.setColor(unpack(highlightbarcolor)) - love.graphics.rectangle("fill", textx, texty, twidth, theight) - end - end - - if showindicator and focus then - love.graphics.setColor(unpack(indicatorcolor)) - love.graphics.rectangle("fill", indicatorx, indicatory, 1, theight) - end - - if not multiline then - object:SetTextOffsetY(height/2 - theight/2) - if offsetx ~= 0 then - object:SetTextOffsetX(0) - else - object:SetTextOffsetX(5) - end - else - if vbar then - if offsety ~= 0 then - if hbar then - object:SetTextOffsetY(5) - else - object:SetTextOffsetY(-5) - end - else - object:SetTextOffsetY(5) - end - else - object:SetTextOffsetY(5) - end - - if hbar then - if offsety ~= 0 then - if linenumbers then - local panel = object:GetLineNumbersPanel() - if vbar then - object:SetTextOffsetX(5) - else - object:SetTextOffsetX(-5) - end - else - if vbar then - object:SetTextOffsetX(5) - else - object:SetTextOffsetX(-5) - end - end - else - object:SetTextOffsetX(5) - end - else - object:SetTextOffsetX(5) - end - - end - - textx = object:GetTextX() - texty = object:GetTextY() - - love.graphics.setFont(font) - - if alltextselected then - love.graphics.setColor(unpack(textselectedcolor)) - else - love.graphics.setColor(unpack(textnormalcolor)) - end - - if multiline then - for i=1, #lines do - love.graphics.print(lines[i], textx, texty + theight * i - theight) - end - else - love.graphics.print(lines[1], textx, texty) - end - -end - ---[[--------------------------------------------------------- - - func: DrawOverTextInput(object) - - desc: draws over the text input object ---]]--------------------------------------------------------- -function skin.DrawOverTextInput(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.textinput_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: DrawScrollButton(object) - - desc: draws the scroll button object ---]]--------------------------------------------------------- -function skin.DrawScrollButton(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local scrolltype = object:GetScrollType() - local down = object.down - local bodydowncolor = skin.controls.button_body_down_color - local borderdowncolor = skin.controls.button_border_down_color - local bodyhovercolor = skin.controls.button_body_hover_color - local borderhovercolor = skin.controls.button_border_hover_color - local bodynohovercolor = skin.controls.button_body_nohover_color - local bordernohovercolor = skin.controls.button_border_nohover_color - local gradientcolor = {} - - if down then - - -- button body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height) - - elseif hover then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(borderhovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - else - - -- button body - love.graphics.setColor(unpack(bodynohovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodynohovercolor[1] - 20, bodynohovercolor[2] - 20, bodynohovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - end - - if scrolltype == "up" then - local image = skin.images["arrow-up.png"] - local imagewidth = image:getWidth() - local imageheight = image:getHeight() - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) - elseif scrolltype == "down" then - local image = skin.images["arrow-down.png"] - local imagewidth = image:getWidth() - local imageheight = image:getHeight() - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) - elseif scrolltype == "left" then - local image = skin.images["arrow-left.png"] - local imagewidth = image:getWidth() - local imageheight = image:getHeight() - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) - elseif scrolltype == "right" then - local image = skin.images["arrow-right.png"] - local imagewidth = image:getWidth() - local imageheight = image:getHeight() - if hover then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(255, 255, 255, 150) - end - love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawSlider(object) - - desc: draws the slider object ---]]--------------------------------------------------------- -function skin.DrawSlider(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local slidtype = object:GetSlideType() - local baroutlinecolor = skin.controls.slider_bar_outline_color - local barcolor = skin.controls.slider_bar_color - - if slidtype == "horizontal" then - - love.graphics.setColor(unpack(baroutlinecolor)) - love.graphics.rectangle("fill", x, y + height/2 - 5, width, 10) - - love.graphics.setColor(unpack(barcolor)) - love.graphics.rectangle("fill", x + 5, y + height/2, width - 10, 1) - - elseif slidtype == "vertical" then - - love.graphics.setColor(unpack(baroutlinecolor)) - love.graphics.rectangle("fill", x + width/2 - 5, y, 10, height) - - love.graphics.setColor(unpack(barcolor)) - love.graphics.rectangle("fill", x + width/2, y + 5, 1, height - 10) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawSliderButton(object) - - desc: draws the slider button object ---]]--------------------------------------------------------- -function skin.DrawSliderButton(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local down = object.down - local bodydowncolor = skin.controls.button_body_down_color - local borderdowncolor = skin.controls.button_border_down_color - local bodyhovercolor = skin.controls.button_body_hover_color - local borderhovercolor = skin.controls.button_border_down_color - local bodynohvercolor = skin.controls.button_body_nohover_color - local bordernohovercolor = skin.controls.button_border_down_color - local gradientcolor = {} - - if down then - - -- button body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height) - - elseif hover then - - -- button body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(borderhovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - else - - -- button body - love.graphics.setColor(unpack(bodynohvercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodynohvercolor[1] - 20, bodynohvercolor[2] - 20, bodynohvercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- button border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawCheckBox(object) - - desc: draws the check box object ---]]--------------------------------------------------------- -function skin.DrawCheckBox(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetBoxWidth() - local height = object:GetBoxHeight() - local checked = object:GetChecked() - local hover = object:GetHover() - local bodycolor = skin.controls.checkbox_body_color - local bordercolor = skin.controls.checkbox_border_color - local checkcolor = skin.controls.checkbox_check_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - - if checked then - love.graphics.setColor(unpack(checkcolor)) - love.graphics.rectangle("fill", x + 4, y + 4, width - 8, height - 8) - end - - if hover then - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x + 4, y + 4, width - 8, height - 8) - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawCollapsibleCategory(object) - - desc: draws the collapsible category object ---]]--------------------------------------------------------- -function skin.DrawCollapsibleCategory(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local text = object:GetText() - local bodycolor = skin.controls.collapsiblecategory_body_color - local textcolor = skin.controls.collapsiblecategory_text_color - local bordercolor = skin.controls.collapsiblecategory_border_color - local font = smallfont - local gradientcolor = {bodycolor[1] - 20, bodycolor[2] - 20, bodycolor[3] - 20, 255} - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(gradientcolor)) - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - love.graphics.setFont(font) - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(text, x + 5, y + 5) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnList(object) - - desc: draws the column list object ---]]--------------------------------------------------------- -function skin.DrawColumnList(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.columnlist_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListHeader(object) - - desc: draws the column list header object ---]]--------------------------------------------------------- -function skin.DrawColumnListHeader(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local hover = object:GetHover() - local name = object:GetName() - local down = object.down - local font = skin.controls.columnlistheader_text_font - local twidth = font:getWidth(object.name) - local theight = font:getHeight(object.name) - local bodydowncolor = skin.controls.columnlistheader_body_down_color - local textdowncolor = skin.controls.columnlistheader_text_down_color - local borderdowncolor = skin.controls.columnlistheader_border_down_color - local bodyhovercolor = skin.controls.columnlistheader_body_hover_color - local textdowncolor = skin.controls.columnlistheader_text_hover_color - local borderdowncolor = skin.controls.columnlistheader_border_down_color - local nohovercolor = skin.controls.columnlistheader_body_nohover_color - local textnohovercolor = skin.controls.columnlistheader_text_nohover_color - local bordernohovercolor = skin.controls.columnlistheader_border_down_color - local gradientcolor = {} - - if down then - - -- header body - love.graphics.setColor(unpack(bodydowncolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textdowncolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - elseif hover then - - -- header body - love.graphics.setColor(unpack(bodyhovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textdowncolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(borderdowncolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - else - - -- header body - love.graphics.setColor(unpack(nohovercolor)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - gradientcolor = {nohovercolor[1] - 20, nohovercolor[2] - 20, nohovercolor[3] - 20, 255} - skin.DrawGradient(x, y - 1, width, height, gradientcolor) - - -- header name - love.graphics.setFont(font) - love.graphics.setColor(unpack(textnohovercolor)) - love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) - - -- header border - love.graphics.setColor(unpack(bordernohovercolor)) - skin.OutlinedRectangle(x, y, width, height, false, false, false, true) - - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListArea(object) - - desc: draws the column list area object ---]]--------------------------------------------------------- -function skin.DrawColumnListArea(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.columnlistarea_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawOverColumnListArea(object) - - desc: draws over the column list area object ---]]--------------------------------------------------------- -function skin.DrawOverColumnListArea(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bordercolor = skin.controls.columnlist_border_color - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawColumnListRow(object) - - desc: draws the column list row object ---]]--------------------------------------------------------- -function skin.DrawColumnListRow(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local colorindex = object:GetColorIndex() - local font = object:GetFont() - local columndata = object:GetColumnData() - local textx = object:GetTextX() - local texty = object:GetTextY() - local parent = object:GetParent() - local cwidth, cheight = parent:GetParent():GetColumnSize() - local theight = font:getHeight("a") - local body1color = skin.controls.columnlistrow_body1_color - local border1color = skin.controls.columnlistrow_border1_color - local body2color = skin.controls.columnlistrow_body2_color - local border2color = skin.controls.columnlistrow_border2_color - local textcolor = skin.controls.columnlistrow_text_color - - object:SetTextPos(5, height/2 - theight/2) - - if colorindex == 1 then - - love.graphics.setColor(unpack(body1color)) - love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) - - love.graphics.setColor(unpack(skin.controls.columnlistrow_border1_color)) - skin.OutlinedRectangle(x, y, width, height, true, false, true, true) - - else - - love.graphics.setColor(unpack(body2color)) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(border2color)) - skin.OutlinedRectangle(x, y, width, height, true, false, true, true) - - end - - for k, v in ipairs(columndata) do - love.graphics.setFont(font) - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(v, x + textx, y + texty) - x = x + cwidth - end - -end - ---[[--------------------------------------------------------- - - func: skin.DrawModalBackground(object) - - desc: draws the modal background object ---]]--------------------------------------------------------- -function skin.DrawModalBackground(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local bodycolor = skin.controls.modalbackground_body_color - - love.graphics.setColor(unpack(bodycolor)) - love.graphics.rectangle("fill", x, y, width, height) - -end - ---[[--------------------------------------------------------- - - func: skin.DrawLineNumbersPanel(object) - - desc: draws the line numbers panel object ---]]--------------------------------------------------------- -function skin.DrawLineNumbersPanel(object) - - local x = object:GetX() - local y = object:GetY() - local width = object:GetWidth() - local height = object:GetHeight() - local offsety = object:GetOffsetY() - local parent = object:GetParent() - local lines = parent:GetLines() - local font = parent:GetFont() - local theight = font:getHeight("a") - local bordercolor = skin.controls.linenumberspanel_border_color - local textcolor = skin.controls.linenumberspanel_text_color - local mody = y - - object:SetWidth(10 + font:getWidth(#lines)) - love.graphics.setFont(font) - - love.graphics.setColor(200, 200, 200, 255) - love.graphics.rectangle("fill", x, y, width, height) - - love.graphics.setColor(unpack(bordercolor)) - skin.OutlinedRectangle(x, y, width, height, true, true, true, false) - - for i=1, #lines do - love.graphics.setColor(unpack(textcolor)) - love.graphics.print(i, object.x + 5, mody - offsety) - mody = mody + theight - end - -end - --- register the skin +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- skin table +local skin = {} + +-- skin info (you always need this in a skin) +skin.name = "Orange" +skin.author = "Nikolai Resokav" +skin.version = "1.0" + +local smallfont = love.graphics.newFont(10) +local imagebuttonfont = love.graphics.newFont(15) +local bordercolor = {143, 143, 143, 255} + +-- controls +skin.controls = {} + +-- frame +skin.controls.frame_border_color = bordercolor +skin.controls.frame_body_color = {232, 232, 232, 255} +skin.controls.frame_top_color = {255, 153, 0, 255} +skin.controls.frame_name_color = {255, 255, 255, 255} +skin.controls.frame_name_font = smallfont + +-- button +skin.controls.button_border_down_color = bordercolor +skin.controls.button_border_nohover_color = bordercolor +skin.controls.button_border_hover_color = bordercolor +skin.controls.button_body_down_color = {255, 173, 51, 255} +skin.controls.button_body_nohover_color = {255, 255, 255, 255} +skin.controls.button_body_hover_color = {255, 184, 77, 255} +skin.controls.button_text_down_color = {255, 255, 255, 255} +skin.controls.button_text_nohover_color = {0, 0, 0, 200} +skin.controls.button_text_hover_color = {255, 255, 255, 255} +skin.controls.button_body_nonclickable_color = {220, 220, 220, 255} +skin.controls.button_text_nonclickable_color = {0, 0, 0, 100} +skin.controls.button_text_font = smallfont + +-- image button +skin.controls.imagebutton_text_down_color = {255, 255, 255, 255} +skin.controls.imagebutton_text_nohover_color = {255, 255, 255, 200} +skin.controls.imagebutton_text_hover_color = {255, 255, 255, 255} +skin.controls.imagebutton_text_font = imagebuttonfont + +-- close button +skin.controls.closebutton_body_down_color = {255, 255, 255, 255} +skin.controls.closebutton_body_nohover_color = {255, 255, 255, 255} +skin.controls.closebutton_body_hover_color = {255, 255, 255, 255} + +-- progress bar +skin.controls.progressbar_border_color = bordercolor +skin.controls.progressbar_body_color = {255, 255, 255, 255} +skin.controls.progressbar_bar_color = {0, 255, 0, 255} +skin.controls.progressbar_text_color = {0, 0, 0, 255} +skin.controls.progressbar_text_font = smallfont + +-- list +skin.controls.list_border_color = bordercolor +skin.controls.list_body_color = {232, 232, 232, 255} + +-- scrollbar +skin.controls.scrollbar_border_down_color = bordercolor +skin.controls.scrollbar_border_hover_color = bordercolor +skin.controls.scrollbar_border_nohover_color = bordercolor +skin.controls.scrollbar_body_down_color = {255, 173, 51, 255} +skin.controls.scrollbar_body_nohover_color = {255, 255, 255, 255} +skin.controls.scrollbar_body_hover_color = {255, 184, 77, 255} + +-- scrollarea +skin.controls.scrollarea_body_color = {200, 200, 200, 255} +skin.controls.scrollarea_border_color = bordercolor + +-- scrollbody +skin.controls.scrollbody_body_color = {0, 0, 0, 0} + +-- panel +skin.controls.panel_body_color = {232, 232, 232, 255} +skin.controls.panel_border_color = bordercolor + +-- tab panel +skin.controls.tabpanel_body_color = {232, 232, 232, 255} +skin.controls.tabpanel_border_color = bordercolor + +-- tab button +skin.controls.tab_border_nohover_color = bordercolor +skin.controls.tab_border_hover_color = bordercolor +skin.controls.tab_body_nohover_color = {255, 255, 255, 255} +skin.controls.tab_body_hover_color = {255, 173, 51, 255} +skin.controls.tab_text_nohover_color = {0, 0, 0, 200} +skin.controls.tab_text_hover_color = {255, 255, 255, 255} +skin.controls.tab_text_font = smallfont + +-- multichoice +skin.controls.multichoice_body_color = {240, 240, 240, 255} +skin.controls.multichoice_border_color = bordercolor +skin.controls.multichoice_text_color = {0, 0, 0, 255} +skin.controls.multichoice_text_font = smallfont + +-- multichoicelist +skin.controls.multichoicelist_body_color = {240, 240, 240, 200} +skin.controls.multichoicelist_border_color = bordercolor + +-- multichoicerow +skin.controls.multichoicerow_body_nohover_color = {240, 240, 240, 255} +skin.controls.multichoicerow_body_hover_color = {255, 117, 26, 255} +skin.controls.multichoicerow_border_color = {50, 50, 50, 255} +skin.controls.multichoicerow_text_nohover_color = {0, 0, 0, 150} +skin.controls.multichoicerow_text_hover_color = {255, 255, 255, 255} +skin.controls.multichoicerow_text_font = smallfont + +-- tooltip +skin.controls.tooltip_border_color = bordercolor +skin.controls.tooltip_body_color = {255, 255, 255, 255} + +-- text input +skin.controls.textinput_border_color = bordercolor +skin.controls.textinput_body_color = {240, 240, 240, 255} +skin.controls.textinput_indicator_color = {0, 0, 0, 255} +skin.controls.textinput_text_normal_color = {0, 0, 0, 255} +skin.controls.textinput_text_selected_color = {255, 255, 255, 255} +skin.controls.textinput_highlight_bar_color = {51, 204, 255, 255} + +-- slider +skin.controls.slider_bar_color = bordercolor +skin.controls.slider_bar_outline_color = {220, 220, 220, 255} + +-- checkbox +skin.controls.checkbox_border_color = bordercolor +skin.controls.checkbox_body_color = {255, 255, 255, 255} +skin.controls.checkbox_check_color = {255, 173, 51, 255} +skin.controls.checkbox_text_color = {0, 0, 0, 255} +skin.controls.checkbox_text_font = smallfont + +-- collapsiblecategory +skin.controls.collapsiblecategory_text_color = {0, 0, 0, 255} +skin.controls.collapsiblecategory_body_color = {255, 255, 255, 255} +skin.controls.collapsiblecategory_border_color = bordercolor + +-- columnlist +skin.controls.columnlist_border_color = bordercolor +skin.controls.columnlist_body_color = {232, 232, 232, 255} + +-- columlistarea +skin.controls.columnlistarea_border_color = bordercolor +skin.controls.columnlistarea_body_color = {232, 232, 232, 255} + +-- columnlistheader +skin.controls.columnlistheader_border_down_color = bordercolor +skin.controls.columnlistheader_border_nohover_color = bordercolor +skin.controls.columnlistheader_border_hover_color = bordercolor +skin.controls.columnlistheader_body_down_color = {255, 173, 51, 255} +skin.controls.columnlistheader_body_nohover_color = {255, 255, 255, 255} +skin.controls.columnlistheader_body_hover_color = {255, 184, 77, 255} +skin.controls.columnlistheader_text_down_color = {255, 255, 255, 255} +skin.controls.columnlistheader_text_nohover_color = {0, 0, 0, 200} +skin.controls.columnlistheader_text_hover_color = {255, 255, 255, 255} +skin.controls.columnlistheader_text_font = smallfont + +-- columnlistrow +skin.controls.columnlistrow_border1_color = bordercolor +skin.controls.columnlistrow_body1_color = {232, 232, 232, 255} +skin.controls.columnlistrow_border2_color = bordercolor +skin.controls.columnlistrow_body2_color = {200, 200, 200, 255} +skin.controls.columnlistrow_text_color = {100, 100, 100, 255} + +-- modalbackground +skin.controls.modalbackground_body_color = {255, 255, 255, 100} + +-- linenumberspanel +skin.controls.linenumberspanel_border_color = bordercolor +skin.controls.linenumberspanel_text_color = {100, 100, 100, 255} + +--[[--------------------------------------------------------- + - func: OutlinedRectangle(object) + - desc: creates and outlined rectangle +--]]--------------------------------------------------------- +function skin.OutlinedRectangle(x, y, width, height, ovt, ovb, ovl, ovr) + + local ovt = ovt or false + local ovb = ovb or false + local ovl = ovl or false + local ovr = ovr or false + + -- top + if not ovt then + love.graphics.rectangle("fill", x, y, width, 1) + end + + -- bottom + if not ovb then + love.graphics.rectangle("fill", x, y + height - 1, width, 1) + end + + -- left + if not ovl then + love.graphics.rectangle("fill", x, y, 1, height) + end + + -- right + if not ovr then + love.graphics.rectangle("fill", x + width - 1, y, 1, height) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawGradient(x, y, width, height, color) + - desc: draws a gradient +--]]--------------------------------------------------------- +function skin.DrawGradient(x, y, width, height, color) + + local color = color + local percent = 0 + + for i=1, (height - 1) do + percent = i/height * 255 + color[4] = loveframes.util.Round(percent) + love.graphics.setColor(unpack(color)) + love.graphics.rectangle("fill", x, y + i, width, 1) + end + +end + +--[[--------------------------------------------------------- + - func: DrawFrame(object) + - desc: draws the frame object +--]]--------------------------------------------------------- +function skin.DrawFrame(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local name = object:GetName() + local bodycolor = skin.controls.frame_body_color + local topcolor = skin.controls.frame_top_color + local bordercolor = skin.controls.frame_border_color + local namecolor = skin.controls.frame_name_color + local font = skin.controls.frame_name_font + local gradientcolor = {topcolor[1] - 20, topcolor[2] - 20, topcolor[3], 255} + + -- frame body + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + -- frame top bar + love.graphics.setColor(topcolor) + love.graphics.rectangle("fill", x, y, width, 25) + skin.DrawGradient(x, y, width, 25, gradientcolor) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y + 25, width, 1) + + -- frame name section + love.graphics.setFont(font) + love.graphics.setColor(namecolor) + love.graphics.print(name, x + 5, y + 5) + + -- frame border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawButton(object) + - desc: draws the button object +--]]--------------------------------------------------------- +function skin.DrawButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local text = object:GetText() + local font = skin.controls.button_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local down = object.down + local enabled = object:GetEnabled() + local clickable = object:GetClickable() + local bodydowncolor = skin.controls.button_body_down_color + local textdowncolor = skin.controls.button_text_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local texthovercolor = skin.controls.button_text_hover_color + local borderhovercolor = skin.controls.button_border_down_color + local bodynohvercolor = skin.controls.button_body_nohover_color + local textnohovercolor = skin.controls.button_text_nohover_color + local bordernohovercolor = skin.controls.button_border_down_color + local bodynonclickablecolor = skin.controls.button_body_nonclickable_color + local textnonclickablecolor = skin.controls.button_text_nonclickable_color + local gradientcolor = {} + + if not enabled or not clickable then + -- button body + love.graphics.setColor(bodynonclickablecolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynonclickablecolor[1] - 20, bodynonclickablecolor[2] - 20, bodynonclickablecolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnonclickablecolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + return + end + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynohvercolor[1] - 20, bodynohvercolor[2] - 20, bodynohvercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + +end + +--[[--------------------------------------------------------- + - func: DrawCloseButton(object) + - desc: draws the close button object +--]]--------------------------------------------------------- +function skin.DrawCloseButton(object) + + local x = object:GetX() + local y = object:GetY() + local staticx = object:GetStaticX() + local parent = object.parent + local parentwidth = parent:GetWidth() + local hover = object:GetHover() + local down = object.down + local image = skin.images["close.png"] + local bodydowncolor = skin.controls.closebutton_body_down_color + local bodyhovercolor = skin.controls.closebutton_body_hover_color + local bodynohovercolor = skin.controls.closebutton_body_nohover_color + + image:setFilter("nearest", "nearest") + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.draw(image, x, y) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.draw(image, x, y) + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.draw(image, x, y) + end + + if staticx ~= (parentwidth - 20) then + object:SetPos(parentwidth - 20, 4) + end + +end + +--[[--------------------------------------------------------- + - func: DrawImage(object) + - desc: draws the image object +--]]--------------------------------------------------------- +function skin.DrawImage(object) + + local x = object:GetX() + local y = object:GetY() + local orientation = object:GetOrientation() + local scalex = object:GetScaleX() + local scaley = object:GetScaleY() + local offsetx = object:GetOffsetX() + local offsety = object:GetOffsetY() + local shearx = object:GetShearX() + local sheary = object:GetShearY() + local image = object.image + local color = object.imagecolor + + if color then + love.graphics.setColor(color) + love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary) + else + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y, orientation, scalex, scaley, offsetx, offsety, shearx, sheary) + end + +end + +--[[--------------------------------------------------------- + - func: DrawImageButton(object) + - desc: draws the image button object +--]]--------------------------------------------------------- +function skin.DrawImageButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local hover = object:GetHover() + local image = object:GetImage() + local down = object.down + local font = skin.controls.imagebutton_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local textdowncolor = skin.controls.imagebutton_text_down_color + local texthovercolor = skin.controls.imagebutton_text_hover_color + local textnohovercolor = skin.controls.imagebutton_text_nohover_color + + if down then + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + 1, y + 1) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2 + 1, y + height - theight - 5 + 1) + love.graphics.setColor(textdowncolor) + love.graphics.print(text, x + width/2 - twidth/2 + 1, y + height - theight - 6 + 1) + elseif hover then + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 5) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6) + else + if image then + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x, y) + end + love.graphics.setFont(font) + love.graphics.setColor(0, 0, 0, 255) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 5) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6) + end + +end + +--[[--------------------------------------------------------- + - func: DrawProgressBar(object) + - desc: draws the progress bar object +--]]--------------------------------------------------------- +function skin.DrawProgressBar(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local value = object:GetValue() + local max = object:GetMax() + local barwidth = object:GetBarWidth() + local font = skin.controls.progressbar_text_font + local text = value .. "/" ..max + local twidth = font:getWidth(text) + local theight = font:getHeight("a") + local bodycolor = skin.controls.progressbar_body_color + local barcolor = skin.controls.progressbar_bar_color + local textcolor = skin.controls.progressbar_text_color + local bordercolor = skin.controls.progressbar_border_color + local gradientcolor = {barcolor[1], barcolor[2] - 20, barcolor[3], 255} + + -- progress bar body + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x, y, barwidth, height) + skin.DrawGradient(x, y, barwidth, height, gradientcolor) + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2) + + -- progress bar border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawScrollArea(object) + - desc: draws the scroll area object +--]]--------------------------------------------------------- +function skin.DrawScrollArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bartype = object:GetBarType() + local bodycolor = skin.controls.scrollarea_body_color + local bordercolor = skin.controls.scrollarea_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + + if bartype == "vertical" then + skin.OutlinedRectangle(x, y, width, height, true, true) + elseif bartype == "horizontal" then + skin.OutlinedRectangle(x, y, width, height, false, false, true, true) + end + +end + +--[[--------------------------------------------------------- + - func: DrawScrollBar(object) + - desc: draws the scroll bar object +--]]--------------------------------------------------------- +function skin.DrawScrollBar(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local dragging = object:IsDragging() + local hover = object:GetHover() + local bartype = object:GetBarType() + local bodydowncolor = skin.controls.scrollbar_body_down_color + local borderdowncolor = skin.controls.scrollbar_border_down_color + local bodyhovercolor = skin.controls.scrollbar_body_hover_color + local borderhovercolor = skin.controls.scrollbar_border_hover_color + local bodynohvercolor = skin.controls.scrollbar_body_nohover_color + local bordernohovercolor = skin.controls.scrollbar_border_nohover_color + local gradientcolor = {} + + if dragging then + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y, width, height, gradientcolor) + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y, width, height, gradientcolor) + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynohvercolor[1] - 20, bodynohvercolor[2] - 20, bodynohvercolor[3] - 20, 255} + skin.DrawGradient(x, y, width, height, gradientcolor) + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + + if bartype == "vertical" then + love.graphics.setColor(bordernohovercolor) + love.graphics.rectangle("fill", x + 3, y + height/2 - 3, width - 6, 1) + love.graphics.rectangle("fill", x + 3, y + height/2, width - 6, 1) + love.graphics.rectangle("fill", x + 3, y + height/2 + 3, width - 6, 1) + else + love.graphics.setColor(bordernohovercolor) + love.graphics.rectangle("fill", x + width/2 - 3, y + 3, 1, height - 6) + love.graphics.rectangle("fill", x + width/2, y + 3, 1, height - 6) + love.graphics.rectangle("fill", x + width/2 + 3, y + 3, 1, height - 6) + end + +end + +--[[--------------------------------------------------------- + - func: DrawScrollBody(object) + - desc: draws the scroll body object +--]]--------------------------------------------------------- +function skin.DrawScrollBody(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.scrollbody_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawPanel(object) + - desc: draws the panel object +--]]--------------------------------------------------------- +function skin.DrawPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.panel_body_color + local bordercolor = skin.controls.panel_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawList(object) + - desc: draws the list object +--]]--------------------------------------------------------- +function skin.DrawList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.list_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawList(object) + - desc: used to draw over the object and it's children +--]]--------------------------------------------------------- +function skin.DrawOverList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordrcolor = skin.controls.list_border_color + + love.graphics.setColor(bordrcolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawTabPanel(object) + - desc: draws the tab panel object +--]]--------------------------------------------------------- +function skin.DrawTabPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local buttonheight = object:GetHeightOfButtons() + local bodycolor = skin.controls.tabpanel_body_color + local bordercolor = skin.controls.tabpanel_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y + buttonheight, width, height - buttonheight) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y + buttonheight - 1, width, height - buttonheight + 2) + + object:SetScrollButtonSize(15, buttonheight) + +end + +--[[--------------------------------------------------------- + - func: DrawTabButton(object) + - desc: draws the tab button object +--]]--------------------------------------------------------- +function skin.DrawTabButton(object) + + local x = object:GetX() + local y = object:GetY() + local hover = object:GetHover() + local text = object:GetText() + local image = object:GetImage() + local tabnumber = object:GetTabNumber() + local parent = object:GetParent() + local ptabnumber = parent:GetTabNumber() + local font = skin.controls.tab_text_font + local twidth = font:getWidth(object.text) + local theight = font:getHeight(object.text) + local imagewidth = 0 + local imageheight = 0 + local bordercolor = skin.controls.tabpanel_border_color + local bodyhovercolor = skin.controls.button_body_hover_color + local texthovercolor = skin.controls.button_text_hover_color + local bodynohovercolor = skin.controls.button_body_nohover_color + local textnohovercolor = skin.controls.button_text_nohover_color + local gradientcolor = {} + + if image then + image:setFilter("nearest", "nearest") + imagewidth = image:getWidth() + imageheight = image:getHeight() + object.width = imagewidth + 15 + twidth + if imageheight > theight then + parent:SetTabHeight(imageheight + 5) + object.height = imageheight + 5 + else + parent:SetTabHeight(theight + 5) + object.height = theight + 5 + end + else + object.width = 10 + twidth + parent:SetTabHeight(theight + 5) + object.height = theight + 5 + end + + local width = object:GetWidth() + local height = object:GetHeight() + + if tabnumber == ptabnumber then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x, y, width, height) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + if image then + -- button image + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + imagewidth + 10, y + height/2 - theight/2) + else + -- button text + love.graphics.setFont(font) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + 5, y + height/2 - theight/2) + end + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x, y, width, height) + gradientcolor = {bodynohovercolor[1] - 20, bodynohovercolor[2] - 20, bodynohovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + if image then + -- button image + love.graphics.setColor(255, 255, 255, 150) + love.graphics.draw(image, x + 5, y + height/2 - imageheight/2) + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(object.text, x + imagewidth + 10, y + height/2 - theight/2) + else + -- button text + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(object.text, x + 5, y + height/2 - theight/2) + end + end + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoice(object) + - desc: draws the multi choice object +--]]--------------------------------------------------------- +function skin.DrawMultiChoice(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local choice = object:GetChoice() + local image = skin.images["multichoice-arrow.png"] + local font = skin.controls.multichoice_text_font + local theight = font:getHeight("a") + local bodycolor = skin.controls.multichoice_body_color + local textcolor = skin.controls.multichoice_text_color + local bordercolor = skin.controls.multichoice_border_color + + image:setFilter("nearest", "nearest") + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + + love.graphics.setColor(textcolor) + love.graphics.setFont(font) + + if choice == "" then + love.graphics.print(text, x + 5, y + height/2 - theight/2) + else + love.graphics.print(choice, x + 5, y + height/2 - theight/2) + end + + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(image, x + width - 20, y + 5) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoiceList(object) + - desc: draws the multi choice list object +--]]--------------------------------------------------------- +function skin.DrawMultiChoiceList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.multichoicelist_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawOverMultiChoiceList(object) + - desc: draws over the multi choice list object +--]]--------------------------------------------------------- +function skin.DrawOverMultiChoiceList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.multichoicelist_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y - 1, width, height + 1) + +end + +--[[--------------------------------------------------------- + - func: DrawMultiChoiceRow(object) + - desc: draws the multi choice row object +--]]--------------------------------------------------------- +function skin.DrawMultiChoiceRow(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local font = skin.controls.multichoicerow_text_font + local bodyhovecolor = skin.controls.multichoicerow_body_hover_color + local texthovercolor = skin.controls.multichoicerow_text_hover_color + local bodynohovercolor = skin.controls.multichoicerow_body_nohover_color + local textnohovercolor = skin.controls.multichoicerow_text_nohover_color + + love.graphics.setFont(font) + + if object.hover then + love.graphics.setColor(bodyhovecolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(texthovercolor) + love.graphics.print(text, x + 5, y + 5) + else + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(textnohovercolor) + love.graphics.print(text, x + 5, y + 5) + end + +end + +--[[--------------------------------------------------------- + - func: DrawToolTip(object) + - desc: draws the tool tip object +--]]--------------------------------------------------------- +function skin.DrawToolTip(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.tooltip_body_color + local bordercolor = skin.controls.tooltip_border_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawText(object) + - desc: draws the text object +--]]--------------------------------------------------------- +function skin.DrawText(object) + +end + +--[[--------------------------------------------------------- + - func: DrawTextInput(object) + - desc: draws the text input object +--]]--------------------------------------------------------- +function skin.DrawTextInput(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local font = object:GetFont() + local focus = object:GetFocus() + local showindicator = object:GetIndicatorVisibility() + local alltextselected = object:IsAllTextSelected() + local textx = object:GetTextX() + local texty = object:GetTextY() + local text = object:GetText() + local multiline = object:GetMultiLine() + local lines = object:GetLines() + local offsetx = object:GetOffsetX() + local offsety = object:GetOffsetY() + local indicatorx = object:GetIndicatorX() + local indicatory = object:GetIndicatorY() + local vbar = object:HasVerticalScrollBar() + local hbar = object:HasHorizontalScrollBar() + local linenumbers = object:GetLineNumbersEnabled() + local itemwidth = object:GetItemWidth() + local theight = font:getHeight("a") + local bodycolor = skin.controls.textinput_body_color + local textnormalcolor = skin.controls.textinput_text_normal_color + local textselectedcolor = skin.controls.textinput_text_selected_color + local highlightbarcolor = skin.controls.textinput_highlight_bar_color + local indicatorcolor = skin.controls.textinput_indicator_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + if alltextselected then + local bary = 0 + if multiline then + for i=1, #lines do + local twidth = font:getWidth(lines[i]) + love.graphics.setColor(highlightbarcolor) + love.graphics.rectangle("fill", textx, texty + bary, twidth, theight) + bary = bary + theight + end + else + local twidth = font:getWidth(text) + love.graphics.setColor(highlightbarcolor) + love.graphics.rectangle("fill", textx, texty, twidth, theight) + end + end + + if showindicator and focus then + love.graphics.setColor(indicatorcolor) + love.graphics.rectangle("fill", indicatorx, indicatory, 1, theight) + end + + if not multiline then + object:SetTextOffsetY(height/2 - theight/2) + if offsetx ~= 0 then + object:SetTextOffsetX(0) + else + object:SetTextOffsetX(5) + end + else + if vbar then + if offsety ~= 0 then + if hbar then + object:SetTextOffsetY(5) + else + object:SetTextOffsetY(-5) + end + else + object:SetTextOffsetY(5) + end + else + object:SetTextOffsetY(5) + end + + if hbar then + if offsety ~= 0 then + if linenumbers then + local panel = object:GetLineNumbersPanel() + if vbar then + object:SetTextOffsetX(5) + else + object:SetTextOffsetX(-5) + end + else + if vbar then + object:SetTextOffsetX(5) + else + object:SetTextOffsetX(-5) + end + end + else + object:SetTextOffsetX(5) + end + else + object:SetTextOffsetX(5) + end + + end + + textx = object:GetTextX() + texty = object:GetTextY() + + love.graphics.setFont(font) + + if alltextselected then + love.graphics.setColor(textselectedcolor) + else + love.graphics.setColor(textnormalcolor) + end + + if multiline then + for i=1, #lines do + love.graphics.print(lines[i], textx, texty + theight * i - theight) + end + else + love.graphics.print(lines[1], textx, texty) + end + +end + +--[[--------------------------------------------------------- + - func: DrawOverTextInput(object) + - desc: draws over the text input object +--]]--------------------------------------------------------- +function skin.DrawOverTextInput(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.textinput_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: DrawScrollButton(object) + - desc: draws the scroll button object +--]]--------------------------------------------------------- +function skin.DrawScrollButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local scrolltype = object:GetScrollType() + local down = object.down + local bodydowncolor = skin.controls.button_body_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local borderhovercolor = skin.controls.button_border_hover_color + local bodynohovercolor = skin.controls.button_body_nohover_color + local bordernohovercolor = skin.controls.button_border_nohover_color + local gradientcolor = {} + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynohovercolor[1] - 20, bodynohovercolor[2] - 20, bodynohovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + + if scrolltype == "up" then + local image = skin.images["arrow-up.png"] + local imagewidth = image:getWidth() + local imageheight = image:getHeight() + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) + elseif scrolltype == "down" then + local image = skin.images["arrow-down.png"] + local imagewidth = image:getWidth() + local imageheight = image:getHeight() + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) + elseif scrolltype == "left" then + local image = skin.images["arrow-left.png"] + local imagewidth = image:getWidth() + local imageheight = image:getHeight() + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) + elseif scrolltype == "right" then + local image = skin.images["arrow-right.png"] + local imagewidth = image:getWidth() + local imageheight = image:getHeight() + image:setFilter("nearest", "nearest") + if hover then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(255, 255, 255, 150) + end + love.graphics.draw(image, x + width/2 - imagewidth/2, y + height/2 - imageheight/2) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawSlider(object) + - desc: draws the slider object +--]]--------------------------------------------------------- +function skin.DrawSlider(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local slidtype = object:GetSlideType() + local baroutlinecolor = skin.controls.slider_bar_outline_color + local barcolor = skin.controls.slider_bar_color + + if slidtype == "horizontal" then + love.graphics.setColor(baroutlinecolor) + love.graphics.rectangle("fill", x, y + height/2 - 5, width, 10) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x + 5, y + height/2, width - 10, 1) + elseif slidtype == "vertical" then + love.graphics.setColor(baroutlinecolor) + love.graphics.rectangle("fill", x + width/2 - 5, y, 10, height) + love.graphics.setColor(barcolor) + love.graphics.rectangle("fill", x + width/2, y + 5, 1, height - 10) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawSliderButton(object) + - desc: draws the slider button object +--]]--------------------------------------------------------- +function skin.DrawSliderButton(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local down = object.down + local bodydowncolor = skin.controls.button_body_down_color + local borderdowncolor = skin.controls.button_border_down_color + local bodyhovercolor = skin.controls.button_body_hover_color + local borderhovercolor = skin.controls.button_border_down_color + local bodynohvercolor = skin.controls.button_body_nohover_color + local bordernohovercolor = skin.controls.button_border_down_color + local gradientcolor = {} + + if down then + -- button body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height) + elseif hover then + -- button body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(borderhovercolor) + skin.OutlinedRectangle(x, y, width, height) + else + -- button body + love.graphics.setColor(bodynohvercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + gradientcolor = {bodynohvercolor[1] - 20, bodynohvercolor[2] - 20, bodynohvercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- button border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawCheckBox(object) + - desc: draws the check box object +--]]--------------------------------------------------------- +function skin.DrawCheckBox(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetBoxWidth() + local height = object:GetBoxHeight() + local checked = object:GetChecked() + local hover = object:GetHover() + local bodycolor = skin.controls.checkbox_body_color + local bordercolor = skin.controls.checkbox_border_color + local checkcolor = skin.controls.checkbox_check_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + + if checked then + love.graphics.setColor(checkcolor) + love.graphics.rectangle("fill", x + 4, y + 4, width - 8, height - 8) + end + + if hover then + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x + 4, y + 4, width - 8, height - 8) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawCollapsibleCategory(object) + - desc: draws the collapsible category object +--]]--------------------------------------------------------- +function skin.DrawCollapsibleCategory(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local text = object:GetText() + local bodycolor = skin.controls.collapsiblecategory_body_color + local textcolor = skin.controls.collapsiblecategory_text_color + local bordercolor = skin.controls.collapsiblecategory_border_color + local font = smallfont + local gradientcolor = {bodycolor[1] - 20, bodycolor[2] - 20, bodycolor[3] - 20, 255} + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(gradientcolor) + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(text, x + 5, y + 5) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnList(object) + - desc: draws the column list object +--]]--------------------------------------------------------- +function skin.DrawColumnList(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.columnlist_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListHeader(object) + - desc: draws the column list header object +--]]--------------------------------------------------------- +function skin.DrawColumnListHeader(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local hover = object:GetHover() + local name = object:GetName() + local down = object.down + local font = skin.controls.columnlistheader_text_font + local twidth = font:getWidth(object.name) + local theight = font:getHeight(object.name) + local bodydowncolor = skin.controls.columnlistheader_body_down_color + local textdowncolor = skin.controls.columnlistheader_text_down_color + local borderdowncolor = skin.controls.columnlistheader_border_down_color + local bodyhovercolor = skin.controls.columnlistheader_body_hover_color + local textdowncolor = skin.controls.columnlistheader_text_hover_color + local borderdowncolor = skin.controls.columnlistheader_border_down_color + local nohovercolor = skin.controls.columnlistheader_body_nohover_color + local textnohovercolor = skin.controls.columnlistheader_text_nohover_color + local bordernohovercolor = skin.controls.columnlistheader_border_down_color + local gradientcolor = {} + + if down then + -- header body + love.graphics.setColor(bodydowncolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + gradientcolor = {bodydowncolor[1] - 20, bodydowncolor[2] - 20, bodydowncolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + elseif hover then + -- header body + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + gradientcolor = {bodyhovercolor[1] - 20, bodyhovercolor[2] - 20, bodyhovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textdowncolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(borderdowncolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + else + -- header body + love.graphics.setColor(nohovercolor) + love.graphics.rectangle("fill", x + 1, y + 1, width - 1, height - 2) + gradientcolor = {nohovercolor[1] - 20, nohovercolor[2] - 20, nohovercolor[3] - 20, 255} + skin.DrawGradient(x, y - 1, width, height, gradientcolor) + -- header name + love.graphics.setFont(font) + love.graphics.setColor(textnohovercolor) + love.graphics.print(name, x + width/2 - twidth/2, y + height/2 - theight/2) + -- header border + love.graphics.setColor(bordernohovercolor) + skin.OutlinedRectangle(x, y, width, height, false, false, false, true) + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListArea(object) + - desc: draws the column list area object +--]]--------------------------------------------------------- +function skin.DrawColumnListArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.columnlistarea_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawOverColumnListArea(object) + - desc: draws over the column list area object +--]]--------------------------------------------------------- +function skin.DrawOverColumnListArea(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bordercolor = skin.controls.columnlist_border_color + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawColumnListRow(object) + - desc: draws the column list row object +--]]--------------------------------------------------------- +function skin.DrawColumnListRow(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local colorindex = object:GetColorIndex() + local font = object:GetFont() + local columndata = object:GetColumnData() + local textx = object:GetTextX() + local texty = object:GetTextY() + local parent = object:GetParent() + local cwidth, cheight = parent:GetParent():GetColumnSize() + local theight = font:getHeight("a") + local body1color = skin.controls.columnlistrow_body1_color + local border1color = skin.controls.columnlistrow_border1_color + local body2color = skin.controls.columnlistrow_body2_color + local border2color = skin.controls.columnlistrow_border2_color + local textcolor = skin.controls.columnlistrow_text_color + + object:SetTextPos(5, height/2 - theight/2) + + if colorindex == 1 then + love.graphics.setColor(body1color) + love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) + love.graphics.setColor(border1color) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + else + love.graphics.setColor(body2color) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(border2color) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + end + + for k, v in ipairs(columndata) do + love.graphics.setFont(font) + love.graphics.setColor(textcolor) + love.graphics.print(v, x + textx, y + texty) + x = x + cwidth + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawModalBackground(object) + - desc: draws the modal background object +--]]--------------------------------------------------------- +function skin.DrawModalBackground(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local bodycolor = skin.controls.modalbackground_body_color + + love.graphics.setColor(bodycolor) + love.graphics.rectangle("fill", x, y, width, height) + +end + +--[[--------------------------------------------------------- + - func: skin.DrawLineNumbersPanel(object) + - desc: draws the line numbers panel object +--]]--------------------------------------------------------- +function skin.DrawLineNumbersPanel(object) + + local x = object:GetX() + local y = object:GetY() + local width = object:GetWidth() + local height = object:GetHeight() + local offsety = object:GetOffsetY() + local parent = object:GetParent() + local lines = parent:GetLines() + local font = parent:GetFont() + local theight = font:getHeight("a") + local bordercolor = skin.controls.linenumberspanel_border_color + local textcolor = skin.controls.linenumberspanel_text_color + local mody = y + + object:SetWidth(10 + font:getWidth(#lines)) + love.graphics.setFont(font) + + love.graphics.setColor(200, 200, 200, 255) + love.graphics.rectangle("fill", x, y, width, height) + + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height, true, true, true, false) + + for i=1, #lines do + love.graphics.setColor(textcolor) + love.graphics.print(i, object.x + 5, mody - offsety) + mody = mody + theight + end + +end + +--[[--------------------------------------------------------- + - func: skin.DrawNumberBox(object) + - desc: draws the numberbox object +--]]--------------------------------------------------------- +function skin.DrawNumberBox(object) + +end + +-- register the skin loveframes.skins.Register(skin) \ No newline at end of file diff --git a/templates.lua b/templates.lua index d27541c..eaeb631 100644 --- a/templates.lua +++ b/templates.lua @@ -1,175 +1,175 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- templates library -loveframes.templates = {} - --- available templates -loveframes.templates.available = {} - --- objects -loveframes.templates.objects = {} - ---[[--------------------------------------------------------- - - func: AddProperty(templatename, property, value) - - desc: creates a property within the specified template - and assigns it to the specified object ---]]--------------------------------------------------------- -function loveframes.templates.AddProperty(templatename, object, property, value) - - -- display an error if name is nil or false - if not templatename then - loveframes.util.Error("Could not create property: No template name given.") - end - - -- display an error if property is nil or false - if not property then - loveframes.util.Error("Could not create property: No property name given.") - end - - local templatename = tostring(templatename) - local property = tostring(property) - local templates = loveframes.templates.available - local template = templates[templatename] - - -- display an error message if the property is not a string - if type(property) ~= "string" then - loveframes.util.Error("Could not create property: Property names must be strings.") - end - - -- display an error message if the property is an empty string - if property == "" then - loveframes.util.Error("Could not create property: Property names must not be empty.") - end - - -- display an error message if the template is invalid - if not template then - loveframes.util.Error("Could not add property '" ..property.. "' to template '" ..templatename.. "': Invalid template.") - end - - local properties = template.properties - local object = properties[object] - - if not object then - loveframes.util.Error("Could not add property '" ..property.. "' to template '" ..templatename.. "': Invalid object.") - end - - -- create the property within the template - object[property] = value - -end - ---[[--------------------------------------------------------- - - func: Register(template) - - desc: registers a template ---]]--------------------------------------------------------- -function loveframes.templates.Register(template) - - -- display and error message if template is nil or false - if not template then - loveframes.util.Error("Could not register template: Missing template argument.") - end - - -- display an error message if template is not a table - if type(template) ~= "table" then - loveframes.util.Error("Could not register template: Template argument must be a table.") - end - - local templates = loveframes.templates.available - local registeredobjects = loveframes.templates.objects - local name = template.name - local properties = template.properties - local objects = loveframes.objects - local base = objects["base"] - local found = false - local foundall = false - - -- display an error message if a template name was not given - if not name then - loveframes.util.Error("Could not register template: No template name given.") - end - - if name == "Base" then - base:include(template.properties["*"]) - end - - -- insert the template into the available templates table - templates[name] = template - -end - ---[[--------------------------------------------------------- - - func: Get(name) - - desc: gets a template ---]]--------------------------------------------------------- -function loveframes.templates.Get(name) - - -- display and error if name is nil or false - if not name then - loveframes.util.Error("Could not create property: No template name given.") - end - - local name = tostring(name) - local templates = loveframes.templates.available - local template = templates[name] - - -- display an error message if the template is invalid - if not template then - loveframes.util.Error("Could not get template: Invalid template.") - end - - -- return the template - return template - -end - ---[[--------------------------------------------------------- - - func: GetAvailable() - - desc: gets all available templates ---]]--------------------------------------------------------- -function loveframes.templates.GetAvailable() - - -- available templates - local templates = loveframes.templates.available - - -- return the templates - return templates - -end - ---[[--------------------------------------------------------- - - func: loveframes.templates.ApplyToObject(object) - - desc: applies the properties of registered templates - to an object ---]]--------------------------------------------------------- -function loveframes.templates.ApplyToObject(object) - - local templates = loveframes.templates.GetAvailable() - local type = object.type - - -- loop through all available templates - for k, v in pairs(templates) do - -- make sure the base template doesn't get applied more than once - if k ~= "Base" then - local properties = v.properties - local hasall = loveframes.util.TableHasKey(properties, "*") - local hasobject = false - if not hasall then - hasobject = loveframes.util.TableHasKey(properties, type) - end - if hasall then - for k, v in pairs(properties["*"]) do - object[k] = v - end - elseif hasobject then - -- apply the template properties to the object - for k, v in pairs(properties[type]) do - object[k] = v - end - end - end - end - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- templates library +loveframes.templates = {} + +-- available templates +loveframes.templates.available = {} + +-- objects +loveframes.templates.objects = {} + +--[[--------------------------------------------------------- + - func: AddProperty(templatename, property, value) + - desc: creates a property within the specified template + and assigns it to the specified object +--]]--------------------------------------------------------- +function loveframes.templates.AddProperty(templatename, object, property, value) + + -- display an error if name is nil or false + if not templatename then + loveframes.util.Error("Could not create property: No template name given.") + end + + -- display an error if property is nil or false + if not property then + loveframes.util.Error("Could not create property: No property name given.") + end + + local templatename = tostring(templatename) + local property = tostring(property) + local templates = loveframes.templates.available + local template = templates[templatename] + + -- display an error message if the property is not a string + if type(property) ~= "string" then + loveframes.util.Error("Could not create property: Property names must be strings.") + end + + -- display an error message if the property is an empty string + if property == "" then + loveframes.util.Error("Could not create property: Property names must not be empty.") + end + + -- display an error message if the template is invalid + if not template then + loveframes.util.Error("Could not add property '" ..property.. "' to template '" ..templatename.. "': Invalid template.") + end + + local properties = template.properties + local object = properties[object] + + if not object then + loveframes.util.Error("Could not add property '" ..property.. "' to template '" ..templatename.. "': Invalid object.") + end + + -- create the property within the template + object[property] = value + +end + +--[[--------------------------------------------------------- + - func: Register(template) + - desc: registers a template +--]]--------------------------------------------------------- +function loveframes.templates.Register(template) + + -- display and error message if template is nil or false + if not template then + loveframes.util.Error("Could not register template: Missing template argument.") + end + + -- display an error message if template is not a table + if type(template) ~= "table" then + loveframes.util.Error("Could not register template: Template argument must be a table.") + end + + local templates = loveframes.templates.available + local registeredobjects = loveframes.templates.objects + local name = template.name + local properties = template.properties + local objects = loveframes.objects + local base = objects["base"] + local found = false + local foundall = false + + -- display an error message if a template name was not given + if not name then + loveframes.util.Error("Could not register template: No template name given.") + end + + if name == "Base" then + base:include(template.properties["*"]) + end + + -- insert the template into the available templates table + templates[name] = template + +end + +--[[--------------------------------------------------------- + - func: Get(name) + - desc: gets a template +--]]--------------------------------------------------------- +function loveframes.templates.Get(name) + + -- display and error if name is nil or false + if not name then + loveframes.util.Error("Could not create property: No template name given.") + end + + local name = tostring(name) + local templates = loveframes.templates.available + local template = templates[name] + + -- display an error message if the template is invalid + if not template then + loveframes.util.Error("Could not get template: Invalid template.") + end + + -- return the template + return template + +end + +--[[--------------------------------------------------------- + - func: GetAvailable() + - desc: gets all available templates +--]]--------------------------------------------------------- +function loveframes.templates.GetAvailable() + + -- available templates + local templates = loveframes.templates.available + + -- return the templates + return templates + +end + +--[[--------------------------------------------------------- + - func: loveframes.templates.ApplyToObject(object) + - desc: applies the properties of registered templates + to an object +--]]--------------------------------------------------------- +function loveframes.templates.ApplyToObject(object) + + local templates = loveframes.templates.GetAvailable() + local type = object.type + + -- loop through all available templates + for k, v in pairs(templates) do + -- make sure the base template doesn't get applied more than once + if k ~= "Base" then + local properties = v.properties + local hasall = loveframes.util.TableHasKey(properties, "*") + local hasobject = false + if not hasall then + hasobject = loveframes.util.TableHasKey(properties, type) + end + if hasall then + for k, v in pairs(properties["*"]) do + object[k] = v + end + elseif hasobject then + -- apply the template properties to the object + for k, v in pairs(properties[type]) do + object[k] = v + end + end + end + end + end \ No newline at end of file diff --git a/templates/base.lua b/templates/base.lua index d582689..c6ec067 100644 --- a/templates/base.lua +++ b/templates/base.lua @@ -1 +1 @@ ---[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- -- Copyright (c) 2012 Kenny Shields -- --]]------------------------------------------------ --[[------------------------------------------------ -- note: This is the base template for all Love Frames objects. You should not edit or delete this template unless you know what you are doing. --]]------------------------------------------------ -- template table local template = {} -- template name template.name = "Base" -- template properties template.properties = {} template.properties["*"] = { x = 0, y = 0, width = 5, height = 5, staticx = 0, staticy = 0, draworder = 0, internal = false, visible = true, hover = false, alwaysupdate = false, retainsize = false, calledmousefunc = false, skin = nil, clickbounds = nil, Draw = nil, Update = nil, OnMouseEnter = nil, OnMouseExit = nil } -- register the template loveframes.templates.Register(template) \ No newline at end of file +--[[------------------------------------------------ -- Love Frames - A GUI library for LOVE -- -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --[[------------------------------------------------ -- note: This is the base template for all Love Frames objects. You should not edit or delete this template unless you know what you are doing. --]]------------------------------------------------ -- template table local template = {} -- template name template.name = "Base" -- template properties template.properties = {} template.properties["*"] = { state = "none", x = 0, y = 0, width = 5, height = 5, staticx = 0, staticy = 0, draworder = 0, internal = false, visible = true, hover = false, alwaysupdate = false, retainsize = false, calledmousefunc = false, skin = nil, clickbounds = nil, Draw = nil, Update = nil, OnMouseEnter = nil, OnMouseExit = nil } -- register the template loveframes.templates.Register(template) \ No newline at end of file diff --git a/util.lua b/util.lua index 8b50c14..d74c435 100644 --- a/util.lua +++ b/util.lua @@ -1,280 +1,282 @@ ---[[------------------------------------------------ - -- Love Frames - A GUI library for LOVE -- - -- Copyright (c) 2012 Kenny Shields -- ---]]------------------------------------------------ - --- util library -loveframes.util = {} - ---[[--------------------------------------------------------- - - func: SetActiveSkin(name) - - desc: sets the active skin ---]]--------------------------------------------------------- -function loveframes.util.SetActiveSkin(name) - - loveframes.config["ACTIVESKIN"] = name - -end - ---[[--------------------------------------------------------- - - func: GetActiveSkin() - - desc: gets the active skin ---]]--------------------------------------------------------- -function loveframes.util.GetActiveSkin() - - local index = loveframes.config["ACTIVESKIN"] - local skin = loveframes.skins.available[index] - - return skin - -end - ---[[--------------------------------------------------------- - - func: BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2) - - desc: checks for a collision between two boxes - - note: i take no credit for this function ---]]--------------------------------------------------------- -function loveframes.util.BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2) - - if x1 > x2 + w2 - 1 or y1 > y2 + h2 - 1 or x2 > x1 + w1 - 1 or y2 > y1 + h1 - 1 then - return false - else - return true - end - -end - ---[[--------------------------------------------------------- - - func: loveframes.util.GetCollisions(object, table) - - desc: gets all objects colliding with the mouse ---]]--------------------------------------------------------- -function loveframes.util.GetCollisions(object, t) - - local x, y = love.mouse.getPosition() - local object = object or loveframes.base - local t = t or {} - - -- add the current object if colliding - if object.visible == true then - local col = loveframes.util.BoundingBox(x, object.x, y, object.y, 1, object.width, 1, object.height) - if col == true and object.collide ~= false then - if object.clickbounds then - local clickcol = loveframes.util.BoundingBox(x, object.clickbounds.x, y, object.clickbounds.y, 1, object.clickbounds.width, 1, object.clickbounds.height) - if clickcol then - table.insert(t, object) - end - else - table.insert(t, object) - end - end - end - - -- check for children - if object.children then - for k, v in ipairs(object.children) do - if v.visible then - loveframes.util.GetCollisions(v, t) - end - end - end - - -- check for internals - if object.internals then - for k, v in ipairs(object.internals) do - if v.visible and v.type ~= "tooltip" then - loveframes.util.GetCollisions(v, t) - end - end - end - - return t - -end - ---[[--------------------------------------------------------- - - func: loveframes.util.GetAllObjects(object, table) - - desc: gets all active objects ---]]--------------------------------------------------------- -function loveframes.util.GetAllObjects(object, t) - - local object = object or loveframes.base - local t = t or {} - - table.insert(t, object) - - if object.internals then - for k, v in ipairs(object.internals) do - loveframes.util.GetAllObjects(v, t) - end - end - - if object.children then - for k, v in ipairs(object.children) do - loveframes.util.GetAllObjects(v, t) - end - end - - return t - -end - ---[[--------------------------------------------------------- - - func: GetDirectoryContents(directory, table) - - desc: gets the contents of a directory and all of - it's subdirectories ---]]--------------------------------------------------------- -function loveframes.util.GetDirectoryContents(dir, t) - - local dir = dir - local t = t or {} - local files = love.filesystem.enumerate(dir) - local dirs = {} - - for k, v in ipairs(files) do - local isdir = love.filesystem.isDirectory(dir.. "/" ..v) - if isdir == true then - table.insert(dirs, dir.. "/" ..v) - else - local parts = loveframes.util.SplitString(v, "([.])") - local extension = parts[#parts] - parts[#parts] = nil - local name = table.concat(parts) - table.insert(t, {path = dir, fullpath = dir.. "/" ..v, requirepath = dir .. "." ..name, name = name, extension = extension}) - end - end - - if #dirs > 0 then - for k, v in ipairs(dirs) do - t = loveframes.util.GetDirectoryContents(v, t) - end - end - - return t - -end - - ---[[--------------------------------------------------------- - - func: Round(num, idp) - - desc: rounds a number based on the decimal limit - - note: i take no credit for this function ---]]--------------------------------------------------------- -function loveframes.util.Round(num, idp) - - local mult = 10^(idp or 0) - - if num >= 0 then - return math.floor(num * mult + 0.5) / mult - else - return math.ceil(num * mult - 0.5) / mult - end - -end - ---[[--------------------------------------------------------- - - func: SplitString(string, pattern) - - desc: splits a string into a table based on a given pattern - - note: i take no credit for this function ---]]--------------------------------------------------------- -function loveframes.util.SplitString(str, pat) - - local t = {} -- NOTE: use {n = 0} in Lua-5.0 - - if pat == " " then - local fpat = "(.-)" .. pat - local last_end = 1 - local s, e, cap = str:find(fpat, 1) - while s do - if s ~= #str then - cap = cap .. " " - end - if s ~= 1 or cap ~= "" then - table.insert(t,cap) - end - last_end = e+1 - s, e, cap = str:find(fpat, last_end) - end - if last_end <= #str then - cap = str:sub(last_end) - table.insert(t, cap) - end - else - local fpat = "(.-)" .. pat - local last_end = 1 - local s, e, cap = str:find(fpat, 1) - while s do - if s ~= 1 or cap ~= "" then - table.insert(t,cap) - end - last_end = e+1 - s, e, cap = str:find(fpat, last_end) - end - if last_end <= #str then - cap = str:sub(last_end) - table.insert(t, cap) - end - end - - return t - -end - ---[[--------------------------------------------------------- - - func: RemoveAll() - - desc: removes all gui elements ---]]--------------------------------------------------------- -function loveframes.util.RemoveAll() - - loveframes.base.children = {} - loveframes.base.internals = {} - -end - ---[[--------------------------------------------------------- - - func: loveframes.util.TableHasKey(table, key) - - desc: checks to see if a table has a specific key ---]]--------------------------------------------------------- -function loveframes.util.TableHasKey(table, key) - - local haskey = false - - for k, v in pairs(table) do - if k == key then - haskey = true - break - end - end - - return haskey - -end - ---[[--------------------------------------------------------- - - func: loveframes.util.Error(message) - - desc: displays a formatted error message ---]]--------------------------------------------------------- -function loveframes.util.Error(message) - - error("[Love Frames] " ..message) - -end - ---[[--------------------------------------------------------- - - func: loveframes.util.CheckForUpdates() - - desc: checks for more recent versions of Love Frames ---]]--------------------------------------------------------- -function loveframes.util.CheckForUpdates() - - local info = loveframes.info - local version = info.version - local stage = info.stage - local socket = require("socket.http") - local b, c, h = socket.request("http://update.nikolairesokav.com/?id=loveframes&version=" ..version.. "&stage=" ..stage) - - if c == 200 then - return b - else - return "An error occurred while checking for updates. Please try again later." - end - +--[[------------------------------------------------ + -- Love Frames - A GUI library for LOVE -- + -- Copyright (c) 2013 Kenny Shields -- +--]]------------------------------------------------ + +-- util library +loveframes.util = {} + +--[[--------------------------------------------------------- + - func: SetActiveSkin(name) + - desc: sets the active skin +--]]--------------------------------------------------------- +function loveframes.util.SetActiveSkin(name) + + loveframes.config["ACTIVESKIN"] = name + +end + +--[[--------------------------------------------------------- + - func: GetActiveSkin() + - desc: gets the active skin +--]]--------------------------------------------------------- +function loveframes.util.GetActiveSkin() + + local index = loveframes.config["ACTIVESKIN"] + local skin = loveframes.skins.available[index] + + return skin + +end + +--[[--------------------------------------------------------- + - func: BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2) + - desc: checks for a collision between two boxes + - note: i take no credit for this function +--]]--------------------------------------------------------- +function loveframes.util.BoundingBox(x1, x2, y1, y2, w1, w2, h1, h2) + + if x1 > x2 + w2 - 1 or y1 > y2 + h2 - 1 or x2 > x1 + w1 - 1 or y2 > y1 + h1 - 1 then + return false + else + return true + end + +end + +--[[--------------------------------------------------------- + - func: loveframes.util.GetCollisions(object, table) + - desc: gets all objects colliding with the mouse +--]]--------------------------------------------------------- +function loveframes.util.GetCollisions(object, t) + + local x, y = love.mouse.getPosition() + local object = object or loveframes.base + local t = t or {} + + -- add the current object if colliding + if object.visible == true then + local col = loveframes.util.BoundingBox(x, object.x, y, object.y, 1, object.width, 1, object.height) + if col == true and object.collide ~= false then + if object.clickbounds then + local clickcol = loveframes.util.BoundingBox(x, object.clickbounds.x, y, object.clickbounds.y, 1, object.clickbounds.width, 1, object.clickbounds.height) + if clickcol then + table.insert(t, object) + end + else + table.insert(t, object) + end + end + end + + -- check for children + if object.children then + for k, v in ipairs(object.children) do + if v.visible then + loveframes.util.GetCollisions(v, t) + end + end + end + + -- check for internals + if object.internals then + for k, v in ipairs(object.internals) do + if v.visible and v.type ~= "tooltip" then + loveframes.util.GetCollisions(v, t) + end + end + end + + return t + +end + +--[[--------------------------------------------------------- + - func: loveframes.util.GetAllObjects(object, table) + - desc: gets all active objects +--]]--------------------------------------------------------- +function loveframes.util.GetAllObjects(object, t) + + local object = object or loveframes.base + local internals = object.internals + local children = object.children + local t = t or {} + + table.insert(t, object) + + if internals then + for k, v in ipairs(internals) do + loveframes.util.GetAllObjects(v, t) + end + end + + if children then + for k, v in ipairs(children) do + loveframes.util.GetAllObjects(v, t) + end + end + + return t + +end + +--[[--------------------------------------------------------- + - func: GetDirectoryContents(directory, table) + - desc: gets the contents of a directory and all of + it's subdirectories +--]]--------------------------------------------------------- +function loveframes.util.GetDirectoryContents(dir, t) + + local dir = dir + local t = t or {} + local files = love.filesystem.enumerate(dir) + local dirs = {} + + for k, v in ipairs(files) do + local isdir = love.filesystem.isDirectory(dir.. "/" ..v) + if isdir == true then + table.insert(dirs, dir.. "/" ..v) + else + local parts = loveframes.util.SplitString(v, "([.])") + local extension = parts[#parts] + parts[#parts] = nil + local name = table.concat(parts) + table.insert(t, {path = dir, fullpath = dir.. "/" ..v, requirepath = dir .. "." ..name, name = name, extension = extension}) + end + end + + if #dirs > 0 then + for k, v in ipairs(dirs) do + t = loveframes.util.GetDirectoryContents(v, t) + end + end + + return t + +end + + +--[[--------------------------------------------------------- + - func: Round(num, idp) + - desc: rounds a number based on the decimal limit + - note: i take no credit for this function +--]]--------------------------------------------------------- +function loveframes.util.Round(num, idp) + + local mult = 10^(idp or 0) + + if num >= 0 then + return math.floor(num * mult + 0.5) / mult + else + return math.ceil(num * mult - 0.5) / mult + end + +end + +--[[--------------------------------------------------------- + - func: SplitString(string, pattern) + - desc: splits a string into a table based on a given pattern + - note: i take no credit for this function +--]]--------------------------------------------------------- +function loveframes.util.SplitString(str, pat) + + local t = {} -- NOTE: use {n = 0} in Lua-5.0 + + if pat == " " then + local fpat = "(.-)" .. pat + local last_end = 1 + local s, e, cap = str:find(fpat, 1) + while s do + if s ~= #str then + cap = cap .. " " + end + if s ~= 1 or cap ~= "" then + table.insert(t,cap) + end + last_end = e+1 + s, e, cap = str:find(fpat, last_end) + end + if last_end <= #str then + cap = str:sub(last_end) + table.insert(t, cap) + end + else + local fpat = "(.-)" .. pat + local last_end = 1 + local s, e, cap = str:find(fpat, 1) + while s do + if s ~= 1 or cap ~= "" then + table.insert(t,cap) + end + last_end = e+1 + s, e, cap = str:find(fpat, last_end) + end + if last_end <= #str then + cap = str:sub(last_end) + table.insert(t, cap) + end + end + + return t + +end + +--[[--------------------------------------------------------- + - func: RemoveAll() + - desc: removes all gui elements +--]]--------------------------------------------------------- +function loveframes.util.RemoveAll() + + loveframes.base.children = {} + loveframes.base.internals = {} + +end + +--[[--------------------------------------------------------- + - func: loveframes.util.TableHasKey(table, key) + - desc: checks to see if a table has a specific key +--]]--------------------------------------------------------- +function loveframes.util.TableHasKey(table, key) + + local haskey = false + + for k, v in pairs(table) do + if k == key then + haskey = true + break + end + end + + return haskey + +end + +--[[--------------------------------------------------------- + - func: loveframes.util.Error(message) + - desc: displays a formatted error message +--]]--------------------------------------------------------- +function loveframes.util.Error(message) + + error("[Love Frames] " ..message) + +end + +--[[--------------------------------------------------------- + - func: loveframes.util.CheckForUpdates() + - desc: checks for more recent versions of Love Frames +--]]--------------------------------------------------------- +function loveframes.util.CheckForUpdates() + + local info = loveframes.info + local version = info.version + local stage = info.stage + local socket = require("socket.http") + local b, c, h = socket.request("http://update.nikolairesokav.com/?id=loveframes&version=" ..version.. "&stage=" ..stage) + + if c == 200 then + return b + else + return "An error occurred while checking for updates. Please try again later." + end + end \ No newline at end of file