Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

"Crop to Selection" implemented

Finally!
  • Loading branch information...
commit bcbaeeed24ba66fc398c6eada914dd458d61b1ec 1 parent 4a8e596
@tannerhelland authored
View
10 Forms/VBP_FormMain.frm
@@ -834,6 +834,9 @@ Begin VB.MDIForm FormMain
Caption = "Resize..."
Shortcut = ^R
End
+ Begin VB.Menu MnuCropSelection
+ Caption = "Crop to Selection"
+ End
Begin VB.Menu MnuImageSepBar1
Caption = "-"
End
@@ -1765,6 +1768,10 @@ Private Sub MnuCountColors_Click()
Process CountColors
End Sub
+Private Sub MnuCropSelection_Click()
+ Process CropToSelection
+End Sub
+
Private Sub MnuCShiftL_Click()
Process ColorShiftLeft, 1
End Sub
@@ -2391,6 +2398,9 @@ Private Sub ctlAccelerator_Accelerator(ByVal nIndex As Long, bCancel As Boolean)
If ctlAccelerator.Key(nIndex) = "Rotate_Left" Then Process Rotate270Clockwise
If ctlAccelerator.Key(nIndex) = "Rotate_Right" Then Process Rotate90Clockwise
+ 'Crop to selection
+ If pdImages(CurrentImage).selectionActive Then Process CropToSelection
+
'Next / Previous image hotkeys ("Page Down" and "Page Up", respectively)
If ctlAccelerator.Key(nIndex) = "Prev_Image" Or ctlAccelerator.Key(nIndex) = "Next_Image" Then
View
51 Modules/VBP_Filters_Rotate.bas
@@ -1,17 +1,58 @@
-Attribute VB_Name = "Filters_Rotate"
+Attribute VB_Name = "Filters_Transform"
'***************************************************************************
-'Filter (Rotation) Interface
+'Image Transformations Interface (including flip/mirror/rotation/crop/etc)
'Copyright ©2000-2012 by Tanner Helland
'Created: 25/January/03
-'Last updated: 05/September/12
-'Last update: Rewrote all rotation code against the new layer system.
+'Last updated: 05/October/12
+'Last update: Added cropping to selection.
'
-'Runs all rotation-style transformations. Includes flip and mirror as well.
+'Runs all image transformations, including rotate, flip, mirror and crop at present.
'
'***************************************************************************
Option Explicit
+'Crop the image to the current selection
+Public Sub MenuCropToSelection()
+
+ 'First, make sure there is an active selection
+ If pdImages(CurrentImage).selectionActive = False Then
+ Message "No active selection found. Crop abandoned."
+ Exit Sub
+ End If
+
+ Message "Cropping image to selected area..."
+
+ 'Create a new layer the size of the active selection
+ Dim tmpLayer As pdLayer
+ Set tmpLayer = New pdLayer
+ tmpLayer.createBlank pdImages(CurrentImage).mainSelection.selWidth, pdImages(CurrentImage).mainSelection.selHeight, pdImages(CurrentImage).mainLayer.getLayerColorDepth
+
+ 'Copy the selection area to the temporary layer
+ BitBlt tmpLayer.getLayerDC, 0, 0, pdImages(CurrentImage).mainSelection.selWidth, pdImages(CurrentImage).mainSelection.selHeight, pdImages(CurrentImage).mainLayer.getLayerDC, pdImages(CurrentImage).mainSelection.selLeft, pdImages(CurrentImage).mainSelection.selTop, vbSrcCopy
+
+ 'Transfer the newly cropped image back into the main layer object
+ pdImages(CurrentImage).mainLayer.createFromExistingLayer tmpLayer
+
+ 'Erase the temporary layer
+ tmpLayer.eraseLayer
+ Set tmpLayer = Nothing
+
+ 'Update the current image size
+ pdImages(CurrentImage).updateSize
+ DisplaySize pdImages(CurrentImage).Width, pdImages(CurrentImage).Height
+
+ Message "Finished. "
+
+ 'Deactivate the current selection, as it's no longer needed
+ pdImages(CurrentImage).selectionActive = False
+ tInit tSelection, False
+
+ 'Redraw the image
+ PrepareViewport FormMain.ActiveForm, "Crop to selection"
+
+End Sub
+
'Flip an image vertically
Public Sub MenuFlip()
View
2  Modules/VBP_LoadModule.bas
@@ -744,6 +744,7 @@ Public Sub LoadMenuShortcuts()
'Image menu
.AddAccelerator vbKeyL, 0, "Rotate_Left"
.AddAccelerator vbKeyR, 0, "Rotate_Right"
+ .AddAccelerator vbKeyX, vbCtrlMask Or vbShiftMask, "Crop_Selection"
'Color Menu
.AddAccelerator vbKeyC, vbCtrlMask Or vbShiftMask, "Bright_Contrast"
@@ -789,6 +790,7 @@ Public Sub LoadMenuShortcuts()
'Image menu
FormMain.MnuRotateClockwise.Caption = FormMain.MnuRotateClockwise.Caption & vbTab & "R"
FormMain.MnuRotate270Clockwise.Caption = FormMain.MnuRotate270Clockwise.Caption & vbTab & "L"
+ FormMain.MnuCropSelection.Caption = FormMain.MnuCropSelection.Caption & vbTab & "Ctrl+Shift+X"
'Color menu
FormMain.MnuBrightness.Caption = FormMain.MnuBrightness.Caption & vbTab & "Ctrl+Shift+C"
View
16 Modules/VBP_MenuIcons.bas
@@ -247,6 +247,7 @@ Public Sub LoadMenuIcons()
.AddImageFromStream LoadResData("DOWNLOADSRC", "CUSTOM") '141
.AddImageFromStream LoadResData("LICENSE", "CUSTOM") '142
.AddImageFromStream LoadResData("SEPIA", "CUSTOM") '143
+ .AddImageFromStream LoadResData("CROPSEL", "CUSTOM") '144
'File Menu
@@ -293,13 +294,14 @@ Public Sub LoadMenuIcons()
'Image Menu
.PutImageToVBMenu 42, 0, 3
.PutImageToVBMenu 19, 2, 3 'Resize
- .PutImageToVBMenu 24, 4, 3 'Mirror
- .PutImageToVBMenu 23, 5, 3 'Flip
- .PutImageToVBMenu 20, 7, 3 'Rotate Clockwise (rotate submenu)
- .PutImageToVBMenu 21, 8, 3 'Rotate Counter-clockwise (rotate submenu)
- .PutImageToVBMenu 22, 9, 3 'Rotate 180 (rotate submenu)
- .PutImageToVBMenu 125, 11, 3 'Isometric
- .PutImageToVBMenu 132, 12, 3 'Tile
+ .PutImageToVBMenu 144, 3, 3 'Crop to Selection
+ .PutImageToVBMenu 24, 5, 3 'Mirror
+ .PutImageToVBMenu 23, 6, 3 'Flip
+ .PutImageToVBMenu 20, 8, 3 'Rotate Clockwise (rotate submenu)
+ .PutImageToVBMenu 21, 9, 3 'Rotate Counter-clockwise (rotate submenu)
+ .PutImageToVBMenu 22, 10, 3 'Rotate 180 (rotate submenu)
+ .PutImageToVBMenu 125, 12, 3 'Isometric
+ .PutImageToVBMenu 132, 13, 3 'Tile
'Color Menu
.PutImageToVBMenu 46, 0, 4 'Brightness/Contrast
View
7 Modules/VBP_ProcessorModule.bas
@@ -171,8 +171,10 @@ Option Explicit
Public Const FreeRotate As Long = 706
'-Isometric
Public Const Isometric As Long = 707
- 'Tiling
+ '-Tiling
Public Const Tile As Long = 708
+ '-Crop to Selection
+ Public Const CropToSelection As Long = 709
'Other filters; numbers 800-899
'-Compound invert
@@ -676,6 +678,9 @@ Public Sub Process(ByVal pType As Long, Optional pOPCODE As Variant = 0, Optiona
Else
FormTile.GenerateTile CByte(pOPCODE), CLng(pOPCODE2), CLng(pOPCODE3)
End If
+ Case CropToSelection
+ MenuCropToSelection
+
End Select
End If
View
3  Modules/VBP_ToolbarModule.bas
@@ -139,6 +139,9 @@ Public Sub tInit(tButton As Byte, tState As Boolean)
If FormMain.lblSelSize.Visible <> tState Then FormMain.lblSelSize.Visible = tState
If FormMain.lblSelPosition.Visible <> tState Then FormMain.lblSelPosition.Visible = tState
+ 'Selection enabling/disabling also affects the Crop to Selection command
+ If FormMain.MnuCropSelection.Enabled <> tState Then FormMain.MnuCropSelection.Enabled = tState
+
End Select
End Sub
View
4 PhotoDemon.vbp
@@ -50,7 +50,7 @@ Form=Forms\VBP_FormPosterize.frm
Form=Forms\VBP_FormImage.frm
Module=MDI_Handler; Modules\VBP_MDIWindow.bas
Module=Filters_Color_Effects; Modules\VBP_Filters_Color_Effects.bas
-Module=Filters_Rotate; Modules\VBP_Filters_Rotate.bas
+Module=Filters_Transform; Modules\VBP_Filters_Rotate.bas
Form=Forms\VBP_FormImportFrx.frm
Class=cFrxFile; Classes\OutsideDevelopment_FrxFile.cls
Class=cFrxItem; Classes\OutsideDevelopment_FrxItem.cls
@@ -108,7 +108,7 @@ Description="PhotoDemon"
CompatibleMode="0"
MajorVer=5
MinorVer=1
-RevisionVer=57
+RevisionVer=59
AutoIncrementVer=1
ServerSupportFiles=0
VersionComments="�2000-2012 Tanner Helland - www.tannerhelland.com"
View
BIN  Resources/PD_icons.RES
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.