Solved

Urgent: Page Turning Code!

Posted on 2004-04-03
12
338 Views
Last Modified: 2010-05-18
I need source code to do a "page turning" like "flip album" does.
0
Comment
Question by:divnet
  • 5
  • 5
  • 2
12 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10749144
If You could explain more presice.
What is "page" here and what do You mean by page turning.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10749286
OK, im not exactly sure what you mean, by flip album.

However, if you want to add page control to your app, you can do the following:


 Drop a Tpanel on your form, set its

 align= alBottom.
 caption = ''   (NONE)
 name = pnlButtons


 Place two buttons on the right size of the panel.

 Set the first ones Caption = 'Next' and the second one's caption = 'Prev'

 Name them btnNext, & btnPrev respectively

 Now drop a TPageControl on the form and set its

  align = alClient
  name = pgeMain

Right click on it and create as many pages as you need.
Then, set each of the tabsheets "Tab Visible" property = False


 add a TActionList component to the form

 double click it, and create two new actions

 name the first 'actNext' and the second 'actPrev'

Set the caption's = 'Next' and 'Prev' respectively

 set the actNext's OnUpdate event to the following code

procedure TfrmMain.actNextUpdate(Sender: TObject);
begin
 actNext.Enabled:= pgeMain.ActivePageIndex <> pgeMain.PageCount - 1;
end;

 set the actPrev OnUpdate event to the following code


procedure TfrmMain.actPrevUpdate(Sender: TObject);
begin
 actPrev.Enabled:= pgeMain.ActivePageIndex <> 0;
end;  


Now go back to the two buttons and set their action property in the obbject inspector = to the matching action

 btnNext :

action = actNext


btnPrev :

 action = actPrev


SHane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10749322
Hi Shane
And I imagine that he wants some kind of animation, graphic rotation or something like that. Sometimes its really difficult to guess asker intnsions, isn't it.
Marek
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10749391
Sorry, i forgot the actual page turning.

You will need to set the OnExecute event of each of the two actions

actNext & actPrev

procedure TfrmMain.actNextExecute(Sender: TObject);
begin
 pgeMain.ActivePageIndex:=  pgeMain.ActivePageIndex + 1;
end;

procedure TfrmMain.actPrevExecute(Sender: TObject);
begin
 pgeMain.ActivePageIndex:=  pgeMain.ActivePageIndex - 1;
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10749424
Yes, it is!

However, if he want's that look as well, he can load a background image that looks like a sheet of notebook paper

http://www.sbac.edu/~tpl/clipart/Education/notebook%20paper.jpg



It all really depends on what type of effect he is looking for, so i guess i will leave it at this - until he explains more

<smile>

Shane
0
 
LVL 1

Author Comment

by:divnet
ID: 10752611
it is an animation effect that appears like the page is turning (like a book page). example is like www.flipalbum.com
0
 
LVL 17

Accepted Solution

by:
mokule earned 500 total points
ID: 10753617
What do You think about this.
Place on a Form
    PaintBox1: TPaintBox;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Timer1: TTimer;
In a folder where exe will be place images named image01.bmp, image02.bmp,image03.bmp and so on. They should be 280 pixels wide and 360 height.

And here is code

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtDlgs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure PaintBox1Paint(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    Counter: integer;
    FotoCounter: integer;
    Folder: string;
  public
    { Public declarations }
  end;

const
  FOTWIDTH = 280;
  FOTHEIGHT = 360;
  UPMARG = 40;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Self.DoubleBuffered := True;
  Self.SetBounds(10,10,2*FOTWIDTH + 50,
                 FOTHEIGHT + UPMARG+80);
  Timer1.Enabled := False;
  Timer1.Interval := 100;
  PaintBox1.Left := 20;
  PaintBox1.Top := 20;
  PaintBox1.Width := 2*FOTWIDTH;
  PaintBox1.Height := FOTHEIGHT + UPMARG;
  Image1.Visible := False;
  Image2.Visible := False;
  Image3.Visible := False;
  Image4.Visible := False;
  Folder := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0)));
  Counter := 0;
  FotoCounter := 0;
  if FileExists('image01.bmp') then
    Image1.Picture.LoadFromFile(Folder+'image01.bmp');
  if FileExists('image02.bmp') then
    Image2.Picture.LoadFromFile(Folder+'image02.bmp');
  if FileExists('image03.bmp') then
    Image3.Picture.LoadFromFile(Folder+'image03.bmp');
  if FileExists('image04.bmp') then
    Image4.Picture.LoadFromFile(Folder+'image04.bmp');
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  fname: string;
begin
  Inc(Counter);
  if Counter <= 20 then
    PaintBox1.Refresh
  else
    begin
    Inc(FotoCounter);
    Counter := 0;
    fname := Folder+'image'+Format('%2.2d',[2*FotoCounter+1])+'.bmp';
    if FileExists(fname) then
      Image1.Picture.LoadFromFile(fname)
    else
      Timer1.Enabled := False;
    fname := Folder+'image'+Format('%2.2d',[2*FotoCounter+2])+'.bmp';
    if FileExists(fname) then
      Image2.Picture.LoadFromFile(fname)
    else
      Timer1.Enabled := False;
    fname := Folder+'image'+Format('%2.2d',[2*FotoCounter+3])+'.bmp';
    if FileExists(fname) then
      Image3.Picture.LoadFromFile(fname)
    else
      Timer1.Enabled := False;
    fname := Folder+'image'+Format('%2.2d',[2*FotoCounter+4])+'.bmp';
    if FileExists(fname) then
      Image4.Picture.LoadFromFile(fname)
    else
      Timer1.Enabled := False;
    end;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
  tp: array[0..2] of TPoint;
  hb: HBITMAP;
begin
  PaintBox1.Canvas.Draw(0,UPMARG,Image1.Picture.Bitmap);
  PaintBox1.Canvas.Draw(FOTWIDTH,UPMARG,Image4.Picture.Bitmap);
  hb := 0;
  if counter < 10 then
    begin
    tp[0].X := FOTWIDTH;
    tp[0].Y := UPMARG;
    tp[1].X := FOTWIDTH+(10-Counter)*FOTWIDTH div 10;
    tp[1].Y := UPMARG-Counter*5;
    tp[2].X := FOTWIDTH;
    tp[2].Y := FOTHEIGHT+UPMARG;
    PlgBlt(PaintBox1.Canvas.Handle,tp,
        Image2.Canvas.Handle,0,0,
        FOTWIDTH,FOTHEIGHT,hb,0,0);
    end
  else
    begin
    tp[0].X := (20-Counter)*FOTWIDTH div 10;
    tp[0].Y := UPMARG-(20-Counter)*5;

    tp[1].X := FOTWIDTH;
    tp[1].Y := UPMARG;

    tp[2].X := (20-Counter)*FOTWIDTH div 10;
    tp[2].Y := FOTHEIGHT+UPMARG-(20-Counter)*5;

    PlgBlt(PaintBox1.Canvas.Handle,tp,
        Image3.Canvas.Handle,0,0,
        FOTWIDTH,FOTHEIGHT,hb,0,0);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Inc(Counter);
  PaintBox1.Refresh;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  Timer1.Enabled := True;
end;

end.
0
 
LVL 1

Author Comment

by:divnet
ID: 10762254
Mokule you have the points. I will give you more if you could show me how to curve the image, more like a book page being turned over.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10762273
ok, but my solution would habe been much less coding involved.

4 - 6 lines of code, and i bet i could have implemeted the solution


Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10762318
Never mind, i miss understood, i just tested mokules code, i see what type of effect you wanted.
Sorry, I misunderstood the question.

<Smile>

Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10765185
The principle on which was based my program was as follows.
The source image rectangle was transfered into destination image parallelogram.

Src image                Dest image
                                      /E
                                    /  |
                                  /    |
A----------B                D     |
|             |                |      |
|             |                |      |
|             |                |    /
|             |                |  /
|             |                |/
C-----------                F


PlgBlt ( PaintBox1.Canvas.Handle,          // Dest image
              tp,                                        // array of points D, E, F
              Image2.Canvas.Handle,          // Src image
              0,                                         // x coordinate of point A
              0,                                         // y coordinate of point A
              FOTWIDTH,                           // width of src rectangle
              FOTHEIGHT,                          // height of src rectangle
              hb, 0, 0);

  If You "divide" Src image into a couple of vertical rectangles and each will be transferred independently it will be possible to more or less simulate curve. This is theory. You must apologize me but because of my "real" duties I can't try to code it yet. If You'll have some patiance may be I'll try to code it in the near future. In kind of good results I'll let You know.
  Besides for achieving curve effect probably better way is use OpenGL or DirectX but I've got too little practice in that area (And lack of time at the moment).

Regards
Marek
0
 
LVL 17

Expert Comment

by:mokule
ID: 10767517
Sorry!
Should be of course: I must apologize You.
 It's my poor English.

Marek
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 80
select query - oracle 16 100
How to create virtual printer while installing my application 5 51
PHP preg_replace code convert to Delphi 14 57
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question