REBOL

 

REBOL Calculator - Source Code

Calculatrice REBOL
Author: Rebolien
File size: 7K
Return to index

 

REBOL [title: "REB-CALC"
        version: "1.0"
        auteur: "Antar BOUMEDIENNE"
     ]
menu1: ["Fichier" "Quitter"]
menu2: ["Edition" "Copier" "Coller"]
menu3: ["?" "Touches" ]
nb: []
VAR1: to-decimal 0.
VAR2: to-decimal 1.
virg?: false
op: "none"
liste-calcul: ["0"]
liste-calcul2: ["0"]
result: to-decimal 0
proc-menu1: does [
    option: parse CFichier/text none 
    switch first option [
    "Quitter" [view/new fen-quit]
    ]
    ; premier item du menu
    CFichier/text: pick CFichier/texts 1
    show CFichier
    ]
proc-menu2: does [
    option: parse CEdition/text none 
    switch first option [
    "Copier" [proc-copier]
    "Coller" [proc-coller]
    ]
    ; premier item du menu
    CEdition/text: pick CEdition/texts 1
    show CEdition
    ]
proc-menu3: does [
    option: parse CAide/text none 
    switch first option [
    "Touches" [view/new fen-touches]
    ]
    ; premier item du menu
    CAide/text: pick CAide/texts 1
    show CAide
    ]
proc-copier: does [write clipboard:// Calcul/text]
proc-coller: does [
            buffer: read clipboard:// 
            typeBuff: string!
            buffer1: 0.1
            if/else error? try [(buffer1: to-decimal buffer)][set 'typeBuff string!][set 'typeBuff decimal! set 'buffer1 to-decimal buffer]
            if (typeBuff = decimal!)[Calcul/text: buffer1 clear liste-calcul insert tail liste-calcul (to-string buffer1) traitement]

            temp: parse calcul/text "."
            if/else (temp = liste-calcul)[set 'virg? false][set 'virg? true]
            unset 'temp ;libération mémoire
            unset 'typBuff ;libération mémoire
            unset 'buffer1 ;libération mémoire
            unset 'buffer ;libération mémoire
                ]
proc-calculer: does [
        switch/default op [
            "addition" [result: add var1 var2];<=> var1 + var2
            "soustraction" [result: subtract var1 var2];<=> var1 - var2
            "division" [result: divide var1 var2];<=> var1 / var2
            "multiplication" [result: multiply var1 var2];<=> var1 * var2
            "puissance" [result: var1 ** var2]
            "carré" [result: var1 ** 2]
            "cube" [result: var1 ** 3]
            "radical" [result: square-root var1]
                        ][
        set 'result to-decimal Calcul/text]
        set 'virg? false
        Calcul/text: to-string Result
        set 'var1 to-decimal Result
        set 'op "none"
        show calcul
        clear nb
        nb: reduce liste-calcul
        clear liste-calcul
        liste-calcul: ["0"]
    ]
traitement: does [if/else any [(op == "none")(op == "radical")(op == "carré")(op == "cube")(op == "negate")] [set 'VAR1 to-decimal to-string liste-calcul Calcul/text: to-string Var1 ][set 'VAR2 to-decimal to-string liste-calcul Calcul/text: to-string Var2] show calcul ]
fen-touches: copy [
size 150x100
backdrop sky
space 0x0
across
origin 0x0
code center 150x25 "Touches:           F1"
return
code center 150x25 "Quitter:     Echap"
return
code center 150x25 "Copier:     CTRL+C"
return
code center 150x25 "Coller:     CTRL+V"
key keycode [#"^["][unview fen-touches]
]
fen-quit: copy [
    style btn0 btn 30x21 font [colors: [250.240.230 255.205.40] size: 8] shadow none
    style lab label center coffee 150x20 font-size 12 shadow 0x0
    size 150x54
    ;backtile Brique-aqua
    backdrop sky
    across
    space 0x0
    origin 0x0
    label 5x5
    return  
    lab "QUITTER?" reblue
    return
    label 5x5
    return
    label 40x20
    btn0 "OUI" "OK" keycode [#"o" #"O"] reblue over-color [q]
    label 10x20
    btn0 "NON" "OK" keycode [#"n" #"N" #"^["] brick crimson [unview fen-quit]
]
fen: copy [
    size 180x151
    backdrop sky
    style lab label 20x20
    style but-n btn 21x21 255.205.40 255.80.37 font [size: 13 align: 'center valgin: 'middle]
    style btn-op btn 21x21 255.228.196 255.164.200 font [size: 17 align: 'center valgin: 'middle]
    style btn-ot btn 60x21 220.20.60 255.80.37 font [size: 18 align: 'center valgin: 'middle]
    style ecart label 3x3
    style stylmenu1 choice  left 250.240.230 font [size: 11 shadow: none colors: [0.0.0 220.20.60]] effect [gradient 0x1 250.240.230 ] edge [color: 0.0.128 size: 0x1]
    across
    space 0x0
    origin 0x0
    CFichier: stylmenu1 55x20 data menu1 [proc-menu1]
    CEdition: stylmenu1 55x20 data menu2 [proc-menu2]
    CAide: stylmenu1 70x20 data menu3 [proc-menu3]
    ecart
    return
    label 5x2 
    return
    ecart
    Calcul: info white right middle 170x20 "0" font [color: 255.0.0] font-size 15 bold bold
    return
    label 5x2 
    return
    ecart
    return
    ecart
    but-n "x^^" 255.80.37 0.0.128 font-color 255.255.255 [set 'op "puissance" clear liste-calcul set 'virg? false]
    ecart
    but-n "7" #"7" [insert tail liste-calcul "7" traitement]
    ecart
    but-n "8" #"8" [insert tail liste-calcul "8" traitement]
    ecart
    but-n "9" #"9" [insert tail liste-calcul "9" traitement]
    ecart
    btn-op "+" #"+" [set 'op "addition" clear liste-calcul liste-calcul: ["0"] set 'virg? false]
    ecart
    btn-op "-" #"-" [set 'op "soustraction" clear liste-calcul liste-calcul: ["0"] set 'virg? false]
    ecart
    but-n "C" #"^(8)" crimson teal font-color 255.255.255 [if/else ((length? liste-calcul) > 1) [clear liste-calcul2 for i 1 ((length? liste-calcul) - 1) 1 [insert tail liste-calcul2 (pick liste-calcul i) ] clear liste-calcul insert liste-calcul reduce liste-calcul2 traitement][clear liste-calcul insert tail liste-calcul "0" traitement]]
    ecart
    return
    ecart
    return
    ecart
    but-n "^½" 255.80.37 0.0.128 font-color 255.255.255 [set 'op "radical" clear liste-calcul set 'virg? false]
    ecart
    but-n "4" #"4" [insert tail liste-calcul "4" traitement]
    ecart
    but-n "5" #"5" [insert tail liste-calcul "5" traitement]
    ecart
    but-n "6" #"6" [insert tail liste-calcul "6" traitement]
    ecart
    btn-op  "x" #"*" [set 'op "multiplication" clear liste-calcul liste-calcul: ["0"] set 'virg? false]
    ecart
    btn-op  "÷" #"/" [set 'op "division" clear liste-calcul liste-calcul: ["0"] set 'virg? false]
    ecart
    return
    ecart
    return
    ecart
    but-n "x²" #"²" 255.80.37 0.0.128 font-color 255.255.255 [set 'op "carré" clear liste-calcul set 'virg? false] 
    ecart
    but-n "1" #"1" [insert tail liste-calcul "1" traitement]
    ecart
    but-n "2" #"2" [insert tail liste-calcul "2" traitement]
    ecart
    but-n "3" #"3" [insert tail liste-calcul "3" traitement]
    ecart
    btn-ot "=" #"^M" [proc-calculer
                    ]
    ecart
    return
    ecart
    return
    ecart
    but-n "x³" 255.80.37 0.0.128 font-color 255.255.255 [set 'op "cube" clear liste-calcul set 'virg? false] 
    ecart
    but-n "0" #"0" [insert tail liste-calcul "0" traitement]
    ecart
    but-n "." #"." [if (virg? == false)[insert tail liste-calcul "." Calcul/text: to-string liste-calcul show calcul set 'virg? true]]
    ecart
    return
    ecart
    return
    key keycode [#"^["] [view/new fen-quit]
    key keycode [#"^C"] [proc-copier]
    key keycode [#"^V"] [proc-coller]
    key keycode [F1] [view/new fen-touches]
    do [CFichier/colors: CAide/colors: CEdition/colors: [250.240.230 220.20.60]]
    
]
fen: center-face layout fen
fen-quit: center-face layout fen-quit
fen-touches: center-face layout fen-touches
view fen