mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-10 03:54:54 -06:00
RasterMultiPage: Gif and Tiff multi page formats example
git-svn-id: svn://ultimatepp.org/upp/trunk@2491 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
fa96c2b294
commit
621ca1a74b
6 changed files with 165 additions and 0 deletions
4
reference/GuiMT/init
Normal file
4
reference/GuiMT/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _GuiMT_icpp_init_stub
|
||||
#define _GuiMT_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#endif
|
||||
50
reference/RasterMultiPage/RasterMultiPage.h
Normal file
50
reference/RasterMultiPage/RasterMultiPage.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef _RasterMultiPage_RasterMultiPage_h
|
||||
#define _RasterMultiPage_RasterMultiPage_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <plugin/gif/gif.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
struct ImageControl : public Ctrl {
|
||||
Rect Fit(const Size &frame, const Size &object) {
|
||||
double objectAspect = object.cx/(double)object.cy;
|
||||
if (frame.cx/(double)frame.cy > objectAspect) {
|
||||
double x = (frame.cx - objectAspect*frame.cy)/2.;
|
||||
return Rect(int(x), 0, int(x + objectAspect*frame.cy), frame.cy);
|
||||
} else {
|
||||
double y = (frame.cy - frame.cx/objectAspect)/2.;
|
||||
return Rect(0, int(y), frame.cx, int(y + frame.cx/objectAspect));
|
||||
}
|
||||
}
|
||||
virtual void Paint(Draw& w) {
|
||||
Size sz = GetSize();
|
||||
w.DrawRect(sz, White());
|
||||
if (img)
|
||||
w.DrawImage(Fit(sz, img.GetSize()), img);
|
||||
}
|
||||
ImageControl& SetImage(const Image& _img) {img = _img; Refresh(); return *this;}
|
||||
ImageControl() {Transparent(); NoWantFocus();}
|
||||
|
||||
Image img;
|
||||
};
|
||||
|
||||
#define LAYOUTFILE <RasterMultiPage/RasterMultiPage.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
class RasterMultiPage : public WithRasterMultiPageLayout<TopWindow> {
|
||||
public:
|
||||
typedef RasterMultiPage CLASSNAME;
|
||||
RasterMultiPage();
|
||||
|
||||
void Browse();
|
||||
void Play();
|
||||
void OpenNext();
|
||||
|
||||
Array<Image> images;
|
||||
Array<int> delays;
|
||||
int ind;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
14
reference/RasterMultiPage/RasterMultiPage.lay
Normal file
14
reference/RasterMultiPage/RasterMultiPage.lay
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
LAYOUT(RasterMultiPageLayout, 384, 376)
|
||||
ITEM(ImageControl, image, SetFrame(InsetFrame()).HSizePosZ(8, 8).VSizePosZ(88, 8))
|
||||
ITEM(Label, openedPage, SetLabel(t_("0")).LeftPosZ(204, 24).TopPosZ(60, 19))
|
||||
ITEM(Label, dv___2, SetLabel(t_("Opened Page:")).LeftPosZ(132, 68).TopPosZ(60, 19))
|
||||
ITEM(Label, numberPages, SetLabel(t_("1")).LeftPosZ(100, 24).TopPosZ(60, 19))
|
||||
ITEM(Label, dv___4, SetLabel(t_("Number of Pages:")).LeftPosZ(8, 88).TopPosZ(60, 19))
|
||||
ITEM(EditString, fileName, HSizePosZ(68, 76).TopPosZ(32, 19))
|
||||
ITEM(Button, openNext, SetLabel(t_("Open Next")).RightPosZ(92, 64).TopPosZ(60, 20))
|
||||
ITEM(Button, play, SetLabel(t_("Play")).RightPosZ(8, 64).TopPosZ(60, 20))
|
||||
ITEM(Button, browse, SetLabel(t_("Browse")).RightPosZ(8, 64).TopPosZ(32, 20))
|
||||
ITEM(Label, dv___9, SetLabel(t_("Load and animate GIF and TIFF files")).HSizePosZ(8, 8).TopPosZ(8, 19))
|
||||
ITEM(Label, dv___10, SetLabel(t_("Image file:")).LeftPosZ(8, 56).TopPosZ(32, 19))
|
||||
END_LAYOUT
|
||||
|
||||
13
reference/RasterMultiPage/RasterMultiPage.upp
Normal file
13
reference/RasterMultiPage/RasterMultiPage.upp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
plugin\tif,
|
||||
plugin\gif;
|
||||
|
||||
file
|
||||
RasterMultiPage.h,
|
||||
main.cpp,
|
||||
RasterMultiPage.lay;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
6
reference/RasterMultiPage/init
Normal file
6
reference/RasterMultiPage/init
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef _RasterMultiPage_icpp_init_stub
|
||||
#define _RasterMultiPage_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "plugin\tif/init"
|
||||
#include "plugin\gif/init"
|
||||
#endif
|
||||
78
reference/RasterMultiPage/main.cpp
Normal file
78
reference/RasterMultiPage/main.cpp
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#include "RasterMultiPage.h"
|
||||
|
||||
RasterMultiPage::RasterMultiPage()
|
||||
{
|
||||
CtrlLayout(*this, "Multi page raster demo");
|
||||
|
||||
browse <<= THISBACK(Browse);
|
||||
play <<= THISBACK(Play);
|
||||
openNext <<= THISBACK(OpenNext);
|
||||
|
||||
Sizeable().Zoomable();
|
||||
}
|
||||
|
||||
void RasterMultiPage::Browse()
|
||||
{
|
||||
FileSel fs;
|
||||
|
||||
fs.PreSelect(fileName);
|
||||
fs.Type("Animation type", "*.gif, *.tif, *.tiff");
|
||||
|
||||
if (fs.ExecuteOpen("Choose animation file"))
|
||||
fileName <<= ~fs;
|
||||
|
||||
FileIn in(fileName.GetData().ToString());
|
||||
One<StreamRaster> raster = StreamRaster::OpenAny(in);
|
||||
if(!raster) {
|
||||
Exclamation("Invalid input");
|
||||
return;
|
||||
}
|
||||
images.Clear();
|
||||
delays.Clear();
|
||||
for (int i = 0; i < raster->GetPageCount(); ++i) {
|
||||
raster->SeekPage(i);
|
||||
images.Add(raster->GetImage());
|
||||
int delay = raster->GetPageDelay(i);
|
||||
delays.Add(delay <= 100 ? 100 : delay);
|
||||
}
|
||||
numberPages = FormatInt(raster->GetPageCount());
|
||||
openedPage = "0";
|
||||
image.SetImage(images[0]);
|
||||
ind = 0;
|
||||
}
|
||||
|
||||
void RasterMultiPage::Play()
|
||||
{
|
||||
if (images.GetCount() <= 1)
|
||||
return;
|
||||
TimeStop t;
|
||||
for (unsigned ms = 0; t.Elapsed() < 4000; ++ind) {
|
||||
if (ind >= images.GetCount())
|
||||
ind = 0;
|
||||
image.SetImage(images[ind]);
|
||||
openedPage = FormatInt(ind);
|
||||
Refresh();
|
||||
Ctrl::ProcessEvents();
|
||||
|
||||
ms += delays[ind];
|
||||
while (t.Elapsed() < ms)
|
||||
Sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
void RasterMultiPage::OpenNext()
|
||||
{
|
||||
if (images.GetCount() <= 1)
|
||||
return;
|
||||
ind++;
|
||||
if (ind >= images.GetCount())
|
||||
ind = 0;
|
||||
image.SetImage(images[ind]);
|
||||
openedPage = FormatInt(ind);
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
RasterMultiPage().Run();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue