krassowski / Anki-TouchScreen

Touchscreen functionality for Anki
https://ankiweb.net/shared/info/1631622775
GNU General Public License v3.0
25 stars 13 forks source link

The lines aren't drawn under the cursor as intended. #8

Open Spkiylfafr opened 5 years ago

Spkiylfafr commented 5 years ago

On Windows 10, with Anki 2.1.8 (71e0c880), even with windows DPI scaling disabled and using the programs scaling, the lines drawing appear far off to the side of where they should be, the further away from the top left that the cursor gets.

In the top left corner it is mostly accurate but the further way from the corner, the further away the point of drawing becomes. This implies to me that it is some sort of high DPI display issue. I am using a 2560x1440p display.

After a small amount of drawing, it begins to lag very badly and a sad square face appears in the top left. At this point the card or drawing stretches out horizontally past where it can be seen (to the right) however this begins immediately after the card has been opened.

Here is a link to a video of the issue: https://my.mixtape.moe/dwgvdj.mp4

KIMYONGUP commented 5 years ago

I experience the same problem.. I also hope this problem should be dealth with soon.

krassowski commented 5 years ago

I think I know what it might be. Could you try to remove the following two lines:

window.addEventListener('resize', resize);
document.body.addEventListener('load', resize)

from the __init__.py file (locate it with help of Anki, from menu choose Tools -> Add-ons -> select touchscreen addon -> View Files button; please remember to restart Anki afterwards) and tell me if it stopped crashing? It obviously would introduce other sizing issues but might confirm my diagnosis and make the add-on somehow usable for you (on some of the cards).

nikoslos commented 5 years ago

The growing canvas is caused by the resize function. In the python ts_resize function a script is added that sets an interval on the resize function. ts_interval = window.setInterval(resize, 750); Every 750ms the resize function is called.

I tried to come up with a solution for the javascript resize function, to prevent the growing canvas and offset drawing.

const windowsScale = 1.25;
var card = document.getElementsByClassName('card')[0]
ctx.canvas.width = Math.max(
    document.body.clientWidth * windowsScale,
    window.innerWidth
) ;
ctx.canvas.height = Math.max(
    document.body.clientHeight * windowsScale,
    window.innerHeight
) ;
canvas.style.width = ctx.canvas.width / windowsScale + 'px';
canvas.style.height = ctx.canvas.height / windowsScale + 'px';
update_pen_settings()

This solves the issue if my main screen is set to 125% scaling. I could not find a way to get the information of the screen scale. It also changes the behavior of resizing, so when you make the anki window smaller the canvas also gets smaller. In the old resize function the canvas stayed the same size (scroll bars appeared). This shouldn't be an issue since there is no point of constantly resizing the anki window. And an other issue is that on long cards (with scroll bars) you can't draw up to the border. (Better than not beeing able to use this addon)

MayconInProjectsDeveloper commented 4 years ago

A tela crescente é causada pela função redimensionar. Na função python ts_resize, é adicionado um script que define um intervalo na função de redimensionamento. ts_interval = window.setInterval(resize, 750); A cada 750ms, a função de redimensionamento é chamada.

Tentei encontrar uma solução para a função de redimensionamento de javascript, para impedir o aumento da tela e o desenho em offset.

const windowsScale = 1.25;
var card = document.getElementsByClassName('card')[0]
ctx.canvas.width = Math.max(
  document.body.clientWidth * windowsScale,
  window.innerWidth
) ;
ctx.canvas.height = Math.max(
  document.body.clientHeight * windowsScale,
  window.innerHeight
) ;
canvas.style.width = ctx.canvas.width / windowsScale + 'px';
canvas.style.height = ctx.canvas.height / windowsScale + 'px';
update_pen_settings()

Isso resolve o problema se minha tela principal estiver configurada para 125% de escala. Não consegui encontrar uma maneira de obter as informações da escala da tela. Ele também altera o comportamento do redimensionamento; portanto, quando você diminui a janela do anki, a tela também diminui. Na antiga função de redimensionamento, a tela permanecia do mesmo tamanho (as barras de rolagem apareciam). Isso não deve ser um problema, pois não há motivo para redimensionar constantemente a janela anki. E outra questão é que, em cartões longos (com barras de rolagem), você não pode desenhar até a borda. (Melhor do que não poder usar este complemento)

**Help me. I am Braziliam and medicine student.

I am inexperienced in programming and wanted to know in which line do I put this code to correct the problem?

Can you help me ?**

nikoslos commented 4 years ago

I'm not sure if this solution still works. You need to replace the content of the resize function. Replace the lines 306-317 with the posted code. Now check in your Windows display settings what scale your main display is set to. Divide the number by 100, if the scale is 200% you get the number 2.0, if it is 150% you get the number 1.5, etc. Replace the number of windowsScale with this number.

Hope it works.

MayconInProjectsDeveloper commented 4 years ago

I'm not sure if this solution still works. You need to replace the content of the resize function. Replace the lines 306-317 with the posted code. Now check in your Windows display settings what scale your main display is set to. Divide the number by 100, if the scale is 200% you get the number 2.0, if it is 150% you get the number 1.5, etc. Replace the number of windowsScale with this number.

Hope it works.

Thaks ! The problem was in the complement ( Ankizoom 2.0 ).