Changeset 1064


Ignore:
Timestamp:
05/15/16 17:34:37 (8 years ago)
Author:
davidb
Message:

Addition of new type of frame transition, with off-screen buffering to make use of alpha-values in transition more seamless; Enhancement of display-mode to be full screen; Enahcements to mouse interactions over images -- now if the mouse is over a pixel in the image that is the same colour as the background-color of the frame, it is treated as equivalent to being over the background, rather than the image item. Overall has a natural feel. You now need to click on 'non-trival' parts of an image to get image-related interactive Expteditee behaviour. (note: this is how text already behaves)

Location:
trunk/src/org/expeditee/gui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r1055 r1064  
    6565
    6666        // modes
    67         public static final int MODE_NORMAL = 0;
    68 
    69         public static final int MODE_AUDIENCE = 1;
    70 
    71         public static final int MODE_XRAY = 2;
     67        protected static final int MODE_NORMAL = 0;
     68
     69        protected static final int MODE_AUDIENCE = 1;
     70
     71        protected static final int MODE_XRAY = 2;
    7272       
    73         public static final int MODE_AUDIENCE_FULLSCREEN = 4;
     73        protected static final int MODE_AUDIENCE_FULLSCREEN = 4;
    7474       
    7575
     
    163163        }
    164164
     165        public static void forceXRayMode(boolean parse) {
     166                setMode(MODE_XRAY,parse);
     167        }
     168       
    165169        /**
    166170         * @return True if Audience Mode is currently on, False otherwise.
     
    559563                                PaintLines(bg, lines);
    560564                } else {
    561                         // Dont paint the
     565                        // Don't paint the
    562566                        if (isActualFrame)
    563567                                PaintLines(bg, freeItemsToPaint);
     
    669673                else {
    670674                    if (DisplayIO.getCurrentSide() == 0) {
    671                         g.drawImage(left, 0, 0, Item.DEFAULT_BACKGROUND, null);
    672                         paintTransition(g,left);
     675                        if (!paintTransition(g,left)) {
     676                                // Nothing fancy occurred, just need to render the next slide to screen
     677                                g.drawImage(left, 0, 0, Item.DEFAULT_BACKGROUND, null);
     678                        }
    673679                    }
    674680                    else {
    675                         g.drawImage(right, 0, 0, Item.DEFAULT_BACKGROUND, null);
    676                         paintTransition(g,right);
     681                        if (!paintTransition(g,right)) {
     682                                // Nothing fancy occurred, just need to render the next slide to screen
     683                                g.drawImage(right, 0, 0, Item.DEFAULT_BACKGROUND, null);
     684                        }
    677685                    }
    678686                }
     
    681689
    682690       
    683     private static void paintTransition(Graphics g, Image image)
     691    private static boolean paintTransition(Graphics g, Image image)
    684692    {
    685                                  
    686         //If we are doing a transition
    687         if(FrameTransitions.getSlide() == true){                                               
    688            
    689             String input = "org.expeditee.gui.FrameTransitions";
    690             String slide_mode_method = FrameTransitions.getslideModeMethod();
    691        
    692             try {
    693                 Class<?> c = Class.forName(input);
    694                
    695                 Class[] cArg = new Class[3];
    696                 cArg[0] = Graphics.class;
    697                 cArg[1] = Image.class;
    698                 cArg[2] = Dimension.class;                                                     
    699                
    700                 //Gets the method of transition and calls it
    701                 Method lMethod = c.getDeclaredMethod(slide_mode_method, cArg);
    702                
    703                 if(lMethod != null){
    704                     // calling static method, so no class parameter needed
    705                     Object o = lMethod.invoke(null, g, image, _MaxSize);
    706                 }
    707                 else{
    708                     System.err.println("Unable to locate the transition '" + slide_mode_method + "'");
    709                 }                                               
    710                
    711             } catch (Exception e) {                                             
    712                
    713                 System.err.println("An Reflection Exception occurred trying to invoke '" + slide_mode_method + "'");
    714                 e.printStackTrace();
    715             }   
    716         }               
    717         //Tells the frame to only transition once
    718         FrameTransitions.setSlideFalse();                               
     693        boolean performed_transition = false;
     694       
     695        //If we are doing a transition
     696        if(FrameTransitions.getSlide() == true){                                               
     697
     698                String input = "org.expeditee.gui.FrameTransitions";
     699                String slide_mode_method = FrameTransitions.getslideModeMethod();
     700
     701                try {
     702                        Class<?> c = Class.forName(input);
     703
     704                        Class[] cArg = new Class[3];
     705                        cArg[0] = Graphics.class;
     706                        cArg[1] = Image.class;
     707                        cArg[2] = Dimension.class;                                                     
     708
     709                        //Gets the method of transition and calls it
     710                        Method lMethod = c.getDeclaredMethod(slide_mode_method, cArg);
     711
     712                        if(lMethod != null){
     713                                // calling static method, so no class parameter needed
     714                                Object o = lMethod.invoke(null, g, image, _MaxSize);
     715                                performed_transition = true;
     716                               
     717                        }
     718                        else{
     719                                System.err.println("Unable to locate the transition '" + slide_mode_method + "'");
     720                        }                                               
     721
     722                } catch (Exception e) {                                         
     723
     724                        System.err.println("An Reflection Exception occurred trying to invoke '" + slide_mode_method + "'");
     725                        e.printStackTrace();
     726                }       
     727        }               
     728        //Tells the frame to only transition once
     729        FrameTransitions.setSlideFalse();               
     730       
     731        return performed_transition;
    719732    }
    720733   
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r1051 r1064  
    4646import org.expeditee.items.ItemUtils;
    4747import org.expeditee.items.Line;
     48import org.expeditee.items.Picture;
    4849import org.expeditee.items.Text;
    4950import org.expeditee.items.UserAppliedPermission;
     
    464465                Item on = FrameUtils.getCurrentItem();
    465466
    466                 if (on == null) {
     467                if ((on == null) || (on instanceof Picture)){
    467468                        navigateFrame(direction);
    468469                        return;
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r1047 r1064  
    15511551                }
    15521552
     1553                if (clicked instanceof Picture) {
     1554                        int mouseX = DisplayIO.getMouseX();
     1555                        int mouseY = FrameMouseActions.getY();
     1556                        Picture clickedOnPicture = (Picture)clicked;
     1557                        Frame current_frame = DisplayIO.getCurrentFrame();
     1558                        Color bg_col = current_frame.getBackgroundColor();
     1559                        if (clickedOnPicture.MouseOverBackgroundPixel(mouseX,mouseY,bg_col)) {
     1560                                // Make 'clicked' null, effectively causing a back() operation
     1561                                return false;
     1562                        }
     1563                }
     1564               
    15531565                return true;
    15541566        }
     
    16171629                        }
    16181630                        // otherwise if the user is pointing at something, pick it up unless shift is down
    1619                 } else if (clicked != null && !isShiftDown) {
    1620                        
    1621                         // check permissions
    1622                         if (!clicked.hasPermission(UserAppliedPermission.full)) {
    1623                                 Item editTarget = clicked.getEditTarget();
    1624                                 if (editTarget != clicked
    1625                                                 && editTarget.hasPermission(UserAppliedPermission.full)) {
    1626                                         clicked = editTarget;
    1627                                 } else {
    1628                                         MessageBay
    1629                                                         .displayMessage("Insufficient permission to pick up item");
    1630                                         return;
    1631                                 }
    1632                         }
    1633                         IndirectMouseActions.getInstance().getDetachLineAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    1634                         // if we're inside a shape, pick it up unless shift is down
    1635                 } else if (clickedIn != null && !isShiftDown) {
    1636                         IndirectMouseActions.getInstance().getGroupPickupAction().exec(new MouseInfo(clicked, clickedIn, false, false));
    16371631                } else {
    1638                         IndirectMouseActions.getInstance().getNewLineAction().exec(new MouseInfo(clicked, clickedIn, false, false));
     1632                        if (clicked instanceof Picture) {
     1633                                int mouseX = DisplayIO.getMouseX();
     1634                                int mouseY = FrameMouseActions.getY();
     1635                                Picture clickedOnPicture = (Picture)clicked;
     1636                                Frame current_frame = DisplayIO.getCurrentFrame();
     1637                                Color bg_col = current_frame.getBackgroundColor();
     1638                                if (clickedOnPicture.MouseOverBackgroundPixel(mouseX,mouseY,bg_col)) {
     1639                                        clicked = null; // Effectively make it as if they haven't clicked on anything
     1640                                }
     1641                        }
     1642                        if (clicked != null && !isShiftDown) {
     1643
     1644                                // check permissions
     1645                                if (!clicked.hasPermission(UserAppliedPermission.full)) {
     1646                                        Item editTarget = clicked.getEditTarget();
     1647                                        if (editTarget != clicked
     1648                                                        && editTarget.hasPermission(UserAppliedPermission.full)) {
     1649                                                clicked = editTarget;
     1650                                        } else {
     1651                                                MessageBay
     1652                                                .displayMessage("Insufficient permission to pick up item");
     1653                                                return;
     1654                                        }
     1655                                }
     1656                                IndirectMouseActions.getInstance().getDetachLineAction().exec(new MouseInfo(clicked, clickedIn, false, false));
     1657                                // if we're inside a shape, pick it up unless shift is down
     1658                        } else if (clickedIn != null && !isShiftDown) {
     1659                                IndirectMouseActions.getInstance().getGroupPickupAction().exec(new MouseInfo(clicked, clickedIn, false, false));
     1660                        } else {
     1661                                IndirectMouseActions.getInstance().getNewLineAction().exec(new MouseInfo(clicked, clickedIn, false, false));
     1662                        }
    16391663                }
    16401664                SessionStats.MovedItems(FreeItems.getInstance());
     
    17271751                                return;
    17281752                                // if the user is clicking on something, merge the items
    1729                                 // unless it is a point onto somethin other than a lineEnd or a
     1753                                // unless it is a point onto something other than a lineEnd or a
    17301754                                // dot
    17311755                        } else if (clicked != null
     
    17821806                        }
    17831807                } else {
     1808                       
     1809                        if (clicked instanceof Picture) {
     1810                                int mouseX = DisplayIO.getMouseX();
     1811                                int mouseY = FrameMouseActions.getY();
     1812                                Picture clickedOnPicture = (Picture)clicked;
     1813                                Frame current_frame = DisplayIO.getCurrentFrame();
     1814                                Color bg_col = current_frame.getBackgroundColor();
     1815                                if (clickedOnPicture.MouseOverBackgroundPixel(mouseX,mouseY,bg_col)) {
     1816                                        clicked = null; // Effectively make it as if they haven't clicked on anything
     1817                                }
     1818                        }
     1819                       
    17841820                        // if the user is pointing at something and shift isn't down, make a copy
    17851821                        if (clicked != null && !isShiftDown()) {
     
    28112847                                                        Item start = l.getStartItem();
    28122848
    2813                                                         // If one end of a line is being delted, remove the
     2849                                                        // If one end of a line is being deleted, remove the
    28142850                                                        // other end if all its connecting lines are being
    2815                                                         // delted
     2851                                                        // deleted
    28162852                                                        if (items.contains(end)) {
    28172853                                                                if (!items.contains(start)
     
    28482884                        // this is a delete command
    28492885                } else {
     2886                       
     2887                        // Special case if toDelete item is an image: only want to delete if over non-background pixel color
     2888                        if (toDelete instanceof Picture) {
     2889                                int mouseX = DisplayIO.getMouseX();
     2890                                int mouseY = FrameMouseActions.getY();
     2891                                Picture clickedOnPicture = (Picture)toDelete;
     2892                                Frame current_frame = DisplayIO.getCurrentFrame();
     2893                                Color bg_col = current_frame.getBackgroundColor();
     2894                                if (clickedOnPicture.MouseOverBackgroundPixel(mouseX,mouseY,bg_col)) {
     2895                                        // behave as if Redo/Undo request, then return
     2896                                        if(isControlDown()) {
     2897                                                DisplayIO.getCurrentFrame().redo();
     2898                                        } else {
     2899                                                DisplayIO.getCurrentFrame().undo();
     2900                                        }
     2901                                        return;
     2902                                }
     2903                                // If get to here, then user clicked on an image (non-trival pixel color),
     2904                                // so go ahead and let it be deleted in the usual way
     2905                        }
     2906                               
     2907                       
    28502908                        // check permissions
    28512909                        if (!toDelete.hasPermission(UserAppliedPermission.full)) {
  • trunk/src/org/expeditee/gui/FrameTransitions.java

    r980 r1064  
    99import java.awt.Image;
    1010import java.awt.RenderingHints;
     11import java.awt.image.BufferedImage;
     12import java.awt.image.ColorModel;
    1113
    1214import org.expeditee.items.Item;
     
    1921        //Stores the frame before the new frame being transitioned to
    2022        private static Image _slideModeBaseImage = null;
    21                        
     23        private static Image _slideModeScratchImage = null;
     24       
    2225        //Tells graphics which method of transition is going to be used
    2326        private static String _slideModeMethod;
     
    4144               
    4245                _slideModeBaseImage = i;
     46                _slideModeScratchImage = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    4347        }
    4448        public static Image getSlideModeBaseImage(){
     
    146150                Graphics2D g2d = (Graphics2D) g;               
    147151               
     152                Graphics2D scratch_g2d = (Graphics2D)_slideModeScratchImage.getGraphics();
     153               
    148154                while(alpha >= 0.1f){                   
    149155                       
    150                         g.drawImage(FrameTransitions.getSlideModeBaseImage(),  0,  0,  Item.DEFAULT_BACKGROUND,  null);                 
    151                         g2d.setComposite(alphaCalcUp(alpha, fadeType));                         
    152                         g2d.setColor(Color.WHITE);
    153                         g2d.fillRect(0, 0, d.width, d.height);
     156                       
     157                        scratch_g2d.drawImage(getSlideModeBaseImage(),  0,  0,  Item.DEFAULT_BACKGROUND,  null);                       
     158                        scratch_g2d.setComposite(alphaCalcUp(alpha, fadeType));                         
     159                        scratch_g2d.setColor(Color.WHITE);
     160                        scratch_g2d.fillRect(0, 0, d.width, d.height);
     161                       
     162                        g2d.drawImage(_slideModeScratchImage, 0, 0, null);
     163                       
    154164                        alpha = alphaCalcUp(alpha, fadeType).getAlpha();
    155165                       
     
    165175                while(alpha <= 0.75f){                 
    166176               
    167                         g.drawImage(i,  0,  0,  Item.DEFAULT_BACKGROUND,  null);
    168                         g2d.setComposite(alphaCalcDown(alpha, fadeType));
    169                         g2d.setColor(Color.WHITE);
    170                         g2d.fillRect(0, 0, d.width, d.height);
     177                        scratch_g2d.drawImage(i,  0,  0,  Item.DEFAULT_BACKGROUND,  null);
     178                        scratch_g2d.setComposite(alphaCalcDown(alpha, fadeType));
     179                        scratch_g2d.setColor(Color.WHITE);
     180                        scratch_g2d.fillRect(0, 0, d.width, d.height);
     181               
     182                        g2d.drawImage(_slideModeScratchImage, 0, 0, null);
     183                       
    171184                        alpha = alphaCalcDown(alpha, fadeType).getAlpha();
    172185                       
     
    181194                }
    182195        }
     196
    183197        //Calculates alpha values for transitions from transparent to opaque
    184198        //AlphaComposite is returned
     
    220234                }
    221235        }
     236       
     237        public static void CrossFade(Graphics g, Image i, Dimension d)
     238        {
     239                // Based on: http://stackoverflow.com/questions/20346661/java-fade-in-and-out-of-images
     240                // TODO: make use of timer, as this example does, rather than fixed delay
     241               
     242                Image inImage = i;
     243                Image outImage = _slideModeBaseImage;
     244                int scratch_x_dim = _slideModeScratchImage.getWidth(null);
     245                int scratch_y_dim = _slideModeScratchImage.getHeight(null);
     246
     247                int anim_timestep_msec = 10;
     248                float alpha = 0.0f;
     249                float alpha_inc = 0.04f;
     250               
     251                Graphics2D g2d = (Graphics2D) g;               
     252
     253                Graphics scratch_g = _slideModeScratchImage.getGraphics();
     254
     255                while(alpha <= 1.0f){                   
     256
     257                        //scratch_g.clearRect(0, 0, scratch_x_dim, scratch_y_dim);
     258                        scratch_g.setColor(Color.WHITE);
     259                        scratch_g.fillRect(0, 0, scratch_x_dim, scratch_y_dim);
     260                       
     261                        Graphics2D scratch_g2d = (Graphics2D) scratch_g.create();
     262                        scratch_g2d.setComposite(AlphaComposite.SrcOver.derive(alpha));
     263                        scratch_g2d.drawImage(inImage, 0, 0, null);
     264
     265                        scratch_g2d.setComposite(AlphaComposite.SrcOver.derive(1f - alpha));
     266                        scratch_g2d.drawImage(outImage, 0, 0, null);
     267                        scratch_g2d.dispose();
     268
     269                        g2d.drawImage(_slideModeScratchImage, 0, 0, null);
     270
     271                        try {
     272                                Thread.sleep(anim_timestep_msec);
     273                        } catch (InterruptedException e) {
     274                                e.printStackTrace();
     275                        }                       
     276
     277                        alpha += alpha_inc;     
     278                }               
     279        }       
     280
     281       
    222282}
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r998 r1064  
    540540        Parse(toDisplay);
    541541
    542         // Test to see if frame transition required, and perform it if one if found
    543         Item frameTransition = getAnnotation(toDisplay, "@frameTransition");
    544         if (frameTransition != null) {
    545             doFrameTransition(frameTransition,current,toDisplay);
    546         }
     542        if (FrameGraphics.isAudienceMode()) {
     543                // Only need to worry about frame transitions when in Audience Mode
    547544               
     545                // Test to see if frame transition specified through annotation, and perform it if one if found
     546                Item frameTransition = getAnnotation(toDisplay, "@frameTransition");
     547                if (frameTransition != null) {
     548                        doFrameTransition(frameTransition,current,toDisplay);
     549                }
     550        }
     551       
    548552        DisplayIO.setCurrentFrame(toDisplay, incrementStats);
    549553        FrameMouseActions.updateCursor();
Note: See TracChangeset for help on using the changeset viewer.