Solved

Urgent: Page Turning Code!

Posted on 2004-04-03
12
333 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
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
Comment Utility
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
Comment Utility
it is an animation effect that appears like the page is turning (like a book page). example is like www.flipalbum.com
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 17

Accepted Solution

by:
mokule earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry!
Should be of course: I must apologize You.
 It's my poor English.

Marek
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now