1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| :- use_module(library(pce)).
% claase XPCE pour mémoriser le texte
:- pce_begin_class(memo_text(fenetre), object).
variable(fenetre, object, both, "fenetre d'affichage").
variable(affi, string, both, "chaine d'affichage").
variable(affi_pos, point, both, "position d'affichage").
% méthode pour l'initialisation du dessin
initialise(P, Fenetre:object) :->
"Création de la classe memo"::
send(P, fenetre, Fenetre),
send(P, affi_pos, new(_, point(200,200))),
send(P, affi, new(_, string(''))).
% message appelé pour modifer le texte
% et l'afficher
my_message(P, L) :->
get(P, affi, T),
efface_texte(P),
send(T, append, L),
send(P, affi, T),
affiche_texte(P).
:-pce_end_class.
go:-
new(W, window('La lecture en couleurs')),
% création de l' objet memo
new(M, memo_text(W)),
send(W,background,colour(black)),
send(W,size, size(850,500)),
send(W, display,
new(B1, box(75,25)), point(35,20)),
send(B1, fill_pattern, colour(white)),
send(B1, recogniser,
click_gesture(left, '', double,
message(@prolog, message_a, W, M))),
send(W, display,
new(B2, box(75,25)), point(135,20)),
send(B2, fill_pattern, colour(blue)),
send(B2, recogniser,
click_gesture(left, '', double,
message(@prolog, message_o, W, M))),
send(W, display,
new(B3, box(75,25)), point(235,20)),
send(B3, fill_pattern, colour(yellow)),
send(B3, recogniser,
click_gesture(left, '', double,
message(@prolog, message_m, W, M))),
send(W, display,
new(B4, box(75,25)), point(335,20)),
send(B4, fill_pattern, colour(green)),
send(B4, recogniser,
click_gesture(left, '', double,
message(@prolog, message_i, W, M))),
send(W, display,
new(B5, box(75,25)), point(145, 135)),
send(B5, fill_pattern, colour(red)),
send(B5, recogniser,
click_gesture(left, '', double,
message(@prolog,message_r, W, M))),
send(W, display,
new(B6, box(75,25)), point(160, 200)),
send(B6, fill_pattern, colour(white)),
send(W, open).
% W est la fenêtre d'affichage
% M est l'objet de mémorisation
message_a(W, M) :-
new(Tx1, text('a')),
send(W, display,Tx1, point(80,25)),
send(M, my_message, new(_, string('a'))).
message_o(W, M) :-
new(Tx1, text('o')),
send(W, display,Tx1, point(180,25)),
send(M, my_message, new(_, string('o'))).
message_m(W, M) :-
new(Tx1, text('m')),
send(W, display,Tx1, point(280,25)),
send(M, my_message, new(_, string('m'))).
message_i(W, M) :-
new(Tx1, text('i')),
send(W, display,Tx1, point(380,25)),
send(M, my_message, new(_, string('i'))).
message_r(W, M) :-
new(Tx1, text('r')),
send(W, display,Tx1, point(180,140)),
send(M, my_message, new(_, string('r'))).
% effacement du texte en réécrivant dessus en blanc.
efface_texte(Obj) :-
get(Obj, fenetre, D),
get(Obj, affi, A),
new(T, text(A)),
get(Obj, affi_pos, P),
send(T, colour(white)),
send(D, display,T, P).
% effacement du texte en réécrivant dessus en blanc.
affiche_texte(Obj) :-
get(Obj, fenetre, D),
get(Obj, affi, A),
new(T, text(A)),
get(Obj, affi_pos, P),
send(T, colour(black)),
send(D, display,T, P). |
Partager