mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Draw, Doc: Image tutorial modernized to new hilighting plus some minor code changes in tutorial examples.
This commit is contained in:
parent
b86d4aa9d9
commit
7b13126b72
7 changed files with 602 additions and 465 deletions
|
|
@ -6,18 +6,19 @@ using namespace Upp;
|
|||
#define IMAGEFILE <Image01/images.iml>
|
||||
#include <Draw/iml.h>
|
||||
|
||||
class MyApp : public TopWindow {
|
||||
public:
|
||||
virtual void Paint(Draw& draw);
|
||||
struct MyApp : TopWindow {
|
||||
MyApp() {
|
||||
const auto isz = MyImages::MyImage().GetSize();
|
||||
SetRect(0, 0, 100 + isz.cx, 100 + isz.cy);
|
||||
}
|
||||
|
||||
void Paint(Draw& w) override {
|
||||
w.DrawRect(GetSize(), SColorFace());
|
||||
w.DrawImage(50, 50, MyImages::MyImage());
|
||||
}
|
||||
};
|
||||
|
||||
void MyApp::Paint(Draw& w)
|
||||
{
|
||||
w.DrawRect(GetSize(), SColorFace());
|
||||
w.DrawImage(50, 50, MyImages::MyImage());
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyApp().Sizeable().Run();
|
||||
MyApp().Run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,27 +6,27 @@ using namespace Upp;
|
|||
#define IMAGEFILE <Image02a/images.iml>
|
||||
#include <Draw/iml.h>
|
||||
|
||||
class MyApp : public TopWindow {
|
||||
public:
|
||||
virtual void Paint(Draw& draw);
|
||||
};
|
||||
|
||||
void MyApp::Paint(Draw& w)
|
||||
{
|
||||
w.DrawRect(GetSize(), SColorPaper());
|
||||
for(int i = 0; i < MyImages::GetCount(); i++) {
|
||||
w.DrawImage(50, 80 + 20 * i, MyImages::Get(i));
|
||||
w.DrawText(80, 80 + 20 * i, MyImages::GetId(i));
|
||||
struct MyApp : TopWindow {
|
||||
MyApp() {
|
||||
SetRect(0, 0, 170, 170);
|
||||
}
|
||||
w.DrawImage(20, 0, 50, 50, MyImages::Get(MyImages::I_Circle));
|
||||
w.DrawText(80, 0, AsString(MyImages::Find("Circle")));
|
||||
}
|
||||
|
||||
void Paint(Draw& w) override {
|
||||
w.DrawRect(GetSize(), SColorPaper());
|
||||
for(int i = 0; i < MyImages::GetCount(); i++) {
|
||||
w.DrawImage(50, 80 + 20 * i, MyImages::Get(i));
|
||||
w.DrawText(80, 80 + 20 * i, MyImages::GetId(i));
|
||||
}
|
||||
w.DrawImage(20, 0, 50, 50, MyImages::Get(MyImages::I_Circle));
|
||||
w.DrawText(80, 0, AsString(MyImages::Find("Circle")));
|
||||
}
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyApp().Sizeable().Run();
|
||||
MyApp().Run();
|
||||
Image m = MyImages::Circle();
|
||||
MyImages::Set(MyImages::I_Circle, MyImages::Triangle());
|
||||
MyImages::Set(MyImages::I_Triangle, m);
|
||||
MyApp().Sizeable().Run();
|
||||
MyApp().Run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,24 +7,24 @@ using namespace Upp;
|
|||
#include <Draw/iml.h>
|
||||
|
||||
class MyApp : public TopWindow {
|
||||
Iml& iml;
|
||||
|
||||
public:
|
||||
virtual void Paint(Draw& draw);
|
||||
|
||||
MyApp(Iml& _iml) : iml(_iml) {}
|
||||
};
|
||||
|
||||
void MyApp::Paint(Draw& w)
|
||||
{
|
||||
w.DrawRect(GetSize(), SColorPaper());
|
||||
for(int i = 0; i < iml.GetCount(); i++) {
|
||||
w.DrawImage(50, 80 + 20 * i, iml.Get(i));
|
||||
w.DrawText(80, 80 + 20 * i, iml.GetId(i));
|
||||
MyApp(Iml& iml) : m_iml(iml) {
|
||||
SetRect(0, 0, 200, 200);
|
||||
}
|
||||
}
|
||||
|
||||
void Paint(Draw& w) override {
|
||||
w.DrawRect(GetSize(), SColorPaper());
|
||||
for(int i = 0; i < m_iml.GetCount(); i++) {
|
||||
w.DrawImage(50, 80 + 20 * i, m_iml.Get(i));
|
||||
w.DrawText(80, 80 + 20 * i, m_iml.GetId(i));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Iml& m_iml;
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyApp(MyImages::Iml()).Sizeable().Run();
|
||||
MyApp(MyImages::Iml()).Run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,54 +5,49 @@ using namespace Upp;
|
|||
struct MyApp : public TopWindow {
|
||||
Image img;
|
||||
|
||||
virtual void Paint(Draw& w);
|
||||
virtual void LeftDown(Point p, dword keyflags);
|
||||
|
||||
typedef MyApp CLASSNAME;
|
||||
MyApp();
|
||||
};
|
||||
|
||||
MyApp::MyApp()
|
||||
{
|
||||
ImageBuffer ib(50, 50);
|
||||
for(int y = 0; y < 50; y++) {
|
||||
RGBA *l = ib[y];
|
||||
for(int x = 0; x < 50; x++) {
|
||||
if(y == 0 || y == 49 || x == 0 || x == 49)
|
||||
*l++ = Black();
|
||||
else {
|
||||
l->a = 2 * (x + y);
|
||||
l->r = 4 * x;
|
||||
l->g = 4 * y;
|
||||
l->b = 200;
|
||||
l++;
|
||||
MyApp() {
|
||||
ImageBuffer ib(50, 50);
|
||||
for(int y = 0; y < 50; y++) {
|
||||
RGBA *l = ib[y];
|
||||
for(int x = 0; x < 50; x++) {
|
||||
if(y == 0 || y == 49 || x == 0 || x == 49) {
|
||||
*l++ = Black();
|
||||
}
|
||||
else {
|
||||
l->a = 2 * (x + y);
|
||||
l->r = 4 * x;
|
||||
l->g = 4 * y;
|
||||
l->b = 200;
|
||||
l++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Premultiply(ib);
|
||||
img = ib;
|
||||
|
||||
SetRect(0, 0, img.GetSize().cx + 50, img.GetSize().cy + 35);
|
||||
}
|
||||
Premultiply(ib);
|
||||
img = ib;
|
||||
}
|
||||
|
||||
void MyApp::Paint(Draw& w)
|
||||
{
|
||||
w.DrawRect(GetSize(), White);
|
||||
w.DrawImage(10, 5, img);
|
||||
w.DrawImage(40, 25, img);
|
||||
}
|
||||
|
||||
void MyApp::LeftDown(Point p, dword keyflags)
|
||||
{
|
||||
ImageBuffer ib(img);
|
||||
for(int y = 15; y < 35; y++) {
|
||||
RGBA *l = ib[y];
|
||||
for(int x = 15; x < 35; x++)
|
||||
l[x] = 100 * Red();
|
||||
void Paint(Draw& w) override {
|
||||
w.DrawRect(GetSize(), White);
|
||||
w.DrawImage(10, 5, img);
|
||||
w.DrawImage(40, 25, img);
|
||||
}
|
||||
img = ib;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void LeftDown(Point p, dword keyflags) override {
|
||||
ImageBuffer ib(img);
|
||||
for(int y = 15; y < 35; y++) {
|
||||
RGBA *l = ib[y];
|
||||
for(int x = 15; x < 35; x++) {
|
||||
l[x] = 100 * Red();
|
||||
}
|
||||
}
|
||||
img = ib;
|
||||
Refresh();
|
||||
}
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MyApp().Sizeable().Run();
|
||||
MyApp().Run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,37 +6,32 @@ struct MyApp : public TopWindow {
|
|||
Image img;
|
||||
FileSel fs;
|
||||
|
||||
void Open();
|
||||
|
||||
virtual void Paint(Draw& w);
|
||||
virtual void LeftDown(Point, dword) { Open(); }
|
||||
|
||||
typedef MyApp CLASSNAME;
|
||||
MyApp();
|
||||
};
|
||||
|
||||
MyApp::MyApp()
|
||||
{
|
||||
fs.Type("Image file", "*.bmp;*.png;*.tif;*.tiff;*.jpg;*.jpeg;*.gif");
|
||||
Sizeable();
|
||||
}
|
||||
|
||||
void MyApp::Paint(Draw& w)
|
||||
{
|
||||
w.DrawRect(GetSize(), White);
|
||||
if(img)
|
||||
w.DrawImage(0, 0, img);
|
||||
else
|
||||
w.DrawText(0, 0, "No image loaded!", Arial(30).Italic());
|
||||
}
|
||||
|
||||
void MyApp::Open()
|
||||
{
|
||||
if(fs.ExecuteOpen("Choose the image file to open")) {
|
||||
img = StreamRaster::LoadFileAny(~fs);
|
||||
Refresh();
|
||||
MyApp() {
|
||||
fs.Type("Image file", "*.bmp;*.png;*.tif;*.tiff;*.jpg;*.jpeg;*.gif");
|
||||
Sizeable();
|
||||
}
|
||||
}
|
||||
|
||||
void Paint(Draw& w) override {
|
||||
w.DrawRect(GetSize(), White);
|
||||
if(img) {
|
||||
w.DrawImage(0, 0, img);
|
||||
}
|
||||
else {
|
||||
w.DrawText(0, 0, "No image loaded!", Arial(30).Italic());
|
||||
}
|
||||
}
|
||||
|
||||
void LeftDown(Point, dword) override {
|
||||
Open();
|
||||
}
|
||||
|
||||
void Open() {
|
||||
if(fs.ExecuteOpen("Choose the image file to open")) {
|
||||
img = StreamRaster::LoadFileAny(~fs);
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,25 +23,20 @@ struct BallMaker : ImageMaker {
|
|||
Color color;
|
||||
int r;
|
||||
|
||||
virtual String Key() const;
|
||||
virtual Image Make() const;
|
||||
String Key() const override {
|
||||
char h[sizeof(int) + 3];
|
||||
*(int *)h = r;
|
||||
h[sizeof(int)] = color.GetR();
|
||||
h[sizeof(int) + 1] = color.GetG();
|
||||
h[sizeof(int) + 2] = color.GetB();
|
||||
return String(h, sizeof(int) + 3);
|
||||
}
|
||||
|
||||
Image Make() const override {
|
||||
return CreateBall(r, color);
|
||||
}
|
||||
};
|
||||
|
||||
String BallMaker::Key() const
|
||||
{
|
||||
char h[sizeof(int) + 3];
|
||||
*(int *)h = r;
|
||||
h[sizeof(int)] = color.GetR();
|
||||
h[sizeof(int) + 1] = color.GetG();
|
||||
h[sizeof(int) + 2] = color.GetB();
|
||||
return String(h, sizeof(int) + 3);
|
||||
}
|
||||
|
||||
Image BallMaker::Make() const
|
||||
{
|
||||
return CreateBall(r, color);
|
||||
}
|
||||
|
||||
Image CreateBallCached(int r, Color color)
|
||||
{
|
||||
BallMaker m;
|
||||
|
|
@ -53,7 +48,7 @@ Image CreateBallCached(int r, Color color)
|
|||
struct MyApp : public TopWindow {
|
||||
bool cached;
|
||||
|
||||
virtual void Paint(Draw& w) {
|
||||
void Paint(Draw& w) override {
|
||||
w.DrawRect(GetSize(), White);
|
||||
for(int y = 0; y < 300; y += 30)
|
||||
for(int i = 10; i < 500; i += i / 3) {
|
||||
|
|
@ -62,7 +57,7 @@ struct MyApp : public TopWindow {
|
|||
}
|
||||
}
|
||||
|
||||
virtual void LeftDown(Point, dword) {
|
||||
void LeftDown(Point, dword) override {
|
||||
cached = true;
|
||||
Title("Now cached - try to resize the window to see the speed");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue