git-svn-id: svn://ultimatepp.org/upp/trunk@5886 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-03-06 17:48:59 +00:00
parent 1e3fe61e70
commit 7332651e56
10 changed files with 320 additions and 483 deletions

View file

@ -0,0 +1,11 @@
uses
CtrlLib,
Painter;
file
main.cpp,
image.iml;
mainconfig
"" = "GUI SSE2";

117
uppdev/GenShard/image.iml Normal file
View file

@ -0,0 +1,117 @@
PREMULTIPLIED
IMAGE_ID(test)
IMAGE_ID(Test2)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,213,89,121,108,213,85,22,198,253,47,183,68,8,208,246,245,117,125,125,251,190,239,107,95,31,175,175,251,190,209)
IMAGE_DATA(210,214,22,186,178,72,129,90,148,10,5,116,148,1,25,194,20,24,16,9,48,44,10,74,68,81,80,38,26,162,113,141)
IMAGE_DATA(107,52,209,24,151,24,227,154,184,47,223,156,115,153,247,210,205,81,103,156,63,230,151,156,188,190,123,239,239,158,243,125)
IMAGE_DATA(231,59,231,222,151,206,74,155,149,54,43,249,68,189,6,196,189,102,68,188,70,20,251,205,88,16,32,243,155,80,20,176)
IMAGE_DATA(192,105,53,193,96,176,194,106,113,192,98,177,193,76,102,177,184,96,179,185,96,183,185,201,92,176,218,156,23,191,91,61)
IMAGE_DATA(176,217,189,112,56,188,169,57,187,221,5,175,211,132,5,65,11,22,132,109,40,114,27,17,37,95,69,30,3,138,130,38)
IMAGE_DATA(196,67,38,68,3,38,196,232,211,105,55,193,108,118,192,104,48,192,110,86,194,101,84,195,168,83,162,64,150,13,141,86)
IMAGE_DATA(13,139,213,74,251,121,224,160,61,217,132,79,59,251,241,136,113,171,213,11,183,147,227,183,32,70,254,34,46,29,98,132)
IMAGE_DATA(41,228,50,32,234,51,34,238,183,16,38,242,229,55,194,97,179,64,163,144,195,162,206,70,194,173,195,173,45,229,88,20)
IMAGE_DATA(15,195,175,215,192,163,202,131,58,63,27,90,157,138,246,117,18,94,231,191,124,184,97,99,140,228,215,98,241,16,46,195)
IMAGE_DATA(69,92,65,43,138,92,90,20,18,143,97,183,158,62,201,7,249,139,18,143,1,183,1,70,121,22,10,201,6,11,237,216)
IMAGE_DATA(84,85,136,3,139,75,112,79,71,25,246,47,138,97,79,67,24,99,113,23,130,218,2,216,44,106,226,142,113,57,47,250)
IMAGE_DATA(177,18,183,22,183,224,219,235,50,34,22,176,163,144,176,133,156,228,139,98,14,219,117,196,167,30,49,226,178,144,48,185)
IMAGE_DATA(213,121,24,45,52,226,239,173,81,60,216,93,129,71,6,107,240,248,80,61,46,220,210,132,179,203,235,113,140,198,118,213)
IMAGE_DATA(23,97,237,2,55,12,178,92,88,77,122,226,204,65,126,156,34,191,86,155,3,102,147,7,62,138,153,115,95,228,183,34)
IMAGE_DATA(232,208,8,30,3,100,17,175,14,133,30,35,125,55,160,221,162,194,61,141,65,60,208,87,142,135,87,214,226,177,213,139)
IMAGE_DATA(112,118,77,7,206,173,105,199,185,91,58,113,106,85,27,246,119,150,96,91,93,12,141,62,27,116,26,25,249,178,93,212)
IMAGE_DATA(145,217,46,180,100,50,217,133,175,24,229,164,144,116,23,178,105,17,38,30,67,46,13,249,33,30,61,164,13,26,91,27)
IMAGE_DATA(49,227,222,246,24,78,14,212,227,225,85,237,56,59,210,131,243,183,245,226,137,209,1,156,89,123,35,78,173,104,198,225)
IMAGE_DATA(174,74,236,104,46,195,178,210,8,138,195,14,68,66,62,242,227,128,201,104,135,209,100,131,65,111,133,159,180,87,72,190)
IMAGE_DATA(162,62,19,252,14,45,153,158,184,212,33,234,97,51,162,218,101,198,104,204,142,125,237,37,184,175,191,10,103,134,9,211)
IMAGE_DATA(112,55,30,191,181,15,231,214,245,225,236,104,63,30,188,169,3,7,186,107,176,163,181,2,35,213,9,84,150,69,16,143)
IMAGE_DATA(7,47,250,49,216,68,173,232,245,38,4,93,122,161,243,8,105,33,68,190,130,118,13,130,78,226,210,195,28,26,80,70)
IMAGE_DATA(124,142,38,60,24,111,141,227,104,95,3,225,90,76,190,250,241,248,186,155,240,143,237,119,226,252,142,187,241,192,200,82)
IMAGE_DATA(28,90,182,16,59,201,215,93,13,37,168,246,56,17,14,71,168,198,124,208,235,44,100,86,104,181,122,4,189,122,161,239)
IMAGE_DATA(8,97,8,56,84,40,116,170,69,222,10,73,27,81,138,35,68,53,52,28,117,96,188,163,20,251,151,182,224,224,202,126)
IMAGE_DATA(156,24,89,131,115,91,183,226,208,109,235,49,212,216,128,229,181,101,24,110,172,196,109,13,229,216,92,23,71,231,130,0)
IMAGE_DATA(113,102,68,189,207,77,181,103,128,78,107,36,35,95,172,13,31,233,156,180,238,119,170,224,183,105,8,31,225,34,30,195)
IMAGE_DATA(148,51,167,42,31,189,164,157,197,137,40,154,74,227,40,242,186,48,212,92,141,191,45,239,195,234,230,90,12,214,215,160)
IMAGE_DATA(56,86,137,197,213,181,184,105,81,61,234,194,62,52,4,73,11,90,29,214,68,227,112,146,38,52,26,19,212,106,29,113)
IMAGE_DATA(72,122,32,190,184,126,61,84,27,94,27,227,162,113,210,127,148,48,70,117,90,148,16,199,253,165,9,52,36,202,80,90)
IMAGE_DATA(90,131,21,132,229,120,95,45,70,23,86,99,91,95,63,198,6,86,226,207,61,55,98,223,64,39,118,119,52,224,206,166)
IMAGE_DATA(4,130,38,3,233,178,14,65,170,99,165,74,15,149,146,176,176,238,8,27,235,220,103,83,193,99,85,35,96,215,18,159)
IMAGE_DATA(164,125,194,87,110,86,97,115,3,241,83,19,199,186,198,114,236,24,28,196,157,45,77,56,186,48,129,29,85,197,216,221)
IMAGE_DATA(219,133,99,183,220,140,35,203,7,112,160,107,17,198,219,170,177,174,150,180,95,88,132,123,186,251,161,37,60,106,149,1)
IMAGE_DATA(42,21,99,32,92,78,61,233,79,3,191,69,73,254,20,52,166,128,143,248,12,176,169,101,88,91,26,194,95,106,75,49)
IMAGE_DATA(222,92,137,67,93,11,49,78,185,185,191,46,129,123,105,236,200,18,170,231,85,253,120,184,191,11,199,187,91,177,187,189)
IMAGE_DATA(18,67,212,87,26,60,22,220,89,81,2,165,66,13,149,90,3,141,90,65,120,84,196,163,6,46,226,206,109,85,144,63)
IMAGE_DATA(13,225,82,9,127,156,55,179,50,23,75,139,156,248,107,99,49,142,117,214,227,244,64,15,246,181,54,225,72,111,63,118)
IMAGE_DATA(183,182,96,111,107,45,30,94,59,68,218,31,197,209,158,78,236,108,171,66,71,60,128,70,143,25,125,190,16,114,228,10)
IMAGE_DATA(194,165,39,95,164,5,167,86,96,242,90,181,240,82,127,96,108,1,194,22,176,43,169,206,212,112,17,135,139,232,12,184)
IMAGE_DATA(187,137,53,223,142,147,195,203,177,190,50,142,53,101,101,88,89,94,142,193,176,31,155,90,202,112,96,168,143,116,218,137)
IMAGE_DATA(173,164,251,198,176,11,78,157,30,250,108,25,97,210,10,254,24,87,200,174,134,143,114,227,37,253,185,41,95,110,193,163)
IMAGE_DATA(74,24,235,198,99,81,160,152,114,184,169,62,134,189,3,109,232,175,140,161,46,98,71,69,212,67,103,142,23,229,17,23)
IMAGE_DATA(42,163,110,180,36,194,24,31,108,197,122,202,87,61,205,73,179,164,200,201,201,135,82,169,33,30,53,148,55,13,124,164)
IMAGE_DATA(3,63,241,231,37,159,94,51,225,33,95,126,194,229,229,188,185,120,92,65,103,134,12,43,43,163,24,105,174,66,162,208)
IMAGE_DATA(143,69,69,33,116,4,10,209,91,92,131,161,68,5,110,173,174,68,103,109,49,54,246,46,196,96,85,28,101,33,23,100)
IMAGE_DATA(249,10,40,10,244,80,80,190,20,236,75,165,184,88,83,140,141,250,133,219,90,32,180,193,190,124,150,2,81,211,94,202)
IMAGE_DATA(161,174,64,138,166,226,0,122,170,98,104,41,13,98,128,114,95,106,52,162,200,104,192,96,145,15,235,155,203,209,88,18)
IMAGE_DATA(196,226,186,82,84,23,71,16,177,153,225,51,107,145,46,209,34,63,95,79,126,245,212,55,104,95,138,221,239,32,44,20)
IMAGE_DATA(191,219,148,15,167,145,252,208,185,235,49,21,144,230,229,240,216,100,208,171,114,161,145,231,209,89,102,163,245,86,84,251)
IMAGE_DATA(180,232,37,30,215,215,151,99,140,172,38,194,103,49,157,117,97,55,245,35,3,202,221,86,180,81,207,115,81,60,217,89)
IMAGE_DATA(102,228,231,217,145,157,173,167,79,3,233,68,71,231,57,105,209,40,131,155,141,240,185,173,114,242,175,164,186,87,136,220)
IMAGE_DATA(205,190,97,14,114,115,178,33,87,228,80,239,48,160,171,60,132,174,226,32,150,212,198,41,223,70,104,84,26,228,229,230)
IMAGE_DATA(209,121,162,196,64,89,33,6,40,150,42,191,11,25,153,58,228,228,90,41,119,22,100,74,117,200,202,54,34,75,106,32)
IMAGE_DATA(205,201,8,87,1,249,148,147,79,57,241,71,247,10,147,28,38,234,137,217,89,114,204,159,95,128,249,115,37,196,73,62)
IMAGE_DATA(157,241,84,251,84,67,46,167,13,185,217,217,200,144,164,65,150,155,131,166,120,8,99,205,148,199,56,229,53,230,71,90)
IMAGE_DATA(6,249,202,49,9,124,146,76,45,178,114,140,200,203,167,59,5,237,239,212,203,104,255,124,152,13,5,80,203,149,144,100)
IMAGE_DATA(20,32,61,77,131,140,12,53,210,211,213,180,159,28,69,228,71,42,145,66,146,158,142,156,204,44,232,41,23,118,186,235)
IMAGE_DATA(148,197,2,184,173,185,30,119,181,55,96,117,69,4,29,137,24,249,50,16,22,51,178,178,140,20,143,129,252,233,145,73)
IMAGE_DATA(159,14,67,46,249,161,154,80,40,196,190,233,233,10,242,165,68,102,166,134,76,79,184,168,7,168,140,232,140,56,209,224)
IMAGE_DATA(231,123,151,5,237,149,37,104,41,139,227,198,202,50,172,169,46,199,150,246,22,220,209,86,71,253,172,4,53,209,24,230)
IMAGE_DATA(165,105,137,59,11,164,153,196,161,68,79,254,180,228,79,71,177,201,144,75,113,167,165,41,144,153,161,66,70,186,6,18)
IMAGE_DATA(9,249,204,208,66,42,213,34,109,190,10,10,234,161,205,97,15,86,16,87,109,126,7,150,85,38,48,210,84,135,13,212)
IMAGE_DATA(143,55,182,53,98,59,245,142,13,45,181,216,216,221,12,167,45,72,241,106,136,63,19,237,111,32,110,8,19,241,152,38)
IMAGE_DATA(209,65,46,99,28,42,226,140,44,67,35,240,72,50,216,216,23,197,68,49,206,157,167,64,87,77,57,213,151,29,203,169)
IMAGE_DATA(126,215,84,37,176,129,122,214,216,226,69,216,218,211,134,63,117,181,96,61,245,255,209,158,110,204,158,163,18,239,73,179)
IMAGE_DATA(201,143,132,242,64,126,132,49,182,116,37,97,33,60,196,91,58,127,210,88,58,229,86,66,38,37,190,165,228,123,246,28)
IMAGE_DATA(5,202,99,49,220,84,87,129,165,37,17,12,215,148,96,172,173,137,124,180,99,11,249,90,223,214,128,29,67,131,116,183)
IMAGE_DATA(136,34,141,48,73,25,19,113,199,248,120,47,41,241,199,251,206,146,206,202,76,93,184,241,127,246,252,252,243,207,194,126)
IMAGE_DATA(252,241,71,124,243,205,55,248,234,171,175,196,247,159,126,250,233,127,230,147,247,254,225,135,31,240,208,67,15,97,144,14)
IMAGE_DATA(91,175,215,75,137,202,0,211,199,54,103,206,28,184,221,110,244,246,246,226,232,209,163,248,250,235,175,255,176,120,120,159)
IMAGE_DATA(19,39,78,192,229,114,225,210,75,47,197,37,151,92,34,124,178,127,30,243,120,60,212,212,178,197,28,143,95,118,217,101)
IMAGE_DATA(144,201,100,56,112,224,128,136,153,185,249,79,30,126,239,227,143,63,70,83,83,147,216,147,45,26,141,98,231,206,157,120)
IMAGE_DATA(249,229,151,69,92,73,222,57,23,111,188,241,6,246,237,219,135,234,234,106,92,117,213,85,34,158,24,137,245,205,55,223)
IMAGE_DATA(252,221,49,240,250,231,158,123,142,46,175,122,225,87,169,84,226,254,251,239,23,190,216,202,232,144,206,205,205,157,100,14)
IMAGE_DATA(135,67,104,129,231,47,92,184,64,63,92,108,130,15,230,226,153,103,158,249,205,49,240,186,87,95,125,149,26,150,74,96)
IMAGE_DATA(168,163,203,25,243,144,196,251,210,75,47,165,184,158,104,156,23,206,125,82,159,159,126,250,41,58,58,58,196,220,188,121)
IMAGE_DATA(243,68,12,201,61,126,141,115,141,70,35,246,91,183,110,221,164,119,248,115,245,234,213,41,127,197,197,197,136,68,34,169)
IMAGE_DATA(24,22,46,92,56,73,119,188,126,215,174,93,98,109,58,53,120,206,209,191,243,207,239,178,190,47,191,252,114,129,251,251)
IMAGE_DATA(239,191,159,52,207,121,86,171,213,41,127,91,233,210,190,113,227,198,212,119,198,249,197,23,95,76,195,196,123,242,124,69)
IMAGE_DATA(69,133,216,227,151,158,23,94,120,1,87,95,125,181,208,246,251,239,191,63,109,254,169,167,158,74,233,255,138,43,174,16)
IMAGE_DATA(120,158,126,250,233,73,57,56,116,232,208,36,140,252,247,39,159,124,34,52,196,121,123,244,209,71,103,140,129,215,117,119)
IMAGE_DATA(119,139,53,155,55,111,158,198,19,127,95,187,118,109,202,127,48,24,20,251,240,248,68,78,90,91,91,167,229,128,109,247)
IMAGE_DATA(238,221,226,93,230,117,166,222,192,61,67,34,145,224,250,235,175,159,17,59,191,179,100,201,18,248,124,62,209,127,56,175)
IMAGE_DATA(201,24,57,15,60,198,86,95,95,47,234,126,234,243,229,151,95,210,225,35,197,53,215,92,131,247,222,123,111,218,252,19)
IMAGE_DATA(79,60,33,226,227,218,154,137,31,126,63,137,119,106,191,77,142,37,109,170,6,146,107,58,59,59,5,191,71,142,28,153)
IMAGE_DATA(198,239,237,183,223,46,106,125,148,46,247,51,105,116,203,150,45,66,63,31,124,240,193,140,243,60,246,209,71,31,137,254)
IMAGE_DATA(195,117,55,211,26,238,79,140,113,120,120,120,218,124,50,183,92,195,83,31,198,202,117,198,177,179,142,94,127,253,245,105)
IMAGE_DATA(107,88,139,10,186,0,177,6,210,210,210,102,244,255,216,99,143,137,121,214,217,212,249,145,145,17,49,247,200,35,143,76)
IMAGE_DATA(123,143,253,113,79,157,168,251,100,14,146,251,188,242,202,43,169,190,196,56,184,150,166,62,231,206,157,19,243,172,145,95)
IMAGE_DATA(194,127,248,240,225,73,227,188,142,245,149,212,119,32,16,72,245,252,215,94,123,13,111,189,245,86,138,35,62,3,147,235)
IMAGE_DATA(54,108,216,48,205,199,217,179,103,197,28,235,120,234,220,29,119,220,33,226,231,158,55,241,97,63,11,22,44,72,237,187)
IMAGE_DATA(105,211,38,161,239,99,199,142,137,122,225,190,118,223,125,247,137,253,216,103,178,62,185,255,79,173,179,61,123,246,136,185)
IMAGE_DATA(155,111,190,121,154,127,238,11,252,110,77,77,205,164,247,24,95,146,123,214,231,249,243,231,177,108,217,178,73,103,192,149)
IMAGE_DATA(87,94,41,198,146,252,38,141,207,176,137,15,223,15,248,61,62,155,167,62,223,126,251,173,168,207,107,175,189,22,239,190)
IMAGE_DATA(251,110,106,156,241,38,247,155,63,127,62,253,104,202,135,145,126,208,248,253,254,73,102,48,24,196,89,199,124,36,215,115)
IMAGE_DATA(76,73,156,159,127,254,185,184,39,92,119,221,117,51,246,23,230,185,167,167,71,196,55,54,54,150,58,107,121,239,137,152)
IMAGE_DATA(102,207,158,141,207,62,251,108,90,205,127,248,225,135,162,119,39,249,103,147,203,229,169,94,196,253,234,151,180,199,15,143)
IMAGE_DATA(177,134,121,15,174,31,238,81,124,207,152,184,31,91,34,145,152,241,125,142,149,239,39,83,207,101,206,23,247,127,142,133)
IMAGE_DATA(247,226,28,253,210,25,200,123,172,88,177,34,213,167,185,23,240,253,42,105,220,123,89,67,204,85,146,159,137,253,112,124)
IMAGE_DATA(124,124,210,122,238,199,123,247,238,77,241,218,216,216,248,155,206,127,206,37,175,231,88,38,250,226,191,185,22,7,6,6)
IMAGE_DATA(240,228,147,79,138,249,131,7,15,10,27,26,26,194,241,227,199,167,173,223,190,125,187,216,43,43,43,11,111,191,253,246)
IMAGE_DATA(175,222,131,248,189,103,159,125,86,220,105,89,239,92,171,220,207,249,61,190,15,240,157,238,212,169,83,162,135,177,222,120)
IMAGE_DATA(95,238,167,204,13,143,39,207,136,239,190,251,78,244,114,222,131,53,199,231,203,239,185,7,62,255,252,243,66,231,124,23)
IMAGE_DATA(225,220,113,205,240,222,251,247,239,23,250,124,241,197,23,197,189,152,199,79,159,62,45,206,236,147,39,79,138,248,185,207)
IMAGE_DATA(48,135,252,46,247,100,198,243,123,159,100,46,248,44,97,61,48,135,161,80,8,219,182,109,19,117,157,188,91,39,127,139)
IMAGE_DATA(112,60,172,113,62,63,39,222,207,222,121,231,157,223,237,123,226,195,123,51,190,137,247,60,142,229,134,27,110,128,85,252)
IMAGE_DATA(19,194,142,185,115,231,10,158,147,243,124,119,101,237,206,116,15,248,111,226,56,115,230,12,86,173,90,133,112,56,44,206)
IMAGE_DATA(193,228,239,130,188,188,60,209,39,248,158,199,57,225,94,246,71,63,19,123,77,178,238,56,166,137,119,146,137,246,255,242)
IMAGE_DATA(252,19,124,36,81,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
IMAGE_END_DATA(3552, 2)

5
uppdev/GenShard/init Normal file
View file

@ -0,0 +1,5 @@
#ifndef _GenShard_icpp_init_stub
#define _GenShard_icpp_init_stub
#include "CtrlLib/init"
#include "Painter/init"
#endif

151
uppdev/GenShard/main.cpp Normal file
View file

@ -0,0 +1,151 @@
#include <CtrlLib/CtrlLib.h>
#include <Painter/Painter.h>
using namespace Upp;
#define IMAGECLASS ImageImg
#define IMAGEFILE <GenShard/image.iml>
#include <Draw/iml_header.h>
#define IMAGECLASS ImageImg
#define IMAGEFILE <GenShard/image.iml>
#include <Draw/iml_source.h>
struct Shard : Moveable<Shard> {
Pointf p[3];
RGBA c[2];
void Paint(Painter& w, Size sz) const {
w.Move(sz * p[0]).Line(sz * p[1]).Line(sz * p[2])
.Fill(sz * p[0], c[0], sz * (p[1] + p[2]) / 2, c[1]);
}
};
Vector<Shard> Generate()
{
Vector<Shard> si;
for(int i = 0; i < 100; i++) {
Shard& s = si.Add();
for(int i = 0; i < 3; i++)
s.p[i] = Pointf(Randomf(), Randomf());
for(int i = 0; i < 2; i++)
s.c[i] = (int)Random(256) * Color(Random(256), Random(256), Random(256));
}
return si;
}
Image MakeImage(const Vector<Shard>& si, Size sz)
{
ImagePainter p(sz);
p.Clear(White());
for(int i = 0; i < si.GetCount(); i++)
si[i].Paint(p, sz);
return p;
}
double sq(int a, int b)
{
double x = a - b;
return x * x;
}
double Distance(const Image& a, const Image& b)
{
int n = a.GetLength();
if(n != b.GetLength())
return 1e300;
const RGBA *sa = a;
const RGBA *ea = sa + n;
const RGBA *sb = b;
int d = 0;
while(sa < ea) {
d += sq(sa->r, sb->r) + sq(sa->g, sb->g) + sq(sa->g, sb->g);
sa++;
sb++;
}
return d;
}
struct MyApp : TopWindow {
Image image;
Vector< Vector<Shard> > gen;
Vector<Image> img;
void Paint(Draw& w) {
Size sz = GetSize();
w.DrawRect(sz, White());
Size isz = image.GetSize();
w.DrawImage(0, 0, image);
for(int j = 0; j < img.GetCount(); j++)
w.DrawImage(isz.cx * j, isz.cy, img[j]);
w.DrawImage(0, 2 * isz.cy, MakeImage(gen[0], 8 * isz));
}
void Render()
{
Size isz = image.GetSize();
img.SetCount(gen.GetCount());
Vector<double> distance;
{ RTIMING("MakeImg");
distance.SetCount(gen.GetCount());
for(int i = 0; i < gen.GetCount(); i++) {
img[i] = MakeImage(gen[i], isz);
distance[i] = Distance(image, img[i]);
}
}
{ RTIMING("Sort");
IndexSort2(distance, img, gen);
}
}
void Mix()
{
Vector< Vector<Shard> > ngen;
for(int i = 3 * gen.GetCount() / 4; i < gen.GetCount(); i++)
gen[i] = Generate();
int q = gen.GetCount();
q *= q;
for(int i = 0; i < gen.GetCount(); i++) {
const Vector<Shard>& a = gen[Random(gen.GetCount())];
const Vector<Shard>& b = gen[Random(20)];
Vector<Shard>& c = ngen.Add();
int ai = 0;
int bi = 0;
while((ai < a.GetCount() || bi < b.GetCount()) && c.GetCount() < 100) {
switch(Random(4)) {
case 0: if(ai < a.GetCount()) ai++; break;
case 1: if(bi < b.GetCount()) bi++; break;
case 2: if(ai < a.GetCount()) c.Add() = a[ai++]; break;
case 3: if(bi < b.GetCount()) c.Add() = b[bi++]; break;
}
}
}
gen = ngen;
Render();
Refresh();
}
void Do()
{
Open();
while(IsOpen()) {
ProcessEvents();
Mix();
GuiSleep(0);
Sync();
}
}
MyApp() {
Sizeable().Zoomable();
image = ImageImg::test();
for(int i = 0; i < 500; i++)
gen.Add() = Generate();
Render();
}
};
GUI_APP_MAIN
{
MyApp().Do();
}

View file

@ -1,25 +0,0 @@
#include "GtkApp.h"
class BackDraw : public SystemDraw {
public:
virtual bool IsPaintingOp(const Rect& r) const; // TODO!
protected:
Pixmap pixmap;
Size size;
Draw *painting;
Point painting_offset;
public:
void Put(SystemDraw& w, int x, int y);
void Put(SystemDraw& w, Point p) { Put(w, p.x, p.y); }
void Create(SystemDraw& w, int cx, int cy);
void Create(SystemDraw& w, Size sz) { Create(w, sz.cx, sz.cy); }
void Destroy();
void SetPaintingDraw(Draw& w, Point off) { painting = &w; painting_offset = off; }
BackDraw();
~BackDraw();
};

View file

@ -8,9 +8,6 @@ library
file
Test.iml,
GtkApp.h,
GtkDraw.cpp,
ImageDraw.cpp,
BackDraw.cpp,
main.cpp;
mainconfig

View file

@ -1,263 +0,0 @@
#include "GtkApp.h"
#include <cairo/cairo-ft.h>
#define LLOG(x)
void CairoDraw::SetColor(Color c)
{
cairo_set_source_rgb(cr, c.GetR() / 255.0, c.GetG() / 255.0, c.GetB() / 255.0);
}
dword CairoDraw::GetInfo() const
{
return DRAWTEXTLINES;
}
Point CairoDraw::GetOffset() const
{
return offset.GetCount() ? offset.Top() : Point(0, 0);
}
void CairoDraw::Push()
{
cairo_save(cr);
offset.Add(GetOffset());
}
void CairoDraw::Pop()
{
if(offset.GetCount())
offset.Drop();
cairo_restore(cr);
}
void CairoDraw::BeginOp()
{
Push();
}
void CairoDraw::EndOp()
{
Pop();
}
void CairoDraw::OffsetOp(Point p)
{
Push();
offset.Top() += p;
cairo_translate(cr, p.x, p.y);
}
void CairoDraw::RectPath(const Rect& r)
{
cairo_rectangle(cr, r.left, r.top, r.GetWidth(), r.GetHeight());
}
bool CairoDraw::ClipOp(const Rect& r)
{
Push();
RectPath(r);
cairo_clip(cr);
return true;
}
bool CairoDraw::ClipoffOp(const Rect& r)
{
Push();
offset.Top() += r.TopLeft();
RectPath(r);
cairo_clip(cr);
cairo_translate(cr, r.left, r.top);
return true;
}
bool CairoDraw::ExcludeClipOp(const Rect& r)
{
RectPath(Rect(-99999, -99999, 99999, r.top));
RectPath(Rect(-99999, r.top, r.left, 99999));
RectPath(Rect(r.right, r.top, 99999, 99999));
RectPath(Rect(r.left, r.bottom, r.right, 99999));
cairo_clip(cr);
return true;
}
bool CairoDraw::IntersectClipOp(const Rect& r)
{
RectPath(r);
cairo_clip(cr);
return true;
}
bool CairoDraw::IsPaintingOp(const Rect& r) const
{
return true;
}
Rect CairoDraw::GetPaintRect() const
{
return Rect(0, 0, INT_MAX, INT_MAX);
}
void CairoDraw::DrawRectOp(int x, int y, int cx, int cy, Color color)
{
SetColor(color);
cairo_rectangle(cr, x, y, cx, cy);
cairo_fill(cr);
}
struct ImageSysData {
Image img;
cairo_surface_t *surface;
void Init(const Image& img);
~ImageSysData();
};
void ImageSysData::Init(const Image& m)
{
img = m;
Size isz = img.GetSize();
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, isz.cx, isz.cy);
cairo_surface_flush(surface);
byte *a = (byte *)cairo_image_surface_get_data(surface);
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, isz.cx);
for(int yy = 0; yy < isz.cy; yy++) {
Copy((RGBA *)a, img[yy], isz.cx);
a += stride;
}
cairo_surface_mark_dirty(surface);
SysImageRealized(img);
}
ImageSysData::~ImageSysData()
{
SysImageReleased(img);
cairo_surface_destroy(surface);
}
struct ImageSysDataMaker : LRUCache<ImageSysData, int64>::Maker {
Image img;
virtual int64 Key() const { return img.GetSerialId(); }
virtual int Make(ImageSysData& object) const { object.Init(img); return img.GetLength(); }
};
void CairoDraw::SysDrawImageOp(int x, int y, const Image& img, Color color)
{
GuiLock __;
if(img.GetLength() == 0)
return;
LLOG("SysDrawImageOp " << img.GetSerialId() << ' ' << img.GetSize());
ImageSysDataMaker m;
static LRUCache<ImageSysData, int64> cache;
LLOG("SysImage cache pixels " << cache.GetSize() << ", count " << cache.GetCount());
m.img = img;
ImageSysData& sd = cache.Get(m);
if(!IsNull(color)) {
SetColor(color);
cairo_mask_surface(cr, sd.surface, x, y);
}
else {
cairo_set_source_surface(cr, sd.surface, x, y);
cairo_paint(cr);
}
cache.Shrink(4 * 1024 * 768, 1000); // Cache must be after Paint because of PaintOnly!
}
void CairoDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color)
{
SetColor(color);
cairo_move_to(cr, x1, y1);
cairo_line_to(cr, x2, y2);
cairo_set_line_width (cr, width);
cairo_stroke(cr);
}
void CairoDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor)
{
}
void CairoDraw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, const int *subpolygon_counts, int scc, const int *disjunct_polygon_counts, int dpcc, Color color, int width, Color outline, uint64 pattern, Color doxor)
{
}
void CairoDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color)
{
}
void CairoDraw::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor)
{
}
namespace Upp {
FcPattern *CreateFcPattern(Font font);
FT_Face FTFace(Font fnt, String *rpath = NULL);
};
struct FontSysData {
cairo_scaled_font_t *scaled_font;
void Init(Font font, int angle);
~FontSysData() { cairo_scaled_font_destroy(scaled_font); }
};
void FontSysData::Init(Font font, int angle)
{
DLOG("FontSysData::Init " << font << ", " << angle);
FcPattern *p = CreateFcPattern(font);
cairo_font_face_t *font_face = cairo_ft_font_face_create_for_pattern(p);
FcPatternDestroy(p);
cairo_matrix_t font_matrix[1], ctm[1];
cairo_matrix_init_identity(ctm);
cairo_matrix_init_scale(font_matrix, font.GetHeight(), font.GetHeight());
if(angle)
cairo_matrix_rotate(font_matrix, -angle * M_2PI / 3600);
cairo_font_options_t *opt = cairo_font_options_create();
scaled_font = cairo_scaled_font_create(font_face, font_matrix, ctm, opt);
cairo_font_options_destroy(opt);
cairo_font_face_destroy(font_face);
}
struct FontDataSysMaker : LRUCache<FontSysData, Tuple2<Font, int> >::Maker {
Font font;
int angle;
virtual Tuple2<Font, int> Key() const { return MakeTuple(font, angle); }
virtual int Make(FontSysData& object) const { object.Init(font, angle); return 1; }
};
void CairoDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx)
{
GuiLock __;
int ascent = font.GetAscent();
double sina = 0;
double cosa = 1;
if(angle)
Draw::SinCos(angle, sina, cosa);
int xpos = 0;
Buffer<cairo_glyph_t> gs(n);
for(int i = 0; i < n; i++) {
cairo_glyph_t& g = gs[i];
g.index = GetGlyphInfo(font, text[i]).glyphi;
g.x = fround(x + cosa * xpos + sina * ascent);
g.y = fround(y + cosa * ascent - sina * xpos);
xpos += dx ? dx[i] : font[text[i]];
}
static LRUCache<FontSysData, Tuple2<Font, int> > cache;
FontDataSysMaker m;
m.font = font;
m.angle = angle;
FontSysData& sf = cache.Get(m);
cairo_set_scaled_font(cr, sf.scaled_font);
SetColor(ink);
cairo_show_glyphs(cr, gs, n);
cache.Shrink(64);
}

View file

@ -1,84 +0,0 @@
#include "GtkApp.h"
void CairoImageDraw::Init(Size sz)
{
isz = sz;
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, isz.cx, isz.cy);
cr = cairo_create(surface);
alpha_surface = NULL;
}
Draw& CairoImageDraw::Alpha()
{
if(!alpha_surface) {
alpha_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, isz.cx, isz.cy);
alpha.cr = cairo_create(alpha_surface);
}
return alpha;
}
void CairoImageDraw::FetchStraight(ImageBuffer& b) const
{
cairo_surface_flush(surface);
byte *a = (byte *)cairo_image_surface_get_data(surface);
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, isz.cx);
RGBA *t = b;
byte *aa = NULL;
if(alpha_surface) {
cairo_surface_flush(alpha_surface);
aa = (byte *)cairo_image_surface_get_data(alpha_surface);
}
for(int yy = 0; yy < isz.cy; yy++) {
RGBA *s = (RGBA *)a;
RGBA *e = s + isz.cx;
if(aa) {
RGBA *ss = (RGBA *)aa;
while(s < e) {
*t = *s++;
(t++)->a = (ss++)->r;
}
aa += stride;
}
else
while(s < e) {
*t = *s++;
(t++)->a = 255;
}
a += stride;
}
}
CairoImageDraw::operator Image() const
{
ImageBuffer img(isz);
FetchStraight(img);
Premultiply(img);
return img;
}
Image CairoImageDraw::GetStraight() const
{
ImageBuffer img(isz);
FetchStraight(img);
return img;
}
CairoImageDraw::CairoImageDraw(Size sz)
{
Init(sz);
}
CairoImageDraw::CairoImageDraw(int cx, int cy)
{
Init(Size(cx, cy));
}
CairoImageDraw::~CairoImageDraw()
{
cairo_destroy(cr);
cairo_surface_destroy(surface);
if(alpha_surface) {
cairo_destroy(alpha.cr);
cairo_surface_destroy(alpha_surface);
}
}

View file

@ -1,104 +1,47 @@
#include "GtkApp.h"
#include <CtrlLib/CtrlLib.h>
#define IMAGECLASS TestImg
#define IMAGEFILE <GtkApp/Test.iml>
#include <Draw/iml_header.h>
#define IMAGECLASS TestImg
#define IMAGEFILE <GtkApp/Test.iml>
#include <Draw/iml_source.h>
void TestDraw(Draw& w)
void gtk_my_patter_add(GtkWidget *filechooser,
const gchar *title,
const gchar *pattern,
const gint id)
{
w.DrawRect(0, 0, 10000, 10000, WhiteGray());
w.DrawRect(0, 0, 100, 100, Yellow());
w.DrawLine(10, 40, 400, 20, 3, Blue());
w.DrawImage(0, 0, TestImg::Test());
w.Clipoff(50, 50, 30, 30);
w.DrawImage(0, 0, TestImg::Test());
w.End();
w.DrawImage(50, 50 + 32, TestImg::Test(), RectC(24, 24, 10, 10));
w.DrawImage(150, 50, TestImg::Test(), Red());
w.DrawImage(150, 50 + 32, TestImg::Test(), RectC(24, 24, 10, 10), Red());
// w.DrawText(20, 20, "Hello GTK!", Roman(50));
w.Offset(150, 50);
const char *text = "Programming is fun";
Font fnt(Roman(60));
FontInfo fi = fnt.Info();
int x = 0;
Vector<int> dx;
for(const char *s = text; *s; s++) {
int width = fi[*s];
w.DrawRect(x, 0, width - 1, fi.GetAscent(), Color(255, 255, 200));
w.DrawRect(x, fi.GetAscent(), width - 1, fi.GetDescent(), Color(255, 200, 255));
w.DrawRect(x + width - 1, 0, 1, fi.GetHeight(), Black());
dx.Add(width + 4);
x += width;
}
w.DrawRect(0, 0, 4, 4, Black());
w.DrawText(0, 0, text, fnt);
w.DrawText(0, 70, text, fnt, Blue(), dx.GetCount(), dx.Begin());
w.DrawRect(50, 400, 2, 2, Black());
w.DrawText(50, 400, 200, "Angled text", Arial(50).Underline(), Red());
w.DrawRect(600, 400, 2, 2, Black());
w.DrawText(600, 400, 1000, "Angled text", Arial(50).Underline(), Black());
w.End();
}
static gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
CairoDraw w(gdk_cairo_create(widget->window));
TestDraw(w);
cairo_destroy(w);
return FALSE;
GtkFileFilter *filter = gtk_file_filter_new();
gtk_file_filter_set_name(filter, title);
gtk_file_filter_add_pattern(filter, pattern);
g_object_set_data( G_OBJECT( filter ), "id", GINT_TO_POINTER( id ) );
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(filechooser), filter);
}
int main( int argc, char *argv[])
{
{
CairoImageDraw w(1000, 1000);
TestDraw(w);
PNGEncoder().SaveFile("/home/cxl/test.png", w);
}
{
CairoImageDraw w(1000, 1000);
TestDraw(w);
for(int i = 0; i < 100; i++)
w.Alpha().DrawRect(i * 10, 0, 10, 1000, GrayColor(255 - i));
PNGEncoder().SaveFile("/home/cxl/test_alpha.png", w);
}
GtkWidget *window;
gtk_init(&argc, &argv);
// codes
GtkWidget *ofd = gtk_file_chooser_dialog_new("open", NULL/*GTK_WINDOW(pmw->window1)*/,
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(ofd), TRUE);
gtk_my_patter_add(ofd, "Plain text (*.txt)", "*.txt", 0);
gtk_my_patter_add(ofd, "XML files (*.xml)", "*.xml", 1);
gtk_my_patter_add(ofd, "All files (*.*)", "*", 2);
int ret = gtk_dialog_run(GTK_DIALOG(ofd));
//
int id = GPOINTER_TO_INT( g_object_get_data(
G_OBJECT( gtk_file_chooser_get_filter( GTK_FILE_CHOOSER( ofd ) ) ), "id" ) );
//
gtk_widget_destroy(ofd);
/*
GtkWidget *window;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size((GtkWindow *)window, 1000, 600);
GtkWidget *darea = gtk_drawing_area_new();
gtk_container_add(GTK_CONTAINER (window), darea);
g_signal_connect(darea, "expose-event", G_CALLBACK(on_expose_event), NULL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
*/
return 0;
}

View file

@ -8,25 +8,10 @@ struct PainterTest : public TopWindow {
DrawPainter p(w, GetSize()/*, MODE_NOAA*/);
p.Clear(White());
p.Text(0, 0, "A", Roman(50));
p.Fill(Black());
p.Translate(100, 100);
p.Rotate(1);
p.Fill(Blue());
p.Translate(200, -200);
p.Scale(1, -1);
p.Fill(Magenta());
p.Scale(1, -1);
p.Translate(-200, 200);
p.Rotate(-1);
p.Fill(Red());
p.Translate(-100, -100);
p.Fill(Green());
p.Move(100, 100);
p.Line(200, 100);
p.Line(300, 300);
p.Fill(Pointf(100, 100), Blue(), Pointf(300, 300), Red());
}
};