From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel Subject: Re: Emacs canvas support Date: Wed, 29 Apr 2020 17:57:03 +0800 Message-ID: <87zhau1uog.fsf@yahoo.com> References: <875zdikdge.fsf.ref@yahoo.com> <875zdikdge.fsf@yahoo.com> <834kt21yyo.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="82466"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Apr 29 11:57:58 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jTjTZ-000LLt-28 for ged-emacs-devel@m.gmane-mx.org; Wed, 29 Apr 2020 11:57:57 +0200 Original-Received: from localhost ([::1]:58790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTjTX-0000Ej-W7 for ged-emacs-devel@m.gmane-mx.org; Wed, 29 Apr 2020 05:57:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36484) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTjSp-0007qg-Kv for emacs-devel@gnu.org; Wed, 29 Apr 2020 05:57:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTjSo-0001HJ-9f for emacs-devel@gnu.org; Wed, 29 Apr 2020 05:57:11 -0400 Original-Received: from sonic306-20.consmr.mail.ne1.yahoo.com ([66.163.189.82]:41201) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jTjSn-0001Gw-PC for emacs-devel@gnu.org; Wed, 29 Apr 2020 05:57:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1588154228; bh=CKM7Ag67H0vtwmZZFCd4rJlJg5OcziJiTwbdJMoV1xw=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject; b=DJeverYIqbLpp/KNreC5tCacMaTXIJs1REdk915OtM3iVvcIfMJqGyIUQqQz+ehvibJylpzkiWzGiVM14VIn7/4ZhW33IcmTttcHs/MZQ4r97C/hXAEfblLKLjGp+1pXrEdLgGRHuduvHdXhmQKYnWmDa4CXHOXz9U07NjrE1SjBa6VG00kjspPqsbs7SyUiUsz6HZr0eagxYqVOBNol/rU8fpR66WItDU3fFKZAzVxR2L06VhiSHDe1SF7a/mlKBqKZBdongioDCY9UOCExSkch3PiZmWFsSCg85RqX8b2JDp8QMCFfoQ1GN5+LwuA6sNVCwAhRyaaZnau7xZ0rsw== X-YMail-OSG: sVLVKYwVM1kUqoIfkXBd34Er_tAkcQ8a088dqJPOHqJKcFKoRaAxXVZwR4RRDEY nbDoV3XiXOMagjPyJzne756k_1zu.pWUvW1yTD0AuH6Bsvf6yIfQz.LcRzOf3aDq7rgvHuVgrgB0 2AaS14E.5_dXuUOlTYjexcHeCOGw2iZzBYsVD7A_34d6BpNVhk8gLYMvwFC5T0ZIall8s6lk4kLf iCqxuG.Jdni6lQHQk93TLO61Yw3Qg1PanuL7o_nBCZ0iHA1l4gVo7Zp79kvAmprU1GwGFXqo.Irc _oyCOcve0eoYCGhkU8opS9bBd_0KtBgvOu4_Pqtwog7SUHwbm8DAqorui4F9FcyG60Qb8QMlADGK pg2qaj3SMVdlAeqhitd2i5_MhWKGpSIF4H6hKMP.RoI.h3UYUtVGiL09BTNLHJaXteFneOhDgWzE NnW1.myx.XniiEscDI6IgfZw1.o4mEGICwPZF242sSJPc_rEoXbORxHYROIJbYBvJi820mQUMjUP 7w6CAEeEOJ9wJiZ6Y2HI694lVNJCUdXzRb.uU6s2tUgQuM9yX1obT34CP22YenTxyBGFkOQLDDaW nFkJNl9Mh2WOmpuAdHXo78lEDkFduP9C_b6FFa0kiSmDOU5gJS3keYmKGe2udCvi4eZu59gSDOi8 FjQ40A8K2vy6OZKxtxoiS.vF.cPT.Gw1MNBQ_q1JQsBb7jRZipBavFsucPQxlTz01R5H9sXKgpae 3xKjWjtx7S83SYsnDNRPhQIH3ktqNXnlfPS2ZRbhls2Xk3qZhflbXzKGr2DmvtEX6uOmopaVEU4P ZIJWxin.Xx9meauLrqNIYDjPBvDiqOjBLzmAPriH7v Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Wed, 29 Apr 2020 09:57:08 +0000 Original-Received: by smtp414.mail.sg3.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 35e3e35e64ac1719ed8f49aa0186f7b4; Wed, 29 Apr 2020 09:57:05 +0000 (UTC) In-Reply-To: <834kt21yyo.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 29 Apr 2020 11:24:31 +0300") X-Mailer: WebService/1.1.15756 hermes Apache-HttpAsyncClient/4.1.4 (Java/11.0.6) Received-SPF: pass client-ip=66.163.189.82; envelope-from=luangruo@yahoo.com; helo=sonic306-20.consmr.mail.ne1.yahoo.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 05:57:08 X-ACL-Warn: Detected OS = Linux 3.1-3.10 X-Received-From: 66.163.189.82 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:248102 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > I've read the code and the docs, but I don't think I have a clear idea > of what "canvases" are and what would be their intended usage. > Perhaps consider starting the documentation with some introductory > comments and even a small tutorial. A canvas is an object that contains memory that can be painted to, and then displayed by setting it as the `display' text property. > It sounds like you are talking about a way to create images > dynamically, but then I don't understand why we need canvas-from-image, > for example. It's not really a way to create images dynamically, but rather paint to a section of the screen. `canvas-from-image' is just a convenience function that produces a paintable canvas from a static image. > Also, is there support for clicking the mouse on a canvas? I don't > see it. You can bind mouse events as usual. > Well, that'd be my main comments. I don't quite understand the parts > of the display code you use for this, they seem like a copy/paste from Correct, glyph production and iterator code code was mostly copied from the xwidgets code, since I was somewhat in a rush. Thanks for the feedback. > other objects, sometimes with comments that weren't updated and still > reference images instead of canvases. I'll fix that promptly. > If the drawing on the canvas is supposed to be modified by Lisp code, > then we'd need a much more elaborate machinery than just one flag to > decide when a canvas needs to be redrawn. Agreed, that is something I've been trying to figure out for some time now. Right now, I just do my best to figure out if the canvas has not touched anything important, and if it has, it just garbages each frame and calls redisplay. Attached is some sample code that should hopefully demonstrate exactly what they are capable of. --=-=-= Content-Type: text/plain Content-Disposition: attach; filename=test.el Content-Description: canvas test (setq canvas (make-canvas 1800 1800)) (erase-buffer) (insert (propertize " " 'display canvas)) (canvas-draw-image canvas (create-image "splash.png") 0 0 180 180 (selected-frame) 1.0) (canvas-ellipse canvas (/ 180 2) (/ 180 2) 130 130 "green") (canvas-rectangle canvas 0 0 180 180 "red" t) (canvas-rectangle canvas 20 20 40 100 "white" t 0.5) (canvas-draw-string canvas 0 0 "Hello, Emacs" "red" 1.0 "monospace" 50) (canvas-draw-string canvas 60 60 "Hello, Emacs" "white" 1.0 '("monospace" t t) 50) (let ((image (create-image "splash.png"))) (canvas-draw-image canvas image 700 20)) (setq track-mouse t) (defun mouse-movement-canvas-4-paint () "The function to be called when the mouse is moved." (interactive "") (track-mouse (let ((event)) (while (mouse-movement-p (setq event (read-event))) (let* ((position (event-start event)) (x (car (posn-x-y position))) (y (cdr (posn-x-y position)))) (message (format "%d %d" x y)) (canvas-filled-arc canvas x y 100.0 (* 45.0 (/ pi 180.0)) pi "blue")))))) (defun mouse-movement-canvas-paint () "The function to be called when the mouse is moved." (interactive "") (track-mouse (let ((event)) (while (mouse-movement-p (setq event (read-event))) (let* ((position (event-start event)) (x (car (posn-x-y position))) (y (cdr (posn-x-y position)))) (message (format "%d %d" x y)) (canvas-ellipse canvas x y 10 10 "blue")))))) (defun mouse-movement-3-canvas-paint () "The function to be called when the mouse is moved." (interactive "") (track-mouse (let ((event)) (while (mouse-movement-p (setq event (read-event))) (let* ((position (event-start event)) (x (car (posn-x-y position))) (y (cdr (posn-x-y position)))) (message (format "%d %d" x y)) (canvas-rectangle canvas x y 80 80 "white")))))) (defun mouse-movement-2-canvas-paint () "The function to be called when the mouse is moved." (interactive "") (track-mouse (let ((event)) (while (mouse-movement-p (setq event (read-event))) (let* ((position (event-start event)) (x (car (posn-x-y position))) (y (cdr (posn-x-y position)))) (message (format "%d %d" x y)) (canvas-draw-string canvas x y "Welcome to Emacs" nil nil nil 22)))))) (local-set-key [down-mouse-1] #'mouse-movement-canvas-paint) (local-set-key [down-mouse-3] #'mouse-movement-2-canvas-paint) (local-set-key [down-mouse-2] #'mouse-movement-3-canvas-paint) (local-set-key [C-down-mouse-1] #'mouse-movement-canvas-4-paint) (canvas-measure-string canvas "hi") (canvas-draw-string canvas 0 0 "Hi" "yellow") (setq canvas2 (canvas-from-image (create-image "splash.png"))) (canvas-rectangle canvas2 0 0 40 20 "orange") (canvas-rectangle canvas2 20 0 40 20 "black") (canvas-rounded-rectangle canvas 20 0 40 20 10.0 "red" nil) (canvas-draw-canvas canvas canvas2 500 500) --=-=-=--