]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add a class to handle screenshots images
authorterencehill <piuntn@gmail.com>
Thu, 12 Aug 2010 17:20:20 +0000 (19:20 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 12 Aug 2010 17:20:20 +0000 (19:20 +0200)
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

gfx/transparent.tga [deleted file]
qcsrc/menu/classes.c
qcsrc/menu/xonotic/dialog_multiplayer_screenshot.c
qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c
qcsrc/menu/xonotic/screenshotimage.c [new file with mode: 0644]

diff --git a/gfx/transparent.tga b/gfx/transparent.tga
deleted file mode 100644 (file)
index 9fabe89..0000000
Binary files a/gfx/transparent.tga and /dev/null differ
index 7f9182f4df4504540e778cc997b7b3c69a37d9c7..021137fc0b9d4415dca7f86cd005aa0eda8435fc 100644 (file)
@@ -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"
index 7c6ca343fcbf95c93696a9250495b7c503906275..c46d631d38cb6099728014feaf8ee2f76e1a61a9 100644 (file)
@@ -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;
index a032874a026b04e183dade713aafea599e75ef7d..07047cf0f9b7d1475ce0e2660856e3473de9388c 100644 (file)
@@ -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 (file)
index 0000000..e348ddd
--- /dev/null
@@ -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