mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
Syncing uppdev
git-svn-id: svn://ultimatepp.org/upp/trunk@599 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
b01eea2a69
commit
61e458d786
13 changed files with 625 additions and 125 deletions
|
|
@ -1,99 +1,82 @@
|
|||
$uvs: PENDING CONFLICT
|
||||
#ifndef _CtrlLibTest_CtrlLibTest_h
|
||||
#define _CtrlLibTest_CtrlLibTest_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
$uvs: REPOSITORY INSERT
|
||||
using namespace Upp;
|
||||
|
||||
template<class T>
|
||||
class WithMinSize : public T
|
||||
{
|
||||
Size minsize;
|
||||
public:
|
||||
virtual Size GetMinSize() const { return minsize; }
|
||||
void SetMinSize(Size sz) { minsize = sz; }
|
||||
};
|
||||
|
||||
#include <ExpandFrame/ExpandFrame.h>
|
||||
$uvs: END REPOSITORY INSERT
|
||||
$uvs: REPOSITORY DELETE
|
||||
|
||||
using namespace Upp;
|
||||
$uvs: END REPOSITORY DELETE
|
||||
|
||||
#define LAYOUTFILE <CtrlLibTest/CtrlLibTest.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
$uvs: REPOSITORY INSERT
|
||||
#define CNT 10
|
||||
$uvs: END REPOSITORY INSERT
|
||||
$uvs: REPOSITORY DELETE
|
||||
#define IMAGECLASS Img
|
||||
#define IMAGEFILE <CtrlLibTest/img.iml>
|
||||
#include <Draw/iml_header.h>
|
||||
|
||||
class Tools : public TopWindow
|
||||
/*
|
||||
class MagickRaster : public Raster
|
||||
{
|
||||
public:
|
||||
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
if (message == WM_MOVE && GetOwner()) {
|
||||
Rect or = GetOwner()->GetScreenRect();
|
||||
Rect r = GetScreenRect();
|
||||
|
||||
if (!or.Contains(r)) {
|
||||
Point tl = r.TopLeft();
|
||||
Point br = r.BottomRight();
|
||||
if (tl.x < or.left)
|
||||
r.OffsetHorz(or.left - tl.x);
|
||||
if (tl.y < or.top)
|
||||
r.OffsetVert(or.top - tl.y);
|
||||
if (br.x > or.bottom)
|
||||
r.OffsetHorz(br.x - or.bottom);
|
||||
if (br.y > or.right)
|
||||
r.OffsetVert(br.y - or.right);
|
||||
SetRect(r);
|
||||
}
|
||||
}
|
||||
return TopWindow::WindowProc(message, wParam, lParam);
|
||||
}
|
||||
virtual Size GetSize() { return sz; }
|
||||
virtual Line GetLine(int line);
|
||||
virtual Info GetInfo();
|
||||
|
||||
MagickRaster(Magick::Image img);
|
||||
MagickRaster(Magick::Image img, int x, int y, int w, int h);
|
||||
private:
|
||||
Magick::PixelPacket * pixels;
|
||||
Size sz;
|
||||
|
||||
void SetImage(Magick::Image, int x, int y, int w, int h);
|
||||
};
|
||||
|
||||
MagickRaster::MagickRaster(Magick::Image)
|
||||
{
|
||||
SetImage(img, 0, 0, img.columns(), img.rows());
|
||||
}
|
||||
|
||||
MagickRaster::MagickRaster(Magick::Image, int x, int y, int w, int h)
|
||||
{
|
||||
SetImage(img, x, y, w, h);
|
||||
}
|
||||
|
||||
void MagickRaster::SetImage(Magick::Image, int x, int y, int w, int h)
|
||||
{
|
||||
pixels = Magick::getPixels(x, y, w, h);
|
||||
sz = Size(w, h);
|
||||
}
|
||||
|
||||
Line MagickRaster::GetLine(int line)
|
||||
{
|
||||
if (Magick::QuantumDepth == 8)
|
||||
return Line((const RGBA *)~lines[line], false);
|
||||
else
|
||||
return Line(~lines[line], this, false)
|
||||
}
|
||||
|
||||
Info MagickRaster::GetInfo()
|
||||
{
|
||||
Info f;
|
||||
f.bpp = Magick::QuantumDepth;
|
||||
f.colors = (1 << f.bpp)*3;
|
||||
f.dots = Size(0, 0);
|
||||
f.hotspot = Point(0, 0);
|
||||
f.kind = IMAGE_ALPHA;
|
||||
return f;
|
||||
}
|
||||
*/
|
||||
|
||||
class ChildWnd : public WithCtrlLibTestLayout<TopWindow> {
|
||||
public:
|
||||
typedef ChildWnd CLASSNAME;
|
||||
ChildWnd();
|
||||
};
|
||||
|
||||
$uvs: END REPOSITORY DELETE
|
||||
class CtrlLibTest : public WithCtrlLibTestLayout<TopWindow> {
|
||||
public:
|
||||
ChildWnd wnd;
|
||||
|
||||
typedef CtrlLibTest CLASSNAME;
|
||||
$uvs: REPOSITORY INSERT
|
||||
|
||||
ParentCtrl paneframe;
|
||||
WithTestLayout< WithMinSize<ParentCtrl> > pane[CNT];
|
||||
ExpandFrame frame[CNT];
|
||||
|
||||
CtrlLibTest() {
|
||||
CtrlLayout(*this, "CtrlLib Test App");
|
||||
Sizeable();
|
||||
for (int i = 0; i < CNT; i++) {
|
||||
CtrlLayout(pane[i]);
|
||||
WString s = Format("Pane %d", i);
|
||||
paneframe.AddFrame(frame[i].Top(pane[i]).SetTitle(s).Expand(true).SetStyle(ExpandFrame::StyleWide()));
|
||||
}
|
||||
}
|
||||
|
||||
void OnButton1()
|
||||
{
|
||||
//Duration t = (Duration)~duration;
|
||||
int i = 1;
|
||||
i++;
|
||||
}
|
||||
$uvs: END REPOSITORY INSERT
|
||||
$uvs: REPOSITORY DELETE
|
||||
ImageBuffer ib;
|
||||
Image img;
|
||||
|
||||
|
||||
CtrlLibTest();
|
||||
$uvs: END REPOSITORY DELETE
|
||||
|
||||
void OnPush1();
|
||||
void OnPush2();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
8
uppdev/CtrlLibTest/CtrlLibTest.iml
Normal file
8
uppdev/CtrlLibTest/CtrlLibTest.iml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
PREMULTIPLIED
|
||||
IMAGE_ID(browser)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,99,16,96,16,96,192,2,254,35,97,124,114,232,24,44,143,12,176,152,1,18,197,192,48,51,176,1,52,51,6)
|
||||
IMAGE_DATA(179,126,74,253,143,47,252,255,99,145,195,22,254,216,192,255,3,7,14,16,82,131,15,80,162,31,172,23,134,201,48,131)
|
||||
IMAGE_DATA(18,253,40,122,201,48,131,18,253,88,245,146,96,6,190,120,166,36,46,113,2,0,5,135,47,120,0,0,0,0,0,0)
|
||||
IMAGE_END_DATA(96, 1)
|
||||
|
|
@ -1,20 +1,7 @@
|
|||
$uvs: PENDING CONFLICT
|
||||
$uvs: REPOSITORY INSERT
|
||||
LAYOUT(CtrlLibTestLayout, 404, 208)
|
||||
UNTYPED(paneframe, LeftPosZ(4, 392).VSizePosZ(4, 44))
|
||||
ITEM(Label, dv___1, SetLabel(t_("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")).LeftPosZ(4, 392).BottomPosZ(9, 19))
|
||||
LAYOUT(CtrlLibTestLayout, 452, 420)
|
||||
ITEM(Button, btn2, SetLabel(t_("Click second")).LeftPosZ(4, 92).TopPosZ(384, 28))
|
||||
ITEM(Button, btn1, SetLabel(t_("Click first")).LeftPosZ(100, 92).TopPosZ(384, 28))
|
||||
ITEM(DropList, edit, LeftPosZ(28, 196).TopPosZ(44, 19))
|
||||
ITEM(ArrayCtrl, arr, LeftPosZ(4, 436).TopPosZ(72, 308))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(TestLayout, 332, 136)
|
||||
ITEM(Button, dv___0, RightPosZ(4, 68).BottomPosZ(4, 20))
|
||||
ITEM(Button, dv___1, LeftPosZ(4, 68).BottomPosZ(4, 20))
|
||||
ITEM(ArrayCtrl, dv___2, LeftPosZ(4, 324).TopPosZ(4, 104))
|
||||
END_LAYOUT
|
||||
|
||||
$uvs: END REPOSITORY INSERT
|
||||
$uvs: REPOSITORY DELETE
|
||||
LAYOUT(CtrlLibTestLayout, 336, 156)
|
||||
ITEM(DropList, drop, LeftPosZ(4, 300).TopPosZ(4, 36))
|
||||
END_LAYOUT
|
||||
|
||||
$uvs: END REPOSITORY DELETE
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
ExpandFrame;
|
||||
|
||||
file
|
||||
CtrlLibTest.h,
|
||||
CtrlLibTest.lay,
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
CtrlLibTest.h,
|
||||
main.cpp,
|
||||
CtrlLibTest.lay;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
|
|
|
|||
234
uppdev/CtrlLibTest/Model.cpp
Normal file
234
uppdev/CtrlLibTest/Model.cpp
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
#include "Model.h"
|
||||
|
||||
bool ModelMesh::Load(String file, VBOLibrary &lib, Point3f scale)
|
||||
{
|
||||
FileIn fin(file);
|
||||
if (!fin.IsOpen())
|
||||
return false;
|
||||
Vector<Triangle> t;
|
||||
Vector<Vertex> v;
|
||||
bool smoothnormals;
|
||||
s % alphasort % smoothnormals;
|
||||
v.Serialize(fin);
|
||||
t.Serialize(t);
|
||||
Scale(v, t, scale, smoothnormals);
|
||||
vbo = lib.GetVertexBuffer(v);
|
||||
if (!vbo) return false;
|
||||
ibo = lib.GetIndexBuffer(t);
|
||||
return ibo > 0;
|
||||
}
|
||||
|
||||
void ModelMesh::Draw()
|
||||
{
|
||||
#error Do model drawing
|
||||
}
|
||||
|
||||
void ModelMesh::Scale(Vector<Vertex> &v, Vector<Vertex> &tri, Point3f scale, bool smooth_normals)
|
||||
{
|
||||
for (int i = 0; i < v.GetCount(); i++) {
|
||||
v[i].pos.x *= scale.x;
|
||||
v[i].pos.y *= scale.y;
|
||||
v[i].pos.z *= scale.z;
|
||||
v[i].normal = Point3f(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
if (smooth_normals) {
|
||||
for (int i = 0; i < tri.GetCount(); i++) {
|
||||
Triangle &t = tri[i];
|
||||
Point3f n = t.GetNormal(v[t.a].pos, v[t.b].pos, v[t.v].pos);
|
||||
v[t.a].normal += n;
|
||||
v[t.b].normal += n;
|
||||
v[t.c].normal += n;
|
||||
}
|
||||
for (int i = 0; i < v.GetCount(); i++)
|
||||
v[i].normal.Unit();
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < tri.GetCount(); i++) {
|
||||
Triangle &t = tri[i];
|
||||
Point3f n = t.GetNormal(v[t.a].pos, v[t.b].pos, v[t.v].pos);
|
||||
v[t.a].normal = n;
|
||||
v[t.b].normal = n;
|
||||
v[t.c].normal = n;
|
||||
}
|
||||
}
|
||||
|
||||
void CreateUpStair(Vector<Vertex> &v, Vector<Quad> &t, float floorcy)
|
||||
{
|
||||
float landingcx = 0.2;
|
||||
float stairstart = 1.0f - landingcx;
|
||||
// 0 - 3 Landing upper face
|
||||
v.Add(Vertex(0.0f, 0.0f, 0.5f));
|
||||
v.Add(Vertex(landingcx, 0.0f, 0.5f));
|
||||
v.Add(Vertex(landingcx, 1.0f, 0.5f));
|
||||
v.Add(Vertex(0.0f, 1.0f, 0.5f));
|
||||
// 4 - 7 Landing lower face
|
||||
v.Add(Vertex(0.0f, 0.0f, 0.5f - floorcy));
|
||||
v.Add(Vertex(landingcx, 0.0f, 0.5f - floorcy));
|
||||
v.Add(Vertex(landingcx, 1.0f, 0.5f - floorcy));
|
||||
v.Add(Vertex(0.0f, 1.0f, 0.5f - floorcy));
|
||||
// 8 - 10 Ramp upper face
|
||||
v.Add(Vertex(stairstart, stairstart, 0.0f));
|
||||
v.Add(Vertex(stairstart, 1.0f, 0.0f));
|
||||
v.Add(Vertex(landingcx, 1.0f, 0.5f));
|
||||
v.Add(Vertex(landingcx, stairstart, 0.5f));
|
||||
// 11 - 13 Ramp lower face
|
||||
v.Add(Vertex(stairstart, stairstart, 0.5f - floorcy));
|
||||
v.Add(Vertex(stairstart, 1.0f, -floorcy));
|
||||
v.Add(Vertex(landingcx, 1.0f, 0.5f - floorcy));
|
||||
v.Add(Vertex(landingcx, stairstart, 0.5f - floorcy));
|
||||
|
||||
float a = floorcy
|
||||
float c = 1.0f - landingcx*2;
|
||||
float d = 0.5f - floorcy;
|
||||
|
||||
AddCube(t, 0, true, true, true);
|
||||
AddCube(t, 8, true, false, true);
|
||||
}
|
||||
|
||||
void CreateDownStair(Vector<Vertex> &v, Vector<Quad> &t, float floorcy)
|
||||
{
|
||||
float landingcx = 0.2;
|
||||
float stairend = 1.0f - landingcx;
|
||||
floorcy = -floorcy;
|
||||
// 0 - 3 Floor pt1 upper face
|
||||
v.Add(Vertex(0.0f, landingcx, 0.0));
|
||||
v.Add(Vertex(1.0f, landingcx, 0.0));
|
||||
v.Add(Vertex(1.0f, 1.0f, 0.0));
|
||||
v.Add(Vertex(0.0f, 1.0f, 0.0));
|
||||
// 4 - 7 Floor pt1 lower face
|
||||
v.Add(Vertex(0.0f, landingcx, floorcy));
|
||||
v.Add(Vertex(1.0f, landingcx, floorcy));
|
||||
v.Add(Vertex(1.0f, 1.0f, floorcy));
|
||||
v.Add(Vertex(0.0f, 1.0f, floorcy));
|
||||
// 8 - 11 Floor pt2 upper face
|
||||
v.Add(Vertex(stairend, 0.0f, 0.0f));
|
||||
v.Add(Vertex(1.0f, 0.0f, 0.0f));
|
||||
v.Add(Vertex(1.0f, landingcx, 0.0f));
|
||||
v.Add(Vertex(stairend, landingcx, 0.0f));
|
||||
// 12 - 15 Floor pt2 lower face
|
||||
v.Add(Vertex(stairend, 0.0f, floorcy));
|
||||
v.Add(Vertex(1.0f, 0.0f, floorcy));
|
||||
v.Add(Vertex(1.0f, landingcx, floorcy));
|
||||
v.Add(Vertex(stairend, landingcx, floorcy));
|
||||
// 16 - 19 Ramp upper face
|
||||
v.Add(Vertex(landingcx, 0.0f, 0.5f));
|
||||
v.Add(Vertex(stairend, 0.0f, 0.5f));
|
||||
v.Add(Vertex(stairend, landingcx, 0.0f));
|
||||
v.Add(Vertex(landingcx, landingcx, 0.0f));
|
||||
// 20 - 23 Ramp lower face
|
||||
v.Add(Vertex(landingcx, 0.0f, 0.5f+floorcy));
|
||||
v.Add(Vertex(stairend, 0.0f, 0.5f+floorcy));
|
||||
v.Add(Vertex(stairend, landingcx, floorcy));
|
||||
v.Add(Vertex(landingcx, landingcx, floorcy));
|
||||
|
||||
// Upper/lower faces
|
||||
AddCube(t, 0, true, true, true);
|
||||
AddCube(t, 8, true, true, true);
|
||||
t.Remove(t.GetCount()-2); // Remove top face
|
||||
AddCube(t, 16, true, true, true);
|
||||
t.Remove(t.GetCount()-3); // Remove right face
|
||||
}
|
||||
|
||||
void CreateTrunk(Vector<Vertex> &v, Vector<Quad> &t)
|
||||
{
|
||||
float thick = 0.1;
|
||||
float height = 0.3;
|
||||
Point3f c(0.5, 0.5, 0.0f)
|
||||
v.Add(Vertex(c.x - thick, c.y - thick, c.z));
|
||||
v.Add(Vertex(c.x + thick, c.y - thick, c.z));
|
||||
v.Add(Vertex(c.x + thick, c.y + thick, c.z));
|
||||
v.Add(Vertex(c.x - thick, c.y + thick, c.z));
|
||||
c.z += height;
|
||||
v.Add(Vertex(c.x - thick, c.y - thick, c.z));
|
||||
v.Add(Vertex(c.x + thick, c.y - thick, c.z));
|
||||
v.Add(Vertex(c.x + thick, c.y + thick, c.z));
|
||||
v.Add(Vertex(c.x - thick, c.y + thick, c.z));
|
||||
AddCube(t, 0, false, true, true);
|
||||
}
|
||||
|
||||
void CreateDownStair(Vector<Vertex> &v, Vector<Quad> &t, float floorcy)
|
||||
{
|
||||
float landingcx = 0.2;
|
||||
float stairend = 1.0f - landingcx;
|
||||
|
||||
CreateDownStair(v, t, floorcy);
|
||||
v[2].y = stairend;
|
||||
v[3].y = stairend;
|
||||
v[6].y = stairend;
|
||||
v[7].y = stairend;
|
||||
CreateUpStair(v, t, floorcy);
|
||||
int pt3ix = v.GetCount();
|
||||
// Floor pt3 upper face
|
||||
v.Add(Vertex(stairend, 0.0f, 0.0f));
|
||||
v.Add(Vertex(1.0f, 0.0f, 0.0f));
|
||||
v.Add(Vertex(1.0f, 1.0f, 0.0f));
|
||||
v.Add(Vertex(stairend, 1.0f, 0.0f));
|
||||
// Floor pt3 lower face
|
||||
v.Add(Vertex(stairend, 0.0f, floorcy));
|
||||
v.Add(Vertex(1.0f, 0.0f, floorcy));
|
||||
v.Add(Vertex(1.0f, 1.0f, floorcy));
|
||||
v.Add(Vertex(stairend, 1.0f, floorcy));
|
||||
|
||||
// Upper/lower faces
|
||||
AddCube(t, pt3ix, true, true, true);
|
||||
t.Remove(t.GetCount() - 4); // Remove left face
|
||||
t.Remove(t.GetCount() - 2); // Remove bottom face
|
||||
}
|
||||
|
||||
void AddCube(Vector<Quad> &t, int ix, bool vertical, bool sides, bool ends)
|
||||
{
|
||||
// Up/Down
|
||||
if (vertical) {
|
||||
AddQuad(t, ix+0, ix+1, ix+2, ix+3); // Up
|
||||
AddQuad(t, ix+7, ix+6, ix+5, ix+4); // Down
|
||||
}
|
||||
if (sides) {
|
||||
// Sides
|
||||
AddQuad(t, ix+4, ix+5, ix+1, ix+0); // Left - 4
|
||||
AddQuad(t, ix+3, ix+2, ix+6, ix+7); // Right - 3
|
||||
}
|
||||
if (ends) {
|
||||
// Ends
|
||||
AddQuad(t, ix+0, ix+3, ix+7, ix+4); // Bottom - 2
|
||||
AddQuad(t, ix+1, ix+2, ix+6, ix+5); // Top - 1
|
||||
}
|
||||
}
|
||||
|
||||
void AddQuad(Vector<Quad> &t, int a, int b, int c, int d)
|
||||
{
|
||||
t.Add(Triangle(a, b, c, d));
|
||||
}
|
||||
|
||||
void SplitTriVertex(Vector<Vertex> &v, Vector<Quad> &t, Vector<Vertex> &vout, Vector<Triangle> &tout)
|
||||
{
|
||||
out.Reserve(t.GetCount()*4);
|
||||
for (int i = 0; i < t.GetCount(); i++) {
|
||||
Quad &q = t[i];
|
||||
int ix = vout.GetCount()
|
||||
Triangle t1(ix, ix+1, ix+2);
|
||||
Triangle t2(ix+2, ix+3, ix);
|
||||
SetTextureCoords(v[t.a], v[t.b], v[t.c], v[t.d]);
|
||||
vout.Add(v[t.a]);
|
||||
vout.Add(v[t.b]);
|
||||
vout.Add(v[t.c]);
|
||||
vout.Add(v[t.d]);
|
||||
tout.Add(t1);
|
||||
tout.Add(t2);
|
||||
}
|
||||
}
|
||||
|
||||
void SetTextureCoords(Vertex &a, Vertex &b, Vertex &c, Vertex &d)
|
||||
{
|
||||
Point2f t;
|
||||
t.x = (a.pos - b.pos).Length();
|
||||
t.y = (d.pos - a.pos).Length();
|
||||
a.tex.x = 0.0f;
|
||||
a.tex.y = 0.0f;
|
||||
b.tex.x = t.x;
|
||||
b.tex.y = 0.0f;
|
||||
c.tex.x = t.xf;
|
||||
c.tex.y = t.yf;
|
||||
d.tex.x = 0.0;
|
||||
d.tex.y = t.yf;
|
||||
}
|
||||
|
||||
34
uppdev/CtrlLibTest/Model.h
Normal file
34
uppdev/CtrlLibTest/Model.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
class ModelMesh : public Moveable<ModelMesh>
|
||||
{
|
||||
public:
|
||||
ModelMesh() : vboid(0), iboid(0) { }
|
||||
|
||||
bool Load(String file, VBOLibrary &lib, Point3f scale);
|
||||
void Draw();
|
||||
private:
|
||||
bool alphasort;
|
||||
GLuint vbo;
|
||||
GLuint ibo;
|
||||
|
||||
void Scale(Vector<Vertex> &v, Vector<Vertex> &tri, Point3f scale)
|
||||
};
|
||||
|
||||
class Billboard : public Moveable<Billboard>
|
||||
{
|
||||
public:
|
||||
Billboard() : depth(0.0f), sz(1.0f), texture(0.0f) { }
|
||||
|
||||
void Set(Point3f position, float size, RGBA col, GLuint texture);
|
||||
void SetDepth(Point3f camera_pos);
|
||||
|
||||
void DoState(GLuint last_texture);
|
||||
|
||||
operator>(const Billboard &b) const { return depth > b.depth; }
|
||||
operator<(const Billboard &b) const { return depth < b.depth; }
|
||||
private:
|
||||
GLuint texture;
|
||||
RGBA color;
|
||||
float depth;
|
||||
Point3f pos;
|
||||
float sz;
|
||||
};
|
||||
166
uppdev/CtrlLibTest/PerlinNoise.cpp
Normal file
166
uppdev/CtrlLibTest/PerlinNoise.cpp
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
#include "CtrlLibTest.h"
|
||||
|
||||
void PerlinNoiseCache::Cache(int cx, int cy)
|
||||
{
|
||||
ASSERT(cx >= 1 && cy >= 1);
|
||||
Clear();
|
||||
sz = Size(cx, cy);
|
||||
InitNoise();
|
||||
int xycnt = cx *cy;
|
||||
cache.Alloc(xycnt);
|
||||
float *q = ~cache;
|
||||
for (int y = 0; y < sz.cy; y++)
|
||||
for (int x = 0; x < sz.cx; x++, q++)
|
||||
*q = PerlinNoise2D(x, y);
|
||||
DeinitNoise();
|
||||
}
|
||||
|
||||
Image PerlinNoiseCache::AsImage() const
|
||||
{
|
||||
ASSERT(~cache);
|
||||
ImageBuffer ib(sz.cx, sz.cy);
|
||||
RGBA *q = ~ib;
|
||||
RGBA *eoi = q + ib.GetLength();
|
||||
const float *v = ~cache;
|
||||
while (q != eoi) {
|
||||
q->r = q->g = q->b = 128 + int(128 * (*v));
|
||||
q->a = 255;
|
||||
q++;
|
||||
v++;
|
||||
}
|
||||
return ib;
|
||||
}
|
||||
|
||||
float PerlinNoiseCache::Get(int x, int y, int z) const
|
||||
{
|
||||
int offset = z * 151;
|
||||
return Get(x+offset, y+offset);
|
||||
}
|
||||
|
||||
float PerlinNoiseCache::Get(float x, float y, int z) const
|
||||
{
|
||||
int integer_X = int(x);
|
||||
float fractional_X = x - integer_X;
|
||||
|
||||
int integer_Y = int(y);
|
||||
float fractional_Y = y - integer_Y;
|
||||
|
||||
float v1 = Get(integer_X, integer_Y, z);
|
||||
float v2 = Get(integer_X + 1, integer_Y, z);
|
||||
float v3 = Get(integer_X, integer_Y + 1, z);
|
||||
float v4 = Get(integer_X + 1, integer_Y + 1, z);
|
||||
|
||||
float i1 = CosineInterpolate(v1, v2, fractional_X);
|
||||
float i2 = CosineInterpolate(v3, v4, fractional_X);
|
||||
|
||||
return CosineInterpolate(i1, i2, fractional_Y);
|
||||
}
|
||||
|
||||
void PerlinNoiseCache::InitNoise()
|
||||
{
|
||||
int xycnt = sz.cx * sz.cy;
|
||||
noise.Alloc(xycnt);
|
||||
float *q = ~noise;
|
||||
for (int y = 0; y < sz.cy; y++)
|
||||
for (int x = 0; x < sz.cx; x++, q++)
|
||||
*q = ((rand() % 10000) - 5000) / 10000.0f;
|
||||
//*q = PerlinNoise::Noise(x, y);
|
||||
}
|
||||
|
||||
inline int Abs(int v) { return (v < 0) ? -v : v; }
|
||||
|
||||
float PerlinNoiseCache::Noise(int x, int y) const
|
||||
{
|
||||
ASSERT(~noise);
|
||||
return noise[Abs((x % sz.cx) + sz.cx * (y % sz.cy))];
|
||||
}
|
||||
|
||||
void PerlinNoiseCache::Clear()
|
||||
{
|
||||
cache.Clear();
|
||||
noise.Clear();
|
||||
sz = Null;
|
||||
}
|
||||
|
||||
/*
|
||||
** Original author: Hugo Elias
|
||||
** http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
|
||||
** Modified and corrected by James Thomas
|
||||
*/
|
||||
float PerlinNoise::Noise(int x, int y) const
|
||||
{
|
||||
int n = x + y * 22283;
|
||||
n = (n<<13) ^ n;
|
||||
return ( 1.0f - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f);
|
||||
}
|
||||
|
||||
float PerlinNoise::SmoothNoise1(int x, int y) const
|
||||
{
|
||||
float corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16;
|
||||
float sides = ( Noise(x-1, y) +Noise(x+1, y) +Noise(x, y-1) +Noise(x, y+1) ) / 8;
|
||||
float center = Noise(x, y) / 4;
|
||||
return corners + sides + center;
|
||||
}
|
||||
|
||||
float PerlinNoise::CosineInterpolate(float a, float b, float x) const
|
||||
{
|
||||
float ft = x * 3.1415927f;
|
||||
float f = (1 - (float)cos(ft)) * 0.5f;
|
||||
return a*(1-f) + b*f;
|
||||
}
|
||||
|
||||
float PerlinNoise::InterpolatedNoise1(float x, float y) const
|
||||
{
|
||||
int integer_X = int(x);
|
||||
float fractional_X = x - integer_X;
|
||||
|
||||
int integer_Y = int(y);
|
||||
float fractional_Y = y - integer_Y;
|
||||
|
||||
float v1 = SmoothNoise1(integer_X, integer_Y);
|
||||
float v2 = SmoothNoise1(integer_X + 1, integer_Y);
|
||||
float v3 = SmoothNoise1(integer_X, integer_Y + 1);
|
||||
float v4 = SmoothNoise1(integer_X + 1, integer_Y + 1);
|
||||
|
||||
float i1 = CosineInterpolate(v1, v2, fractional_X);
|
||||
float i2 = CosineInterpolate(v3, v4, fractional_X);
|
||||
|
||||
return CosineInterpolate(i1, i2, fractional_Y);
|
||||
}
|
||||
|
||||
float PerlinNoise::PerlinNoise2D(int x, int y) const
|
||||
{
|
||||
float total = 0;
|
||||
float amplitude = 1.0f;
|
||||
float max = 0.0f;
|
||||
int frequency = 1;
|
||||
float fx = float(x);
|
||||
float fy = float(y);
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
total = total + InterpolatedNoise1(fx / frequency, fy / frequency) * amplitude;
|
||||
max += amplitude;
|
||||
amplitude *= persistence;
|
||||
frequency <<= 1;
|
||||
}
|
||||
return total / max;
|
||||
}
|
||||
|
||||
float PerlinNoise::PerlinNoise2D(float x, float y) const
|
||||
{
|
||||
float total = 0;
|
||||
float amplitude = 1.0f;
|
||||
float max = 0.0f;
|
||||
int frequency = 1;
|
||||
float fx = float(x);
|
||||
float fy = float(y);
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
total = total + InterpolatedNoise1(fx / frequency, fy / frequency) * amplitude;
|
||||
max += amplitude;
|
||||
amplitude *= persistence;
|
||||
frequency <<= 1;
|
||||
}
|
||||
return total / max;
|
||||
}
|
||||
/*
|
||||
** End of Hugo Elias code
|
||||
*/
|
||||
61
uppdev/CtrlLibTest/PerlinNoise.h
Normal file
61
uppdev/CtrlLibTest/PerlinNoise.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#ifndef _CtrlLibTest_PerlinNoise_h_
|
||||
#define _CtrlLibTest_PerlinNoise_h_
|
||||
|
||||
#include <Core/Core.h>
|
||||
using namespace Upp;
|
||||
|
||||
struct PerlinNoise
|
||||
{
|
||||
public:
|
||||
PerlinNoise() : octaves(2), persistence(0.5f) {}
|
||||
|
||||
PerlinNoise &Octaves(int _octaves) { octaves = minmax(_octaves, 2, 31); return *this; }
|
||||
PerlinNoise &Persistence(float _pers) { persistence = _pers; return *this; }
|
||||
|
||||
virtual float Noise(int x, int y) const;
|
||||
float SmoothNoise1(int x, int y) const;
|
||||
float InterpolatedNoise1(float x, float y) const;
|
||||
float CosineInterpolate(float a, float b, float x) const;
|
||||
|
||||
float PerlinNoise2D(int x, int y) const;
|
||||
float PerlinNoise2D(float x, float y) const;
|
||||
float PerlinNoise3D(int x, int y, int z, int offset = 0x151) const
|
||||
{ return PerlinNoise2D(x + offset*z, y + offset*z); }
|
||||
float PerlinNoise3D(float x, float y, int z, int offset = 0x151) const
|
||||
{ return PerlinNoise2D(x + offset*z, y + offset*z); }
|
||||
protected:
|
||||
int octaves;
|
||||
float persistence;
|
||||
};
|
||||
|
||||
class PerlinNoiseCache : private PerlinNoise, public Moveable<PerlinNoiseCache>
|
||||
{
|
||||
public:
|
||||
PerlinNoiseCache() { Clear(); }
|
||||
void Cache(int cx, int cy);
|
||||
|
||||
PerlinNoiseCache &Octaves(int _octaves) { octaves = minmax(_octaves, 2, 31); return *this; }
|
||||
PerlinNoiseCache &Persistence(float _pers) { persistence = max(0.0f, _pers); return *this; }
|
||||
|
||||
Image AsImage() const;
|
||||
void Clear();
|
||||
|
||||
Size GetXY() const { return sz; }
|
||||
|
||||
float Get(int x, int y) const { ASSERT(~cache); return cache[(x % sz.cx) + sz.cx * (y % sz.cy)]; }
|
||||
float Get(int x, int y, int z) const;
|
||||
float Get(float x, float y, int z) const;
|
||||
virtual float operator()(int x, int y, int z) const { return Get(x, y, z); }
|
||||
virtual float operator()(float x, float y, int z) const { return Get(x, y, z); }
|
||||
|
||||
private:
|
||||
Size sz;
|
||||
Buffer<float> cache;
|
||||
Buffer<float> noise;
|
||||
|
||||
void InitNoise();
|
||||
void DeinitNoise() { noise.Clear(); }
|
||||
virtual float Noise(int x, int y) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef _CtrlLibTest_icpp_init_stub
|
||||
#define _CtrlLibTest_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "ExpandFrame/init"
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,25 +1,31 @@
|
|||
$uvs: PENDING CONFLICT
|
||||
#include "CtrlLibTest.h"
|
||||
|
||||
$uvs: REPOSITORY INSERT
|
||||
// Run
|
||||
$uvs: END REPOSITORY INSERT
|
||||
$uvs: REPOSITORY DELETE
|
||||
#define IMAGECLASS Img
|
||||
#define IMAGEFILE <CtrlLibTest/img.iml>
|
||||
#include <Draw/iml_source.h>
|
||||
ChildWnd::ChildWnd()
|
||||
{
|
||||
CtrlLayout(*this, "Child Window");
|
||||
btn1.Hide();
|
||||
btn2.Hide();
|
||||
}
|
||||
|
||||
CtrlLibTest::CtrlLibTest()
|
||||
{
|
||||
Sizeable();
|
||||
CtrlLayout(*this);
|
||||
drop.SetFrame(InsetFrame());
|
||||
drop.Add("DropList");
|
||||
CtrlLayout(*this, "Main Window");
|
||||
btn1 <<= THISBACK(OnPush1);
|
||||
btn2 <<= THISBACK(OnPush2);
|
||||
}
|
||||
|
||||
void CtrlLibTest::OnPush1()
|
||||
{
|
||||
wnd.Open(this);
|
||||
wnd.TopMost();
|
||||
}
|
||||
|
||||
void CtrlLibTest::OnPush2()
|
||||
{
|
||||
PromptOK("I'm invisible!");
|
||||
}
|
||||
|
||||
$uvs: END REPOSITORY DELETE
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
CtrlLibTest().Run();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
DropList dl;
|
||||
for(int i = 0; i < 100; i++)
|
||||
dl.Add(i);
|
||||
TopWindow w;
|
||||
w.Add(dl.HSizePos().TopPos(0, 20));
|
||||
w.Add(dl.LeftPos(10, 50).TopPos(0, 20));
|
||||
dl.DropWidth(120);
|
||||
dl.Tip("Tip!");
|
||||
w.Run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,23 @@ topic "class aaa : public WithaaaLayout<TopWindow> ";
|
|||
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
|
||||
[b42;2 $$9,9#13035079074754324216151401829390:normal]
|
||||
[{_}
|
||||
[s0; &]
|
||||
[s0; [6 POČÍTAČ]&]
|
||||
[s0; [6 ZUB]&]
|
||||
[s0; [6 ZUBY]&]
|
||||
[s0; [6 LASO]&]
|
||||
[s0; [6 LASY]&]
|
||||
[s0; [6 LÁVA]&]
|
||||
[s0; [6 VLASY]&]
|
||||
[s0; [6 OČI]&]
|
||||
[s0; [6 NOS]&]
|
||||
[s0; [6 VA]&]
|
||||
[s0; [6 LAVA]&]
|
||||
[s0; [6 HALA]&]
|
||||
[s0; [6 HLAVA]&]
|
||||
[s0; [6 LUK]&]
|
||||
[s0; [6 OKNO]&]
|
||||
[s0; [6 KŮŽE]&]
|
||||
[s0; [6 LOPATA]&]
|
||||
[s0;6 &]
|
||||
[s0; ]
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
TITLE("class aaa : public WithaaaLayout<TopWindow> ")
|
||||
COMPRESSED
|
||||
120,156,133,145,203,74,195,64,20,134,95,165,208,174,164,200,185,206,57,51,179,113,225,66,112,225,3,132,32,105,27,37,216,86,237,101,37,246,217,61,209,44,133,134,33,129,48,223,63,255,119,166,161,217,98,1,75,152,195,149,167,220,247,47,221,121,123,106,155,65,196,107,71,90,223,30,159,114,29,121,12,158,13,217,149,81,40,197,11,25,73,137,5,157,178,56,179,67,89,111,187,227,177,109,182,228,254,11,81,64,100,74,104,226,226,200,230,20,44,1,16,24,41,10,59,105,217,244,199,117,219,64,108,231,216,158,19,103,64,0,67,4,38,3,86,65,100,138,8,50,66,208,210,239,55,109,243,144,234,8,200,40,165,41,170,167,72,19,129,72,31,49,97,100,32,86,204,154,202,170,127,29,246,255,41,233,85,37,131,50,156,250,221,100,212,73,189,185,211,138,129,166,101,154,91,28,43,26,135,229,209,136,3,35,74,154,81,37,42,9,80,57,244,159,231,225,208,239,250,253,105,74,24,16,9,235,10,173,70,133,203,229,114,139,2,127,147,178,232,130,16,189,9,227,95,120,
|
||||
24,106,134,172,142,14,108,66,106,161,254,209,29,186,221,100,178,18,170,147,135,47,125,158,48,197,68,193,163,191,230,8,128,144,136,111,12,82,99,177,151,211,4,143,220,8,229,101,158,199,144,88,193,50,152,152,74,152,16,38,140,65,194,232,31,215,80,246,239,135,93,183,109,155,175,231,239,89,115,132,58,107,127,0,149,36,136,204,
|
||||
120,156,133,81,219,106,219,80,16,252,21,131,67,31,138,41,123,61,23,233,165,42,45,164,216,68,129,92,32,21,162,200,137,90,68,109,183,181,157,167,82,67,223,147,95,233,31,244,41,201,127,101,149,42,84,10,133,8,161,195,156,221,217,157,25,21,52,218,219,131,9,140,225,153,39,121,91,127,170,46,23,219,178,104,68,66,90,145,166,95,166,121,76,91,62,26,159,61,114,80,70,33,103,31,100,36,37,22,12,20,37,48,7,72,206,23,213,102,83,22,11,10,225,129,68,70,34,175,132,94,130,4,100,31,200,184,4,64,224,73,81,56,144,38,23,245,230,188,44,192,218,217,218,163,227,8,8,224,17,129,201,3,171,32,50,217,8,242,132,160,73,189,186,40,139,125,151,182,4,105,77,169,51,233,206,166,137,128,77,111,105,194,200,64,172,24,213,37,243,250,115,179,250,159,37,125,214,146,135,164,217,214,203,206,81,37,233,203,215,154,162,81,221,196,141,189,173,21,181,101,177,117,196,70,35,114,26,81,197,36,9,80,178,174,191,95,54,235,122,89,175,182,221,132,6,145,
|
||||
48,157,163,79,77,194,110,183,123,133,2,127,147,242,166,5,193,116,19,218,157,249,240,168,17,162,6,12,192,94,72,189,89,255,86,173,171,101,231,100,46,148,118,62,194,36,140,29,58,75,20,130,233,215,104,3,192,76,216,105,65,170,189,28,146,109,71,110,121,45,41,78,226,216,66,98,5,31,193,139,87,49,39,132,14,45,72,104,253,219,111,72,86,95,215,203,106,81,22,63,62,254,28,21,27,72,71,47,202,135,163,112,163,195,252,246,234,230,250,56,187,189,42,255,93,126,56,121,51,68,103,61,56,203,142,242,33,28,84,111,126,157,102,61,124,250,164,110,235,222,247,224,65,126,212,111,206,6,131,7,112,63,155,13,224,147,242,236,100,218,223,50,61,232,107,156,222,253,190,251,243,174,223,157,31,102,199,143,116,247,24,71,121,15,50,83,218,63,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue