this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Renamed new "hotspot" code and references to "anchor" instead. Added GPU_GetDefaultAnchor() and GPU_GetAnchor().

+99 -64
+17 -9
include/SDL_gpu.h
··· 231 231 Uint16 texture_w, texture_h; // Underlying texture dimensions 232 232 Uint8 has_mipmaps; 233 233 234 - float hotspot_x; // Normalized coords for the point at which the image is blitted. Default is (0.5, 0.5), that is, the image is drawn centered. 235 - float hotspot_y; // These are always interpreted as inverted. (0,0) is in the upper left and would draw as SDL_BlitSurface() does. 234 + float anchor_x; // Normalized coords for the point at which the image is blitted. Default is (0.5, 0.5), that is, the image is drawn centered. 235 + float anchor_y; // These are interpreted according to GPU_SetCoordinateMode() and range from (0.0 - 1.0) normally. 236 236 237 237 SDL_Color color; 238 238 Uint8 use_blending; ··· 594 594 Uint8 coordinate_mode; 595 595 596 596 /*! Default is (0.5, 0.5) - images draw centered. */ 597 - float default_image_hotspot_x; 598 - float default_image_hotspot_y; 597 + float default_image_anchor_x; 598 + float default_image_anchor_y; 599 599 600 600 struct GPU_RendererImpl* impl; 601 601 }; ··· 791 791 792 792 DECLSPEC Uint8 SDLCALL GPU_GetCoordinateMode(void); 793 793 794 - /*! Sets the default image blitting hotspot for newly created images. 795 - * \see GPU_SetHotspot 794 + /*! Sets the default image blitting anchor for newly created images. 795 + * \see GPU_SetAnchor 796 796 */ 797 - DECLSPEC void SDLCALL GPU_SetDefaultHotspot(float hotspot_x, float hotspot_y); 797 + DECLSPEC void SDLCALL GPU_SetDefaultAnchor(float anchor_x, float anchor_y); 798 + 799 + /*! Returns the default image blitting anchor through the given variables. 800 + * \see GPU_GetAnchor 801 + */ 802 + DECLSPEC void SDLCALL GPU_GetDefaultAnchor(float* anchor_x, float* anchor_y); 798 803 799 804 // End of RendererControls 800 805 /*! @} */ ··· 1067 1072 /*! Sets the image filtering mode, if supported by the renderer. */ 1068 1073 DECLSPEC void SDLCALL GPU_SetImageFilter(GPU_Image* image, GPU_FilterEnum filter); 1069 1074 1070 - /*! Sets the image hotspot, which is the point about which the image is blitted. The default is to blit the image on-center (0.5, 0.5). The hotspot is in inverted (+y down) normalized coordinates (0.0-1.0). */ 1071 - DECLSPEC void SDLCALL GPU_SetHotspot(GPU_Image* image, float hotspot_x, float hotspot_y); 1075 + /*! Sets the image anchor, which is the point about which the image is blitted. The default is to blit the image on-center (0.5, 0.5). The anchor is in normalized coordinates (0.0-1.0). */ 1076 + DECLSPEC void SDLCALL GPU_SetAnchor(GPU_Image* image, float anchor_x, float anchor_y); 1077 + 1078 + /*! Returns the image anchor via the passed parameters. The anchor is in normalized coordinates (0.0-1.0). */ 1079 + DECLSPEC void SDLCALL GPU_GetAnchor(GPU_Image* image, float* anchor_x, float* anchor_y); 1072 1080 1073 1081 /*! Gets the current pixel snap setting. The default value is GPU_SNAP_POSITION_AND_DIMENSIONS. */ 1074 1082 DECLSPEC GPU_SnapEnum SDLCALL GPU_GetSnapMode(GPU_Image* image);
+30 -6
src/SDL_gpu.c
··· 1685 1685 } 1686 1686 1687 1687 1688 - void GPU_SetDefaultHotspot(float hotspot_x, float hotspot_y) 1688 + void GPU_SetDefaultAnchor(float anchor_x, float anchor_y) 1689 1689 { 1690 1690 if(_gpu_current_renderer == NULL) 1691 1691 return; 1692 + 1693 + _gpu_current_renderer->default_image_anchor_x = anchor_x; 1694 + _gpu_current_renderer->default_image_anchor_y = anchor_y; 1695 + } 1692 1696 1693 - _gpu_current_renderer->default_image_hotspot_x = hotspot_x; 1694 - _gpu_current_renderer->default_image_hotspot_y = hotspot_y; 1697 + void GPU_GetDefaultAnchor(float* anchor_x, float* anchor_y) 1698 + { 1699 + if(_gpu_current_renderer == NULL) 1700 + return; 1701 + 1702 + if(anchor_x != NULL) 1703 + *anchor_x = _gpu_current_renderer->default_image_anchor_x; 1704 + 1705 + if(anchor_y != NULL) 1706 + *anchor_y = _gpu_current_renderer->default_image_anchor_y; 1695 1707 } 1696 1708 1697 - void GPU_SetHotspot(GPU_Image* image, float hotspot_x, float hotspot_y) 1709 + void GPU_SetAnchor(GPU_Image* image, float anchor_x, float anchor_y) 1698 1710 { 1699 1711 if(image == NULL) 1700 1712 return; 1701 1713 1702 - image->hotspot_x = hotspot_x; 1703 - image->hotspot_y = hotspot_y; 1714 + image->anchor_x = anchor_x; 1715 + image->anchor_y = anchor_y; 1716 + } 1717 + 1718 + void GPU_GetAnchor(GPU_Image* image, float* anchor_x, float* anchor_y) 1719 + { 1720 + if(image == NULL) 1721 + return; 1722 + 1723 + if(anchor_x != NULL) 1724 + *anchor_x = image->anchor_x; 1725 + 1726 + if(anchor_y != NULL) 1727 + *anchor_y = image->anchor_y; 1704 1728 } 1705 1729 1706 1730 GPU_SnapEnum GPU_GetSnapMode(GPU_Image* image)
+2 -2
src/renderer_GLES_1.c
··· 40 40 renderer->min_shader_version = 0; 41 41 renderer->max_shader_version = 0; 42 42 43 - renderer->default_image_hotspot_x = 0.5f; 44 - renderer->default_image_hotspot_y = 0.5f; 43 + renderer->default_image_anchor_x = 0.5f; 44 + renderer->default_image_anchor_y = 0.5f; 45 45 46 46 renderer->current_context_target = NULL; 47 47
+2 -2
src/renderer_GLES_2.c
··· 44 44 renderer->min_shader_version = 100; 45 45 renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 46 46 47 - renderer->default_image_hotspot_x = 0.5f; 48 - renderer->default_image_hotspot_y = 0.5f; 47 + renderer->default_image_anchor_x = 0.5f; 48 + renderer->default_image_anchor_y = 0.5f; 49 49 50 50 renderer->current_context_target = NULL; 51 51
+2 -2
src/renderer_GLES_3.c
··· 44 44 renderer->min_shader_version = 100; 45 45 renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 46 46 47 - renderer->default_image_hotspot_x = 0.5f; 48 - renderer->default_image_hotspot_y = 0.5f; 47 + renderer->default_image_anchor_x = 0.5f; 48 + renderer->default_image_anchor_y = 0.5f; 49 49 50 50 renderer->current_context_target = NULL; 51 51
+14 -14
src/renderer_GL_common.inl
··· 2054 2054 result->bytes_per_pixel = bytes_per_pixel; 2055 2055 result->has_mipmaps = 0; 2056 2056 2057 - result->hotspot_x = renderer->default_image_hotspot_x; 2058 - result->hotspot_y = renderer->default_image_hotspot_y; 2057 + result->anchor_x = renderer->default_image_anchor_x; 2058 + result->anchor_y = renderer->default_image_anchor_y; 2059 2059 2060 2060 result->color = white; 2061 2061 result->use_blending = 1; ··· 2304 2304 result->bytes_per_pixel = bytes_per_pixel; 2305 2305 result->has_mipmaps = 0; 2306 2306 2307 - result->hotspot_x = renderer->default_image_hotspot_x; 2308 - result->hotspot_y = renderer->default_image_hotspot_y; 2307 + result->anchor_x = renderer->default_image_anchor_x; 2308 + result->anchor_y = renderer->default_image_anchor_y; 2309 2309 2310 2310 result->color = white; 2311 2311 result->use_blending = 1; ··· 3997 3997 } 3998 3998 3999 3999 // Center the image on the given coords 4000 - dx1 = x - w * image->hotspot_x; 4001 - dy1 = y - h * image->hotspot_y; 4002 - dx2 = x + w * (1.0f - image->hotspot_x); 4003 - dy2 = y + h * (1.0f - image->hotspot_y); 4000 + dx1 = x - w * image->anchor_x; 4001 + dy1 = y - h * image->anchor_y; 4002 + dx2 = x + w * (1.0f - image->anchor_x); 4003 + dy2 = y + h * (1.0f - image->anchor_y); 4004 4004 4005 4005 if(image->snap_mode == GPU_SNAP_DIMENSIONS || image->snap_mode == GPU_SNAP_POSITION_AND_DIMENSIONS) 4006 4006 { ··· 4091 4091 4092 4092 w = (src_rect == NULL? image->w : src_rect->w); 4093 4093 h = (src_rect == NULL? image->h : src_rect->h); 4094 - renderer->impl->BlitTransformX(renderer, image, src_rect, target, x, y, w*image->hotspot_x, h*image->hotspot_y, degrees, 1.0f, 1.0f); 4094 + renderer->impl->BlitTransformX(renderer, image, src_rect, target, x, y, w*image->anchor_x, h*image->anchor_y, degrees, 1.0f, 1.0f); 4095 4095 } 4096 4096 4097 4097 static void BlitScale(GPU_Renderer* renderer, GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float scaleX, float scaleY) ··· 4110 4110 4111 4111 w = (src_rect == NULL? image->w : src_rect->w); 4112 4112 h = (src_rect == NULL? image->h : src_rect->h); 4113 - renderer->impl->BlitTransformX(renderer, image, src_rect, target, x, y, w*image->hotspot_x, h*image->hotspot_y, 0.0f, scaleX, scaleY); 4113 + renderer->impl->BlitTransformX(renderer, image, src_rect, target, x, y, w*image->anchor_x, h*image->anchor_y, 0.0f, scaleX, scaleY); 4114 4114 } 4115 4115 4116 4116 static void BlitTransform(GPU_Renderer* renderer, GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float degrees, float scaleX, float scaleY) ··· 4129 4129 4130 4130 w = (src_rect == NULL? image->w : src_rect->w); 4131 4131 h = (src_rect == NULL? image->h : src_rect->h); 4132 - renderer->impl->BlitTransformX(renderer, image, src_rect, target, x, y, w*image->hotspot_x, h*image->hotspot_y, degrees, scaleX, scaleY); 4132 + renderer->impl->BlitTransformX(renderer, image, src_rect, target, x, y, w*image->anchor_x, h*image->anchor_y, degrees, scaleX, scaleY); 4133 4133 } 4134 4134 4135 4135 static void BlitTransformX(GPU_Renderer* renderer, GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float pivot_x, float pivot_y, float degrees, float scaleX, float scaleY) ··· 4225 4225 y2 *= image->base_h/(float)image->h; 4226 4226 } 4227 4227 4228 - // Create vertices about the hotspot 4228 + // Create vertices about the anchor 4229 4229 dx1 = -pivot_x; 4230 4230 dy1 = -pivot_y; 4231 4231 dx2 = w - pivot_x; ··· 4252 4252 4253 4253 // Apply transforms 4254 4254 4255 - // Scale about the hotspot 4255 + // Scale about the anchor 4256 4256 if(scaleX != 1.0f || scaleY != 1.0f) 4257 4257 { 4258 4258 dx1 *= scaleX; ··· 4267 4267 dx4 = dx1; 4268 4268 dy4 = dy2; 4269 4269 4270 - // Rotate about the hotspot 4270 + // Rotate about the anchor 4271 4271 if(degrees != 0.0f) 4272 4272 { 4273 4273 float cosA = cos(degrees*M_PI/180);
+2 -2
src/renderer_OpenGL_1.c
··· 39 39 renderer->min_shader_version = 110; 40 40 renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 41 41 42 - renderer->default_image_hotspot_x = 0.5f; 43 - renderer->default_image_hotspot_y = 0.5f; 42 + renderer->default_image_anchor_x = 0.5f; 43 + renderer->default_image_anchor_y = 0.5f; 44 44 45 45 renderer->current_context_target = NULL; 46 46
+2 -2
src/renderer_OpenGL_1_BASE.c
··· 38 38 renderer->min_shader_version = 0; 39 39 renderer->max_shader_version = 0; 40 40 41 - renderer->default_image_hotspot_x = 0.5f; 42 - renderer->default_image_hotspot_y = 0.5f; 41 + renderer->default_image_anchor_x = 0.5f; 42 + renderer->default_image_anchor_y = 0.5f; 43 43 44 44 renderer->current_context_target = NULL; 45 45
+2 -2
src/renderer_OpenGL_2.c
··· 37 37 renderer->min_shader_version = 110; 38 38 renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 39 39 40 - renderer->default_image_hotspot_x = 0.5f; 41 - renderer->default_image_hotspot_y = 0.5f; 40 + renderer->default_image_anchor_x = 0.5f; 41 + renderer->default_image_anchor_y = 0.5f; 42 42 43 43 renderer->current_context_target = NULL; 44 44
+2 -2
src/renderer_OpenGL_3.c
··· 41 41 renderer->min_shader_version = 110; 42 42 renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 43 43 44 - renderer->default_image_hotspot_x = 0.5f; 45 - renderer->default_image_hotspot_y = 0.5f; 44 + renderer->default_image_anchor_x = 0.5f; 45 + renderer->default_image_anchor_y = 0.5f; 46 46 47 47 renderer->current_context_target = NULL; 48 48
+2 -2
src/renderer_OpenGL_4.c
··· 39 39 renderer->min_shader_version = 110; 40 40 renderer->max_shader_version = SDL_GPU_GLSL_VERSION; 41 41 42 - renderer->default_image_hotspot_x = 0.5f; 43 - renderer->default_image_hotspot_y = 0.5f; 42 + renderer->default_image_anchor_x = 0.5f; 43 + renderer->default_image_anchor_y = 0.5f; 44 44 45 45 renderer->current_context_target = NULL; 46 46
+3 -3
tests/CMakeLists.txt
··· 130 130 add_executable(transform-matrix-test transform-matrix/main.c) 131 131 target_link_libraries (transform-matrix-test ${TEST_LIBS}) 132 132 133 - add_executable(hotspot-test hotspot/main.c) 134 - target_link_libraries (hotspot-test ${TEST_LIBS}) 133 + add_executable(anchor-test anchor/main.c) 134 + target_link_libraries (anchor-test ${TEST_LIBS}) 135 135 136 136 add_executable(video-test video/main.c) 137 - target_link_libraries (video-test ${TEST_LIBS}) 137 + target_link_libraries (video-test ${TEST_LIBS})
+19 -16
tests/hotspot/main.c tests/anchor/main.c
··· 23 23 24 24 Uint8 mode = 0; 25 25 26 - float hotspot_x = 0.5f; 27 - float hotspot_y = 0.5f; 26 + float anchor_x = 0.5f; 27 + float anchor_y = 0.5f; 28 28 29 29 float angle = 0.0f; 30 30 float scale = 1.0f; ··· 49 49 done = 1; 50 50 if(event.key.keysym.sym == SDLK_1) 51 51 { 52 - hotspot_x = 0.5f; 53 - hotspot_y = 0.5f; 52 + anchor_x = 0.5f; 53 + anchor_y = 0.5f; 54 54 } 55 55 if(event.key.keysym.sym == SDLK_2) 56 56 { 57 - hotspot_x = 0.0f; 58 - hotspot_y = 0.0f; 57 + anchor_x = 0.0f; 58 + anchor_y = 0.0f; 59 59 } 60 60 if(event.key.keysym.sym == SDLK_3) 61 61 { 62 - hotspot_x = 1.0f; 63 - hotspot_y = 1.0f; 62 + anchor_x = 1.0f; 63 + anchor_y = 1.0f; 64 64 } 65 65 if(event.key.keysym.sym == SDLK_4) 66 66 { 67 - hotspot_x = 1.0f; 68 - hotspot_y = 0.5f; 67 + anchor_x = 1.0f; 68 + anchor_y = 0.5f; 69 69 } 70 70 if(event.key.keysym.sym == SDLK_SPACE) 71 71 mode = !mode; 72 + if(event.key.keysym.sym == SDLK_BACKSPACE) 73 + GPU_SetCoordinateMode(!GPU_GetCoordinateMode()); 72 74 } 73 75 } 74 76 77 + 75 78 if(keystates[SDL_SCANCODE_UP]) 76 - hotspot_y -= dt; 79 + anchor_y -= (GPU_GetCoordinateMode()? -dt : dt); 77 80 if(keystates[SDL_SCANCODE_DOWN]) 78 - hotspot_y += dt; 81 + anchor_y += (GPU_GetCoordinateMode()? -dt : dt); 79 82 if(keystates[SDL_SCANCODE_LEFT]) 80 - hotspot_x -= dt; 83 + anchor_x -= dt; 81 84 if(keystates[SDL_SCANCODE_RIGHT]) 82 - hotspot_x += dt; 85 + anchor_x += dt; 83 86 84 - GPU_SetHotspot(image, hotspot_x, hotspot_y); 87 + GPU_SetAnchor(image, anchor_x, anchor_y); 85 88 86 89 GPU_Clear(screen); 87 90 ··· 107 110 108 111 GPU_Rectangle(screen, screen->w/2 - image->w/2, screen->h/2 - image->h/2, screen->w/2 + image->w/2, screen->h/2 + image->h/2, GPU_MakeColor(0, 255, 255, 255)); 109 112 110 - GPU_CircleFilled(screen, screen->w/2 - image->w/2 + image->hotspot_x * image->w, screen->h/2 - image->h/2 + image->hotspot_y * image->h, 5, GPU_MakeColor(255, 0, 0, 255)); 113 + GPU_CircleFilled(screen, screen->w/2 - image->w/2 + anchor_x * image->w, screen->h/2 - image->h/2 + anchor_y * image->h, 5, GPU_MakeColor(255, 0, 0, 255)); 111 114 112 115 GPU_Circle(screen, 0, 0, 5, GPU_MakeColor(255, 128, 0, 255)); 113 116 GPU_Circle(screen, screen->w, 0, 5, GPU_MakeColor(255, 128, 0, 255));