Advertisement
Guest User

Untitled

a guest
May 19th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. #include <vcl.h>
  2. #pragma hdrstop
  3.  
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. int width100, height100;
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12. : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TForm1::OpenPicture1Accept(TObject *Sender)
  17. {
  18. Image1->Picture->LoadFromFile( OpenPicture1->Dialog->FileName);
  19. Image1->SetBounds(0, 0, Image1->Picture->Graphic->Width, Image1->Picture->Graphic->Height);
  20. Action1->Enabled = true;
  21. bool const can_zoom = (dynamic_cast<TIcon*> (Image1->Picture->Graphic) == NULL);
  22. Zoom->Enabled = can_zoom;
  23. Zoom25->Enabled = can_zoom;
  24. Zoom50->Enabled = can_zoom;
  25. Zoom100->Enabled = can_zoom;
  26. Zoom200->Enabled = can_zoom;
  27. Zoom400->Enabled = can_zoom;
  28. ZoomIn->Enabled = can_zoom;
  29. ZoomOut->Enabled = can_zoom;
  30. Zoom100->Checked = true;
  31. width100 = Image1->Picture->Width;
  32. height100 = Image1->Picture->Height;
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TForm1::Action1Execute(TObject *Sender)
  36. {
  37. Zoom100->Checked = false;
  38.  
  39. Zoom->Enabled = false;
  40. Zoom25->Enabled = false;
  41. Zoom50->Enabled = false;
  42. Zoom100->Enabled = false;
  43. Zoom200->Enabled = false;
  44. Zoom400->Enabled = false;
  45. ZoomIn->Enabled = false;
  46. ZoomOut->Enabled = false;
  47. TAction* const Action = dynamic_cast<TAction*>(Sender);
  48. if (Action != NULL)
  49. {
  50. float const scale_factor = Action->Tag / 100.0f;
  51. Image1->SetBounds(0, 0, scale_factor *
  52. Image1->Picture->Graphic->Width, scale_factor *
  53. Image1->Picture->Graphic->Height
  54. );
  55.  
  56. ZoomIn->Enabled = (Action != Zoom400);
  57. ZoomOut->Enabled = (Action != Zoom25);
  58. Action1->Enabled = false;
  59. }
  60. }
  61. //---------------------------------------------------------------------------
  62.  
  63. void __fastcall TForm1::ZoomInExecute(TObject *Sender)
  64. {
  65. if (Zoom25->Checked)
  66. {
  67. Zoom50->Execute();
  68. }
  69. else if (Zoom50->Checked)
  70. {
  71. Zoom100->Execute();
  72. }
  73. else if (Zoom100->Checked)
  74. {
  75. Zoom200->Execute();
  76. }
  77. else if (Zoom200->Checked)
  78. {
  79. Zoom400->Execute();
  80. }
  81. }
  82. //---------------------------------------------------------------------------
  83.  
  84. void __fastcall TForm1::ZoomOutExecute(TObject *Sender)
  85. {
  86. if (Zoom400->Checked)
  87. {
  88. Zoom200->Execute();
  89. }
  90. else if (Zoom200->Checked)
  91. {
  92. Zoom100->Execute();
  93. }
  94. else if (Zoom100->Checked)
  95. {
  96. Zoom50->Execute();
  97. }
  98. else if (Zoom50->Checked)
  99. {
  100. Zoom25->Execute();
  101. }
  102. }
  103. //---------------------------------------------------------------------------
  104.  
  105. void __fastcall TForm1::ZoomExecute(TObject *Sender)
  106. {
  107. Image1->Picture->Graphic = NULL;
  108. }
  109. //---------------------------------------------------------------------------
  110.  
  111. void __fastcall TForm1::Zoom25Execute(TObject *Sender)
  112. {
  113. Image1->Width = width100 * 0.25;
  114. Image1->Height = height100 * 0.25;
  115. }
  116. //---------------------------------------------------------------------------
  117.  
  118. void __fastcall TForm1::Zoom50Execute(TObject *Sender)
  119. {
  120. Image1->Width = width100 * 0.5;
  121. Image1->Height = height100 * 0.5;
  122. }
  123. //---------------------------------------------------------------------------
  124.  
  125. void __fastcall TForm1::Zoom100Execute(TObject *Sender)
  126. {
  127. Image1->Width = width100 * 1;
  128. Image1->Height = height100 * 1;
  129. }
  130. //---------------------------------------------------------------------------
  131.  
  132. void __fastcall TForm1::Zoom200Execute(TObject *Sender)
  133. {
  134. Image1->Width = width100 * 2;
  135. Image1->Height = height100 * 2;
  136. }
  137. //---------------------------------------------------------------------------
  138.  
  139. void __fastcall TForm1::Zoom400Execute(TObject *Sender)
  140. {
  141. Image1->Width = width100 * 4;
  142. Image1->Height = height100 * 4;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement