setting background image after failure seems ineffective

Posted by Fiendish on Sun 03 Jun 2012 11:16 PM — 5 posts, 21,761 views.

USA Global Moderator #0
I am finding that, in the event that my image path is invalid or the file is corrupt, the following code does not save the background from turning blue-green. Am I doing something wrong?


if 0 ~= SetBackgroundImage(imgpath,13) then
   ColourNote("yellow","red","Error loading background image.")
   SetBackgroundImage("",0)
   SetBackgroundColour(0x000000)
end


The note appears but the background is not salvaged.
Amended on Mon 04 Jun 2012 04:38 AM by Fiendish
Netherlands #1
Do you have any other scripts running?

I opened a fresh world through a bogus Quick Connect, went to the immediate window and pasted your code there. I initialized imgpath to a dummy location, and made the colour a dark reddish colour, which worked fine. It also worked when I made my background another colour first, and used the original black colour from your sample.

Thus, I cannot help but think the problem is elsewhere in your code, be it in another plugin or script, or temporary code you've forgotten about or did not properly comment/remove at some point. :)
USA Global Moderator #2
I realize now that I just had the wrong color set in the outsidefillcolour TextRectangle field.

Quote:
I opened a fresh world through a...

Try this first and you'll see what I mean.
TextRectangle(10, 10, 300, 300,
      5,  -- BorderOffset, 
      ColourNameToRGB ("darkgray"),    -- BorderColour, 
      2,  -- BorderWidth, 
      ColourNameToRGB ("darkslategray"),  -- OutsideFillColour, 
      miniwin.brush_solid) -- OutsideFillStyle


Nick, the documentation for SetBackgroundImage says
Quote:
This sets a background image for output window. The text in the output window is drawn on top of this. If the image does not completely fill the window, the background colour is visible beneath it.

But, if you use a TextRectangle, this is not an analogous effect to SetBackgroundColour. That's a bit confusing.
Amended on Mon 04 Jun 2012 11:55 PM by Fiendish
Australia Forum Administrator #3
Ah yes, it looks like it draws the rectangle after the background image. That would explain what you saw would it?
USA Global Moderator #4
Nick Gammon said:

Ah yes, it looks like it draws the rectangle after the background image. That would explain what you saw would it?
Indeed. And that's fine. I just got momentarily confused by SetBackgroundColour setting the main output area color vs SetBackgroundImage setting what shows behind the main output. Could you perhaps just add a note on the SetBackgroundColour docs referencing the outsidefill field of TextRectangle?