]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge remote-tracking branch 'origin/master' into terencehill/screenshot_viewer
authorSamual Lenks <samual@xonotic.org>
Sun, 18 Aug 2013 18:47:02 +0000 (14:47 -0400)
committerSamual Lenks <samual@xonotic.org>
Sun, 18 Aug 2013 18:47:02 +0000 (14:47 -0400)
12 files changed:
gfx/menu/luminos/skinvalues.txt
gfx/menu/wickedx/skinvalues.txt [changed mode: 0755->0644]
gfx/menu/xaw/skinvalues.txt
qcsrc/menu/classes.c
qcsrc/menu/item/image.c
qcsrc/menu/skin-customizables.inc
qcsrc/menu/xonotic/dialog_multiplayer.c
qcsrc/menu/xonotic/dialog_multiplayer_screenshot.c [new file with mode: 0644]
qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c [new file with mode: 0644]
qcsrc/menu/xonotic/mainwindow.c
qcsrc/menu/xonotic/screenshotimage.c [new file with mode: 0644]
qcsrc/menu/xonotic/screenshotlist.c [new file with mode: 0644]

index e79dba0e099fd157d28f4c8f7ad7692b3568f7c1..2277f9d684231dc4abdd688c87784a4980710ce8 100755 (executable)
@@ -180,6 +180,7 @@ COLOR_DIALOG_MODEL              '1 1 1'
 COLOR_DIALOG_CROSSHAIR          '1 1 1'
 COLOR_DIALOG_HUD                '1 1 1'
 COLOR_DIALOG_SERVERINFO         '1 1 1'
+COLOR_DIALOG_SCREENSHOTVIEWER   '1 1 1'
 COLOR_DIALOG_CVARS              '1 0 0'
 COLOR_DIALOG_HUDCONFIRM         '1 0 0'
 
old mode 100755 (executable)
new mode 100644 (file)
index 1560512..be0ee5b
@@ -180,6 +180,7 @@ COLOR_DIALOG_MODEL              '1 1 1'
 COLOR_DIALOG_CROSSHAIR          '1 1 1'
 COLOR_DIALOG_HUD                '1 1 1'
 COLOR_DIALOG_SERVERINFO         '1 1 1'
+COLOR_DIALOG_SCREENSHOTVIEWER   '1 1 1'
 COLOR_DIALOG_CVARS              '1 0 0'
 COLOR_DIALOG_HUDCONFIRM         '1 0 0'
 
index 3bd555f031ed32255e35cec19596893bfc5597dc..d401de3e534e07db8b097bc9f383cb273c88c44a 100644 (file)
@@ -35,6 +35,7 @@ COLOR_DIALOG_MODEL              '1 1 1'
 COLOR_DIALOG_CROSSHAIR          '1 1 1'
 COLOR_DIALOG_HUD                '1 1 1'
 COLOR_DIALOG_SERVERINFO         '1 1 1'
+COLOR_DIALOG_SCREENSHOTVIEWER   '1 1 1'
 COLOR_DIALOG_CVARS              '1 0 0'
 COLOR_DIALOG_HUDCONFIRM         '1 0 0'
 
index f00971674ef8bca06675809fcc1526744450969b..a9a9c65fbb913fcc18b05ede24ebb03e4ab3e49b 100644 (file)
 #include "xonotic/weaponslist.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"
 #include "xonotic/colorpicker.c"
 #include "xonotic/colorpicker_string.c"
 #include "xonotic/cvarlist.c"
index a7e63b0e116f88c2c1327794a436a7a03fda599b..8ae17dbcc1a2558a6250489e2bb2e7be378a4a77 100644 (file)
@@ -5,9 +5,22 @@ CLASS(Image) EXTENDS(Item)
        METHOD(Image, toString, string(entity))
        METHOD(Image, resizeNotify, void(entity, vector, vector, vector, vector))
        METHOD(Image, updateAspect, void(entity))
+       METHOD(Image, initZoom, void(entity))
+       METHOD(Image, setZoom, void(entity, float, float))
+       METHOD(Image, drag_setStartPos, float(entity, vector))
+       METHOD(Image, drag, float(entity, vector))
        ATTRIB(Image, src, string, string_null)
        ATTRIB(Image, color, vector, '1 1 1')
-       ATTRIB(Image, forcedAspect, float, 0)
+       ATTRIB(Image, forcedAspect, float, 0) // special values: -1 keep image aspect ratio, -2 keep image size but bound to the containing box, -3 always keep image size
+       ATTRIB(Image, zoomBox, float, 0) // used by forcedAspect -2 when the image is larger than the containing box
+       ATTRIB(Image, zoomFactor, float, 1)
+       ATTRIB(Image, zoomOffset, vector, '0.5 0.5 0')
+       ATTRIB(Image, zoomSnapToTheBox, float, 1) // snap the zoomed in image to the box borders when zooming/dragging it
+       ATTRIB(Image, zoomTime, float, 0)
+       ATTRIB(Image, zoomLimitedByTheBox, float, 0) // forbids zoom if image would be larger than the containing box
+       ATTRIB(Image, zoomMax, float, 0)
+       ATTRIB(Image, start_zoomOffset, vector, '0 0 0')
+       ATTRIB(Image, start_coords, vector, '0 0 0')
        ATTRIB(Image, imgOrigin, vector, '0 0 0')
        ATTRIB(Image, imgSize, vector, '0 0 0')
 ENDCLASS(Image)
@@ -22,14 +35,28 @@ void Image_configureImage(entity me, string path)
 {
        me.src = path;
 }
+void Image_initZoom(entity me)
+{
+       me.zoomOffset = '0.5 0.5 0';
+       me.zoomFactor = 1;
+       if (me.forcedAspect == -2)
+               me.zoomBox = -1; // calculate zoomBox at the first updateAspect call
+       if (me.zoomLimitedByTheBox)
+               me.zoomMax = -1; // calculate zoomMax at the first updateAspect call
+}
+
 void Image_draw(entity me)
 {
+       if(me.imgSize_x > 1 || me.imgSize_y > 1)
+               draw_SetClip();
        draw_Picture(me.imgOrigin, me.src, me.imgSize, me.color, 1);
+       if(me.imgSize_x > 1 || me.imgSize_y > 1)
+               draw_ClearClip();
        SUPER(Image).draw(me);
 }
 void Image_updateAspect(entity me)
 {
-       float asp;
+       float asp = 0;
        if(me.size_x <= 0 || me.size_y <= 0)
                return;
        if(me.forcedAspect == 0)
@@ -39,26 +66,155 @@ void Image_updateAspect(entity me)
        }
        else
        {
+               vector sz = '0 0 0';
                if(me.forcedAspect < 0)
                {
-                       vector sz;
                        sz = draw_PictureSize(me.src);
                        asp = sz_x / sz_y;
                }
                else
                        asp = me.forcedAspect;
-               if(me.size_x > asp * me.size_y)
+
+               if(me.forcedAspect <= -2)
+               {
+                       me.imgSize_x = sz_x / me.size_x;
+                       me.imgSize_y = sz_y / me.size_y;
+                       if(me.zoomBox < 0 && (me.imgSize_x > 1 || me.imgSize_y > 1))
+                       {
+                               // image larger than the containing box, zoom it out to fit into the box
+                               if(me.size_x > asp * me.size_y)
+                                       me.zoomBox = (me.size_y * asp / me.size_x) / me.imgSize_x;
+                               else
+                                       me.zoomBox = (me.size_x / (asp * me.size_y)) / me.imgSize_y;
+                               me.zoomFactor = me.zoomBox;
+                       }
+               }
+               else
+               {
+                       if(me.size_x > asp * me.size_y)
+                       {
+                               // x too large, so center x-wise
+                               me.imgSize = eY + eX * (me.size_y * asp / me.size_x);
+                       }
+                       else
+                       {
+                               // y too large, so center y-wise
+                               me.imgSize = eX + eY * (me.size_x / (asp * me.size_y));
+                       }
+               }
+       }
+
+       if (me.zoomMax < 0)
+       {
+               if(me.zoomBox > 0)
+                       me.zoomMax = me.zoomBox;
+               else
+               {
+                       if(me.size_x > asp * me.size_y)
+                               me.zoomMax = (me.size_y * asp / me.size_x) / me.imgSize_x;
+                       else
+                               me.zoomMax = (me.size_x / (asp * me.size_y)) / me.imgSize_y;
+               }
+       }
+
+       if (me.zoomMax > 0 && me.zoomFactor > me.zoomMax)
+               me.zoomFactor = me.zoomMax;
+       if (me.zoomFactor)
+               me.imgSize = me.imgSize * me.zoomFactor;
+
+       if(me.imgSize_x > 1 || me.imgSize_y > 1)
+       {
+               if(me.zoomSnapToTheBox)
+               {
+                       if(me.imgSize_x > 1)
+                               me.zoomOffset_x = bound(0.5/me.imgSize_x, me.zoomOffset_x, 1 - 0.5/me.imgSize_x);
+                       else
+                               me.zoomOffset_x = bound(1 - 0.5/me.imgSize_x, me.zoomOffset_x, 0.5/me.imgSize_x);
+
+                       if(me.imgSize_y > 1)
+                               me.zoomOffset_y = bound(0.5/me.imgSize_y, me.zoomOffset_y, 1 - 0.5/me.imgSize_y);
+                       else
+                               me.zoomOffset_y = bound(1 - 0.5/me.imgSize_y, me.zoomOffset_y, 0.5/me.imgSize_y);
+               }
+               else
+               {
+                       me.zoomOffset_x = bound(0, me.zoomOffset_x, 1);
+                       me.zoomOffset_y = bound(0, me.zoomOffset_y, 1);
+               }
+       }
+       else
+               me.zoomOffset = '0.5 0.5 0';
+
+       me.imgOrigin_x = 0.5 - me.zoomOffset_x * me.imgSize_x;
+       me.imgOrigin_y = 0.5 - me.zoomOffset_y * me.imgSize_y;
+}
+float Image_drag_setStartPos(entity me, vector coords)
+{
+       //if(me.imgSize_x > 1 || me.imgSize_y > 1) // check disabled: mousewheel zoom may start from a non-zoomed-in image
+       {
+               me.start_zoomOffset = me.zoomOffset;
+               me.start_coords = coords;
+       }
+       return 1;
+}
+float Image_drag(entity me, vector coords)
+{
+       if(me.imgSize_x > 1 || me.imgSize_y > 1)
+       {
+               me.zoomOffset_x = me.start_zoomOffset_x + (me.start_coords_x - coords_x) / me.imgSize_x;
+               me.zoomOffset_y = me.start_zoomOffset_y + (me.start_coords_y - coords_y) / me.imgSize_y;
+               me.updateAspect(me);
+       }
+       return 1;
+}
+void Image_setZoom(entity me, float z, float atMousePosition)
+{
+       float prev_zoomFactor;
+       prev_zoomFactor = me.zoomFactor;
+       if (z < 0) // multiply by the current zoomFactor (but can also snap to real dimensions or to box)
+       {
+               me.zoomFactor *= -z;
+               float realSize_in_the_middle, boxSize_in_the_middle;
+               realSize_in_the_middle = ((prev_zoomFactor - 1) * (me.zoomFactor - 1) < 0);
+               boxSize_in_the_middle = (me.zoomBox > 0 && (prev_zoomFactor - me.zoomBox) * (me.zoomFactor - me.zoomBox) < 0);
+               if (realSize_in_the_middle && boxSize_in_the_middle)
                {
-                       // x too large, so center x-wise
-                       me.imgSize = eY + eX * (me.size_y * asp / me.size_x);
+                       // snap to real dimensions or to box
+                       if (prev_zoomFactor < me.zoomFactor)
+                               me.zoomFactor = min(1, me.zoomBox);
+                       else
+                               me.zoomFactor = max(1, me.zoomBox);
                }
+               else if (realSize_in_the_middle)
+                       me.zoomFactor = 1; // snap to real dimensions
+               else if (boxSize_in_the_middle)
+                       me.zoomFactor = me.zoomBox; // snap to box
+       }
+       else if (z == 0) // reset (no zoom)
+       {
+               if (me.zoomBox > 0)
+                       me.zoomFactor = me.zoomBox;
                else
+                       me.zoomFactor = 1;
+       }
+       else // directly set
+               me.zoomFactor = z;
+       me.zoomFactor = bound(1/16, me.zoomFactor, 16);
+       if (me.zoomMax > 0 && me.zoomFactor > me.zoomMax)
+               me.zoomFactor = me.zoomMax;
+       if (prev_zoomFactor != me.zoomFactor)
+       {
+               me.zoomTime = time;
+               if (atMousePosition)
                {
-                       // y too large, so center y-wise
-                       me.imgSize = eX + eY * (me.size_x / (asp * me.size_y));
+                       me.zoomOffset_x = me.start_zoomOffset_x + (me.start_coords_x - 0.5) / me.imgSize_x;
+                       me.zoomOffset_y = me.start_zoomOffset_y + (me.start_coords_y - 0.5) / me.imgSize_y;
+                       // updateAspect will reset zoomOffset to '0.5 0.5 0' if
+                       // with this zoomFactor the image will not be zoomed in
+                       // (updateAspect will check the new values of imgSize).
                }
-               me.imgOrigin = '0.5 0.5 0' - 0.5 * me.imgSize;
        }
+       me.updateAspect(me);
 }
 void Image_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 {
index 6b5cac042ca970af7df0cc83c1c4e9f5e5e14585..4c0a08a8c57641112d9bdde34ca50a31c259484f 100644 (file)
@@ -70,6 +70,7 @@ SKINBEGIN
        SKINVECTOR(COLOR_DIALOG_HUD, '1 0.7 0.7');
        SKINVECTOR(COLOR_DIALOG_SERVERINFO, '0.7 0.7 1');
        SKINVECTOR(COLOR_DIALOG_CVARS, '1 0 0');
+       SKINVECTOR(COLOR_DIALOG_SCREENSHOTVIEWER, '0.7 0.7 1');
        SKINVECTOR(COLOR_DIALOG_HUDCONFIRM, '1 0 0');
 
        // nexposee positions of windows (they are the scale transformation
index 2c86f79c38fe322dfe77e8a16cd862a17c896029..0ea41972121c63ea2692b38af84e56c919dd4e5d 100644 (file)
@@ -5,7 +5,7 @@ CLASS(XonoticMultiplayerDialog) EXTENDS(XonoticDialog)
        ATTRIB(XonoticMultiplayerDialog, color, vector, SKINCOLOR_DIALOG_MULTIPLAYER)
        ATTRIB(XonoticMultiplayerDialog, intendedWidth, float, 0.96)
        ATTRIB(XonoticMultiplayerDialog, rows, float, 24)
-       ATTRIB(XonoticMultiplayerDialog, columns, float, 4)
+       ATTRIB(XonoticMultiplayerDialog, columns, float, 5)
 ENDCLASS(XonoticMultiplayerDialog)
 #endif
 
@@ -18,8 +18,8 @@ void XonoticMultiplayerDialog_fill(entity me)
                me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Servers"), makeXonoticServerListTab()));
                me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Create"), makeXonoticServerCreateTab()));
                me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Demos"), makeXonoticDemoBrowserTab()));
+               me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Screenshots"), makeXonoticScreenshotBrowserTab()));
                me.TD(me, 1, 1, e = mc.makeTabButton(mc, _("Player Setup"), makeXonoticPlayerSettingsTab()));
-
        me.TR(me);
        me.TR(me);
                me.TD(me, me.rows - 2, me.columns, mc);
diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_screenshot.c b/qcsrc/menu/xonotic/dialog_multiplayer_screenshot.c
new file mode 100644 (file)
index 0000000..4352937
--- /dev/null
@@ -0,0 +1,65 @@
+#ifdef INTERFACE
+CLASS(XonoticScreenshotBrowserTab) EXTENDS(XonoticTab)
+       METHOD(XonoticScreenshotBrowserTab, fill, void(entity))
+       ATTRIB(XonoticScreenshotBrowserTab, title, string, "Screenshot")
+       ATTRIB(XonoticScreenshotBrowserTab, intendedWidth, float, 1)
+       ATTRIB(XonoticScreenshotBrowserTab, rows, float, 22)
+       ATTRIB(XonoticScreenshotBrowserTab, columns, float, 6.5)
+       ATTRIB(XonoticScreenshotBrowserTab, name, string, "ScreenshotBrowser")
+       
+       METHOD(XonoticScreenshotBrowserTab, loadPreviewScreenshot, void(entity, string))
+       ATTRIB(XonoticScreenshotBrowserTab, screenshotImage, entity, NULL)
+       ATTRIB(XonoticScreenshotBrowserTab, currentScrPath, string, string_null)
+ENDCLASS(XonoticScreenshotBrowserTab)
+entity makeXonoticScreenshotBrowserTab();
+#endif
+
+#ifdef IMPLEMENTATION
+entity makeXonoticScreenshotBrowserTab()
+{
+       entity me;
+       me = spawnXonoticScreenshotBrowserTab();
+       me.configureDialog(me);
+       return me;
+}
+void XonoticScreenshotBrowserTab_loadPreviewScreenshot(entity me, string scrImage)
+{
+       if (me.currentScrPath == scrImage)
+               return;
+       if (me.currentScrPath)
+               strunzone(me.currentScrPath);
+       me.currentScrPath = strzone(scrImage);
+       me.screenshotImage.load(me.screenshotImage, me.currentScrPath);
+}
+void XonoticScreenshotBrowserTab_fill(entity me)
+{
+       entity e, slist;
+       slist = makeXonoticScreenshotList();
+       float slist_height = me.rows - 2;
+       me.TR(me);
+               me.TD(me, 1, 0.5, e = makeXonoticTextLabel(0, "Filter:"));
+               me.TD(me, 1, me.columns - 1.5, e = makeXonoticInputBox(0, string_null));
+                       e.onChange = ScreenshotList_Filter_Would_Change;
+                       e.onChangeEntity = slist;
+                       slist.screenshotViewerDialog = main.screenshotViewerDialog;
+                       main.screenshotViewerDialog.scrList = slist;
+               me.TD(me, 1, 1, e = makeXonoticButton(_("Refresh"), '0 0 0'));
+                       e.onClick = ScreenshotList_Refresh_Click;
+                       e.onClickEntity = slist;
+       me.TR(me);
+               me.TD(me, slist_height, me.columns, slist);
+
+       me.gotoRC(me, slist_height + 1, 0);
+               me.TD(me, 1, me.columns, e = makeXonoticButton(_("Open in the viewer"), '0 0 0'));
+                       e.onClick = StartScreenshot_Click;
+                       e.onClickEntity = slist;
+/*
+       me.TR(me);
+               me.TD(me, me.rows - me.currentRow, me.columns, e = makeXonoticScreenshotImage());
+                       e.showTitle = 0;
+                       me.screenshotImage = e;
+                       slist.screenshotPreview = e;
+                       slist.screenshotBrowserDialog = me;
+*/
+}
+#endif
diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c b/qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c
new file mode 100644 (file)
index 0000000..146f496
--- /dev/null
@@ -0,0 +1,171 @@
+#ifdef INTERFACE
+CLASS(XonoticScreenshotViewerDialog) EXTENDS(XonoticDialog)
+       METHOD(XonoticScreenshotViewerDialog, fill, void(entity))
+       METHOD(XonoticScreenshotViewerDialog, keyDown, float(entity, float, float, float))
+       METHOD(XonoticScreenshotViewerDialog, loadScreenshot, void(entity, string))
+       METHOD(XonoticScreenshotViewerDialog, close, void(entity))
+       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, 4)
+       ATTRIB(XonoticScreenshotViewerDialog, color, vector, SKINCOLOR_DIALOG_SCREENSHOTVIEWER)
+       ATTRIB(XonoticScreenshotViewerDialog, scrList, entity, NULL)
+       ATTRIB(XonoticScreenshotViewerDialog, screenshotImage, entity, NULL)
+       ATTRIB(XonoticScreenshotViewerDialog, slideShowButton, entity, NULL)
+       ATTRIB(XonoticScreenshotViewerDialog, currentScrPath, string, string_null)
+ENDCLASS(XonoticScreenshotViewerDialog)
+#endif
+
+#ifdef IMPLEMENTATION
+float music_playlist_index_backup;
+void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage)
+{
+       // disable music as it can lag depending on image loading time
+       if(!cvar("menu_screenshotviewer_enablemusic"))
+       if(cvar("music_playlist_index") != 999) // if the playlist isn't paused
+       {
+               // pause music
+               if(cvar("music_playlist_index") != -1)
+               {
+                       music_playlist_index_backup = cvar("music_playlist_index");
+                       cvar_set("music_playlist_sampleposition0", "0");
+                       cvar_set("music_playlist_index", "999");
+               }
+               else
+                       localcmd("\ncd pause\n");
+       }
+
+       if (me.currentScrPath == scrImage)
+               return;
+       if (me.currentScrPath)
+               strunzone(me.currentScrPath);
+       me.currentScrPath = strzone(scrImage);
+       me.screenshotImage.load(me.screenshotImage, me.currentScrPath);
+       me.frame.setText(me.frame, me.screenshotImage.screenshotTitle);
+}
+void prevScreenshot_Click(entity btn, entity me)
+{
+       me.scrList.goScreenshot(me.scrList, -1);
+}
+void nextScreenshot_Click(entity btn, entity me)
+{
+       me.scrList.goScreenshot(me.scrList, +1);
+}
+void increaseZoom_Click(entity btn, entity me)
+{
+       me.screenshotImage.setZoom(me.screenshotImage, -2, FALSE);
+}
+void decreaseZoom_Click(entity btn, entity me)
+{
+       me.screenshotImage.setZoom(me.screenshotImage, -1/2, FALSE);
+}
+void resetZoom_Click(entity btn, entity me)
+{
+       me.screenshotImage.setZoom(me.screenshotImage, 0, FALSE);
+}
+void toggleSlideShow_Click(entity btn, entity me)
+{
+       if (me.slideShowButton.forcePressed)
+       {
+               me.scrList.stopSlideShow(me.scrList);
+               me.slideShowButton.forcePressed = 0;
+       }
+       else
+       {
+               me.scrList.startSlideShow(me.scrList);
+               me.slideShowButton.forcePressed = 1;
+       }
+}
+float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift)
+{
+       switch(key)
+       {
+               case K_KP_LEFTARROW:
+               case K_LEFTARROW:
+                       me.scrList.goScreenshot(me.scrList, -1);
+                       return 1;
+               case K_KP_RIGHTARROW:
+               case K_RIGHTARROW:
+                       me.scrList.goScreenshot(me.scrList, +1);
+                       return 1;
+               case K_KP_ENTER:
+               case K_ENTER:
+               case K_SPACE:
+                       // we cannot use SPACE/ENTER directly, as in a dialog they are needed
+                       // to press buttons while browsing with only the keyboard
+                       if (shift & S_CTRL)
+                       {
+                               toggleSlideShow_Click(world, me);
+                               return 1;
+                       }
+                       return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
+               default:
+                       if (key == K_MWHEELUP || ascii == '+')
+                       {
+                               me.screenshotImage.setZoom(me.screenshotImage, -2, (key == K_MWHEELUP));
+                               return 1;
+                       }
+                       else if (key == K_MWHEELDOWN || ascii == '-')
+                       {
+                               me.screenshotImage.setZoom(me.screenshotImage, -1/2, (key == K_MWHEELDOWN));
+                               return 1;
+                       }
+                       if (me.scrList.keyDown(me.scrList, key, ascii, shift))
+                       {
+                               // keyDown has already changed the selected item
+                               me.scrList.goScreenshot(me.scrList, 0);
+                               return 1;
+                       }
+                       return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
+       }
+}
+void XonoticScreenshotViewerDialog_close(entity me)
+{
+       // resume music
+       if(!cvar("menu_screenshotviewer_enablemusic"))
+       if(cvar("music_playlist_index") == 999)
+       {
+               cvar_set("music_playlist_index", ftos(music_playlist_index_backup));
+       }
+       else
+               localcmd("\ncd resume\n");
+
+       me.scrList.stopSlideShow(me.scrList);
+       me.slideShowButton.forcePressed = 0;
+       SUPER(XonoticScreenshotViewerDialog).close(me);
+}
+void XonoticScreenshotViewerDialog_fill(entity me)
+{
+       entity e;
+       me.TR(me);
+               me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage());
+                       e.showTitle = 0; // dialog title is enough
+                       me.screenshotImage = e;
+       me.gotoRC(me, me.rows - 1, 0);
+               me.TDempty(me, 1/20 * me.columns);
+               me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("-", '0 0 0'));
+                       e.onClick = decreaseZoom_Click;
+                       e.onClickEntity = me;
+               me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("+", '0 0 0'));
+                       e.onClick = increaseZoom_Click;
+                       e.onClickEntity = me;
+               me.TD(me, 1, 2/20 * me.columns, e = makeXonoticButton(_("Reset"), '0 0 0'));
+                       e.onClick = resetZoom_Click;
+                       e.onClickEntity = me;
+
+               me.TDempty(me, 2/20 * me.columns);
+               me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Previous"), '0 0 0'));
+                       e.onClick = prevScreenshot_Click;
+                       e.onClickEntity = me;
+               me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Next"), '0 0 0'));
+                       e.onClick = nextScreenshot_Click;
+                       e.onClickEntity = me;
+
+               me.TDempty(me, 2/20 * me.columns);
+               me.TD(me, 1, 4/20 * me.columns, e = makeXonoticButton(_("Slide show"), '0 0 0'));
+                       e.onClick = toggleSlideShow_Click;
+                       e.onClickEntity = me;
+                       me.slideShowButton = e;
+}
+#endif
index f9d86c2dd229276aadb7272c9484f165bb1ad606..288a6bc06852c0940229c7dfa88aa24a4613396f 100644 (file)
@@ -11,6 +11,7 @@ CLASS(MainWindow) EXTENDS(ModalController)
        ATTRIB(MainWindow, winnerDialog, entity, NULL)
        ATTRIB(MainWindow, serverInfoDialog, entity, NULL)
        ATTRIB(MainWindow, cvarsDialog, entity, NULL)
+       ATTRIB(MainWindow, screenshotViewerDialog, entity, NULL)
        ATTRIB(MainWindow, viewDialog, entity, NULL)
        ATTRIB(MainWindow, modelDialog, entity, NULL)
        ATTRIB(MainWindow, crosshairDialog, entity, NULL)
@@ -116,10 +117,14 @@ void MainWindow_configureMainWindow(entity me)
        i = spawnXonoticHUDInfoMessagesDialog();
        i.configureDialog(i);
        me.addItemCentered(me, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z);
-
+       
        i = spawnXonoticHUDPhysicsDialog();
        i.configureDialog(i);
        me.addItemCentered(me, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z);
+       
+       me.screenshotViewerDialog = i = spawnXonoticScreenshotViewerDialog();
+       i.configureDialog(i);
+       me.addItemCentered(me, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z);
 
        i = spawnXonoticHUDCenterprintDialog();
        i.configureDialog(i);
diff --git a/qcsrc/menu/xonotic/screenshotimage.c b/qcsrc/menu/xonotic/screenshotimage.c
new file mode 100644 (file)
index 0000000..469f177
--- /dev/null
@@ -0,0 +1,95 @@
+#ifdef INTERFACE
+CLASS(XonoticScreenshotImage) EXTENDS(XonoticImage)
+       METHOD(XonoticScreenshotImage, configureXonoticScreenshotImage, void(entity))
+       METHOD(XonoticScreenshotImage, load, void(entity, string))
+       METHOD(XonoticScreenshotImage, draw, void(entity))
+       ATTRIB(XonoticScreenshotImage, focusable, float, 1) // mousePress and mouseDrag work only if focusable is set
+       METHOD(XonoticScreenshotImage, mousePress, float(entity, vector))
+       METHOD(XonoticScreenshotImage, mouseDrag, float(entity, vector))
+       METHOD(XonoticScreenshotImage, mouseMove, float(entity, vector))
+       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, screenshotTime, float, 0)
+       ATTRIB(XonoticScreenshotImage, screenshotTitle, string, string_null)
+ENDCLASS(XonoticScreenshotImage)
+entity makeXonoticScreenshotImage();
+#endif
+
+#ifdef IMPLEMENTATION
+entity makeXonoticScreenshotImage()
+{
+       entity me;
+       me = spawnXonoticScreenshotImage();
+       me.configureXonoticScreenshotImage(me);
+       return me;
+}
+
+void XonoticScreenshotImage_configureXonoticScreenshotImage(entity me)
+{
+       me.configureXonoticImage(me, string_null, -2);
+       me.zoomLimitedByTheBox = FALSE; // enable this to forbid enlarging the image more than the containing box (if making use of draw_SetClip is a too bad thing)
+       me.zoomSnapToTheBox = FALSE; // disabled: it's cooler
+}
+
+void XonoticScreenshotImage_load(entity me, string theImage)
+{
+       me.screenshotTime = time;
+       me.src = theImage;
+       if (me.screenshotTitle)
+               strunzone(me.screenshotTitle);
+       me.screenshotTitle = strzone(substring(me.src, 13, strlen(theImage) - 13)); //strip "/screenshots/"
+
+       me.initZoom(me); // this image may have a different size
+       me.setZoom(me, 0, 0);
+}
+
+float XonoticScreenshotImage_mousePress(entity me, vector coords)
+{
+       return me.drag_setStartPos(me, coords);
+}
+
+float XonoticScreenshotImage_mouseDrag(entity me, vector coords)
+{
+       return me.drag(me, coords);
+}
+
+float XonoticScreenshotImage_mouseMove(entity me, vector coords)
+{
+       return me.drag_setStartPos(me, coords);
+}
+
+void XonoticScreenshotImage_draw(entity me)
+{
+       if (me.src != "")
+       {
+               float theAlpha;
+               SUPER(XonoticScreenshotImage).draw(me);
+               if (me.showTitle && time < me.screenshotTime + 4) // 3 seconds at full alpha, 1 second fading out
+               {
+                       theAlpha = (4 - (time - me.screenshotTime));
+                       draw_CenterText('0.5 0 0', me.screenshotTitle, me.realFontSize, '1 1 1', theAlpha, FALSE);
+               }
+               if (time < me.zoomTime + 2) // 1 seconds at full alpha, 1 second fading out
+               {
+                       string zoomString;
+                       float z;
+                       z = me.zoomFactor * 100;
+                       if (z - floor(z) == 0)
+                               zoomString = sprintf("%d%%", z);
+                       else
+                               zoomString = sprintf("%.2f%%", z);
+                       theAlpha = (2 - (time - me.zoomTime));
+                       draw_Text('0.05 0.95 0', zoomString, me.realFontSize, '1 1 1', theAlpha, 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
diff --git a/qcsrc/menu/xonotic/screenshotlist.c b/qcsrc/menu/xonotic/screenshotlist.c
new file mode 100644 (file)
index 0000000..49582e8
--- /dev/null
@@ -0,0 +1,293 @@
+#ifdef INTERFACE
+CLASS(XonoticScreenshotList) EXTENDS(XonoticListBox)
+       METHOD(XonoticScreenshotList, configureXonoticScreenshotList, void(entity))
+       ATTRIB(XonoticScreenshotList, rowsPerItem, float, 1)
+       METHOD(XonoticScreenshotList, resizeNotify, void(entity, vector, vector, vector, vector))
+       METHOD(XonoticScreenshotList, setSelected, void(entity, float))
+       METHOD(XonoticScreenshotList, draw, void(entity))
+       METHOD(XonoticScreenshotList, drawListBoxItem, void(entity, float, vector, float))
+       METHOD(XonoticScreenshotList, getScreenshots, void(entity))
+       METHOD(XonoticScreenshotList, previewScreenshot, void(entity))
+       METHOD(XonoticScreenshotList, startScreenshot, void(entity))
+       METHOD(XonoticScreenshotList, screenshotName, string(entity, float))
+       METHOD(XonoticScreenshotList, clickListBoxItem, void(entity, float, vector))
+       METHOD(XonoticScreenshotList, keyDown, float(entity, float, float, float))
+       METHOD(XonoticScreenshotList, destroy, void(entity))
+       METHOD(XonoticScreenshotList, showNotify, void(entity))
+       ATTRIB(XonoticScreenshotList, listScreenshot, float, -1)
+       ATTRIB(XonoticScreenshotList, realFontSize, vector, '0 0 0')
+       ATTRIB(XonoticScreenshotList, columnNameOrigin, float, 0)
+       ATTRIB(XonoticScreenshotList, columnNameSize, float, 0)
+       ATTRIB(XonoticScreenshotList, realUpperMargin, float, 0)
+       ATTRIB(XonoticScreenshotList, origin, vector, '0 0 0')
+       ATTRIB(XonoticScreenshotList, itemAbsSize, vector, '0 0 0')
+       ATTRIB(XonoticScreenshotList, lastClickedScreenshot, float, -1)
+       ATTRIB(XonoticScreenshotList, lastClickedTime, float, 0)
+       ATTRIB(XonoticScreenshotList, filterString, string, string_null)
+       ATTRIB(XonoticScreenshotList, filterBox, entity, NULL)
+       ATTRIB(XonoticScreenshotList, filterTime, float, 0)
+
+       ATTRIB(XonoticScreenshotList, newScreenshotTime, float, 0)
+       ATTRIB(XonoticScreenshotList, newSlideShowScreenshotTime, float, 0)
+       ATTRIB(XonoticScreenshotList, prevSelectedItem, float, 0)
+
+       ATTRIB(XonoticScreenshotList, screenshotBrowserDialog, entity, NULL)
+       ATTRIB(XonoticScreenshotList, screenshotPreview, entity, NULL)
+       ATTRIB(XonoticScreenshotList, screenshotViewerDialog, entity, NULL)
+       METHOD(XonoticScreenshotList, goScreenshot, void(entity, float))
+       METHOD(XonoticScreenshotList, startSlideShow, void(entity))
+       METHOD(XonoticScreenshotList, stopSlideShow, void(entity))
+ENDCLASS(XonoticScreenshotList)
+
+entity makeXonoticScreenshotList();
+void StartScreenshot_Click(entity btn, entity me);
+void ScreenshotList_Refresh_Click(entity btn, entity me);
+void ScreenshotList_Filter_Would_Change(entity box, entity me);
+void ScreenshotList_Filter_Change(entity box, entity me);
+#endif
+
+#ifdef IMPLEMENTATION
+
+entity makeXonoticScreenshotList()
+{
+       entity me;
+       me = spawnXonoticScreenshotList();
+       me.configureXonoticScreenshotList(me);
+       return me;
+}
+
+void XonoticScreenshotList_configureXonoticScreenshotList(entity me)
+{
+       me.configureXonoticListBox(me);
+       me.getScreenshots(me);
+}
+
+string XonoticScreenshotList_screenshotName(entity me, float i )
+{
+       string s;
+       s = bufstr_get(me.listScreenshot, i);
+       s = substring(s, 12, strlen(s) - 12 - 4);  // screenshots/, .<ext>
+       return s;
+}
+
+// if subdir is TRUE look in subdirectories too (1 level)
+void getScreenshots_for_ext(entity me, string ext, float subdir)
+{
+       string s;
+       if (subdir)
+               s="screenshots/*/";
+       else
+               s="screenshots/";
+       if(me.filterString)
+               s=strcat(s, me.filterString, ext);
+       else
+               s=strcat(s, "*", ext);
+
+       float list, i, n;
+       list = search_begin(s, FALSE, TRUE);
+       if(list >= 0)
+       {
+               n = search_getsize(list);
+               for(i = 0; i < n; ++i)
+                       bufstr_add(me.listScreenshot, search_getfilename(list, i), TRUE);
+               search_end(list);
+       }
+
+       if (subdir)
+               getScreenshots_for_ext(me, ext, FALSE);
+}
+
+void XonoticScreenshotList_getScreenshots(entity me)
+{
+       if (me.listScreenshot >= 0)
+               buf_del(me.listScreenshot);
+       me.listScreenshot = buf_create();
+       if (me.listScreenshot < 0)
+       {
+               me.nItems = 0;
+               return;
+       }
+       getScreenshots_for_ext(me, ".jpg", TRUE);
+       getScreenshots_for_ext(me, ".tga", TRUE);
+       getScreenshots_for_ext(me, ".png", TRUE);
+       me.nItems = buf_getsize(me.listScreenshot);
+       if(me.nItems > 0)
+               buf_sort(me.listScreenshot, 128, FALSE);
+}
+
+void XonoticScreenshotList_destroy(entity me)
+{
+       if(me.nItems > 0)
+               buf_del(me.listScreenshot);
+}
+
+void XonoticScreenshotList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
+{
+       me.itemAbsSize = '0 0 0';
+       SUPER(XonoticScreenshotList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
+
+       me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
+       me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
+       me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
+
+       me.columnNameOrigin = me.realFontSize_x;
+       me.columnNameSize = 1 - 2 * me.realFontSize_x;
+}
+
+void XonoticScreenshotList_setSelected(entity me, float i)
+{
+       if (me.newSlideShowScreenshotTime)
+               me.startSlideShow(me);
+       me.prevSelectedItem = me.selectedItem;
+       SUPER(XonoticScreenshotList).setSelected(me, i);
+       if (me.pressed && me.selectedItem != me.prevSelectedItem)
+       {
+               // while dragging the scrollbar (or an item)
+               // for a smooth mouse movement do not load immediately the new selected images
+               me.newScreenshotTime = time + 0.22; // dragging an item we need a delay > 0.2 (from listbox: me.dragScrollTimer = time + 0.2;)
+       }
+       else if (time > me.newScreenshotTime)
+       {
+               me.newScreenshotTime = 0;
+               me.previewScreenshot(me); // load the preview on selection change
+       }
+}
+
+void XonoticScreenshotList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
+{
+       string s;
+       if(isSelected)
+               draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
+
+       s = me.screenshotName(me,i);
+       s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
+       draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
+}
+
+void XonoticScreenshotList_showNotify(entity me)
+{
+       me.getScreenshots(me);
+       me.previewScreenshot(me);
+}
+
+void ScreenshotList_Refresh_Click(entity btn, entity me)
+{
+       me.getScreenshots(me);
+       me.setSelected(me, 0); //always select the first element after a list update
+}
+
+void ScreenshotList_Filter_Change(entity box, entity me)
+{
+       if(me.filterString)
+               strunzone(me.filterString);
+
+       if(box.text != "")
+       {
+               if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
+                       me.filterString = strzone(box.text);
+               else
+                       me.filterString = strzone(strcat("*", box.text, "*"));
+       }
+       else
+               me.filterString = string_null;
+
+       ScreenshotList_Refresh_Click(world, me);
+}
+
+void ScreenshotList_Filter_Would_Change(entity box, entity me)
+{
+       me.filterBox = box;
+       me.filterTime = time + 0.5;
+}
+
+void XonoticScreenshotList_draw(entity me)
+{
+       if (me.filterTime && time > me.filterTime)
+       {
+               ScreenshotList_Filter_Change(me.filterBox, me);
+               me.filterTime = 0;
+       }
+       if (me.newScreenshotTime && time > me.newScreenshotTime)
+       {
+               me.previewScreenshot(me);
+               me.newScreenshotTime = 0;
+       }
+       else if (me.newSlideShowScreenshotTime && time > me.newSlideShowScreenshotTime)
+       {
+               if (me.selectedItem == me.nItems - 1) //last screenshot?
+               {
+                       // restart from the first screenshot
+                       me.setSelected(me, 0);
+                       me.goScreenshot(me, +0);
+               }
+               else
+                       me.goScreenshot(me, +1);
+       }
+       SUPER(XonoticScreenshotList).draw(me);
+}
+
+void XonoticScreenshotList_startSlideShow(entity me)
+{
+       me.newSlideShowScreenshotTime = time + 3;
+}
+
+void XonoticScreenshotList_stopSlideShow(entity me)
+{
+       me.newSlideShowScreenshotTime = 0;
+}
+
+void XonoticScreenshotList_goScreenshot(entity me, float d)
+{
+       if(!me.screenshotViewerDialog)
+               return;
+       me.setSelected(me, me.selectedItem + d);
+       me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", me.screenshotName(me,me.selectedItem)));
+}
+
+void XonoticScreenshotList_startScreenshot(entity me)
+{
+       me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", me.screenshotName(me,me.selectedItem)));
+       // pop up screenshot
+       DialogOpenButton_Click_withCoords(NULL, me.screenshotViewerDialog, me.origin + eX * (me.columnNameOrigin * me.size_x) + eY * ((me.itemHeight * me.selectedItem - me.scrollPos) * me.size_y), eY * me.itemAbsSize_y + eX * (me.itemAbsSize_x * me.columnNameSize));
+}
+
+void XonoticScreenshotList_previewScreenshot(entity me)
+{
+       if(!me.screenshotBrowserDialog)
+               return;
+       if (me.nItems <= 0)
+               me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, "");
+       else
+               me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, strcat("/screenshots/", me.screenshotName(me,me.selectedItem)));
+}
+
+void StartScreenshot_Click(entity btn, entity me)
+{
+       me.startScreenshot(me);
+}
+
+void XonoticScreenshotList_clickListBoxItem(entity me, float i, vector where)
+{
+       if(i == me.lastClickedScreenshot)
+               if(time < me.lastClickedTime + 0.3)
+               {
+                       // DOUBLE CLICK!
+                       // pop up screenshot
+                       me.setSelected(me, i);
+                       me.startScreenshot(me);
+               }
+       me.lastClickedScreenshot = i;
+       me.lastClickedTime = time;
+}
+
+float XonoticScreenshotList_keyDown(entity me, float scan, float ascii, float shift)
+{
+       if(scan == K_ENTER || scan == K_KP_ENTER) {
+               me.startScreenshot(me);
+               return 1;
+       }
+       if(scan == K_MWHEELUP || scan == K_MWHEELDOWN)
+               me.newScreenshotTime = time + 0.2;
+       return SUPER(XonoticScreenshotList).keyDown(me, scan, ascii, shift);
+}
+#endif