Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- int width100, height100;
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::OpenPicture1Accept(TObject *Sender)
- {
- Image1->Picture->LoadFromFile( OpenPicture1->Dialog->FileName);
- Image1->SetBounds(0, 0, Image1->Picture->Graphic->Width, Image1->Picture->Graphic->Height);
- Action1->Enabled = true;
- bool const can_zoom = (dynamic_cast<TIcon*> (Image1->Picture->Graphic) == NULL);
- Zoom->Enabled = can_zoom;
- Zoom25->Enabled = can_zoom;
- Zoom50->Enabled = can_zoom;
- Zoom100->Enabled = can_zoom;
- Zoom200->Enabled = can_zoom;
- Zoom400->Enabled = can_zoom;
- ZoomIn->Enabled = can_zoom;
- ZoomOut->Enabled = can_zoom;
- Zoom100->Checked = true;
- width100 = Image1->Picture->Width;
- height100 = Image1->Picture->Height;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Action1Execute(TObject *Sender)
- {
- Zoom100->Checked = false;
- Zoom->Enabled = false;
- Zoom25->Enabled = false;
- Zoom50->Enabled = false;
- Zoom100->Enabled = false;
- Zoom200->Enabled = false;
- Zoom400->Enabled = false;
- ZoomIn->Enabled = false;
- ZoomOut->Enabled = false;
- TAction* const Action = dynamic_cast<TAction*>(Sender);
- if (Action != NULL)
- {
- float const scale_factor = Action->Tag / 100.0f;
- Image1->SetBounds(0, 0, scale_factor *
- Image1->Picture->Graphic->Width, scale_factor *
- Image1->Picture->Graphic->Height
- );
- ZoomIn->Enabled = (Action != Zoom400);
- ZoomOut->Enabled = (Action != Zoom25);
- Action1->Enabled = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::ZoomInExecute(TObject *Sender)
- {
- if (Zoom25->Checked)
- {
- Zoom50->Execute();
- }
- else if (Zoom50->Checked)
- {
- Zoom100->Execute();
- }
- else if (Zoom100->Checked)
- {
- Zoom200->Execute();
- }
- else if (Zoom200->Checked)
- {
- Zoom400->Execute();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::ZoomOutExecute(TObject *Sender)
- {
- if (Zoom400->Checked)
- {
- Zoom200->Execute();
- }
- else if (Zoom200->Checked)
- {
- Zoom100->Execute();
- }
- else if (Zoom100->Checked)
- {
- Zoom50->Execute();
- }
- else if (Zoom50->Checked)
- {
- Zoom25->Execute();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::ZoomExecute(TObject *Sender)
- {
- Image1->Picture->Graphic = NULL;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Zoom25Execute(TObject *Sender)
- {
- Image1->Width = width100 * 0.25;
- Image1->Height = height100 * 0.25;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Zoom50Execute(TObject *Sender)
- {
- Image1->Width = width100 * 0.5;
- Image1->Height = height100 * 0.5;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Zoom100Execute(TObject *Sender)
- {
- Image1->Width = width100 * 1;
- Image1->Height = height100 * 1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Zoom200Execute(TObject *Sender)
- {
- Image1->Width = width100 * 2;
- Image1->Height = height100 * 2;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Zoom400Execute(TObject *Sender)
- {
- Image1->Width = width100 * 4;
- Image1->Height = height100 * 4;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement