changeset 71:1fd20d231376

Fix objScale with 2D zoom; implement objWidth and objHeight.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 01 Apr 2011 23:49:12 +0200
parents 281dcd7217df
children f9eb96a4cce0
files scn2k/scn2k_grp.cc scn2k/scn2k_grp.h scn2k/scn2k_grpimpl.cc window/picture.cc window/picture.h
diffstat 5 files changed, 52 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/scn2k/scn2k_grp.cc
+++ b/scn2k/scn2k_grp.cc
@@ -42,7 +42,7 @@ GrpObj::GrpObj(void) :
 	_posx(0), _posy(0), clip_area(0,0,0,0),
 	alpha(255), order(0), surface_num(0), print_moji(""), print_size(0), print_r(-1),print_g(-1),print_b(-1),
 	dig_number(0), dig_digit(0),
-	zoom(-1), rotate(-1), attr(GrpObj::HIDDEN) {
+	zoomx(-1), zoomy(-1), rotate(-1), attr(GrpObj::HIDDEN) {
 	int i;
 	for (i=0; i<9; i++) {
 		posx[i] = posy[i] = 0;
@@ -168,7 +168,7 @@ void GrpObj::Update(void) {
 	}
 	if (picture == NULL) return;
 	if (attr & UPDATE_POS) {
-		if (zoom != -1) {
+		if (zoomx != -1 || zoomy != -1) {
 			int w=0, h=0;
 			GetSrcGeom(w,h);
 			picture->Move(_posx-w/2, _posy-h/2);
@@ -229,7 +229,7 @@ void GrpObj::UpdateSurface(void) {
 		GetSrcGeom(width, height);
 		if (width <= 0 || height <= 0) return;
 		// surface の設定
-		if (surface_num == 0 && ( (zoom > 0 && zoom != 256) || rotate > 0)) {
+		if (surface_num == 0 && ( ((zoomx > 0 && zoomx != 256) || (zoomy > 0 && zoomy != 256)) || rotate > 0)) {
 			ZoomRotate();
 		} else {
 			// 普通に surface を設定
@@ -257,7 +257,7 @@ void GrpObj::ZoomRotate(void) {
 	Surface* surface_orig = pic_parent->Root().NewSurface(path.c_str());
 	if (surface_orig == NULL) return;
 
-	Surface* zoom_surface = pic_parent->Root().RotZoomSurface(surface_orig, double(zoom)/256.0, rotate);
+	Surface* zoom_surface = pic_parent->Root().RotZoomSurface(surface_orig, double(zoomx)/256.0, double(zoomy)/256.0, rotate);
 	Rect zoom_r (*zoom_surface);
 	picture->SetSurface(zoom_surface, 0, 0);
 	picture->SetSurfaceFreeFlag();
@@ -467,14 +467,16 @@ void GrpObj::CreateGanSpecial(Event::Con
 	}
 }
 
-void GrpObj::SetZoomRotate(int new_zoom, int new_rotate) {
-	if (zoom == new_zoom && rotate == new_rotate) return;
-	if ( zoom == -1 || new_zoom == -1) {
+void GrpObj::SetZoomRotate(int new_zoom_x, int new_zoom_y, int new_rotate) {
+	if (zoomx == new_zoom_x && zoomy == new_zoom_y && rotate == new_rotate) return;
+	if (zoomx == -1 || zoomy == -1 || new_zoom_x == -1 || new_zoom_y == -1) {
 		attr = Attribute(attr | UPDATE_POS); // centering する
 	}
-	zoom = new_zoom;
+	zoomx = new_zoom_x;
+	zoomy = new_zoom_y;
 	if (new_rotate != -1) rotate = new_rotate;
-	if (zoom < 0) zoom = 256;
+	if (zoomx < 0) zoomx = 256;
+	if (zoomy < 0) zoomy = 256;
 	if (rotate < 0) rotate = 0;
 	else if (rotate > 360) rotate %= 360;
 
@@ -749,10 +751,12 @@ Grp::Grp(Event::Container& _event, PicCo
 	RegisterCommand(1, 82, 1038, "objBgNumOpts", (CmdImpl) &Grp::impl_objNumOpts);
 	RegisterCommand(1, 81, 1039, "objPattNo", (CmdImpl) &Grp::impl_objPattNo);
 	RegisterCommand(1, 82, 1039, "objBgPattNo", (CmdImpl) &Grp::impl_objPattNo);
-	RegisterCommand(1, 81, 1046, "objScale", (CmdImpl) &Grp::impl_objScale); //FIXME: Broken behaviour
+	RegisterCommand(1, 81, 1046, "objScale", (CmdImpl) &Grp::impl_objScale);
 	RegisterCommand(1, 82, 1046, "objBgScale", (CmdImpl) &Grp::impl_objScale);
-	RegisterCommand(1, 81, 1047, "objWidth", NULL);
-	RegisterCommand(1, 82, 1047, "objBgWidth", NULL);
+	RegisterCommand(1, 81, 1047, "objWidth", (CmdImpl) &Grp::impl_objWidth);
+	RegisterCommand(1, 82, 1047, "objBgWidth", (CmdImpl) &Grp::impl_objWidth);
+	RegisterCommand(1, 81, 1048, "objHeight", (CmdImpl) &Grp::impl_objHeight);
+	RegisterCommand(1, 82, 1048, "objBgHeight", (CmdImpl) &Grp::impl_objHeight);
 	RegisterCommand(1, 81, 1049, "objRotate", (CmdImpl) &Grp::impl_objRotate);
 	RegisterCommand(1, 82, 1049, "objBgRotate", (CmdImpl) &Grp::impl_objRotate);
 
--- a/scn2k/scn2k_grp.h
+++ b/scn2k/scn2k_grp.h
@@ -76,7 +76,7 @@ struct GrpObj {
 	int dig_number, dig_digit;
 
 	// zoom / rotate 関係
-	int zoom; // 256 で 1 倍
+	int zoomx, zoomy; // 256 で 1 倍
 	int rotate; // 0-360度
 
 	vector<Rect> src_pos;
@@ -99,7 +99,7 @@ struct GrpObj {
 	void SetAlpha(void);
 	void SetAlpha(int alpha);
 	void SetSurfaceNum(int num = -1);
-	void SetZoomRotate(int zoom=-1, int rotate=-1);
+	void SetZoomRotate(int zoomx=-1, int zoomy=-1, int rotate=-1);
 	void SetClipArea(int x, int y, int width, int height);
 	void GetSrcGeom(int& width, int& height);
 	void SetUpdate(void);
@@ -200,6 +200,8 @@ class Grp : public CommandHandler {
 		void impl_objNumOpts(Cmd &cmd);
 		void impl_objPattNo(Cmd &cmd);
 		void impl_objScale(Cmd &cmd);
+		void impl_objWidth(Cmd &cmd);
+		void impl_objHeight(Cmd &cmd);
 		void impl_objRotate(Cmd &cmd);
 		void impl_objPosDims(Cmd &cmd);
 		void impl_refresh(Cmd &cmd);
--- a/scn2k/scn2k_grpimpl.cc
+++ b/scn2k/scn2k_grpimpl.cc
@@ -629,9 +629,35 @@ void Grp::impl_objScale(Cmd& cmd) {
 	int base_arg = 0;
 	GrpObj* g = GetGraphicObjVarMode(cmd, base_arg, (cmd.cmd2 == 0x51));
 
-	int zoom = (cmd.args[base_arg + 1].value + cmd.args[base_arg + 2].value)/2; //FIXME: eurk
+	int zoomx = cmd.args[base_arg + 1].value;
+	zoomx = zoomx*256/100;
+
+	int zoomy = cmd.args[base_arg + 2].value;
+	zoomy = zoomy*256/100;
+
+	g->SetZoomRotate(zoomx, zoomy, -1);
+	cmd.clear();
+}
+
+void Grp::impl_objWidth(Cmd& cmd) {
+	int base_arg = 0;
+	GrpObj* g = GetGraphicObjVarMode(cmd, base_arg, (cmd.cmd2 == 0x51));
+
+	int zoom = cmd.args[base_arg + 1].value;
 	zoom = zoom*256/100;
-	g->SetZoomRotate(zoom, -1);
+
+	g->SetZoomRotate(zoom, -1, -1);
+	cmd.clear();
+}
+
+void Grp::impl_objHeight(Cmd& cmd) {
+	int base_arg = 0;
+	GrpObj* g = GetGraphicObjVarMode(cmd, base_arg, (cmd.cmd2 == 0x51));
+
+	int zoom = cmd.args[base_arg + 1].value;
+	zoom = zoom*256/100;
+
+	g->SetZoomRotate(-1, zoom, -1);
 	cmd.clear();
 }
 
@@ -646,7 +672,7 @@ void Grp::impl_objRotate(Cmd& cmd) {
 		angle += 360;
 	}
 	angle %= 360;
-	g->SetZoomRotate(-1, angle);
+	g->SetZoomRotate(-1, -1, angle);
 	cmd.clear();
 }
 
--- a/window/picture.cc
+++ b/window/picture.cc
@@ -961,8 +961,8 @@ Surface* PicRoot::NewSurface(const char*
 	return s;
 }
 
-Surface* PicRoot::RotZoomSurface(Surface* from, double zoom, double rotate) {
-	Surface* ret = (Surface*)rotozoomSurface( (SDL_Surface*)from, rotate, zoom, SMOOTHING_OFF);
+Surface* PicRoot::RotZoomSurface(Surface* from, double zoomx, double zoomy, double rotate) {
+	Surface* ret = (Surface*)rotozoomSurfaceXY( (SDL_Surface*)from, rotate, zoomx, zoomy, SMOOTHING_OFF);
 	return ret;
 }
 
--- a/window/picture.h
+++ b/window/picture.h
@@ -216,7 +216,7 @@ struct PicRoot {
 		Surface* NewSurfaceFromRGBAData(int w, int h, char* data, MaskType with_mask) const; // data は malloc されたものであること(SDLの内部仕様)
 		Surface* NewSurface(int w, int h, MaskType with_mask) const;
 		Surface* NewSurface(const char* filename, MaskType with_mask = ALPHA_MASK);
-		Surface* RotZoomSurface(Surface* from, double zoom, double rotate_angle);
+		Surface* RotZoomSurface(Surface* from, double zoomx, double zoomy, double rotate_angle);
 		void DeleteSurface(Surface* s);
 		void BlitSurface(Surface* src, const Rect& src_rpos, const unsigned char* alpha, const Rect& alpha_r,  Surface* dest, const Rect& dest_rpos, int attribute) const;
 		void BlitSurface(Surface* src, const Rect& src_rpos, Surface* dest, const Rect& dest_rpos) const {