Initial release
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
##########################################################################################
|
||||
# VSTGUI GFXTest Application
|
||||
##########################################################################################
|
||||
set(target GFXTest)
|
||||
|
||||
set(${target}_sources
|
||||
"source/app.cpp"
|
||||
"source/drawdevicetests.cpp"
|
||||
"source/drawdevicetests.h"
|
||||
)
|
||||
|
||||
set(${target}_resources
|
||||
"resource/Window.uidesc"
|
||||
"resource/DrawDeviceTests.uidesc"
|
||||
)
|
||||
|
||||
vstgui_add_executable(${target} "${${target}_sources}")
|
||||
vstgui_add_resources(${target} "${${target}_resources}")
|
||||
vstgui_set_target_bundle_id(${target} "vstgui.tests.gfxtest")
|
||||
vstgui_set_target_infoplist(${target} "resource/Info.plist")
|
||||
vstgui_set_target_rcfile(${target} "resource/gfxtest.rc")
|
||||
vstgui_set_cxx_version(${target} ${VSTGUI_CXX_VERSION})
|
||||
target_include_directories(${target} PRIVATE ../../../)
|
||||
set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} FOLDER Tests)
|
||||
|
||||
+301
@@ -0,0 +1,301 @@
|
||||
{
|
||||
"vstgui-ui-description": {
|
||||
"version": "1",
|
||||
"variables": {},
|
||||
"bitmaps": {},
|
||||
"fonts": {},
|
||||
"colors": {
|
||||
"background": "#c6c6c6ff",
|
||||
"halfwhite": "#ffffff94"
|
||||
},
|
||||
"gradients": {
|
||||
"Default TextButton Gradient": [
|
||||
{
|
||||
"rgba": "#dcdcdcff",
|
||||
"start": "0"
|
||||
},
|
||||
{
|
||||
"rgba": "#b4b4b4ff",
|
||||
"start": "1"
|
||||
}
|
||||
],
|
||||
"Default TextButton Gradient Highlighted": [
|
||||
{
|
||||
"rgba": "#b4b4b4ff",
|
||||
"start": "0"
|
||||
},
|
||||
{
|
||||
"rgba": "#646464ff",
|
||||
"start": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"control-tags": {
|
||||
"ViewSelector": "0"
|
||||
},
|
||||
"custom": {
|
||||
"UIGridController": {
|
||||
"Grids": "1x 1,5x 5,10x 10,12x 12,15x 15",
|
||||
"Size": "10, 10"
|
||||
},
|
||||
"UITemplateController": {
|
||||
"SelectedTemplate": "Window"
|
||||
},
|
||||
"UIEditController": {
|
||||
"EditViewScale": "1",
|
||||
"EditorSize": "0, 0, 673, 618",
|
||||
"SplitViewSize_0_0": "0.7820945945945946276012250564235728234053",
|
||||
"SplitViewSize_0_1": "0.1841216216216216283729778524502762593329",
|
||||
"SplitViewSize_1_0": "0.4966216216216216006174022368213627487421",
|
||||
"SplitViewSize_1_1": "0.4966216216216216006174022368213627487421",
|
||||
"SplitViewSize_2_0": "0.6196136701337295882296984927961602807045",
|
||||
"SplitViewSize_2_1": "0.3729569093610698438112649455433711409569",
|
||||
"TabSwitchValue": "1",
|
||||
"Version": "1"
|
||||
},
|
||||
"UIAttributesController": {},
|
||||
"UIViewCreatorDataSource": {
|
||||
"SelectedRow": "28"
|
||||
},
|
||||
"UIGradientsDataSource": {
|
||||
"SelectedRow": "-1"
|
||||
},
|
||||
"UIBitmapsDataSource": {
|
||||
"SelectedRow": "-1"
|
||||
},
|
||||
"UIColorsDataSource": {
|
||||
"SelectedRow": "0"
|
||||
},
|
||||
"UITagsDataSource": {
|
||||
"SelectedRow": "-1"
|
||||
},
|
||||
"UIDescFilePath": {
|
||||
"path": "/Users/scheffle/Source/vstgui/vstgui/tests/gfxtest/resource/DrawDeviceTests.uidesc"
|
||||
}
|
||||
},
|
||||
"templates": {
|
||||
"Window": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "background",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "300, 300",
|
||||
"sub-controller": "ViewCreator",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CSegmentButton": {
|
||||
"attributes": {
|
||||
"autosize": "left right top ",
|
||||
"class": "CSegmentButton",
|
||||
"control-tag": "ViewSelector",
|
||||
"default-value": "0.5",
|
||||
"font": "~ NormalFont",
|
||||
"frame-color": "~ BlackCColor",
|
||||
"frame-width": "1",
|
||||
"gradient": "Default TextButton Gradient",
|
||||
"gradient-highlighted": "Default TextButton Gradient Highlighted",
|
||||
"icon-text-margin": "0",
|
||||
"max-value": "1",
|
||||
"min-value": "0",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "10, 10",
|
||||
"round-radius": "5",
|
||||
"segment-names": "Lines/Rects,BitmapFilter,InvalidRects",
|
||||
"selection-mode": "Single",
|
||||
"size": "280, 20",
|
||||
"style": "horizontal",
|
||||
"text-alignment": "center",
|
||||
"text-color": "~ BlackCColor",
|
||||
"text-color-highlighted": "~ WhiteCColor",
|
||||
"transparent": "false",
|
||||
"wants-focus": "true",
|
||||
"wheel-inc-value": "0.1"
|
||||
}
|
||||
},
|
||||
"UIViewSwitchContainer": {
|
||||
"attributes": {
|
||||
"animation-style": "fade",
|
||||
"animation-time": "80",
|
||||
"animation-timing-function": "linear",
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ BlackCColor",
|
||||
"background-color-draw-style": "stroked",
|
||||
"class": "UIViewSwitchContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "10, 40",
|
||||
"size": "280, 250",
|
||||
"template-names": "Rects,BitmapFilter,InvalidRegion",
|
||||
"template-switch-control": "ViewSelector",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CScrollView": {
|
||||
"attributes": {
|
||||
"auto-drag-scrolling": "false",
|
||||
"auto-hide-scrollbars": "false",
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "halfwhite",
|
||||
"background-color-draw-style": "filled",
|
||||
"bordered": "true",
|
||||
"class": "CScrollView",
|
||||
"container-size": "500, 500",
|
||||
"follow-focus-view": "false",
|
||||
"horizontal-scrollbar": "true",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"overlay-scrollbars": "false",
|
||||
"scrollbar-background-color": "#ffffffc8",
|
||||
"scrollbar-frame-color": "~ BlackCColor",
|
||||
"scrollbar-scroller-color": "~ BlueCColor",
|
||||
"scrollbar-width": "16",
|
||||
"size": "280, 250",
|
||||
"template": "Rects",
|
||||
"transparent": "false",
|
||||
"vertical-scrollbar": "true",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Rects": {
|
||||
"attributes": {
|
||||
"auto-drag-scrolling": "false",
|
||||
"auto-hide-scrollbars": "false",
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "halfwhite",
|
||||
"background-color-draw-style": "filled",
|
||||
"bordered": "true",
|
||||
"class": "CScrollView",
|
||||
"container-size": "500, 500",
|
||||
"follow-focus-view": "false",
|
||||
"horizontal-scrollbar": "true",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"overlay-scrollbars": "false",
|
||||
"scrollbar-background-color": "#ffffffc8",
|
||||
"scrollbar-frame-color": "~ BlackCColor",
|
||||
"scrollbar-scroller-color": "~ BlueCColor",
|
||||
"scrollbar-width": "16",
|
||||
"size": "400, 400",
|
||||
"transparent": "false",
|
||||
"vertical-scrollbar": "true",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CView": {
|
||||
"attributes": {
|
||||
"class": "CView",
|
||||
"custom-view-name": "RectsView",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "500, 500",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"InvalidRegion": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ BlackCColor",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "true",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CView": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"class": "CView",
|
||||
"custom-view-name": "InvalidRegionView",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"BitmapFilter": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ BlackCColor",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "true",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CView": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"class": "CView",
|
||||
"custom-view-name": "BitmapsFilterView",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"BitmapFilter": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ BlackCColor",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "true",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CView": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"class": "CView",
|
||||
"custom-view-name": "BitmapsFilterView",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "400, 400",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>GFXTest</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>GFXTest</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2016 Arne Scheffler. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1 @@
|
||||
BNDL????
|
||||
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"vstgui-ui-description": {
|
||||
"version": "1",
|
||||
"variables": {},
|
||||
"bitmaps": {},
|
||||
"fonts": {},
|
||||
"colors": {},
|
||||
"gradients": {
|
||||
"Default TextButton Gradient": [
|
||||
{
|
||||
"rgba": "#dcdcdcff",
|
||||
"start": "0"
|
||||
},
|
||||
{
|
||||
"rgba": "#b4b4b4ff",
|
||||
"start": "1"
|
||||
}
|
||||
],
|
||||
"Default TextButton Gradient Highlighted": [
|
||||
{
|
||||
"rgba": "#b4b4b4ff",
|
||||
"start": "0"
|
||||
},
|
||||
{
|
||||
"rgba": "#646464ff",
|
||||
"start": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"control-tags": {
|
||||
"ShowDrawDeviceTests": "0"
|
||||
},
|
||||
"custom": {
|
||||
"UIDescFilePath": {
|
||||
"path": "/Users/scheffle/Source/vstgui/vstgui/tests/gfxtest/resource/Window.uidesc"
|
||||
},
|
||||
"UIGridController": {
|
||||
"Grids": "1x 1,5x 5,10x 10,12x 12,15x 15",
|
||||
"Size": "10, 10"
|
||||
},
|
||||
"UITemplateController": {
|
||||
"SelectedTemplate": "Window"
|
||||
},
|
||||
"UIEditController": {
|
||||
"EditViewScale": "1",
|
||||
"EditorSize": "0, 0, 500, 500",
|
||||
"SplitViewSize_0_0": "0.7278481012658227777833985783217940479517",
|
||||
"SplitViewSize_0_1": "0.2299578059071729907447689811306190676987",
|
||||
"SplitViewSize_1_0": "0.4662447257383966481292247863166267052293",
|
||||
"SplitViewSize_1_1": "0.523206751054852370330650046525988727808",
|
||||
"SplitViewSize_2_0": "0.6400000000000000133226762955018784850836",
|
||||
"SplitViewSize_2_1": "0.3499999999999999777955395074968691915274",
|
||||
"TabSwitchValue": "0",
|
||||
"Version": "1"
|
||||
},
|
||||
"UIAttributesController": {
|
||||
"UIAttributesController": "tag"
|
||||
},
|
||||
"UIViewCreatorDataSource": {
|
||||
"SelectedRow": "23"
|
||||
},
|
||||
"UITagsDataSource": {
|
||||
"SelectedRow": "-1"
|
||||
}
|
||||
},
|
||||
"templates": {
|
||||
"Window": {
|
||||
"attributes": {
|
||||
"autosize": "left right top bottom ",
|
||||
"background-color": "~ GreyCColor",
|
||||
"background-color-draw-style": "filled and stroked",
|
||||
"class": "CViewContainer",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "0, 0",
|
||||
"size": "300, 300",
|
||||
"transparent": "false",
|
||||
"wants-focus": "false"
|
||||
},
|
||||
"children": {
|
||||
"CTextButton": {
|
||||
"attributes": {
|
||||
"background-offset": "0, 0",
|
||||
"class": "CTextButton",
|
||||
"control-tag": "ShowDrawDeviceTests",
|
||||
"default-value": "0.5",
|
||||
"font": "~ SystemFont",
|
||||
"frame-color": "~ BlackCColor",
|
||||
"frame-color-highlighted": "~ BlackCColor",
|
||||
"frame-width": "1",
|
||||
"gradient": "Default TextButton Gradient",
|
||||
"gradient-highlighted": "Default TextButton Gradient Highlighted",
|
||||
"icon-position": "left",
|
||||
"icon-text-margin": "0",
|
||||
"kick-style": "false",
|
||||
"max-value": "1",
|
||||
"min-value": "0",
|
||||
"mouse-enabled": "true",
|
||||
"opacity": "1",
|
||||
"origin": "10, 10",
|
||||
"round-radius": "6",
|
||||
"size": "190, 20",
|
||||
"text-alignment": "center",
|
||||
"text-color": "~ BlackCColor",
|
||||
"text-color-highlighted": "~ WhiteCColor",
|
||||
"title": "Show DrawDevice Tests",
|
||||
"transparent": "false",
|
||||
"wants-focus": "true",
|
||||
"wheel-inc-value": "0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,59 @@
|
||||
// This file is part of VSTGUI. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this
|
||||
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
|
||||
|
||||
#include "drawdevicetests.h"
|
||||
#include "vstgui/standalone/include/helpers/appdelegate.h"
|
||||
#include "vstgui/standalone/include/helpers/uidesc/modelbinding.h"
|
||||
#include "vstgui/standalone/include/helpers/value.h"
|
||||
#include "vstgui/standalone/include/helpers/windowlistener.h"
|
||||
#include "vstgui/standalone/include/iapplication.h"
|
||||
#include "vstgui/standalone/include/iuidescwindow.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
namespace Standalone {
|
||||
|
||||
using namespace Application;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class GFXTestApp : public DelegateAdapter, public WindowListenerAdapter
|
||||
{
|
||||
public:
|
||||
GFXTestApp () : DelegateAdapter ({"gfxtest", "1.0.0", "vstgui.tests.gfxtest"}) {}
|
||||
|
||||
void finishLaunching () override
|
||||
{
|
||||
auto modelBinding = UIDesc::ModelBindingCallbacks::make ();
|
||||
modelBinding->addValue (Value::make ("ShowDrawDeviceTests"),
|
||||
UIDesc::ValueCalls::onAction ([] (auto& value) {
|
||||
makeDrawDeviceTestsWindow ();
|
||||
value.performEdit (0.);
|
||||
}));
|
||||
|
||||
UIDesc::Config config;
|
||||
config.uiDescFileName = "Window.uidesc";
|
||||
config.viewName = "Window";
|
||||
config.modelBinding = modelBinding;
|
||||
config.windowConfig.title = "GFXTests";
|
||||
config.windowConfig.autoSaveFrameName = "GFXTestsWindow";
|
||||
config.windowConfig.style.border ().close ().size ().centered ();
|
||||
if (auto window = UIDesc::makeWindow (config))
|
||||
{
|
||||
window->show ();
|
||||
window->registerWindowListener (this);
|
||||
}
|
||||
else
|
||||
{
|
||||
IApplication::instance ().quit ();
|
||||
}
|
||||
}
|
||||
|
||||
void onClosed (const IWindow& window) override { IApplication::instance ().quit (); }
|
||||
};
|
||||
|
||||
static Init gAppDelegate (std::make_unique<GFXTestApp> ());
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // Standalone
|
||||
} // VSTGUI
|
||||
+396
@@ -0,0 +1,396 @@
|
||||
// This file is part of VSTGUI. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this
|
||||
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
|
||||
|
||||
#include "drawdevicetests.h"
|
||||
#include "vstgui/lib/cbitmap.h"
|
||||
#include "vstgui/lib/cbitmapfilter.h"
|
||||
#include "vstgui/lib/cfileselector.h"
|
||||
#include "vstgui/lib/cframe.h"
|
||||
#include "vstgui/lib/cgraphicstransform.h"
|
||||
#include "vstgui/lib/coffscreencontext.h"
|
||||
#include "vstgui/lib/platform/iplatformbitmap.h"
|
||||
#include "vstgui/lib/platform/platformfactory.h"
|
||||
#include "vstgui/standalone/include/helpers/menubuilder.h"
|
||||
#include "vstgui/standalone/include/helpers/uidesc/customization.h"
|
||||
#include "vstgui/standalone/include/helpers/uidesc/modelbinding.h"
|
||||
#include "vstgui/standalone/include/helpers/value.h"
|
||||
#include "vstgui/standalone/include/iapplication.h"
|
||||
#include "vstgui/standalone/include/iuidescwindow.h"
|
||||
#include "vstgui/uidescription/cstream.h"
|
||||
#include "vstgui/uidescription/delegationcontroller.h"
|
||||
#include "vstgui/uidescription/iuidescription.h"
|
||||
#include "vstgui/uidescription/uiattributes.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
namespace Standalone {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class CustomDrawView : public CView
|
||||
{
|
||||
public:
|
||||
using DrawFunction = std::function<void (CustomDrawView* view, CDrawContext& context, CPoint viewSize)>;
|
||||
|
||||
CustomDrawView (DrawFunction func) : CView (CRect (0, 0, 0, 0)), func (func) {}
|
||||
|
||||
void draw (CDrawContext* context) override
|
||||
{
|
||||
if (func)
|
||||
{
|
||||
CDrawContext::Transform t (
|
||||
*context, CGraphicsTransform ().translate (getViewSize ().getTopLeft ()));
|
||||
func (this, *context, getViewSize ().getSize ());
|
||||
}
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override
|
||||
{
|
||||
if (func && buttons.isLeftButton ())
|
||||
{
|
||||
if (buttons.getModifierState () & kShift)
|
||||
saveAsPNG ();
|
||||
else
|
||||
invalid ();
|
||||
}
|
||||
return kMouseEventHandled;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string getSavePath ()
|
||||
{
|
||||
if (auto fs =
|
||||
owned (CNewFileSelector::create (getFrame (), CNewFileSelector::kSelectSaveFile)))
|
||||
{
|
||||
fs->setDefaultExtension (CFileExtension ("PNG", "png"));
|
||||
if (fs->runModal ())
|
||||
{
|
||||
return fs->getSelectedFile (0);
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void saveAsPNG ()
|
||||
{
|
||||
auto filePath = getSavePath ();
|
||||
if (filePath.empty ())
|
||||
return;
|
||||
|
||||
auto size = getViewSize ().getSize ();
|
||||
auto scaleFactor = getFrame ()->getScaleFactor ();
|
||||
if (auto offscreen = COffscreenContext::create (size, scaleFactor))
|
||||
{
|
||||
offscreen->beginDraw ();
|
||||
func (this, *offscreen, size);
|
||||
offscreen->endDraw ();
|
||||
auto bitmap = offscreen->getBitmap ();
|
||||
if (auto platformBitmap = bitmap->getPlatformBitmap ())
|
||||
{
|
||||
auto buffer =
|
||||
getPlatformFactory ().createBitmapMemoryPNGRepresentation (platformBitmap);
|
||||
if (buffer.empty ())
|
||||
return;
|
||||
CFileStream stream;
|
||||
if (!stream.open (filePath.data (), CFileStream::kBinaryMode |
|
||||
CFileStream::kWriteMode |
|
||||
CFileStream::kTruncateMode))
|
||||
return;
|
||||
stream.writeRaw (buffer.data (), static_cast<uint32_t> (buffer.size ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DrawFunction func;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void drawRects (CDrawContext& context, CPoint size)
|
||||
{
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setFillColor (MakeCColor (0, 0, 0, 100));
|
||||
context.drawRect (CRect ().setSize (size), kDrawFilled);
|
||||
|
||||
//--
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setFrameColor (kBlackCColor);
|
||||
context.setLineStyle (kLineSolid);
|
||||
context.setLineWidth (1);
|
||||
context.drawRect (CRect (5, 5, 10, 10), kDrawStroked);
|
||||
context.setFrameColor (MakeCColor (0, 0, 0, 150));
|
||||
context.drawLine ({10, 5}, {25, 5});
|
||||
context.drawLine ({5, 10}, {5, 25});
|
||||
//--
|
||||
context.setDrawMode (kAliasing);
|
||||
auto hairline = context.getHairlineSize ();
|
||||
CRect r2 (40, 5, 50, 15);
|
||||
context.setLineWidth (5);
|
||||
context.setFrameColor (CColor (0, 0, 255, 100));
|
||||
context.drawRect (r2);
|
||||
context.setLineWidth (3);
|
||||
context.setFrameColor (CColor (255, 0, 0, 100));
|
||||
context.drawRect (r2);
|
||||
context.setLineWidth (1);
|
||||
context.setFrameColor (CColor (0, 255, 0, 100));
|
||||
context.drawRect (r2);
|
||||
//--
|
||||
r2 = {60, 5, 70, 15};
|
||||
context.setLineWidth (hairline);
|
||||
context.setFrameColor (CColor (0, 255, 0, 200));
|
||||
context.drawRect (r2);
|
||||
r2.inset (hairline, hairline);
|
||||
context.setFrameColor (CColor (255, 0, 0, 200));
|
||||
context.drawRect (r2);
|
||||
r2.inset (hairline, hairline);
|
||||
context.setFrameColor (CColor (0, 0, 255, 200));
|
||||
context.drawRect (r2);
|
||||
//--
|
||||
CRect r {5, 50, 0, 0};
|
||||
r.setSize ({20, 20});
|
||||
context.setLineWidth (1);
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setFillColor (MakeCColor (255, 0, 0, 255));
|
||||
context.drawRect (r, kDrawFilled);
|
||||
context.setFillColor (MakeCColor (0, 0, 0, 200));
|
||||
context.drawEllipse (r, kDrawFilled);
|
||||
context.setFrameColor (CColor (0, 255, 0, 100));
|
||||
context.drawRect (r, kDrawStroked);
|
||||
//--
|
||||
r = {50, 50, 80, 80};
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setLineWidth (1);
|
||||
context.setFrameColor (CColor (0, 255, 255, 100));
|
||||
context.drawLine (r.getTopLeft (), r.getTopRight ());
|
||||
context.drawLine (r.getBottomLeft (), r.getBottomRight ());
|
||||
r.inset (10, -10);
|
||||
context.drawLine (r.getTopRight (), r.getBottomRight ());
|
||||
context.drawLine (r.getTopLeft (), r.getBottomLeft ());
|
||||
r.left++;
|
||||
r.top += 11;
|
||||
r.bottom -= 10;
|
||||
context.setFillColor (CColor (255, 0, 0, 100));
|
||||
context.drawRect (r, kDrawFilled);
|
||||
//--
|
||||
r = {90, 90, 120, 120};
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setLineWidth (1);
|
||||
context.setFrameColor (CColor (0, 0, 255, 100));
|
||||
context.setFillColor (CColor (255, 0, 0, 100));
|
||||
context.drawEllipse (r, kDrawFilledAndStroked);
|
||||
r.offset (40, 0);
|
||||
context.setDrawMode (kAntiAliasing);
|
||||
context.drawEllipse (r, kDrawFilledAndStroked);
|
||||
//--
|
||||
r = {90, 130, 120, 160};
|
||||
context.setDrawMode (kAliasing);
|
||||
context.setLineWidth (1);
|
||||
context.setFrameColor (CColor (0, 0, 255, 100));
|
||||
context.setFillColor (CColor (255, 0, 0, 100));
|
||||
context.drawEllipse (r, kDrawFilled);
|
||||
r2 = r;
|
||||
r2.extend (1, 1);
|
||||
context.drawEllipse (r2, kDrawStroked);
|
||||
r.offset (40, 0);
|
||||
context.setDrawMode (kAntiAliasing);
|
||||
context.drawEllipse (r, kDrawFilled);
|
||||
r2 = r;
|
||||
r2.extend (1, 1);
|
||||
context.drawEllipse (r2, kDrawStroked);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void drawBitmapFilter (CustomDrawView* view, CDrawContext& context, CPoint size)
|
||||
{
|
||||
auto boxBlurFilter = owned (BitmapFilter::Factory::getInstance ().createFilter (BitmapFilter::Standard::kBoxBlur));
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kRadius, 2);
|
||||
|
||||
auto offscreen = COffscreenContext::create ({20., 20.});
|
||||
offscreen->beginDraw ();
|
||||
offscreen->setFillColor (kRedCColor);
|
||||
offscreen->drawRect ({5, 5, 15, 15}, kDrawFilled);
|
||||
offscreen->endDraw ();
|
||||
auto bitmap = shared (offscreen->getBitmap ());
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kInputBitmap, bitmap.get ());
|
||||
boxBlurFilter->run (true);
|
||||
bitmap->draw (&context, {0, 0, 20, 20});
|
||||
|
||||
offscreen = COffscreenContext::create ({20., 20.});
|
||||
offscreen->beginDraw ();
|
||||
offscreen->clearRect({0, 0, 20, 20});
|
||||
offscreen->setFillColor (kGreenCColor);
|
||||
offscreen->drawRect ({5, 5, 15, 15}, kDrawFilled);
|
||||
offscreen->endDraw ();
|
||||
bitmap = shared (offscreen->getBitmap ());
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kInputBitmap, bitmap.get ());
|
||||
boxBlurFilter->run (true);
|
||||
bitmap->draw (&context, {20, 0, 40, 20});
|
||||
|
||||
offscreen = COffscreenContext::create ({20., 20.});
|
||||
offscreen->beginDraw ();
|
||||
offscreen->clearRect({0, 0, 20, 20});
|
||||
offscreen->setFillColor (kBlueCColor);
|
||||
offscreen->drawRect ({5, 5, 15, 15}, kDrawFilled);
|
||||
offscreen->endDraw ();
|
||||
bitmap = shared (offscreen->getBitmap ());
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kInputBitmap, bitmap.get ());
|
||||
boxBlurFilter->run (true);
|
||||
bitmap->draw (&context, {40, 0, 60, 20});
|
||||
|
||||
offscreen = COffscreenContext::create ({20., 20.});
|
||||
offscreen->beginDraw ();
|
||||
offscreen->clearRect({0, 0, 20, 20});
|
||||
offscreen->setFillColor (kGreyCColor);
|
||||
offscreen->drawRect ({5, 5, 15, 15}, kDrawFilled);
|
||||
offscreen->endDraw ();
|
||||
bitmap = shared (offscreen->getBitmap ());
|
||||
boxBlurFilter->setProperty (BitmapFilter::Standard::Property::kInputBitmap, bitmap.get ());
|
||||
boxBlurFilter->run (true);
|
||||
bitmap->draw (&context, {60, 0, 80, 20});
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class InvalidateRegionTestView : public CView
|
||||
{
|
||||
public:
|
||||
InvalidateRegionTestView (const CRect& size) : CView (size) {}
|
||||
|
||||
void printRect (const char* prefix, const CRect& r)
|
||||
{
|
||||
#if DEBUG
|
||||
DebugPrint ("%s, %d,%d (%dx%d)\n", prefix, static_cast<int32_t> (r.left),
|
||||
static_cast<int32_t> (r.top), static_cast<int32_t> (r.right - r.left),
|
||||
static_cast<int32_t> (r.bottom - r.top));
|
||||
#endif
|
||||
}
|
||||
|
||||
CMouseEventResult onMouseDown (CPoint& where, const CButtonState& state) override
|
||||
{
|
||||
auto r1 = getViewSize ();
|
||||
r1.setWidth (r1.getWidth () / 2.);
|
||||
auto r2 = r1;
|
||||
r2.offset (r2.getWidth (), 0);
|
||||
|
||||
r2.inset (10, 50);
|
||||
r2.setHeight (r2.getHeight () / 2.);
|
||||
auto r3 = r2;
|
||||
r2.inset (0, 10);
|
||||
r3.offset (0, r3.getHeight ());
|
||||
r3.inset (0, 10);
|
||||
|
||||
r1.inset (10, 0);
|
||||
|
||||
invalRect (r1);
|
||||
invalRect (r2);
|
||||
invalRect (r3);
|
||||
return kMouseDownEventHandledButDontNeedMovedOrUpEvents;
|
||||
}
|
||||
|
||||
void invalRect (const CRect& r)
|
||||
{
|
||||
printRect ("InvalidRect: ", r);
|
||||
invalidRect (r);
|
||||
}
|
||||
|
||||
void drawRect (CDrawContext* context, const CRect& r) override
|
||||
{
|
||||
if (r == getViewSize ())
|
||||
{
|
||||
context->setFillColor (kWhiteCColor);
|
||||
context->drawRect (r, kDrawFilled);
|
||||
}
|
||||
else
|
||||
{
|
||||
printRect ("DrawRect: ", r);
|
||||
|
||||
double h, s, v;
|
||||
color.toHSV (h, s, v);
|
||||
h += 40;
|
||||
color.fromHSV (h, s, v);
|
||||
context->setFillColor (color);
|
||||
context->drawRect (r, kDrawFilled);
|
||||
}
|
||||
setDirty (false);
|
||||
}
|
||||
bool toggle {false};
|
||||
CColor color {kRedCColor};
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class ViewCreator : public DelegationController
|
||||
{
|
||||
public:
|
||||
ViewCreator (IController* parent) : DelegationController (parent) {}
|
||||
|
||||
CView* createView (const UIAttributes& attributes, const IUIDescription* description) override
|
||||
{
|
||||
if (auto customViewName = attributes.getAttributeValue (IUIDescription::kCustomViewName))
|
||||
{
|
||||
if (*customViewName == "RectsView")
|
||||
{
|
||||
return new CustomDrawView ([] (auto view, auto& ctx, auto size) { drawRects (ctx, size); });
|
||||
}
|
||||
if (*customViewName == "BitmapsFilterView")
|
||||
{
|
||||
return new CustomDrawView (
|
||||
[] (auto view, auto& ctx, auto size) { drawBitmapFilter (view, ctx, size); });
|
||||
}
|
||||
else if (*customViewName == "InvalidRegionView")
|
||||
{
|
||||
return new InvalidateRegionTestView (CRect (0, 0, 500, 500));
|
||||
}
|
||||
}
|
||||
return DelegationController::createView (attributes, description);
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
class DrawDeviceTestsCustomization : public UIDesc::Customization, public NoMenuBuilder
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void makeDrawDeviceTestsWindow ()
|
||||
{
|
||||
static UTF8String windowTitle = "DrawDeviceTests";
|
||||
const auto& windows = IApplication::instance ().getWindows ();
|
||||
for (auto& window : windows)
|
||||
{
|
||||
if (window->getTitle () == windowTitle)
|
||||
{
|
||||
window->activate ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto modelBinding = UIDesc::ModelBindingCallbacks::make ();
|
||||
modelBinding->addValue (Value::makeStringListValue (
|
||||
"ViewSelector", {"Lines/Rects", "BitmapFilter", "InvalidRects"}));
|
||||
|
||||
auto drawDeviceTestsCustomization = std::make_shared<DrawDeviceTestsCustomization> ();
|
||||
drawDeviceTestsCustomization->addCreateViewControllerFunc (
|
||||
"ViewCreator",
|
||||
[] (const auto& name, auto parent, const auto uiDesc) { return new ViewCreator (parent); });
|
||||
|
||||
UIDesc::Config config;
|
||||
config.uiDescFileName = "DrawDeviceTests.uidesc";
|
||||
config.viewName = "Window";
|
||||
config.customization = drawDeviceTestsCustomization;
|
||||
config.modelBinding = modelBinding;
|
||||
config.windowConfig.title = windowTitle;
|
||||
config.windowConfig.autoSaveFrameName = "DrawDeviceTestsWindow";
|
||||
config.windowConfig.style.border ().close ().size ().centered ();
|
||||
if (auto window = UIDesc::makeWindow (config))
|
||||
window->show ();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // Standalone
|
||||
} // VSTGUI
|
||||
@@ -0,0 +1,15 @@
|
||||
// This file is part of VSTGUI. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this
|
||||
// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
|
||||
|
||||
#pragma once
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace VSTGUI {
|
||||
namespace Standalone {
|
||||
|
||||
void makeDrawDeviceTestsWindow ();
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // Standalone
|
||||
} // VSTGUI
|
||||
Reference in New Issue
Block a user