slideshow

This commit is contained in:
nothings.org 2007-08-24 13:08:03 +00:00
parent ec3905f418
commit e9559c7fce
4 changed files with 112 additions and 23 deletions

72
imv.c
View File

@ -54,9 +54,8 @@ typedef int Bool;
int do_show; Bool do_show;
int delay_time = 4000; float delay_time = 4;
// all programs get the version number from the same place: version.bat // all programs get the version number from the same place: version.bat
#define set static char * #define set static char *
@ -601,7 +600,8 @@ char helptext_left[] =
" B: toggle border\n" " B: toggle border\n"
"SHIFT-B: toggle border but keep stripe\n" "SHIFT-B: toggle border but keep stripe\n"
" CTRL-B: toggle white stripe in border\n" " CTRL-B: toggle white stripe in border\n"
" L: toggle filename label\n" " L: toggle filename label\n"
" S: slideshow in current directory\n"
; ;
char helptext_right[] = char helptext_right[] =
@ -1501,7 +1501,7 @@ void advance(int dir)
cache[i].bail = 1; cache[i].bail = 1;
if (do_show) if (do_show)
SetTimer(win, 0, delay_time, NULL); SetTimer(win, 0, (int)(delay_time*1000), NULL);
} }
// ctrl-O, or initial command if no filename: run // ctrl-O, or initial command if no filename: run
@ -1798,6 +1798,8 @@ void reg_save(void)
reg_set("lfs", &label_font_height, 4); reg_set("lfs", &label_font_height, 4);
reg_set("label", &show_label, 4); reg_set("label", &show_label, 4);
reg_set("stbi", &only_stbi, 4); reg_set("stbi", &only_stbi, 4);
reg_set("border", &show_frame, 4);
reg_set("stime", &delay_time, 4);
RegCloseKey(zreg); RegCloseKey(zreg);
} }
} }
@ -1814,6 +1816,9 @@ void reg_load(void)
if (reg_get("cache", &temp, 4)) if (reg_get("cache", &temp, 4))
max_cache_bytes = temp << 20; max_cache_bytes = temp << 20;
reg_get("stbi", &only_stbi, 4); reg_get("stbi", &only_stbi, 4);
reg_get("border", &show_frame, 4);
extra_border = show_frame;
reg_get("stime", &delay_time, 4);
RegCloseKey(zreg); RegCloseKey(zreg);
} }
} }
@ -1837,6 +1842,23 @@ static int get_dialog_number(int id)
return atoi(buffer); return atoi(buffer);
} }
// set an edit control's text from an integer
static void set_dialog_numberf(int id, float value)
{
char buffer[16];
sprintf(buffer, "%.2f", value);
SetWindowText(GetDlgItem(dialog, id), buffer);
}
// get an edit control's text as an integer
static float get_dialog_numberf(int id)
{
char buffer[32];
int n = GetWindowText(GetDlgItem(dialog,id), buffer, sizeof(buffer)-1);
buffer[n] = 0;
return (float) atof(buffer);
}
// clamp an edit control's text into an integer range (and // clamp an edit control's text into an integer range (and
// remove non-integer chacters) // remove non-integer chacters)
static void dialog_clamp(int id, int low, int high) static void dialog_clamp(int id, int low, int high)
@ -1848,6 +1870,15 @@ static void dialog_clamp(int id, int low, int high)
set_dialog_number(id,x); set_dialog_number(id,x);
} }
static void dialog_clampf(int id, float low, float high)
{
float x = get_dialog_numberf(id);
if (x < low) x = low;
else if (x > high) x = high;
else return;
set_dialog_numberf(id,x);
}
extern unsigned char *rom_images[]; // preference images extern unsigned char *rom_images[]; // preference images
// preferences dialog windows procedure // preferences dialog windows procedure
@ -1880,10 +1911,12 @@ BOOL CALLBACK PrefDlgProc(HWND hdlg, UINT imsg, WPARAM wparam, LPARAM lparam)
SendMessage(GetDlgItem(hdlg, DIALOG_upsample), BM_SETCHECK, upsample_cubic, 0); SendMessage(GetDlgItem(hdlg, DIALOG_upsample), BM_SETCHECK, upsample_cubic, 0);
SendMessage(GetDlgItem(hdlg, DIALOG_showlabel), BM_SETCHECK, show_label, 0); SendMessage(GetDlgItem(hdlg, DIALOG_showlabel), BM_SETCHECK, show_label, 0);
SendMessage(GetDlgItem(hdlg, DIALOG_stbi_only), BM_SETCHECK, only_stbi, 0); SendMessage(GetDlgItem(hdlg, DIALOG_stbi_only), BM_SETCHECK, only_stbi, 0);
SendMessage(GetDlgItem(hdlg, DIALOG_showborder), BM_SETCHECK, show_frame, 0);
for (i=0; i < 6; ++i) for (i=0; i < 6; ++i)
set_dialog_number(DIALOG_r1+i, alpha_background[0][i]); set_dialog_number(DIALOG_r1+i, alpha_background[0][i]);
set_dialog_number(DIALOG_cachesize, max_cache_bytes >> 20); set_dialog_number(DIALOG_cachesize, max_cache_bytes >> 20);
set_dialog_number(DIALOG_labelheight, label_font_height); set_dialog_number(DIALOG_labelheight, label_font_height);
set_dialog_numberf(DIALOG_slideshowtime, delay_time);
return TRUE; return TRUE;
} }
case WM_PAINT: { case WM_PAINT: {
@ -1920,10 +1953,14 @@ BOOL CALLBACK PrefDlgProc(HWND hdlg, UINT imsg, WPARAM wparam, LPARAM lparam)
case DIALOG_labelheight: case DIALOG_labelheight:
if (n == EN_KILLFOCUS) dialog_clamp(k,1,200); if (n == EN_KILLFOCUS) dialog_clamp(k,1,200);
break; break;
case DIALOG_slideshowtime:
if (n == EN_KILLFOCUS) dialog_clampf(k,0,3600 * 24 * 31); // 1 month
break;
case IDOK: { case IDOK: {
// user clicked ok... copy out current values to check for changes // user clicked ok... copy out current values to check for changes
unsigned char cur[6]; unsigned char curc[6];
int new_border;
int old_cubic = upsample_cubic; int old_cubic = upsample_cubic;
memcpy(cur, alpha_background, 6); memcpy(cur, alpha_background, 6);
@ -1932,12 +1969,14 @@ BOOL CALLBACK PrefDlgProc(HWND hdlg, UINT imsg, WPARAM wparam, LPARAM lparam)
alpha_background[0][i] = get_dialog_number(DIALOG_r1+i); alpha_background[0][i] = get_dialog_number(DIALOG_r1+i);
max_cache_bytes = get_dialog_number(DIALOG_cachesize) << 20; max_cache_bytes = get_dialog_number(DIALOG_cachesize) << 20;
label_font_height = get_dialog_number(DIALOG_labelheight); label_font_height = get_dialog_number(DIALOG_labelheight);
delay_time = get_dialog_numberf(DIALOG_slideshowtime);
upsample_cubic = BST_CHECKED == SendMessage(GetDlgItem(hdlg,DIALOG_upsample ), BM_GETCHECK,0,0); upsample_cubic = BST_CHECKED == SendMessage(GetDlgItem(hdlg,DIALOG_upsample ), BM_GETCHECK,0,0);
show_label = BST_CHECKED == SendMessage(GetDlgItem(hdlg,DIALOG_showlabel), BM_GETCHECK,0,0); show_label = BST_CHECKED == SendMessage(GetDlgItem(hdlg,DIALOG_showlabel), BM_GETCHECK,0,0);
only_stbi = BST_CHECKED == SendMessage(GetDlgItem(hdlg,DIALOG_stbi_only), BM_GETCHECK,0,0); only_stbi = BST_CHECKED == SendMessage(GetDlgItem(hdlg,DIALOG_stbi_only), BM_GETCHECK,0,0);
new_border = BST_CHECKED == SendMessage(GetDlgItem(hdlg,DIALOG_showborder),BM_GETCHECK,0,0);
// if alpha_background changed, clear the cache of any images that used it // if alpha_background changed, clear the cache of any images that used it
if (memcmp(alpha_background, cur, 6)) { if (memcmp(alpha_background, curc, 6)) {
stb_mutex_begin(cache_mutex); stb_mutex_begin(cache_mutex);
for (i=0; i < MAX_CACHED_IMAGES; ++i) { for (i=0; i < MAX_CACHED_IMAGES; ++i) {
if (cache[i].status == LOAD_available) { if (cache[i].status == LOAD_available) {
@ -1960,6 +1999,13 @@ BOOL CALLBACK PrefDlgProc(HWND hdlg, UINT imsg, WPARAM wparam, LPARAM lparam)
advance(0); advance(0);
} }
// if border changed, update
if (new_border != show_frame) {
toggle_frame();
extra_border = show_frame;
if (cur) frame(cur);
}
// save the data out to the registry // save the data out to the registry
reg_save(); reg_save();
@ -2061,6 +2107,7 @@ int WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// if the most recently-browsed and displayable image is an error, show it // if the most recently-browsed and displayable image is an error, show it
if (best->status == LOAD_error_reading || best->status == LOAD_error_decoding) if (best->status == LOAD_error_reading || best->status == LOAD_error_decoding)
set_error(best); set_error(best);
break; break;
} }
@ -2130,7 +2177,6 @@ int WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_TIMER: { case WM_TIMER: {
advance(1); advance(1);
return 0; return 0;
break;
} }
#define MY_SHIFT (1 << 16) #define MY_SHIFT (1 << 16)
@ -2163,10 +2209,10 @@ int WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
InvalidateRect(win, NULL, FALSE); InvalidateRect(win, NULL, FALSE);
break; break;
case 'S': case 's': case 'S':
do_show = !do_show; do_show = !do_show;
if (do_show) if (do_show)
SetTimer(win,0,delay_time,NULL); SetTimer(win,0,(int)(1000*delay_time),NULL);
else else
KillTimer(win,0); KillTimer(win,0);
break; break;
@ -2518,6 +2564,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
pending_resize.image = NULL; pending_resize.image = NULL;
} }
cur_filename = strdup(filename); cur_filename = strdup(filename);
if (!show_frame) {
x += FRAME;
y += FRAME;
w -= FRAME*2;
h -= FRAME*2;
}
// create the window // create the window
hWnd = CreateWindow(szAppName, displayName, hWnd = CreateWindow(szAppName, displayName,

View File

@ -1,5 +1,6 @@
Version 0.96: Beta 8 ( ) Version 0.96: Beta 8 ( )
* feature: TGA support in stb_image * feature: TGA support in stb_image
* feature: save border choice to registry (expose in prefs)
Version 0.95: Beta 7 ( 2007-08-15 ) Version 0.95: Beta 7 ( 2007-08-15 )
* bugfix: minor stb_image.c fixes * bugfix: minor stb_image.c fixes

30
pref.rc
View File

@ -52,15 +52,15 @@ END
// Dialog // Dialog
// //
IDD_pref DIALOG DISCARDABLE 0, 0, 161, 196 IDD_pref DIALOG DISCARDABLE 0, 0, 161, 226
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "imv(stb) preferences" CAPTION "imv(stb) preferences"
FONT 8, "MS Sans Serif" FONT 8, "MS Sans Serif"
BEGIN BEGIN
DEFPUSHBUTTON "OK",IDOK,23,172,50,14 DEFPUSHBUTTON "OK",IDOK,23,199,50,14
PUSHBUTTON "Cancel",IDCANCEL,83,172,50,14 PUSHBUTTON "Cancel",IDCANCEL,83,199,50,14
CONTROL "High-quality resizing",DIALOG_upsample,"Button", CONTROL "High-quality &resizing",DIALOG_upsample,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,23,116,76,10 BS_AUTOCHECKBOX | WS_TABSTOP,23,166,76,10
EDITTEXT DIALOG_r1,57,50,19,12,ES_RIGHT | ES_AUTOHSCROLL EDITTEXT DIALOG_r1,57,50,19,12,ES_RIGHT | ES_AUTOHSCROLL
EDITTEXT DIALOG_g1,79,50,19,12,ES_RIGHT | ES_AUTOHSCROLL EDITTEXT DIALOG_g1,79,50,19,12,ES_RIGHT | ES_AUTOHSCROLL
EDITTEXT DIALOG_b1,101,50,19,12,ES_RIGHT | ES_AUTOHSCROLL EDITTEXT DIALOG_b1,101,50,19,12,ES_RIGHT | ES_AUTOHSCROLL
@ -71,16 +71,20 @@ BEGIN
EDITTEXT DIALOG_r2,57,63,19,12,ES_RIGHT | ES_AUTOHSCROLL EDITTEXT DIALOG_r2,57,63,19,12,ES_RIGHT | ES_AUTOHSCROLL
EDITTEXT DIALOG_g2,79,63,19,12,ES_RIGHT | ES_AUTOHSCROLL EDITTEXT DIALOG_g2,79,63,19,12,ES_RIGHT | ES_AUTOHSCROLL
EDITTEXT DIALOG_b2,101,63,19,12,ES_RIGHT | ES_AUTOHSCROLL EDITTEXT DIALOG_b2,101,63,19,12,ES_RIGHT | ES_AUTOHSCROLL
EDITTEXT DIALOG_cachesize,10,130,21,13,ES_AUTOHSCROLL EDITTEXT DIALOG_cachesize,10,150,21,13,ES_AUTOHSCROLL
LTEXT "Size of image cache in megabytes",IDC_STATIC,35,133,107, LTEXT "Size of image cache (megabytes)",IDC_STATIC,34,153,107,
8 8
LTEXT "",DIALOG_image,45,7,70,28 LTEXT "",DIALOG_image,45,7,70,28
EDITTEXT DIALOG_labelheight,11,99,20,12,ES_AUTOHSCROLL EDITTEXT DIALOG_labelheight,10,118,21,12,ES_AUTOHSCROLL
LTEXT "Label font height",IDC_STATIC,35,101,104,10 LTEXT "Label font height",IDC_STATIC,34,120,56,10
CONTROL "Show filename label",DIALOG_showlabel,"Button", CONTROL "Show filename &label",DIALOG_showlabel,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,23,87,120,10 BS_AUTOCHECKBOX | WS_TABSTOP,23,104,120,10
CONTROL "Only use stb_image loaders",DIALOG_stbi_only,"Button", CONTROL "Only use stb_image loaders",DIALOG_stbi_only,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,23,149,111,10 BS_AUTOCHECKBOX | WS_TABSTOP,23,179,111,10
CONTROL "Show &border",DIALOG_showborder,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,23,91,82,10
EDITTEXT DIALOG_slideshowtime,10,134,21,12,ES_AUTOHSCROLL
LTEXT "Slideshow time (seconds)",IDC_STATIC,34,136,96,10
END END
@ -97,7 +101,7 @@ BEGIN
LEFTMARGIN, 7 LEFTMARGIN, 7
RIGHTMARGIN, 154 RIGHTMARGIN, 154
TOPMARGIN, 7 TOPMARGIN, 7
BOTTOMMARGIN, 189 BOTTOMMARGIN, 219
END END
END END
#endif // APSTUDIO_INVOKED #endif // APSTUDIO_INVOKED

32
resource.h Normal file
View File

@ -0,0 +1,32 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by pref.rc
//
#define IDD_DIALOG1 101
#define IDD_pref 101
#define IDI_ICON1 102
#define DIALOG_upsample 1000
#define DIALOG_r1 1001
#define DIALOG_g1 1002
#define DIALOG_b1 1003
#define DIALOG_r2 1004
#define DIALOG_g2 1005
#define DIALOG_b2 1006
#define DIALOG_cachesize 1007
#define DIALOG_image 1008
#define DIALOG_labelheight 1009
#define DIALOG_showlabel 1010
#define DIALOG_stbi_only 1011
#define DIALOG_showborder 1012
#define DIALOG_slideshowtime 1013
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1013
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif