Пример #1
0
        public void view_contribution(collection_item i)
        {
            //ImageSource src = new BitmapImage(new Uri(configurations.GetAbsoluteContributionPath() + contribution_id.ToString() + ".jpg"));
            //window_manager.contributions.Add(contribution_id, src);
            //the_image.Source = src;
            this.item = i;
            //the_media.Visibility = System.Windows.Visibility.Collapsed;
            //the_image.Visibility = System.Windows.Visibility.Visible;
            if (i.is_image || i.is_audio)
            {
                if (i.is_audio)
                {
                    the_item.Background = new ImageBrush(configurations.img_sound_image_pic);
                    the_item.UpdateLayout();
                    string fname = i._contribution.media_url;
                    string ext = fname.Substring(fname.Length - 4, 4);
                    the_media.Source = new Uri(configurations.GetAbsoluteContributionPath() + item._contribution.id.ToString() + ext);
                    the_media.Play();
                    return;
                }
                //if (window_manager.contributions.ContainsKey(i._contribution.id))
                //{
                //    double h = window_manager.contributions[i._contribution.id].Height;
                //    double w = window_manager.contributions[i._contribution.id].Width;
                //    the_item.Height = (h / w) * the_item.Width;
                //    the_item.Background = new ImageBrush(window_manager.contributions[i._contribution.id]);
                //    the_item.UpdateLayout();
                //}
                //else
                //{
                    worker.DoWork += new DoWorkEventHandler(load_image);
                    worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(show_image);
                    worker.RunWorkerAsync((object)i._contribution.id);
                //}

            }
            if (i.is_video)
            {
                if (window_manager.thumbnails.ContainsKey(i._contribution.id))
                {
                    the_item.Background = new ImageBrush(window_manager.thumbnails[i._contribution.id]);
                    the_item.UpdateLayout();
                }
                string fname = i._contribution.media_url;
                string ext = fname.Substring(fname.Length - 4, 4);
                the_media.Source = new Uri(configurations.GetAbsoluteContributionPath() + item._contribution.id.ToString() + ext);
                the_media.Play();
                the_media.MediaOpened += new RoutedEventHandler(the_media_MediaOpened);
                //the_media.Loaded += new RoutedEventHandler(the_media_Loaded);
            }
        }
        public bool start_drag(ListBoxItem item, collection_item contribution_item, TouchDevice touch_device, ImageSource i)
        {
            Image i2 = new Image();
            i2.Source = i;
            ContentControl cursorVisual = new ContentControl()
            {
                Content = i2,
                Style = FindResource("CursorStyle") as Style
            };

            //SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged);

            List<InputDevice> devices = new List<InputDevice>();
            devices.Add(touch_device);
            foreach (TouchDevice touch in item.TouchesCapturedWithin)
            {
                if (touch != touch_device)
                {
                    devices.Add(touch);
                }
            }

            SurfaceDragCursor startDragOkay =
                SurfaceDragDrop.BeginDragDrop(
                  this.contributions,         // The SurfaceListBox object that the cursor is dragged out from.
                  item,                       // The SurfaceListBoxItem object that is dragged from the drag source.
                  cursorVisual,               // The visual element of the cursor.
                  contribution_item,          // The data associated with the cursor.
                  devices,                    // The input devices that start dragging the cursor.
                  DragDropEffects.Copy);      // The allowed drag-and-drop effects of the operation.

            return (startDragOkay != null);
        }
Пример #3
0
        public static void open_contribution_window(collection_item citem, double pos_x, double pos_y, string ctype)
        {
            if (window_manager.image_frames.Count + 1 > configurations.max_image_display_frame)
                return;

            //window_frame frame = new window_frame();
            window_content content = new window_content();
            //contribution_view m = new contribution_view();
            //m.view_contribution(citem);
            image_frame iframe = new image_frame();
            iframe.view_contribution(citem);
            content.initialize_comments(citem._contribution);
            iframe.window_content.Content = content;
            if (!configurations.center_commentarea_and_keyboard)
            {
                iframe.the_content.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                content.center_keyboard = false;
            }
            iframe.UpdateLayout();
            content.initialize_contents(null, Type.GetType("nature_net.Contribution"), citem._contribution.id, iframe, iframe.the_content.Width);
            //frame.window_content.Content = content;
            //window_manager.image_display_frames.Add(frame);
            //open_window(frame, pos_x, pos_y);
            //m.center_image();
            //frame.hide_change_view();
            //frame.set_title(ctype);
            main_canvas.Children.Add(iframe);
            iframe.UpdateLayout();
            window_manager.image_frames.Add(iframe);

            double h = iframe.ActualHeight;
            pos_x = pos_x - (iframe.ActualWidth / 2);
            //try { h = ((window_content)(iframe.window_content.Content)).the_item.ActualHeight; }
            //catch (Exception) { }
            if (pos_y > window_manager.main_canvas.ActualHeight - h)
                pos_y = window_manager.main_canvas.ActualHeight - h;
            TranslateTransform m = new TranslateTransform(pos_x, pos_y);
            Matrix matrix = m.Value;
            iframe.RenderTransform = new MatrixTransform(matrix);
            UpdateZOrder(iframe, true);
        }
        public collection_item create_collection_item_from_contribution(Contribution c)
        {
            collection_item ci = new collection_item();
            ci._contribution = c;
            int i = c.id;

            if (c.media_url == null) return ci;
            string fname = c.media_url;
            string ext = fname.Substring(fname.Length - 4, 4);
            ext = ext.ToLower();
            if (ext == ".jpg" || ext == ".bmp" || ext == ".png")
                ci.is_image = true;
            if (ext == ".wmv" || ext == ".mpg" || ext == "mpeg" || ext == ".avi" || ext == ".mp4" || ext == ".3gp" || ext == ".mov")
                ci.is_video = true;
            if (ext == ".wav" || ext == ".mp3")
                ci.is_audio = true;

            if (!window_manager.thumbnails.ContainsKey(i))
            {
                if (!window_manager.downloaded_contributions.Contains(i))
                {
                    bool result = file_manager.download_file_from_googledirve(c.media_url, i);
                    if (result) window_manager.downloaded_contributions.Add(i);
                }

                ImageSource img = null;
                if (ci.is_image)
                    img = configurations.GetThumbnailFromImage(i.ToString() + ext, configurations.thumbnail_pixel_height);
                if (ci.is_video)
                    img = configurations.GetThumbnailFromVideo(i.ToString() + ext, configurations.thumbnail_video_span, configurations.thumbnail_pixel_height);
                if (ci.is_audio)
                    img = configurations.img_sound_image_pic;
                if (img == null)
                    return ci;

                if (!window_manager.thumbnails.ContainsKey(i))
                {
                    // save the thumbnail
                    try
                    {
                        BitmapSource bs = img as BitmapSource;
                        if (!ci.is_audio)
                        {
                            configurations.SaveThumbnail(bs, i.ToString());
                        }
                        img = new BitmapImage(new Uri(configurations.GetAbsoluteThumbnailPath() + i.ToString() + ".jpg"));
                        img.Freeze();
                        window_manager.thumbnails.Add(i, img);
                    }
                    catch (Exception) { }   // not a problem
                }
            }

            return ci;
        }