Skip to content

Commit

Permalink
chore: 消除部分编译器警告 (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
yixy-only authored Feb 4, 2025
1 parent 5978ca1 commit d1aebb1
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 39 deletions.
15 changes: 14 additions & 1 deletion include/ege/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ class button : public egeControlBase
CTL_INIT; // must be the first line
size(64, 32);
_font_height = 12;
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(_face, sizeof(_face), "SimSun");
#else
strcpy(_face, "SimSun");
#endif

_line_color = BLACK;
_bg_color = EGERGB(100, 100, 100);
_text_color = BLACK;
Expand Down Expand Up @@ -238,7 +243,11 @@ class button : public egeControlBase

void caption(const char* text)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(_caption, sizeof(_caption), text);
#else
strcpy(_caption, text);
#endif
redraw();
}

Expand All @@ -250,7 +259,11 @@ class button : public egeControlBase

void font(const char* fontface)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(_face, sizeof(_face), fontface);
#else
strcpy(_face, fontface);
#endif
redraw();
}

Expand Down Expand Up @@ -302,7 +315,7 @@ class button : public egeControlBase
protected:
void updatesidewidth()
{
_side_width = ((geth() < getw()) ? geth() : getw()) * 0.2;
_side_width = (int)(((geth() < getw()) ? geth() : getw()) * 0.2);
}

#ifdef DEBUG
Expand Down
2 changes: 1 addition & 1 deletion include/ege/egecontrolbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PushTarget
#define CTL_PREINITEND }
#define CTL_DEFPARAM int inherit = inherit_level_e, ege::egeControlBase *pParent = NULL
#define CTL_INITBASE(parent) \
egecontrolbase_preinit_obj(this, inherit_level_e), parent(inherit, (ege::egeControlBase*)pParent)
parent(inherit, (ege::egeControlBase*)pParent), egecontrolbase_preinit_obj(this, inherit_level_e)
#define CTL_INIT \
InitObject iobj(this, inherit_level_e); \
ege::PushTarget _pushtarget(buf());
Expand Down
12 changes: 12 additions & 0 deletions include/ege/label.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ class label : public egeControlBase
m_fontheight = 12;
m_alpha = 0xff;
m_transparent = false;
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(m_face, sizeof(m_face), "SimSun");
#else
strcpy(m_face, "SimSun");
#endif
redraw();
}

void caption(const char* text)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(m_caption, sizeof(m_caption), text);
#else
strcpy(m_caption, text);
#endif
redraw();
}

Expand All @@ -47,7 +55,11 @@ class label : public egeControlBase

void font(const char* fontface)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
strcpy_s(m_face, sizeof(m_face), fontface);
#else
strcpy(m_face, fontface);
#endif
redraw();
}

Expand Down
10 changes: 5 additions & 5 deletions src/ege_dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ namespace dll
if (func_timeBeginPeriod) {
return func_timeBeginPeriod(uPeriod);
}
return NULL;
return MMSYSERR_NOTSUPPORTED;
}

MMRESULT timeEndPeriod(UINT uPeriod)
{
if (func_timeEndPeriod) {
func_timeEndPeriod(uPeriod);
}
return NULL;
return MMSYSERR_NOTSUPPORTED;
}

MMRESULT timeSetEvent(UINT uDelay,UINT uResolution,LPTIMECALLBACK fptc,DWORD_PTR dwUser,UINT fuEvent)
Expand All @@ -201,7 +201,7 @@ namespace dll
return func_timeSetEvent(uDelay, uResolution, fptc, dwUser, fuEvent);
}

return NULL;
return MMSYSERR_NOTSUPPORTED;
}

MMRESULT timeKillEvent(UINT uTimerID)
Expand All @@ -210,7 +210,7 @@ namespace dll
return func_timeKillEvent(uTimerID);
}

return NULL;
return MMSYSERR_NOTSUPPORTED;
}

MCIERROR mciSendCommandW(MCIDEVICEID mciId,UINT uMsg,DWORD_PTR dwParam1,DWORD_PTR dwParam2)
Expand All @@ -219,7 +219,7 @@ namespace dll
return func_mciSendCommandW(mciId, uMsg, dwParam1, dwParam2);
}

return NULL;
return MMSYSERR_ERROR;
}

// ----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/ege_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#define _ALLOW_RUNTIME_LIBRARY_MISMATCH
#endif

#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#define EGE_GRAPH_LIB_BUILD
#define EGE_DEPRECATE(function, msg)

Expand Down
2 changes: 2 additions & 0 deletions src/egecontrolbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ egeControlBase基类定义和相关操作
#define _ALLOW_RUNTIME_LIBRARY_MISMATCH
#endif

#ifdef _MSC_VER
#pragma warning(disable : 4786)
#endif

#include <algorithm>
// #include <set>
Expand Down
6 changes: 2 additions & 4 deletions src/egegapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ void setviewport(int left, int top, int right, int bottom, int clip, PIMAGE pimg
}

graphics->ResetTransform();
graphics->TranslateTransform(img->m_vpt.left, img->m_vpt.top);
graphics->TranslateTransform((Gdiplus::REAL)img->m_vpt.left, (Gdiplus::REAL)img->m_vpt.top);

SetViewportOrgEx(img->m_hDC, img->m_vpt.left, img->m_vpt.top, NULL);
MoveToEx(img->m_hDC, 0, 0, NULL);
Expand Down Expand Up @@ -2991,7 +2991,6 @@ int inputbox_getline(const char* title, const char* text, LPSTR buf, int len)

int inputbox_getline(const wchar_t* title, const wchar_t* text, LPWSTR buf, int len)
{
struct _graph_setting* pg = &graph_setting;
IMAGE bg;
IMAGE window;
int w = 400, h = 300, x = (getwidth() - w) / 2, y = (getheight() - h) / 2;
Expand Down Expand Up @@ -3070,7 +3069,6 @@ static double static_lastFrameTime = 0.0; /* 上一帧更新时间 */
*/
void updateFrameRate(bool addFrameCount)
{
static bool firstUpdate = true;
struct _graph_setting* pg = &graph_setting;
double currentTime = get_highfeq_time_ls(pg);

Expand Down Expand Up @@ -3107,7 +3105,7 @@ void resetFrameRate()

float getfps()
{
return static_frameRate;
return (float)static_frameRate;
}

double fclock()
Expand Down
36 changes: 34 additions & 2 deletions src/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void outtextrect(int x, int y, int w, int h, const wchar_t* text, PIMAGE pimg)
if (img->m_texttype.vert != TOP_TEXT) {
// 测量实际输出时的文本区域
RECT measureRect = rect;
int textHeight = DrawTextW(img->m_hDC, text, -1, &measureRect, format | DT_CALCRECT);
DrawTextW(img->m_hDC, text, -1, &measureRect, format | DT_CALCRECT);

int heightDiff = rect.bottom - measureRect.bottom;

Expand Down Expand Up @@ -184,7 +184,12 @@ void xyprintf(int x, int y, const char* format, ...)
{
struct _graph_setting* pg = &graph_setting;
char* buff = (char*)pg->g_t_buff;
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
size_t bufferCount = sizeof(pg->g_t_buff);
vsprintf_s(buff, bufferCount, format, v);
#else
vsprintf(buff, format, v);
#endif
outtextxy(x, y, buff);
}
va_end(v);
Expand All @@ -197,7 +202,13 @@ void xyprintf(int x, int y, const wchar_t* format, ...)
{
struct _graph_setting* pg = &graph_setting;
wchar_t* buff = (wchar_t*)pg->g_t_buff;

#if defined(_MSC_VER) && (_MSC_VER >= 1400)
size_t bufferCount = sizeof(pg->g_t_buff) / sizeof(wchar_t);
vswprintf_s(buff, bufferCount, format, v);
#else
vswprintf(buff, format, v);
#endif
outtextxy(x, y, buff);
}
va_end(v);
Expand All @@ -210,7 +221,12 @@ void rectprintf(int x, int y, int w, int h, const char* format, ...)
{
struct _graph_setting* pg = &graph_setting;
char* buff = (char*)pg->g_t_buff;
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
size_t bufferCount = sizeof(pg->g_t_buff);
vsprintf_s(buff, bufferCount, format, v);
#else
vsprintf(buff, format, v);
#endif
outtextrect(x, y, w, h, buff);
}
va_end(v);
Expand All @@ -223,7 +239,12 @@ void rectprintf(int x, int y, int w, int h, const wchar_t* format, ...)
{
struct _graph_setting* pg = &graph_setting;
wchar_t* buff = (wchar_t*)pg->g_t_buff;
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
size_t bufferCount = sizeof(pg->g_t_buff) / sizeof(wchar_t);
vswprintf_s(buff, bufferCount, format, v);
#else
vswprintf(buff, format, v);
#endif
outtextrect(x, y, w, h, buff);
}
va_end(v);
Expand Down Expand Up @@ -320,8 +341,14 @@ void ege_xyprintf(int x, int y, const char* format, ...)
{
struct _graph_setting* pg = &graph_setting;
// 由于 ege_drawtext 同样使用这块缓冲区, 从中间开始写入以避免区域重叠造成转换失败
char* buff = (char*)(pg->g_t_buff + 4096);
const int bufferLength = sizeof(pg->g_t_buff) / sizeof(pg->g_t_buff[0]);
char* buff = (char*)(pg->g_t_buff + bufferLength / 2);
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
size_t bufferCount = sizeof(pg->g_t_buff) / 2;
vsprintf_s(buff, bufferCount, format, v);
#else
vsprintf(buff, format, v);
#endif
ege_outtextxy(x, y, buff);
}
va_end(v);
Expand All @@ -334,7 +361,12 @@ void ege_xyprintf(int x, int y, const wchar_t* format, ...)
{
struct _graph_setting* pg = &graph_setting;
wchar_t* buff = (wchar_t*)pg->g_t_buff;
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
size_t bufferCount = sizeof(pg->g_t_buff) / sizeof(wchar_t);
vswprintf_s(buff, bufferCount, format, v);
#else
vswprintf(buff, format, v);
#endif
ege_outtextxy(x, y, buff);
}
va_end(v);
Expand Down
2 changes: 1 addition & 1 deletion src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ BOOL init_instance(HINSTANCE hInstance)
void setinitmode(int mode, int x, int y)
{
g_initoption = mode;
struct _graph_setting* pg = &graph_setting;

if (mode & INIT_NOBORDER) {
if (mode & INIT_CHILD) {
g_windowstyle = WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_VISIBLE;
Expand Down
38 changes: 17 additions & 21 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,6 @@ int IMAGE::getimage(const char* filename, int zoomWidth, int zoomHeight)

int getimage_from_bitmap(PIMAGE pimg, Gdiplus::Bitmap& bitmap)
{
Gdiplus::PixelFormat srcPixelFormat = bitmap.GetPixelFormat();

// 将图像尺寸调整至和 bitmap 一致
int width = bitmap.GetWidth();
int height = bitmap.GetHeight();
Expand Down Expand Up @@ -2139,7 +2137,7 @@ static void draw_flat_trangle_alpha(PIMAGE dc_dest, const struct trangle2d* dt,
int s = float2int((float)t2d.p[0].y), e = float2int((float)t2d.p[2].y), h, m = float2int((float)t2d.p[1].y);
int rs, re;
int i, lh, rh;
float dm = t2d.p[1].y, dh;

struct point2d pl, pr, pt;
struct point2d spl, spr;

Expand All @@ -2151,7 +2149,7 @@ static void draw_flat_trangle_alpha(PIMAGE dc_dest, const struct trangle2d* dt,
spr.x = t3d.p[2].x - t3d.p[0].x;
spl.y = t3d.p[1].y - t3d.p[0].y;
spr.y = t3d.p[2].y - t3d.p[0].y;
dh = dm - s;

h = m - s;
rs = s;
if (s < y1) {
Expand Down Expand Up @@ -2268,7 +2266,6 @@ static void draw_flat_trangle_alpha(PIMAGE dc_dest, const struct trangle2d* dt,
spl.y = t3d.p[0].y - t3d.p[2].y;
spr.y = t3d.p[1].y - t3d.p[2].y;

dh = e - dm;
h = e - m;
re = e;
if (m < y1) {
Expand Down Expand Up @@ -2377,7 +2374,7 @@ static void draw_flat_trangle_alpha_s(PIMAGE dc_dest, const struct trangle2d* dt
int s = float2int((float)t2d.p[0].y), e = float2int((float)t2d.p[2].y), h, m = float2int((float)t2d.p[1].y);
int rs, re;
int i, lh, rh;
float dm = t2d.p[1].y, dh;

struct point2d pl, pr, pt;
struct point2d spl, spr;

Expand All @@ -2389,7 +2386,7 @@ static void draw_flat_trangle_alpha_s(PIMAGE dc_dest, const struct trangle2d* dt
spr.x = t3d.p[2].x - t3d.p[0].x;
spl.y = t3d.p[1].y - t3d.p[0].y;
spr.y = t3d.p[2].y - t3d.p[0].y;
dh = dm - s;

h = m - s;
rs = s;
if (s < y1) {
Expand Down Expand Up @@ -2507,7 +2504,6 @@ static void draw_flat_trangle_alpha_s(PIMAGE dc_dest, const struct trangle2d* dt
spl.y = t3d.p[0].y - t3d.p[2].y;
spr.y = t3d.p[1].y - t3d.p[2].y;

dh = e - dm;
h = e - m;
re = e;
if (m < y1) {
Expand Down Expand Up @@ -2710,10 +2706,10 @@ int putimage_rotatetransparent(PIMAGE imgDest, PCIMAGE imgSrc, int xCenterDest,
float zoom)
{
const PIMAGE img = CONVERT_IMAGE(imgDest);
int zoomed_width = widthSrc * zoom;
int zoomed_height = heightSrc * zoom;
int zoomed_center_x = (xCenterSrc - xOriginSrc) * zoom;
int zoomed_center_y = (yCenterSrc - yOriginSrc) * zoom;
int zoomed_width = (int)round(widthSrc * zoom);
int zoomed_height = (int)round(heightSrc * zoom);
int zoomed_center_x = (int)round((xCenterSrc - xOriginSrc) * zoom);
int zoomed_center_y = (int)round((yCenterSrc - yOriginSrc) * zoom);
/* zoom */
PIMAGE zoomed_img = newimage(zoomed_width, zoomed_height);
putimage(
Expand All @@ -2731,10 +2727,10 @@ int putimage_rotatetransparent(PIMAGE imgDest, PCIMAGE imgSrc, int xCenterDest,
see:
https://stackoverflow.com/questions/36201381/how-to-rotate-image-canvas-pixel-manipulation
*/
putpixel_savealpha(src_x, src_y, color, img);
putpixel_savealpha(src_x + 0.5, src_y, color, img);
putpixel_savealpha(src_x, src_y + 0.5, color, img);
putpixel_savealpha(src_x + 0.5, src_y + 0.5, color, img);
putpixel_savealpha((int)src_x, (int)src_y, color, img);
putpixel_savealpha((int)(src_x + 0.5), (int)src_y, color, img);
putpixel_savealpha((int)src_x, (int)(src_y + 0.5), color, img);
putpixel_savealpha((int)(src_x + 0.5), (int)(src_y + 0.5), color, img);
}
}
}
Expand Down Expand Up @@ -3277,11 +3273,11 @@ int savebmp(PCIMAGE pimg, FILE* file, bool withAlphaChannel)
bitmapInfoHeader.bV4ClrImportant = 0; // 颜色表中所有颜色都重要

// --------------- BITMAPV4HEADER 特有参数 ------------------
bitmapInfoHeader.bV4RedMask = 0x00FF0000;
bitmapInfoHeader.bV4GreenMask = 0x0000FF00;
bitmapInfoHeader.bV4BlueMask = 0x000000FF;
bitmapInfoHeader.bV4AlphaMask = 0xFF000000;
bitmapInfoHeader.bV4CSType = LCS_sRGB; // 使用标准 RGB 颜色空间
bitmapInfoHeader.bV4RedMask = 0x00FF0000U;
bitmapInfoHeader.bV4GreenMask = 0x0000FF00U;
bitmapInfoHeader.bV4BlueMask = 0x000000FFU;
bitmapInfoHeader.bV4AlphaMask = 0xFF000000U;
bitmapInfoHeader.bV4CSType = 0x73524742U; // 使用标准 RGB 颜色空间(LCS_sRGB宏: 'sRGB' 的值)
// 当 bV4CSType 为 'sRGB' 或 'Win ' 时忽略以下参数
//bitmapInfoHeader.bV4Endpoints
//bitmapInfoHeader.bV4GammaRed
Expand Down
Loading

0 comments on commit d1aebb1

Please sign in to comment.