Re-implemented scaling to visual typesetting.

Originally committed to SVN as r1328.
This commit is contained in:
Rodrigo Braz Monteiro 2007-07-01 03:17:56 +00:00
parent d06fdfda65
commit 4dd3a031c6
4 changed files with 236 additions and 1 deletions

View file

@ -218,6 +218,7 @@ aegisub_SOURCES = \
visual_tool_cross.cpp \ visual_tool_cross.cpp \
visual_tool_rotatexy.cpp \ visual_tool_rotatexy.cpp \
visual_tool_rotatez.cpp \ visual_tool_rotatez.cpp \
visual_tool_scale.cpp \
MatroskaParser.c MatroskaParser.c
noinst_HEADERS = \ noinst_HEADERS = \

View file

@ -71,6 +71,7 @@
#include "visual_tool_cross.h" #include "visual_tool_cross.h"
#include "visual_tool_rotatez.h" #include "visual_tool_rotatez.h"
#include "visual_tool_rotatexy.h" #include "visual_tool_rotatexy.h"
#include "visual_tool_scale.h"
/////// ///////
@ -650,7 +651,7 @@ void VideoDisplay::SetVisualMode(int mode) {
//case 1: visual = new VisualToolDrag(this); break; //case 1: visual = new VisualToolDrag(this); break;
case 2: visual = new VisualToolRotateZ(this); break; case 2: visual = new VisualToolRotateZ(this); break;
case 3: visual = new VisualToolRotateXY(this); break; case 3: visual = new VisualToolRotateXY(this); break;
//case 4: visual = new VisualToolScale(this); break; case 4: visual = new VisualToolScale(this); break;
//case 5: visual = new VisualToolClip(this); break; //case 5: visual = new VisualToolClip(this); break;
default: visual = NULL; default: visual = NULL;
} }

View file

@ -0,0 +1,170 @@
// Copyright (c) 2007, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
///////////
// Headers
#include "visual_tool_scale.h"
#include "subs_grid.h"
#include "subs_edit_box.h"
#include "ass_file.h"
#include "ass_dialogue.h"
#include "utils.h"
///////////////
// Constructor
VisualToolScale::VisualToolScale(VideoDisplay *_parent)
: VisualTool(_parent)
{
_parent->ShowCursor(false);
}
//////////
// Update
void VisualToolScale::Update() {
// Render parent
GetParent()->Render();
}
////////
// Draw
void VisualToolScale::Draw() {
// Get line to draw
AssDialogue *line = GetActiveDialogueLine();
if (!line) return;
// Get line position and rotation
int dx,dy;
float rx,ry,rz;
GetLinePosition(line,dx,dy);
GetLineRotation(line,rx,ry,rz);
// Set dx/dy
int len = 160;
dx = MID(len/2+10,dx,sw-len/2-30);
dy = MID(len/2+10,dy,sh-len/2-30);
// Set colours
SetLineColour(colour[0]);
SetFillColour(colour[1],0.3f);
// Transform grid
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(dx,dy,0.0f);
float matrix[16] = { 2500, 0, 0, 0, 0, 2500, 0, 0, 0, 0, 1, 1, 0, 0, 2500, 2500 };
glMultMatrixf(matrix);
glScalef(1.0f,1.0f,8.0f);
if (ry != 0.0f) glRotatef(ry,0.0f,-1.0f,0.0f);
if (rx != 0.0f) glRotatef(rx,-1.0f,0.0f,0.0f);
if (rz != 0.0f) glRotatef(rz,0.0f,0.0f,-1.0f);
// Scale parameters
int lenx = int(1.6 * curScaleX);
int leny = int(1.6 * curScaleY);
int drawX = len/2 + 10;
int drawY = len/2 + 10;
// Draw length markers
SetLineColour(colour[3],1.0f,2);
DrawLine(-lenx/2,drawY+10,lenx/2,drawY+10);
DrawLine(drawX+10,-leny/2,drawX+10,leny/2);
SetLineColour(colour[0],1.0f,1);
SetFillColour(colour[1],0.3f);
DrawCircle(lenx/2,drawY+10,4);
DrawCircle(drawX+10,-leny/2,4);
// Draw horizontal scale
SetLineColour(colour[0],1.0f,1);
DrawRectangle(-len/2,drawY,len/2+1,drawY+5);
SetLineColour(colour[0],1.0f,2);
DrawLine(-len/2+1,drawY+5,-len/2+1,drawY+15);
DrawLine(len/2,drawY+5,len/2,drawY+15);
// Draw vertical scale
SetLineColour(colour[0],1.0f,1);
DrawRectangle(drawX,-len/2,drawX+5,len/2+1);
SetLineColour(colour[0],1.0f,2);
DrawLine(drawX+5,-len/2+1,drawX+15,-len/2+1);
DrawLine(drawX+5,len/2,drawX+15,len/2);
// Restore gl's state
glPopMatrix();
}
/////////////////
// Start holding
void VisualToolScale::InitializeHold() {
startX = mouseX;
startY = mouseY;
GetLineScale(curDiag,origScaleX,origScaleY);
curScaleX = origScaleX;
curScaleY = origScaleY;
curDiag->StripTag(_T("\\fscx"));
curDiag->StripTag(_T("\\fscy"));
}
///////////////
// Update hold
void VisualToolScale::UpdateHold() {
// Calculate
curScaleX = (float(mouseX - startX)/0.8f) + origScaleX;
curScaleY = (float(startY - mouseY)/0.8f) + origScaleY;
if (curScaleX < 0.0f) curScaleX = 0.0f;
if (curScaleY < 0.0f) curScaleY = 0.0f;
// Snap
if (shiftDown) {
curScaleX = (float)((int)((curScaleX+12.5f)/25.0f))*25.0f;
curScaleY = (float)((int)((curScaleY+12.5f)/25.0f))*25.0f;
}
}
///////////////
// Commit hold
void VisualToolScale::CommitHold() {
VideoContext::Get()->grid->editBox->SetOverride(_T("\\fscx"),PrettyFloat(wxString::Format(_T("(%0.3f)"),curScaleX)),0,false);
VideoContext::Get()->grid->editBox->SetOverride(_T("\\fscy"),PrettyFloat(wxString::Format(_T("(%0.3f)"),curScaleY)),0,false);
}

View file

@ -0,0 +1,63 @@
// Copyright (c) 2007, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
///////////
// Headers
#include "visual_tool.h"
/////////////////////////
// Z Rotation tool class
class VisualToolScale : public VisualTool {
private:
float curScaleX,startScaleX,origScaleX;
float curScaleY,startScaleY,origScaleY;
int startX,startY;
bool CanHold() { return true; }
void InitializeHold();
void UpdateHold();
void CommitHold();
public:
VisualToolScale(VideoDisplay *parent);
void Update();
void Draw();
};