Author Topic: Could the background be a drawing or a picture  (Read 542 times)

Offline arw01

  • Hero Member
  • *****
  • Join Date: Oct 2013
  • Location:
  • Posts: 891
  • Kudos: 0
Could the background be a drawing or a picture
« on: October 27, 2014, 11:07:31 PM »
picked up from Dave's Whole House model thread..

http://falconchristmas.com/forum/index.php/topic,1449.20.html

Code: [Select]
void xLightsFrame::UpdatePreview()
{
    const wxColour *color;
    wxString SelModelName=ListBoxElementList->GetStringSelection();
    //ScrolledWindowPreview->ClearBackground();
    wxClientDC dc(ScrolledWindowPreview);
    dc.Clear();
    for (int i=0; i<PreviewModels.size(); i++)
    {
        color = (PreviewModels[i]->name == SelModelName) ? wxYELLOW : wxLIGHT_GREY;
        PreviewModels[i]->DisplayModelOnWindow(ScrolledWindowPreview,color);
    }
}

I was thinking this was responsible for the actual yellow on the grid highlighting and de-highlighting as it played along, not actually drawing in the preview area.  See the wxYELLOW and wx_LIGHT_GREY would represent that to me.

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,734
  • Kudos: 205
Re: Could the background be a drawing or a picture
« Reply #1 on: October 27, 2014, 11:20:20 PM »
Yeah, you're right, I shouldn't go from memory sometimes.  :)

I tracked this down a while ago but never got around to changing any code.

It's xLightsFrame::PreviewOutput()

ScrolledWindowPreview is the window that the models are drawn on via:

PreviewModels[m]->DisplayModelOnWindow(ScrolledWindowPreview);

If you look for ScrolledWindowPreview in xLightsMain.cpp, you can change it's initial color to confirm that is the window.

There is already some work done inside xLightsFrame::OnButtonSetBackgroundClick() in TabPreview, but I am not sure of the state of it.
-
Chris

Offline smeighan

  • Moderator
  • *****
  • Join Date: Mar 2013
  • Location: Highlands Ranch, Colorado
  • Posts: 1,035
  • Kudos: 11
    • Nutcracker123
Re: Could the background be a drawing or a picture
« Reply #2 on: October 28, 2014, 12:30:33 AM »
Mat wrote this code 18 months ago. He was going great, he wrote preview function in less than one week. He then ran into a snag loading an image into the background. I dont remember if he said it was a bug in wxwidgets, or performance. Maybe ill ping him. He worked on it for 1-2 weeks and i then said we will go with preview without a background image. it was a nice to have. people were so impressed with the preview that no one really was complaining. It was on matt's to do to go back and review.

He told me he planned on switching to opengl for both performance but also features. In feb of this year he started that process. He then got a job at LOR and the preview rewrite was put on hold.

Dave Pitts is also looking into the how to get a background image loaded.
Sean
Littleton, CO Latest releases http://nutcracker123.com/nutcracker/releases xLights/Nutcracker Forum http://nutcracker123.com/forum/index.php Facebook [url=https://www.facebook.com/groups

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,734
  • Kudos: 205
Re: Could the background be a drawing or a picture
« Reply #3 on: October 28, 2014, 01:56:40 AM »
If you want to work on this, here is a patch that may get you going.  This code displays a background image on the preview window.  The image gets resized when the window is resized which may not be desirable in the final code.  I've attached a diff against a fairly recent TabPreview.cpp file.

This is an example, it is by no means complete.

To test it, apply the patch, then edit TabPreview.cpp and look for the following:

Code: [Select]
#define TEST_BACKGROUND

#ifdef TEST_BACKGROUND
wxString theFilename = "ToTestPutTheFullPathToYourBackgroundFilenameHere.jpg";

Change the value of 'theFilename' to the full path to a background image.  Compile and run.

Go to the preview screen and open a sequence using the Open button.  This will also load the preview image.  For some reason I haven't looked into yet, the image will not display until you resize the window, so resize it by a pixel or two.  You should see a background image now.

You can move models around, and play the sequence and it will play the models over top of the background image.

There are a few optimizations in the code to try to make it fast.  The code caches the background image so it is only loaded once.  Then we only resize this cached image when necessary.  After we resize, we cache the bitmap so that all we have to do on screen refreshes is to draw the bitmap to the window before drawing the models onto the window.

Again, this is a hack and not complete, but hopefully it will help give you something to go on since it is working code to display a background.  It needs some wxWidgets glue to select the background file, some other glue to maintain the aspect ratio, etc. but I think that it could be usable.  Drawing the bitmap every 50ms frame refresh did not seem to cause that much of a CPU load on my Linux system.  I can't say for sure how performance on Windows will be since I don't run xLights on Windows.

[attachment deleted by admin]

 

Back to top