mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
git-svn-id: svn://ultimatepp.org/upp/trunk@946 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
6bf9814adb
commit
11b403afa8
6 changed files with 0 additions and 312 deletions
|
|
@ -1,39 +0,0 @@
|
|||
#ifndef _PainterExamples_Examples_h_
|
||||
#define _PainterExamples_Examples_h_
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <PainterSvg/PainterSvg.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <PainterSvg demo/Examples.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
void RegisterExample(const char *name, void (*ex)(Painter& pw));
|
||||
|
||||
struct App : TopWindow {
|
||||
virtual void Paint(Draw& w);
|
||||
|
||||
SplitterFrame split;
|
||||
ArrayCtrl list;
|
||||
FrameBottom< WithCtrlLayout<StaticRect> > ctrl;
|
||||
|
||||
typedef App CLASSNAME;
|
||||
|
||||
void DoPaint0(Painter& sw);
|
||||
void DoPaint(Painter& sw);
|
||||
void Print();
|
||||
void Benchmark();
|
||||
void Sync();
|
||||
void ToSlider(EditDouble *e, SliderCtrl *slider);
|
||||
void ToEdit(EditDouble *e, SliderCtrl *slider);
|
||||
void Pair(EditDouble& e, SliderCtrl& slider);
|
||||
void ToSlider();
|
||||
void Reset();
|
||||
void Serialize(Stream& s);
|
||||
|
||||
App();
|
||||
~App();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
LAYOUT(CtrlLayout, 212, 384)
|
||||
ITEM(Label, dv___0, SetLabel(t_("Translate X")).LeftPosZ(4, 72).TopPosZ(4, 19))
|
||||
ITEM(EditDoubleSpin, translate_x, Min(0).Max(2000).LeftPosZ(4, 64).TopPosZ(24, 19))
|
||||
ITEM(SliderCtrl, translate_x_slider, HSizePosZ(72, 4).TopPosZ(22, 24))
|
||||
ITEM(Label, dv___3, SetLabel(t_("Translate Y")).LeftPosZ(4, 72).TopPosZ(48, 19))
|
||||
ITEM(EditDoubleSpin, translate_y, Min(0).Max(2000).LeftPosZ(4, 64).TopPosZ(68, 19))
|
||||
ITEM(SliderCtrl, translate_y_slider, HSizePosZ(72, 4).TopPosZ(66, 24))
|
||||
ITEM(Label, dv___6, SetLabel(t_("Rotate")).LeftPosZ(4, 52).TopPosZ(92, 19))
|
||||
ITEM(EditDoubleSpin, rotate, Min(0).Max(6.29).LeftPosZ(4, 64).TopPosZ(112, 19))
|
||||
ITEM(SliderCtrl, rotate_slider, HSizePosZ(72, 4).TopPosZ(110, 24))
|
||||
ITEM(Label, dv___9, SetLabel(t_("Scale")).LeftPosZ(4, 52).TopPosZ(136, 19))
|
||||
ITEM(EditDoubleSpin, scale, Min(0).Max(3).LeftPosZ(4, 64).TopPosZ(156, 19))
|
||||
ITEM(SliderCtrl, scale_slider, HSizePosZ(72, 4).TopPosZ(154, 24))
|
||||
ITEM(Label, dv___12, SetLabel(t_("Scale X")).LeftPosZ(4, 52).TopPosZ(180, 19))
|
||||
ITEM(EditDoubleSpin, scale_x, Min(0).Max(2).LeftPosZ(4, 64).TopPosZ(200, 19))
|
||||
ITEM(SliderCtrl, scale_x_slider, HSizePosZ(72, 4).TopPosZ(198, 24))
|
||||
ITEM(Label, dv___15, SetLabel(t_("Opacity")).LeftPosZ(4, 52).TopPosZ(224, 19))
|
||||
ITEM(EditDoubleSpin, opacity, SetInc(0.05).Min(0).Max(1).LeftPosZ(4, 64).TopPosZ(244, 19))
|
||||
ITEM(SliderCtrl, opacity_slider, HSizePosZ(72, 4).TopPosZ(242, 24))
|
||||
ITEM(Option, painting, SetLabel(t_("Paint through Painting")).LeftPosZ(4, 128).TopPosZ(268, 20))
|
||||
ITEM(DropList, linejoin, LeftPosZ(4, 100).BottomPosZ(33, 19))
|
||||
ITEM(DropList, linecap, RightPosZ(4, 100).BottomPosZ(33, 19))
|
||||
ITEM(Button, reset, SetLabel(t_("Reset")).LeftPosZ(4, 64).BottomPosZ(4, 24))
|
||||
ITEM(Button, print, SetLabel(t_("Print")).HSizePosZ(72, 80).BottomPosZ(4, 24))
|
||||
ITEM(Button, benchmark, SetLabel(t_("Benchmark")).RightPosZ(4, 72).BottomPosZ(4, 24))
|
||||
ITEM(Switch, quality, SetLabel(t_("Antialiased\nNoAA\nSubpixel")).LeftPosZ(4, 204).TopPosZ(312, 16))
|
||||
ITEM(Option, transparent, SetLabel(t_("Transparent background")).LeftPosZ(4, 204).TopPosZ(288, 20))
|
||||
END_LAYOUT
|
||||
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
description "Svg Painter demo";
|
||||
|
||||
uses
|
||||
CtrlLib,
|
||||
PainterSvg;
|
||||
|
||||
file
|
||||
Examples.h,
|
||||
SvgDemo.cpp,
|
||||
main.cpp,
|
||||
Examples.lay;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI",
|
||||
"" = "GUI SSE2";
|
||||
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#include "Examples.h"
|
||||
|
||||
void ParseSVG(Painter& p, const char *svg);
|
||||
|
||||
void SvgDemo(Painter& sw)
|
||||
{
|
||||
String file = "C:\\demo.svg";
|
||||
|
||||
try {
|
||||
if (FileExists(file))
|
||||
ParseSVG(sw, LoadFileBOM(file));
|
||||
else {
|
||||
sw.Scale(1./20);
|
||||
sw.Text(200, 200, "Please copy the svg file in '" + file + "'", Font(Font::ARIAL, 400));
|
||||
sw.Text(200, 700, "or change String file in SvgDemo.cpp", Font(Font::ARIAL, 400));
|
||||
sw.Opacity(1);
|
||||
sw.Stroke(1, Black());
|
||||
sw.Fill(Black());
|
||||
}
|
||||
}
|
||||
catch(XmlError e) {
|
||||
LOG("SVG XML error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
INITBLOCK {
|
||||
RegisterExample("Svg demo", SvgDemo);
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
#ifndef _PainterSvg_demo_icpp_init_stub
|
||||
#define _PainterSvg_demo_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "PainterSvg/init"
|
||||
#endif
|
||||
|
|
@ -1,195 +0,0 @@
|
|||
#include "Examples.h"
|
||||
|
||||
struct Example {
|
||||
void (*example)(Painter& pw);
|
||||
String name;
|
||||
};
|
||||
|
||||
Array<Example>& Examples()
|
||||
{
|
||||
static Array<Example> x;
|
||||
return x;
|
||||
};
|
||||
|
||||
void RegisterExample(const char *name, void (*ex)(Painter& pw))
|
||||
{
|
||||
Example& x = Examples().Add();
|
||||
x.name = name;
|
||||
x.example = ex;
|
||||
}
|
||||
|
||||
void App::DoPaint0(Painter& sw)
|
||||
{
|
||||
sw.Translate(~ctrl.translate_x, ~ctrl.translate_y);
|
||||
sw.Rotate(~ctrl.rotate);
|
||||
sw.Scale(~ctrl.scale, (double)~ctrl.scale * (double)~ctrl.scale_x);
|
||||
sw.Opacity(~ctrl.opacity);
|
||||
sw.LineCap(~ctrl.linecap);
|
||||
sw.LineJoin(~ctrl.linejoin);
|
||||
{ PAINTER_TIMING("FILL");
|
||||
if(ctrl.transparent)
|
||||
sw.Clear(RGBAZero());
|
||||
else
|
||||
sw.Clear(White());
|
||||
}
|
||||
if(list.IsCursor())
|
||||
Examples()[list.GetCursor()].example(sw);
|
||||
}
|
||||
|
||||
void App::DoPaint(Painter& sw)
|
||||
{
|
||||
if(ctrl.painting) {
|
||||
PaintingPainter h(2000, 2000);
|
||||
DoPaint0(h);
|
||||
sw.Paint(h);
|
||||
}
|
||||
else
|
||||
DoPaint0(sw);
|
||||
}
|
||||
|
||||
void App::Print()
|
||||
{
|
||||
PaintingPainter sw(1000, 1000);
|
||||
DoPaint(sw);
|
||||
PrinterJob pb;
|
||||
if(pb.Execute())
|
||||
pb.GetDraw().DrawPainting(0, 0, 4000, 4000, sw);
|
||||
}
|
||||
|
||||
void App::Benchmark()
|
||||
{
|
||||
int time;
|
||||
int time0 = GetTickCount();
|
||||
int n = 0;
|
||||
for(;;) {
|
||||
time = GetTickCount();
|
||||
if(time - time0 > 1000) break;
|
||||
ImageBuffer ib(800, 600);
|
||||
BufferPainter sw(ib, ctrl.quality);
|
||||
PAINTER_TIMING("Paint");
|
||||
DoPaint(sw);
|
||||
n++;
|
||||
}
|
||||
PromptOK("Benchmark: " + AsString(double(time - time0) / n) + " ms");
|
||||
}
|
||||
|
||||
void App::Paint(Draw& w)
|
||||
{
|
||||
Size sz = GetSize();
|
||||
if(ctrl.transparent) {
|
||||
for(int y = 0; y + 32 < sz.cy; y += 32)
|
||||
for(int x = 0; x + 32 < sz.cx; x += 32)
|
||||
w.DrawRect(x, y, 32, 32, (x ^ y) & 32 ? Color(254, 172, 120) : Color(124, 135, 253));
|
||||
}
|
||||
ImageBuffer ib(sz);
|
||||
BufferPainter sw(ib, ctrl.quality);
|
||||
DoPaint(sw);
|
||||
w.DrawImage(0, 0, ib);
|
||||
}
|
||||
|
||||
void App::Sync()
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void App::ToSlider(EditDouble *e, SliderCtrl *slider)
|
||||
{
|
||||
double v = ~*e;
|
||||
*slider <<= fround(1000.0 * (v - e->GetMin()) / (e->GetMax() - e->GetMin()));
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void App::ToEdit(EditDouble *e, SliderCtrl *slider)
|
||||
{
|
||||
int x = ~*slider;
|
||||
*e <<= x * (e->GetMax() - e->GetMin()) / 1000.0 + e->GetMin();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void App::Pair(EditDouble& e, SliderCtrl& slider)
|
||||
{
|
||||
e <<= THISBACK2(ToSlider, &e, &slider);
|
||||
slider <<= THISBACK2(ToEdit, &e, &slider);
|
||||
slider.MinMax(0, 1000);
|
||||
}
|
||||
|
||||
void App::ToSlider()
|
||||
{
|
||||
ToSlider(&ctrl.rotate, &ctrl.rotate_slider);
|
||||
ToSlider(&ctrl.scale, &ctrl.scale_slider);
|
||||
ToSlider(&ctrl.scale_x, &ctrl.scale_x_slider);
|
||||
ToSlider(&ctrl.translate_x, &ctrl.translate_x_slider);
|
||||
ToSlider(&ctrl.translate_y, &ctrl.translate_y_slider);
|
||||
ToSlider(&ctrl.opacity, &ctrl.opacity_slider);
|
||||
}
|
||||
|
||||
void App::Reset()
|
||||
{
|
||||
ctrl.rotate <<= ctrl.translate_x <<= ctrl.translate_y <<= 0;
|
||||
ctrl.scale <<= ctrl.scale_x <<= ctrl.opacity <<= 1.0;
|
||||
ctrl.painting = false;
|
||||
ctrl.quality = MODE_ANTIALIASED;
|
||||
ctrl.linejoin <<= LINEJOIN_MITER;
|
||||
ctrl.linecap <<= LINECAP_BUTT;
|
||||
ToSlider();
|
||||
}
|
||||
|
||||
void App::Serialize(Stream& s)
|
||||
{
|
||||
s
|
||||
% ctrl.rotate % ctrl.rotate_slider
|
||||
% ctrl.scale % ctrl.scale_slider
|
||||
% ctrl.scale_x % ctrl.scale_x_slider
|
||||
% ctrl.translate_x % ctrl.translate_x_slider
|
||||
% ctrl.translate_y % ctrl.translate_y_slider
|
||||
% ctrl.opacity % ctrl.opacity_slider
|
||||
% ctrl.painting % ctrl.quality % ctrl.transparent
|
||||
;
|
||||
}
|
||||
|
||||
App::App() {
|
||||
AddFrame(split);
|
||||
split.Left(list, HorzLayoutZoom(200));
|
||||
list.WhenSel = THISBACK(Sync);
|
||||
list.AddColumn();
|
||||
list.NoHeader();
|
||||
for(int i = 0; i < Examples().GetCount(); i++)
|
||||
list.Add(Examples()[i].name);
|
||||
list.FindSetCursor(LoadFile(ConfigFile("last")));
|
||||
Sync();
|
||||
Sizeable().Zoomable();
|
||||
ctrl.Height(ctrl.GetLayoutSize().cy);
|
||||
CtrlLayout(ctrl);
|
||||
list.InsertFrame(0, ctrl);
|
||||
Pair(ctrl.rotate, ctrl.rotate_slider);
|
||||
Pair(ctrl.scale, ctrl.scale_slider);
|
||||
Pair(ctrl.scale_x, ctrl.scale_x_slider);
|
||||
Pair(ctrl.translate_x, ctrl.translate_x_slider);
|
||||
Pair(ctrl.translate_y, ctrl.translate_y_slider);
|
||||
Pair(ctrl.opacity, ctrl.opacity_slider);
|
||||
ctrl.linecap.Add(LINECAP_BUTT, "Butt caps");
|
||||
ctrl.linecap.Add(LINECAP_SQUARE, "Square caps");
|
||||
ctrl.linecap.Add(LINECAP_ROUND, "Round caps");
|
||||
ctrl.linejoin.Add(LINEJOIN_MITER, "Miter joins");
|
||||
ctrl.linejoin.Add(LINEJOIN_ROUND, "Round joins");
|
||||
ctrl.linejoin.Add(LINEJOIN_BEVEL, "Bevel joins");
|
||||
ctrl.linecap <<= ctrl.linejoin <<= ctrl.painting <<= ctrl.quality <<= ctrl.transparent <<= THISBACK(Sync);
|
||||
ctrl.reset <<= THISBACK(Reset);
|
||||
ctrl.benchmark <<= THISBACK(Benchmark);
|
||||
ctrl.print <<= THISBACK(Print);
|
||||
Reset();
|
||||
LoadFromFile(*this);
|
||||
Title("Painter 2.0");
|
||||
}
|
||||
|
||||
App::~App()
|
||||
{
|
||||
if(list.IsCursor())
|
||||
SaveFile(ConfigFile("last"), list.GetKey());
|
||||
StoreToFile(*this);
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
App().Run();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue