From: terencehill Date: Thu, 12 Aug 2010 17:20:20 +0000 (+0200) Subject: Add a class to handle screenshots images X-Git-Tag: xonotic-v0.8.0~139^2~1^2~155^2~59 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=40221b4e6409140061092073663593abecdcc321;p=xonotic%2Fxonotic-data.pk3dir.git Add a class to handle screenshots images This allowed me to - fix title not properly centered - simply don't draw the image instead of drawing gfx/transparent - fade out the title after 3 seconds --- diff --git a/gfx/transparent.tga b/gfx/transparent.tga deleted file mode 100644 index 9fabe89c3..000000000 Binary files a/gfx/transparent.tga and /dev/null differ diff --git a/qcsrc/menu/classes.c b/qcsrc/menu/classes.c index 7f9182f4d..021137fc0 100644 --- a/qcsrc/menu/classes.c +++ b/qcsrc/menu/classes.c @@ -81,6 +81,7 @@ #include "xonotic/dialog_multiplayer_playersetup_waypoint.c" #include "xonotic/dialog_multiplayer_demo.c" #include "xonotic/demolist.c" +#include "xonotic/screenshotimage.c" #include "xonotic/dialog_multiplayer_screenshot.c" #include "xonotic/dialog_multiplayer_screenshot_screenshotviewer.c" #include "xonotic/screenshotlist.c" diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_screenshot.c b/qcsrc/menu/xonotic/dialog_multiplayer_screenshot.c index 7c6ca343f..c46d631d3 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_screenshot.c +++ b/qcsrc/menu/xonotic/dialog_multiplayer_screenshot.c @@ -26,11 +26,8 @@ void XonoticScreenshotBrowserTab_loadPreviewScreenshot(entity me, string scrImag { if (me.currentScrPath) strunzone(me.currentScrPath); - if (scrImage == "") - scrImage = "/gfx/transparent"; me.currentScrPath = strzone(scrImage); - me.screenshotImage.configureImage(me.screenshotImage, me.currentScrPath); - me.screenshotImage.updateAspect(me.screenshotImage); + me.screenshotImage.configureXonoticScreenshotImage(me.screenshotImage, me.currentScrPath); } void XonoticScreenshotBrowserTab_fill(entity me) { @@ -57,8 +54,8 @@ void XonoticScreenshotBrowserTab_fill(entity me) e.onClick = StartScreenshot_Click; e.onClickEntity = slist; me.TR(me); - me.TD(me, me.rows - 10, me.columns, e = makeXonoticImage(string_null, -1)); - e.src = "/gfx/transparent"; // in case there isn't any screenshot to show + me.TD(me, me.rows - 10, me.columns, e = makeXonoticScreenshotImage()); + e.showTitle = 0; me.screenshotImage = e; slist.screenshotPreview = e; slist.screenshotBrowserDialog = me; diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c b/qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c index a032874a0..07047cf0f 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c +++ b/qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c @@ -1,18 +1,16 @@ #ifdef INTERFACE -CLASS(XonoticScreenshotViewerDialog) EXTENDS(XonoticRootDialog) +CLASS(XonoticScreenshotViewerDialog) EXTENDS(XonoticDialog) METHOD(XonoticScreenshotViewerDialog, fill, void(entity)) METHOD(XonoticScreenshotViewerDialog, keyDown, float(entity, float, float, float)) METHOD(XonoticScreenshotViewerDialog, loadScreenshot, void(entity, string)) ATTRIB(XonoticScreenshotViewerDialog, title, string, "Screenshot Viewer") + ATTRIB(XonoticScreenshotViewerDialog, name, string, "ScreenshotViewer") ATTRIB(XonoticScreenshotViewerDialog, intendedWidth, float, 1) ATTRIB(XonoticScreenshotViewerDialog, rows, float, 25) ATTRIB(XonoticScreenshotViewerDialog, columns, float, 6.5) - ATTRIB(XonoticScreenshotViewerDialog, screenshotImage, entity, NULL) ATTRIB(XonoticScreenshotViewerDialog, color, vector, SKINCOLOR_DIALOG_MULTIPLAYER) ATTRIB(XonoticScreenshotViewerDialog, scrList, entity, NULL) - ATTRIB(XonoticScreenshotViewerDialog, titleLabel, entity, NULL) - - ATTRIB(XonoticScreenshotViewerDialog, currentScrName, string, string_null) + ATTRIB(XonoticScreenshotViewerDialog, screenshotImage, entity, NULL) ATTRIB(XonoticScreenshotViewerDialog, currentScrPath, string, string_null) ENDCLASS(XonoticScreenshotViewerDialog) #endif @@ -23,13 +21,7 @@ void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage) if (me.currentScrPath) strunzone(me.currentScrPath); me.currentScrPath = strzone(scrImage); - me.screenshotImage.configureImage(me.screenshotImage, me.currentScrPath); - me.screenshotImage.updateAspect(me.screenshotImage); - - if (me.currentScrName) - strunzone(me.currentScrName); - me.currentScrName = strzone(substring(scrImage, 13, strlen(scrImage) - 13)); - me.titleLabel.setText(me.titleLabel, me.currentScrName); + me.screenshotImage.configureXonoticScreenshotImage(me.screenshotImage, me.currentScrPath); } void prevScreenshot_Click(entity btn, entity me) { @@ -39,7 +31,6 @@ void nextScreenshot_Click(entity btn, entity me) { me.scrList.goScreenshot(me.scrList, +1); } - float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift) { switch(key) @@ -65,12 +56,9 @@ float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, f void XonoticScreenshotViewerDialog_fill(entity me) { entity e; - me.TR(me); - me.TD(me, me.rows - 1, me.columns, e = makeXonoticImage(string_null, -1)); + me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage()); me.screenshotImage = e; - me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, "")); - me.titleLabel = e; me.gotoRC(me, me.rows - 1, 0); me.TD(me, 1, me.columns/2, e = makeXonoticButton("Previous", '0 0 0')); e.onClick = prevScreenshot_Click; diff --git a/qcsrc/menu/xonotic/screenshotimage.c b/qcsrc/menu/xonotic/screenshotimage.c new file mode 100644 index 000000000..e348ddd17 --- /dev/null +++ b/qcsrc/menu/xonotic/screenshotimage.c @@ -0,0 +1,54 @@ +#ifdef INTERFACE +CLASS(XonoticScreenshotImage) EXTENDS(Image) + METHOD(XonoticScreenshotImage, configureXonoticScreenshotImage, void(entity, string)) + METHOD(XonoticScreenshotImage, draw, void(entity)) + METHOD(XonoticScreenshotImage, resizeNotify, void(entity, vector, vector, vector, vector)) + ATTRIB(XonoticScreenshotImage, realFontSize, vector, '0 0 0') + ATTRIB(XonoticScreenshotImage, fontSize, float, SKINFONTSIZE_NORMAL) + ATTRIB(XonoticScreenshotImage, showTitle, float, 1) + ATTRIB(XonoticScreenshotImage, showTitleTime, float, 0) + ATTRIB(XonoticScreenshotImage, screenshotTitle, string, string_null) +ENDCLASS(XonoticScreenshotImage) +entity makeXonoticScreenshotImage(); +#endif + +#ifdef IMPLEMENTATION +entity makeXonoticScreenshotImage() +{ + entity me; + me = spawnXonoticScreenshotImage(); + me.configureXonoticScreenshotImage(me, string_null); + return me; +} + +void XonoticScreenshotImage_configureXonoticScreenshotImage(entity me, string theImage) +{ + me.configureImage(me, theImage); + me.forcedAspect = -1; + me.showTitleTime = time + 3; // show title for 3 seconds + me.updateAspect(me); + if (me.screenshotTitle) + strunzone(me.screenshotTitle); + me.screenshotTitle = strzone(substring(me.src, 13, strlen(theImage) - 13)); //strip "/screenshots/" +} + +void XonoticScreenshotImage_draw(entity me) +{ + if (me.src != "") + { + SUPER(XonoticScreenshotImage).draw(me); + if (me.showTitle && time < me.showTitleTime + 1) // fade title out in 1 second + { + float alpha = (1 - (time - me.showTitleTime)); + draw_CenterText('0.5 0 0', me.screenshotTitle, me.realFontSize, '1 1 1', alpha, FALSE); + } + } +} + +void XonoticScreenshotImage_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + SUPER(XonoticScreenshotImage).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); + me.realFontSize_y = me.fontSize / absSize_y; + me.realFontSize_x = me.fontSize / absSize_x; +} +#endif