Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Sdl 1.3:如何输入简单的缩放9网格以调整图像大小?_C++_C_Sdl_Nine Patch_Scale9grid_Sdl 2 - Fatal编程技术网

C++ Sdl 1.3:如何输入简单的缩放9网格以调整图像大小?

C++ Sdl 1.3:如何输入简单的缩放9网格以调整图像大小?,c++,c,sdl,nine-patch,scale9grid,sdl-2,C++,C,Sdl,Nine Patch,Scale9grid,Sdl 2,我们有这样一个图像: 我们有4个坐标,顶部:10,底部:10,左侧:10,右侧:10,我们必须调整大小到像newWidth:100,newHeight:35这样的值,我们有一些SDL_Rect Sprite,它是从一些SDL_Surface*按钮生成的 那么如何在SDL中输入9层缩放?我制作了一个演示项目,使用和执行9层渲染: 查看render()函数,如果您愿意,可以复制它-它是许可的 关键是使用的srcrect和dstrect参数-前者是要渲染的源纹理的哪一部分,后者是要渲染到的目标(渲

我们有这样一个图像:

我们有4个坐标,顶部:10,底部:10,左侧:10,右侧:10,我们必须调整大小到像newWidth:100,newHeight:35这样的值,我们有一些
SDL_Rect Sprite
,它是从一些
SDL_Surface*按钮生成的


那么如何在SDL中输入9层缩放?

我制作了一个演示项目,使用和执行9层渲染:

查看
render()
函数,如果您愿意,可以复制它-它是许可的

关键是使用的
srcrect
dstrect
参数-前者是要渲染的源纹理的哪一部分,后者是要渲染到的目标(渲染目标)的哪一部分

对于9层,角点按原样复制;对于中间部分,根据要渲染的方式(拉伸或重复),
srrect
将是相同的,但
dstrect
将拉伸或重复

另一件事是(还没有)。因此,如果要渲染为重复模式,则需要使用循环

以下是项目终止时的功能:

int渲染(
SDL_渲染器*渲染器,SDL_曲面*s,SDL_纹理*t,
int x,int y,int top,int bottom,int left,int right,int w,int h,
布尔(重复)
{
const int srcX[]={0,左,s->w-右};
const int srcY[]={0,top,s->h-bottom};
const int srcW[]={left,s->w-右-左,右};
const int srcH[]={top,s->h-bottom-top,bottom};
const int dstX[]={x,x+左,x+w-右,x+w};
const int dstY[]={y,y+top,y+h-bottom,y+h};
const int dstW[]={左,w-右-左,右};
const int dstH[]={top,h-bottom-top,bottom};
SDL__Rect src;
SDL-Rect dst;
对于(int i=0;i<3;i++)
{
src.x=srcX[i];
src.w=srcW[i];
dst.w=重复?srcW[i]:dstW[i];
对于(dst.x=dstX[i];dst.xdstX[i+1])
{
src.w=dst.w=dstX[i+1]-dst.x;
}
对于(int j=0;j<3;j++)
{
src.y=srcY[j];
src.h=srcH[j];
dst.h=重复?srcH[j]:dstH[j];
对于(dst.y=dst[j];dst.ydst[j+1])
{
src.h=dst.h=dstY[j+1]-dst.y;
}
const int res=SDL_RenderCopy(渲染器、t、src和dst);
如果(res!=0)
{
返回res;
}
}
}
}
}
返回0;
}