- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我们有这样一张图片:
我们有 4 个坐标 top:10, bottom:10, left:10, right:10 我们已经调整到像 newWidth:100, newHeight:35 这样的值 我们有一些生成的 SDL_Rect Sprite
从一些 SDL_Surface *button
如何在 Sprite 上执行这样的调整大小转换?
那么如何在SDL中实现9-slice scaling呢?
最佳答案
我制作了一个使用 c 执行 9 切片渲染的演示项目和 sdl-2这里:https://github.com/cxong/sdl2-9-slice
查看 render()
函数,如果您愿意,可以复制它 - 它已获得许可。
关键是使用SDL_RenderCopy()
的srcrect
和dstrect
参数- 前者是要渲染源纹理的哪一部分,后者是要渲染到目标(渲染目标)的哪一部分。
对于 9 切片,角按原样复制;对于中间部分,根据您想要呈现的方式 - 拉伸(stretch)或重复 - srcrect
将相同,但 dstrect
将拉伸(stretch)或重复。
另一件事是SDL does not do texture repeating (然而)。所以如果你想渲染为重复模式,你需要使用循环。
这是项目终止时的功能:
int render(
SDL_Renderer *renderer, SDL_Surface *s, SDL_Texture *t,
int x, int y, int top, int bottom, int left, int right, int w, int h,
bool repeat)
{
const int srcX[] = {0, left, s->w - right};
const int srcY[] = {0, top, s->h - bottom};
const int srcW[] = {left, s->w - right - left, right};
const int srcH[] = {top, s->h - bottom - top, bottom};
const int dstX[] = {x, x + left, x + w - right, x + w};
const int dstY[] = {y, y + top, y + h - bottom, y + h};
const int dstW[] = {left, w - right - left, right};
const int dstH[] = {top, h - bottom - top, bottom};
SDL_Rect src;
SDL_Rect dst;
for (int i = 0; i < 3; i++)
{
src.x = srcX[i];
src.w = srcW[i];
dst.w = repeat ? srcW[i] : dstW[i];
for (dst.x = dstX[i]; dst.x < dstX[i + 1]; dst.x += dst.w)
{
if (dst.x + dst.w > dstX[i + 1])
{
src.w = dst.w = dstX[i + 1] - dst.x;
}
for (int j = 0; j < 3; j++)
{
src.y = srcY[j];
src.h = srcH[j];
dst.h = repeat ? srcH[j] : dstH[j];
for (dst.y = dstY[j]; dst.y < dstY[j + 1]; dst.y += dst.h)
{
if (dst.y + dst.h > dstY[j + 1])
{
src.h = dst.h = dstY[j + 1] - dst.y;
}
const int res = SDL_RenderCopy(renderer, t, &src, &dst);
if (res != 0)
{
return res;
}
}
}
}
}
return 0;
}
关于c++ - SDL 1.3 : how to inplement simple scale-9-grid for image resize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6479387/
我想创建一个对象,比方说一个饼图。 class Pie def initialize(name, flavor) @name = name @flavor = flavor e
我正在寻找类似于 Log property in Linq DataContext 的功能. 最佳答案 所有执行的 SQL 都写入 Trace,因此您可以使用 TraceListener 访问。 关于
使用 django-simple-history ,如何从我的模型中获取最后更改的对象? 我尝试了 MyModel.history.most_recent(),它需要一个模型实例,因此可能会返回所选实
我定期使用 Eclipse 调试器,这一直困扰着我关于 IDE 的问题。步进过滤是一个非常宝贵的工具,这样我就不会进入没有源代码或者我根本不感兴趣的类。但是,Eclipse 在大多数情况下都没有正确处
我基于有向图构建一棵树。源数据是 SQL 表中的一系列父子关系。它肯定是一棵树(无论如何我都会验证)。我想要一组从根到每片叶子的简单路径。数据是会计“科目表”中的标题,路径类似于“根 -> Asset
我对如何在torii中使用ember-simple-auth有点困惑 我正在使用ember-cli-simple-auth和ember-cli-simple-auth-torii 我得到下面提到的错误
考虑以下用 simple-xml 注释注释的枚举: @Root(name="days") public enum DaysOfWeek { SUNDAY("blue", 30), MO
我有一个 json 文件,我正在 excel 中创建一些 vba 代码。我想用java读取这个json文件。为此,我编写了以下代码 try { Class.forName("org.j
我在尝试使用 google 的 simple-json 解析一个简单的 json 时遇到了一个奇怪的问题。 这是我的代码,它不起作用: String s = args[0].toString(); J
我正在尝试解析下面的 json 文件: {"units":[{"id":42, "title":"Hello World", "positi
我正在使用 simple-import-sort eslint 插件进行 react 。我想我的 .eslintrc.js是对的,但我无法使这个特定的插件工作。我在文件的第一行收到以下错误: 未找到规
我正在尝试解析子文件,但我不知道自己做错了什么(当然,我也不知道自己做对了什么)。 文件.json [{ "arrOne":{ "one":"a", "two":"b",
在我的Angel 16(独立的)应用程序中,我有一个简单的服务来测试LangChain和OpenAI。同样的代码在NodeJS应用程序中运行得非常好,然而,当从角度运行时,OpenAI返回的结果总是空
我正在尝试测试连接到数据库的 Web 应用程序 - 我的 Junit 代码不执行连接。 设置按照 https://github.com/h-thurow/Simple-JNDI InitialCont
我正在尝试制作一个小型应用程序,它可以通过 ISBN 在亚马逊上搜索一本书。我是 Amazon Web Service 的新手。 我正在关注以下链接: http://flyingpies.wordpr
我正在使用简单 XML 序列化 (simple-xml-2.6.6.jar) here将我的 XML 响应从 webservice 转换为 POJO 类。 XML 是:
Simple UI混合开发的必经之路~ Simple UI快速上手 在混合开发的模式下,如果想使用django admin,又嫌弃后台不符合你的审美?Simple UI给你想要的答案,我不是打广告的~
Simple JSON是Google开发的Java JSON解析框架,基于Apache协议。 下载的文件是:json_simple.jar 例子1:很方便的方式,使用JSONValue
我有一个 simple_form 表单设置,它会很好地显示内联错误。我遇到过一些用户看不到这些错误的问题,并要求在非常长的表格顶部进行清晰的枚举。我使用了 Rails 教程中的代码设置:
我正在使用简单的 XML 框架,只是重命名了一些 XML 布局,这些布局现在似乎不再起作用了。 这是我的 XML: 2 0 1
我是一名优秀的程序员,十分优秀!