]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/screenshotlist.qc
Merge branch 'master' into TimePath/vehicles_cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / screenshotlist.qc
index c8f3becfa03c69a9b47c57cd489c2ebf078a78b8..e7693a2e351080f0eaa6e7fba4807c040f2fbc6a 100644 (file)
@@ -1,19 +1,21 @@
-#ifdef INTERFACE
-CLASS(XonoticScreenshotList) EXTENDS(XonoticListBox)
-       METHOD(XonoticScreenshotList, configureXonoticScreenshotList, void(entity))
+#ifndef SCREENSHOTLIST_H
+#define SCREENSHOTLIST_H
+#include "listbox.qc"
+CLASS(XonoticScreenshotList, 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, doubleClickListBoxItem, void(entity, float, vector))
-       METHOD(XonoticScreenshotList, keyDown, float(entity, float, float, float))
-       METHOD(XonoticScreenshotList, destroy, void(entity))
-       METHOD(XonoticScreenshotList, showNotify, void(entity))
+       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, int, vector, bool, bool));
+       METHOD(XonoticScreenshotList, getScreenshots, void(entity));
+       METHOD(XonoticScreenshotList, previewScreenshot, void(entity));
+       METHOD(XonoticScreenshotList, startScreenshot, void(entity));
+       METHOD(XonoticScreenshotList, screenshotName, string(entity, float));
+       METHOD(XonoticScreenshotList, doubleClickListBoxItem, 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)
@@ -27,14 +29,13 @@ CLASS(XonoticScreenshotList) EXTENDS(XonoticListBox)
 
        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))
+       METHOD(XonoticScreenshotList, goScreenshot, void(entity, float));
+       METHOD(XonoticScreenshotList, startSlideShow, void(entity));
+       METHOD(XonoticScreenshotList, stopSlideShow, void(entity));
 ENDCLASS(XonoticScreenshotList)
 
 entity makeXonoticScreenshotList();
@@ -49,7 +50,7 @@ void ScreenshotList_Filter_Change(entity box, entity me);
 entity makeXonoticScreenshotList()
 {
        entity me;
-       me = spawnXonoticScreenshotList();
+       me = NEW(XonoticScreenshotList);
        me.configureXonoticScreenshotList(me);
        return me;
 }
@@ -71,7 +72,7 @@ string XonoticScreenshotList_screenshotName(entity me, float i)
        return s;
 }
 
-// if subdir is TRUE look in subdirectories too (1 level)
+// if subdir is true look in subdirectories too (1 level)
 void getScreenshots_for_ext(entity me, string ext, float subdir)
 {
        string s;
@@ -85,7 +86,7 @@ void getScreenshots_for_ext(entity me, string ext, float subdir)
                s=strcat(s, "*", ext);
 
        float list, i, n;
-       list = search_begin(s, FALSE, TRUE);
+       list = search_begin(s, false, true);
        if(list >= 0)
        {
                n = search_getsize(list);
@@ -98,15 +99,15 @@ void getScreenshots_for_ext(entity me, string ext, float subdir)
                        {
                                s = strreplace("/", "^7/", s); // clear colors at the forward slash
                                s = strcat("/", rgb_to_hexcolor(SKINCOLOR_SCREENSHOTLIST_SUBDIR), s); // add a forward slash for sorting, then color
-                               bufstr_add(me.listScreenshot, s, TRUE);
+                               bufstr_add(me.listScreenshot, s, true);
                        }
-                       else { bufstr_add(me.listScreenshot, s, TRUE); }
+                       else { bufstr_add(me.listScreenshot, s, true); }
                }
                search_end(list);
        }
 
        if (subdir)
-               getScreenshots_for_ext(me, ext, FALSE);
+               getScreenshots_for_ext(me, ext, false);
 }
 
 void XonoticScreenshotList_getScreenshots(entity me)
@@ -119,12 +120,12 @@ void XonoticScreenshotList_getScreenshots(entity me)
                me.nItems = 0;
                return;
        }
-       getScreenshots_for_ext(me, ".jpg", TRUE);
-       getScreenshots_for_ext(me, ".tga", TRUE);
-       getScreenshots_for_ext(me, ".png", TRUE);
+       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);
+               buf_sort(me.listScreenshot, 128, false);
 }
 
 void XonoticScreenshotList_destroy(entity me)
@@ -138,25 +139,24 @@ void XonoticScreenshotList_resizeNotify(entity me, vector relOrigin, vector relS
        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.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;
+       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;
+       float selectedItem_save = me.selectedItem;
        SUPER(XonoticScreenshotList).setSelected(me, i);
-       if (me.pressed && me.selectedItem != me.prevSelectedItem)
+       if (me.pressed && me.selectedItem != selectedItem_save)
        {
-               // 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;)
+               // avoid immediate image loading on quick repeated selection changes
+               me.newScreenshotTime = time + 0.22;
        }
        else if (time > me.newScreenshotTime)
        {
@@ -165,11 +165,16 @@ void XonoticScreenshotList_setSelected(entity me, float i)
        }
 }
 
-void XonoticScreenshotList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
+void XonoticScreenshotList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
 {
        string s;
        if(isSelected)
                draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
+       else if(isFocused)
+       {
+               me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
+               draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
+       }
 
        s = me.screenshotName(me,i);
        s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
@@ -260,7 +265,7 @@ void XonoticScreenshotList_startScreenshot(entity me)
 {
        me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(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));
+       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)
@@ -289,8 +294,6 @@ float XonoticScreenshotList_keyDown(entity me, float scan, float ascii, float sh
                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