public MultiControllerInstruction(int controllerIndex, Instruction instruction)
 {
     this.controllerIndex = controllerIndex;
     this.x = instruction.x;
     this.y = instruction.y;
     this.w = instruction.w;
     this.h = instruction.h;
     this.image = instruction.image;
     this.longPause = instruction.longPause;
 }
        public void Draw(Instruction instruction)
        {
            //lock (bufferedGraphics) {

            Log.Instance.Write("Starting windows draw instruction");
            try
            {
                if (instruction.image == null) { Log.Instance.Write("Null Image"); };

                Rectangle targetAreaRect = new Rectangle(
                        xOff + instruction.x * xSize,
                        yOff + instruction.y * ySize,
                        instruction.w * xSize,
                        instruction.h * ySize
                        );
                targetarearect = targetAreaRect;
                if (imagestyle == ImageStyle.CenterFill)
                {
                    destRect = targetAreaRect;
                    double ratio = (double)instruction.image.Width / (double)instruction.image.Height;
                    double targetRatio = (double)instruction.w / (double)instruction.h;
                    if (ratio > targetRatio)
                    {
                        int diff = instruction.image.Width - (int)((double)instruction.image.Height * targetRatio);
                        sourceRect = new Rectangle(
                            diff / 2,
                            0,
                            instruction.image.Width - diff,
                            instruction.image.Height
                            );
                    }
                    else if (ratio < targetRatio)
                    {
                        int diff = instruction.image.Height - (int)((double)instruction.image.Width / targetRatio);
                        sourceRect = new Rectangle(
                            0,
                            diff / 2,
                            instruction.image.Width,
                            instruction.image.Height - diff
                            );
                    }
                    else
                    {
                        sourceRect = new Rectangle(Point.Empty, instruction.image.Size);
                    }
                }
                else
                {
                    float scale = Math.Min(
                        (float)(instruction.w * xSize) / (float)instruction.image.Width,
                        (float)(instruction.h * ySize) / (float)instruction.image.Height);
                    int w = (int)((float)instruction.image.Width * scale);
                    int h = (int)((float)instruction.image.Height * scale);
                    const int padding = 4;
                    destRect = new Rectangle(
                        xOff + instruction.x * xSize + instruction.w * xSize / 2 - w / 2 + padding,
                        yOff + instruction.y * ySize + instruction.h * ySize / 2 - h / 2 + padding,
                        w - padding * 2, h - padding * 2);
                    sourceRect = new Rectangle(Point.Empty, instruction.image.Size);
                }

                try {
                    if (instruction.image == null) { Log.Instance.Write("Null Image"); };
                    Log.Instance.Write("Start transistion");

                    trans = new Org.Kuhn.Yapss.transitions.transition(this,bufferedGraphics, destRect, sourceRect, GraphicsUnit.Pixel,config);

                    if (instruction.longPause == true)
                    {
               			Log.Instance.Write("transition Out");
                        trans.transitionout(OrigImage(targetAreaRect,Screen.AllScreens[instruction.screen].Bounds), targetAreaRect);
                    }
                    Log.Instance.Write("transition In");
                    trans.transitionin(instruction.image, targetAreaRect);//});
                    Log.Instance.Write("transitions Done");
                } catch(ThreadAbortException){//ignore}
                } catch (Exception Ex) {
                    Log.Instance.Write("Transition Error");
                    Log.Instance.Write(Ex.Message);
                } finally {

                }

            }
            catch (Exception ex)
            {
                Log.Instance.Write("Draw Error");
                Log.Instance.Write(ex.Message);
            }
        }
 private Instruction instruction(int x, int y, int w, int h, bool longPause)
 {
     layout.Set(x, y, new Cell(w, h));
     rounds[x, y] = round;
     Instruction i = new Instruction();
     i.x = x;
     i.y = y;
     i.w = w;
     i.h = h;
     i.image = imageSource.GetImage(w * xPixels, h * yPixels);
     i.longPause = longPause;
     return i;
 }