Exemplo n.º 1
0
        public void AppendTo(jQueryObject mangaArea, int offset, int sign, MangaPage otherPage)
        {
            if (Settings.UseAnimation)
            {
                imageObject.AddClass("fade");
                Window.SetTimeout(
                    delegate
                    {
                        imageObject.AddClass("in");
                    },
                    1);
            }

            imageObject.AddClass("read-manga-page").AppendTo(mangaArea);
            Offset = offset + sign * otherPage.Width;
            OffsetY = Height > mangaArea.GetHeight() ? 0 : ((mangaArea.GetHeight() - Height) / 2);
        }
Exemplo n.º 2
0
        private void TouchHandler(jQueryTouchEvent e)
        {
            if (!inTransition)
            {
                if (e.Type == "touch_start")
                {
                    inTouchHandler = true;
                    touchInitialOffset = Offset;
                    touchInitialXPosition = e.ClientX;

                    if (Settings.DisplayType == 2 && (currentVerticalScrollPage = GetMangaPageFromClientX(touchInitialXPosition)) != null && currentVerticalScrollPage.Height > attachedObject.GetHeight())
                    {
                        touchScrollDirection = 0;
                        touchInitialOffsetY = currentVerticalScrollPage.OffsetY;
                        touchInitialYPosition = e.ClientY;
                    }
                    else
                    {
                        touchScrollDirection = 1;
                    }
                }

                if (inTouchHandler)
                {
                    inTouchHandler = e.Type != "touch_end";

                    if (touchScrollDirection == 0)
                    {
                        if (Math.Abs(e.ClientX - touchInitialXPosition) > 35)
                        {
                            touchScrollDirection = 1;
                        }
                        else if (Math.Abs(e.ClientY - touchInitialYPosition) > 35)
                        {
                            touchScrollDirection = 2;

                            // try to snap to current page
                            if (Settings.UseAnimation)
                            {
                                mangaArea.AddClass("navigate");
                                Offset = -currentVerticalScrollPage.Offset;
                                Utility.OnTransitionEnd(
                                    mangaArea,
                                    delegate
                                    {
                                        mangaArea.RemoveClass("navigate");
                                    });
                            }
                            else
                            {
                                Offset = -currentVerticalScrollPage.Offset;
                            }
                        }
                    }

                    if (touchScrollDirection != 2)
                    {
                        MangaPage firstPage;
                        int targetOffset = e.ClientX - touchInitialXPosition + touchInitialOffset;
                        int minOffset = attachedObject.GetWidth() / 2 - (firstPage = GetMangaPage(pagesHead)).Offset - firstPage.Width;
                        int maxOffset = attachedObject.GetWidth() / 2 - GetMangaPage(pagesTail).Offset;
                        Offset = targetOffset < minOffset ? minOffset : targetOffset > maxOffset ? maxOffset : targetOffset;
                        RefreshMangaArea(false);

                        if (Settings.UseAnimation)
                        {
                            int index = 0;

                            if (e.Type == "touch_start")
                            {
                                lastTouchTime = new List<Date>();
                                lastTouchOffset = new List<int>();
                                lastTouchTime[0] = new Date();
                                lastTouchOffset[0] = Offset;
                            }
                            else
                            {
                                Date currentTime = new Date();
                                index = lastTouchOffset[lastTouchOffset.Count - 1] == Offset && currentTime - lastTouchTime[lastTouchOffset.Count - 1] < 100 ? lastTouchOffset.Count - 1 : lastTouchOffset.Count;
                                lastTouchTime[index] = currentTime;
                                lastTouchOffset[index] = Offset;
                            }

                            if (e.Type == "touch_end" && index > 0)
                            {
                                int dx = lastTouchOffset[index] - lastTouchOffset[index - 1];
                                int dt = lastTouchTime[index] - lastTouchTime[index - 1] + 1;
                                int distance = Math.Round(dx * 100 / dt);

                                lastTouchOffset = (List<int>)(object)(lastTouchTime = null);

                                if (distance != 0)
                                {
                                    inTransition = true;
                                    mangaArea.AddClass("inertia");
                                    Offset += distance;
                                    Utility.OnTransitionEnd(
                                        mangaArea,
                                        delegate
                                        {
                                            inTransition = false;
                                            mangaArea.RemoveClass("inertia");
                                            RefreshMangaArea();

                                            minOffset = attachedObject.GetWidth() / 2 - (firstPage = GetMangaPage(pagesHead)).Offset - firstPage.Width;
                                            maxOffset = attachedObject.GetWidth() / 2 - GetMangaPage(pagesTail).Offset;

                                            if (Offset < minOffset || Offset > maxOffset)
                                            {
                                                inTransition = true;
                                                mangaArea.AddClass("inertia-bounce");
                                                Offset = Offset < minOffset ? minOffset : maxOffset;
                                                Utility.OnTransitionEnd(
                                                    mangaArea,
                                                    delegate
                                                    {
                                                        inTransition = false;
                                                        mangaArea.RemoveClass("inertia-bounce");
                                                        RefreshMangaArea();
                                                    });
                                            }
                                        });
                                }
                            }
                        }
                    }

                    if (touchScrollDirection != 1)
                    {
                        int targetOffset = e.ClientY - touchInitialYPosition + touchInitialOffsetY;
                        int minOffset = attachedObject.GetHeight() - currentVerticalScrollPage.Height;
                        int maxOffset = 0;
                        currentVerticalScrollPage.OffsetY = targetOffset < minOffset ? minOffset : targetOffset > maxOffset ? maxOffset : targetOffset;

                        if (Settings.UseAnimation)
                        {
                            int index = 0;

                            if (e.Type == "touch_start")
                            {
                                lastTouchTimeY = new List<Date>();
                                lastTouchOffsetY = new List<int>();
                                lastTouchTimeY[0] = new Date();
                                lastTouchOffsetY[0] = currentVerticalScrollPage.OffsetY;
                            }
                            else
                            {
                                Date currentTime = new Date();
                                index = lastTouchOffsetY[lastTouchOffsetY.Count - 1] == currentVerticalScrollPage.OffsetY && currentTime - lastTouchTimeY[lastTouchOffsetY.Count - 1] < 100 ? lastTouchOffsetY.Count - 1 : lastTouchOffsetY.Count;
                                lastTouchTimeY[index] = currentTime;
                                lastTouchOffsetY[index] = currentVerticalScrollPage.OffsetY;
                            }

                            if (e.Type == "touch_end" && index > 0)
                            {
                                int dy = lastTouchOffsetY[index] - lastTouchOffsetY[index - 1];
                                int dt = lastTouchTimeY[index] - lastTouchTimeY[index - 1] + 1;
                                int distance = Math.Round(dy * 100 / dt);

                                lastTouchOffsetY = (List<int>)(object)(lastTouchTimeY = null);

                                if (distance != 0)
                                {
                                    inTransition = true;
                                    currentVerticalScrollPage.AttachedObject.AddClass("inertia");
                                    currentVerticalScrollPage.OffsetY += distance;
                                    Utility.OnTransitionEnd(
                                        currentVerticalScrollPage.AttachedObject,
                                        delegate
                                        {
                                            inTransition = false;
                                            currentVerticalScrollPage.AttachedObject.RemoveClass("inertia");

                                            if (currentVerticalScrollPage.OffsetY < minOffset || currentVerticalScrollPage.OffsetY > maxOffset)
                                            {
                                                inTransition = true;
                                                currentVerticalScrollPage.AttachedObject.AddClass("inertia-bounce");
                                                currentVerticalScrollPage.OffsetY = currentVerticalScrollPage.OffsetY < minOffset ? minOffset : maxOffset;
                                                Utility.OnTransitionEnd(
                                                    currentVerticalScrollPage.AttachedObject,
                                                    delegate
                                                    {
                                                        inTransition = false;
                                                        currentVerticalScrollPage.AttachedObject.RemoveClass("inertia-bounce");
                                                    });
                                            }
                                        });
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void Insert(MangaPage page)
        {
            if (insertedPages.Count == 0)
            {
                Action insert = delegate
                {
                    pagesTail = pagesHead = page.Page;
                    page.AppendTo(mangaArea, 0, 0, page);

                    if (attachedObject.GetWidth() > page.Width)
                    {
                        Offset = (jQuery.Window.GetWidth() - page.Width) / 2;
                    }
                    else if (manga.ltr)
                    {
                        Offset = 0;
                    }
                    else
                    {
                        Offset = jQuery.Window.GetWidth() - page.Width;
                    }
                };

                Action callback = delegate
                {
                    insertedPages[page.Page] = page;
                    RefreshMangaArea();
                };

                if (Settings.KindleRefreshDelay > 0)
                {
                    KindleRefreshScreen(insert, callback);
                }
                else
                {
                    insert();
                    callback();
                }
            }
            else if (page.Page == pagesTail + 1)
            {
                MangaPage lastPage = GetMangaPage(pagesTail);
                page.AppendTo(mangaArea, lastPage.Offset, -1, page);
                pagesTail = page.Page;
                insertedPages[page.Page] = page;
                RefreshMangaArea();
            }
            else if (page.Page == pagesHead - 1)
            {
                MangaPage firstPage = GetMangaPage(pagesHead);
                page.AppendTo(mangaArea, firstPage.Offset, 1, firstPage);
                pagesHead = page.Page;
                insertedPages[page.Page] = page;
                RefreshMangaArea();
            }
            else
            {
                return;
            }
        }
Exemplo n.º 4
0
 private void Remove(MangaPage page)
 {
     insertedPages.Remove(page.Page);
     page.Remove();
     if (page.Page == pagesTail) pagesTail--;
     if (page.Page == pagesHead) pagesHead++;
 }
Exemplo n.º 5
0
 private MangaPage GetMangaPage(int page)
 {
     if (loadedPages.ContainsKey(page))
     {
         return loadedPages[page];
     }
     else
     {
         return loadedPages[page] = new MangaPage(manga.id, page, attachedObject.GetWidth(), attachedObject.GetHeight(), manga.ltr, manga.pages);
     }
 }