Controlling canvas size

Started by cormullion, February 23, 2008, 08:33:11 AM

Previous topic - Next topic

cormullion

Is there a way to specify a canvas size, other than by making the entire window un-resizable?

newBert

#1
Is it not possible with gs:set-size ?


Quote

syntax: (gs:set-size sym-id int-width int-height)

parameter: sym-id - The name of the component of which a preferred size is set.

parameter: int-width - The preferred width of the component.

parameter: int-height - The preferred height of the component.



Note that not all layouts allow setting the size of a component. The grid and border layouts will size the component to its maximum possible in the layout.


I tried it in my script :

#!/usr/bin/newlisp
;=======================================
; Turtle graphics   (NewLISP + GUI-server)
; mandala.lsp
; NewLISP v9.2.5 - Bertrand Carette (nov. 2007)
;=======================================
;; initialization GUI-server
(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
(gs:init)

;; constants & variables
(constant 'PI2 (acos 0) 'DP2 (div PI2 90)) ; degre -> radian
(set 'WIDTH 400 'HEIGHT 400) ; size of the window
(set 'coorX 0 'coorY 0) ; coordinates of the "turtle"
(set 'dir 0) ; orientation (heading to the north)
(set 'back-color '(1 1 1)) ; backcolor = white
(set 'pen-color '(0 0 0)) ; pen = black
(set 'pen true) ; pen is down

;; building the GUI
(gs:frame 'WIN 100 100 WIDTH (add HEIGHT 32) "NewLISP Turtle")
(gs:canvas 'Canvas)
(gs:set-size 'Canvas WIDTH HEIGHT)
(gs:set-background 'Canvas back-color)
(gs:window-resized 'WIN 'resize-action)
(gs:add-to 'WIN 'Canvas)
(gs:set-visible 'WIN true)

;; graphic procedures (commands for the turtle)
(define (home)
; center of the screen, heading to north
(pen-up)
(set 'coorX 0 'coorY 0)
(set 'dir PI2)
(pen-down))

(define (clear-screen)
(gs:delete-tag 'L)
(home))

(define (pen-down)
(set 'pen true))

(define (pen-up)
(set 'pen nil))

(define (pendown?)
pen)

(define (set-pos x y)
;  set the new position of the turtle
(set 'coorX (add (div WIDTH 2) coorX) 'coorY (sub (div HEIGHT 2) coorY))
(set 'newX (add (div WIDTH 2) x) 'newY (sub (div HEIGHT 2) y))
(if (pendown?)
; draw if pen is down
(gs:draw-line 'L (int coorX) (int coorY) (int newX) (int newY) pen-color ))
(set 'coorX x 'coorY y))

(define (pos)
; return current position
(cons coorX coorY))

(define (forward dist)
(set-pos (add coorX (mul dist (cos dir)))
(add coorY (mul dist (sin dir)))))

(define (backward dist)
(forward (- dist)))

(define (set-heading angle)
; set the orientation
(set 'dir (mod angle 360)))

(define (orientation)
; return current heading
dir)

(define (right degre)
; set orientation to the right (in degre)
(set-heading (sub dir (mul degre DP2))))

(define (left degre)
; set orientation to the left (in degre)
(set-heading (add dir (mul degre DP2))))

(define (resize-action id w h , x y)
(set 'x (int (sub (div w 2) (div WIDTH 2))) 'y (int (sub (div h 2) (div HEIGHT 2))))
(gs:move-tag 'L x y)
(set 'WIDTH (int w) 'HEIGHT (int h)))


;; main program (a Turtle Graphics program : mandala.lsp)
(define (get-vectors)
; create an array of vectors
(home)
(pen-up)
(set 'nsom 20) ; amount of vertices
(set 'sommets (array (+ nsom 1)))
(set 'rayon 280) ; radius
(set 'angle (/ 360 nsom))
(for (i 0 nsom)
(home)
(right (* i angle))
(forward rayon)
(nth-set (sommets i) (pos)))
) ; end define

(define (draw-vectors , a b)
; pen down and draw the mandala
(for (i 0 nsom)
(set 'a i)
(for (j 0 a)
(set 'b j)
(pen-up)
(set-pos (first (sommets a)) (last (sommets a)))
(pen-down)
(set-pos (first (sommets b)) (last (sommets b)))))
) ; end define

(get-vectors)
(draw-vectors)
(gs:update)

;; event loop
(gs:listen)


And you can resize the window

;)
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>

cormullion

#2
You're right! I've been using a grid layout, so I shall try another approach.



thanks

newBert

#3
Sorry, I am still not quite at ease with 'grid-layout' ;)
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>

newBert

#4
Quote from: "newBert"Sorry, I am still not quite at ease with 'grid-layout' ;)


P.S.: but if you find a solution for your problem, it interests me :)
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>

newdep

#5
..yes  there is...



Look at the nlist.lsp layout it uses then make sure you place the canvas in one of the layout positions..



I have here a nlist-plugin on the shelf (which i cant finish currently because im too bussy with other things..) but that plugin uses canvas

and that looks pritty nice ;-)



Btw.. I did also put it inside a Tab..

Btw2: i did not peek at the example of newbert, im just passing by..
-- (define? (Cornflakes))

cormullion

#6
It works quite well, so far, so thanks very much guys!  http://unbalanced-parentheses.nfshost.com/index.cgi?view-post-id=20080228212226">//http://unbalanced-parentheses.nfshost.com/index.cgi?view-post-id=20080228212226