IonicWind Software

IWBasic => Games and Graphics => Topic started by: Brian on July 22, 2019, 04:08:48 AM

Title: DevIL image viewer program
Post by: Brian on July 22, 2019, 04:08:48 AM
Hello,

I picked up this program from a long time ago, and decided to do something with it, just for fun. I've added quite a lot to the original (see comments at the beginning of the listing). It will load and save quite a lot of formats

There is everything you should need to compile the program. If I have missed anything, let me know. Just move the includes and libs to the correct folders

Three things I can't figure out:

In the BrowseForFolder, I want it to jump and highlight the current folder when loading up. Any ideas?

When viewing an image larger than the actual screen size, I want it to reduce the size of the displayed image so that it fits. Any ideas?

And how do I colour the size grip when the statusbar changes to green, to signal an image has been loaded correctly?

Any comments, ideas, please let me know,

Brian

PS: I have updated the DevIL DLLs to the latest version
Title: Re: DevIL image viewer program
Post by: fasecero on July 22, 2019, 12:20:37 PM
Nice program! Can't help with any of these questions really.

QuoteIn the BrowseForFolder, I want it to jump and highlight the current folder when loading up. Any ideas?

Check the source code, this must be happening when processing the message BFF_JUMPTOPATH
SENDMESSAGE win,BFF_JUMPTOPATH,LEN(Paths),Paths,BFF
QuoteWhen viewing an image larger than the actual screen size, I want it to reduce the size of the displayed image so that it fits. Any ideas?

Same as before. Probably inside ilutConvertToHBitmap in conjunction with the code after that (loadfile function).

QuoteAnd how do I colour the size grip when the statusbar changes to green, to signal an image has been loaded correctly?

I think you can't do this unless you draw the statusbar yourself which is really hard to do.
Title: Re: DevIL image viewer program
Post by: Brian on July 26, 2019, 08:39:56 AM
Update: Now populates the file list box faster; added keyboard shortcuts, and various other tweaks

Brian
Title: Re: DevIL image viewer program
Post by: Brian on July 28, 2019, 08:39:00 AM
Help! If anyone can help with this problem, I would be very grateful. I am banging my head over this one

When the program starts up, the window is 1024 x 768. If you click on a graphic that is smaller than the client window (the grey area), the image fits perfectly in the centre

I am calculating if the image width or height is greater than the client area, and using iluScale to resize the image to fit, but obviously it is not working like I think it should be

Any ideas?

Brian
Title: Re: DevIL image viewer program
Post by: fasecero on July 29, 2019, 04:03:38 PM
I have more or less fixed the first example you posted because that treeview looks much better. I had to change many things, I will try to explain them briefly.

- The handle of the treeview is the handle of the BFF control. Denying this made me waste a lot of time.

- Once the treeview handle is obtained, adding TVS_SHOWSELALWAYS is simple, but it didn't work. The treeview seem to have some customdraw code that I couldn't remove by subclassing it. The only way to achieve this was to use a .manifest file and enabling visual styles.

' GET THE TREEVIEW HANDLE
INT tv_hwnd = GetDlgItem(win.hWnd, BFF)

' MODIFY THE TREEVIEW
IF tv_hwnd THEN
' SHOW ALWAYS THE SELECTION ON THE TREEVIEW
LONG lStyle = GetWindowLong(tv_hwnd, GWL_STYLE)
lStyle = lStyle | TVS_SHOWSELALWAYS
' lStyle = lStyle & NOT(TVS_HASLINES) '  <-- if you want to remove the treeview lines uncomment this
SetWindowLong(tv_hwnd, GWL_STYLE, lStyle)

' SET WINDOWS EXPLORER STYLE / YOU MUST USE A .MANIFEST FILE
SetWindowTheme(tv_hwnd, L"explorer", NULL) ' the treeview is unicode!!

' SET INITIAL FOCUS ON THE TREEVIEW
_SetFocus(tv_hwnd)
ENDIF

- To successfully paint listbox background & elements using visual styles it is necessary to subclass win DIALOG, and process the WM_CTLCOLORLISTBOX message.

SUB subclassProc(hWnd:INT,uMsg:INT,wParam:INT,lParam:INT,uIdSubclass:UINT_PTR,dwRefData:DWORD_PTR),INT
HDC         hDC
    PAINTSTRUCT Ps
WINRECT rc

SELECT uMsg
CASE WM_CTLCOLORLISTBOX ' PAINT FILELISTBOX
IF lParam = GetDlgItem(win.hWnd, FLB) THEN
HDC hdcStatic = wParam
SetTextColor(hdcStatic, RGB(0,0,0))
SetBkColor(hdcStatic, RGB(240,240,240))
IF hbrBkgnd = NULL THEN hbrBkgnd = CreateSolidBrush(RGB(240,240,240))
RETURN hbrBkgnd
ENDIF

CASE WM_PAINT ' PAINT THE IMAGE
hDC = BeginPaint(hWnd, &Ps)
GetClientRect(hWnd, rc)
OnPaint(hDC, rc)
EndPaint(hWnd, &Ps)

RETURN 0
ENDSELECT

RETURN DefSubclassProc(hWnd, uMsg, wParam, lParam)
ENDSUB

- Finally, I didn't like at all that the application resizes according to the image. I decided to always start the DIALOG maximized and the image is the one that fits the screen size. Unfortunately this was impossible to achieve with SHOWIMAGE, so I had to process the WM_PAINT message and draw the image using double buffer, since for some reason the ILXXX dll functions seem to "modify" the win device context.

SUB OnPaint(INT hDC, WINRECT rc)
' start double buffer
INT hdcMem = CreateCompatibleDC(hDC)
HBITMAP memBM = CreateCompatibleBitmap(hDC, rc.right - rc.left, rc.bottom - rc.top)
HBITMAP OldmemBM = SelectObject(hdcMem, memBM)

' paint background color
HBRUSH hbrBkgnd = CreateSolidBrush(RGB(190,190,190))
FillRect(hdcMem, rc, hbrBkgnd)
DeleteObject(hbrBkgnd)

' paint image
PaintImage(hdcMem, rc)

' finish double buffer
BitBlt(hDC, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hdcMem, 0, 0, SRCCOPY)
SelectObject(hdcMem, OldmemBM)
DeleteObject(memBM)
DeleteDC(hdcMem)
ENDSUB

SUB PaintImage(INT hDC, WINRECT rc)
BITMAP bit
INT hdcMem = CreateCompatibleDC(hDC)
INT oldBitmap = SelectObject(hdcMem, bitmap)
GetObject(bitmap, LEN(bit), &bit)

SetStretchBltMode(hDC, HALFTONE)
StretchBlt(hDC, splitWidth + paddingX, paddingY, w, h, hdcMem, 0, 0, bit.bmWidth, bit.bmHeight, SRCCOPY)
SelectObject(hdcMem, oldBitmap)
DeleteDC(hdcMem)
ENDSUB

Complete code and .manifest file below. EDIT: .manifest file not allowed as attachments. But make sure to use a .manifest file or some code will not work.
Title: Re: DevIL image viewer program
Post by: Brian on July 30, 2019, 04:03:40 AM
Fasecero,

Thanks for the code. Will have to look later, as I am out most of the day

When I compiled, I noticed straight away that the treeview selection didn't jump to the saved folder. It jumps to the root directory of the folder, but not the saved folder

And using a manifest removes the file icons in the FileListBox. Did you notice this?

Unless the manifest file I am using is the wrong type. I know there are quite a few variations. You could always post it with a .txt extension, instead of .manifest, and point out that it needs renaming

That way, I can be certain that we are the same

Brian
Title: Re: DevIL image viewer program
Post by: fasecero on July 30, 2019, 11:46:39 AM
Yes, sorry. I give up. I can't solve the issues you posted without modifying the dll source code.
Title: Re: DevIL image viewer program
Post by: Brian on July 30, 2019, 12:23:21 PM
That's OK - miracles take a bit longer!

Anyway, I have been working on it today, and have come up with a version that works in respect of centring an image that is smaller than the window, and resizing an image if it is larger. It also resizes the image if you resize the program window

Only thing that doesn't work correctly (yet) is the crop function, and zoom. Will take a look at those as time goes on. Also, when it redraws after a window, resizing could be quicker, I reckon

Otherwise, quite happy with this version. Thing is, you can go on the internet and type "image viewers" and take your pick. But there is nothing like the satisfaction of creating something of your own

Many thanks for your help in this. Please take a look at my latest offering

Brian
Title: Re: DevIL image viewer program
Post by: fasecero on July 30, 2019, 12:39:27 PM
QuoteThing is, you can go on the internet and type "image viewers" and take your pick. But there is nothing like the satisfaction of creating something of your own

I can't agree more on that

QuotePlease take a look at my latest offering

this version you posted is fantastic. You really get the hang of those il functions. Well done!