Subversion Repositories Kolibri OS

Rev

Rev 112 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
41 mikedld 1
get_titlebar_height: ; edi = window draw_data pointer
2
        mov     al,[edi+WDATA.fl_wstyle]
3
        and     al,0x0F
4
        cmp     al,0x03
5
        jne     @f
6
        mov     eax,[_skinh]
7
        ret
8
    @@: mov     eax,21
9
        ret
10
 
11
get_rolledup_height: ; edi = window draw_data pointer
12
        mov     al,[edi+WDATA.fl_wstyle]
13
        and     al,0x0F
14
        cmp     al,0x03
15
        jne     @f
16
        mov     eax,[_skinh]
17
        add     eax,3
18
        ret
19
    @@: or      al,al
20
        jnz     @f
21
        mov     eax,21
22
        ret
23
    @@: mov     eax,21+2
24
        ret
25
 
26
 
1 ha 27
setwindowdefaults:
28
        pushad
29
 
30
        xor   eax,eax
31
        mov   ecx,0xc000
32
       @@:
33
        inc   eax
34
        add   ecx,2
35
        mov   [ecx+0x000],ax          ; process no
36
        mov   [ecx+0x400],ax          ; positions in stack
37
        cmp   ecx,0xc400-2            ; the more high, the more surface
38
        jnz   @b
39
 
40
        popad
41
        ret
42
 
43
 
44
 
45
; eax = cx
46
; ebx = cy
47
; ecx = ex
48
; edx = ey
49
; идея: перебрать все окна, начиная с самого нижнего,
112 poddubny 50
;       и для попавших в заданную область
51
;       частей окон вызвать setscreen
1 ha 52
align 4
53
calculatescreen:
54
        pushad
102 poddubny 55
        pushfd
1 ha 56
        cli
57
 
112 poddubny 58
        push    edx ecx ebx eax
1 ha 59
 
112 poddubny 60
        mov     esi, 1
61
        call    setscreen
62
 
63
        mov     ebp, [0x3004]        ; number of processes
64
        cmp     ebp, 1
65
        jbe     .finish
1 ha 66
        align 4
67
      .new_wnd:
102 poddubny 68
        movzx   edi, word [0xC400 + esi * 2]
69
        shl     edi, 5
70
 
71
        cmp     [0x3000+edi+0xa], byte 9
72
        je      .not_wnd
73
 
74
        add     edi, window_data
112 poddubny 75
        test    [edi+WDATA.fl_wstate], WSTATE_MINIMIZED
41 mikedld 76
        jnz     .not_wnd
112 poddubny 77
 
114 mikedld 78
        mov     eax,[edi+WDATA.box.left]
112 poddubny 79
        cmp     eax, [esp+RECT.right]
80
        ja      .out_of_bounds
114 mikedld 81
        mov     ebx,[edi+WDATA.box.top]
112 poddubny 82
        cmp     ebx, [esp+RECT.bottom]
83
        ja      .out_of_bounds
114 mikedld 84
        mov     ecx,[edi+WDATA.box.width]
112 poddubny 85
        add     ecx, eax
86
        cmp     ecx, [esp+RECT.left]
87
        jb      .out_of_bounds
114 mikedld 88
        mov     edx,[edi+WDATA.box.height]
112 poddubny 89
        add     edx, ebx
90
        cmp     edx, [esp+RECT.top]
91
        jb      .out_of_bounds
92
 
93
	cmp     eax, [esp+RECT.left]
94
        jae     @f
95
        mov     eax, [esp+RECT.left]
96
     @@:
97
	cmp     ebx, [esp+RECT.top]
98
        jae     @f
99
        mov     ebx, [esp+RECT.top]
100
     @@:
101
	cmp     ecx, [esp+RECT.right]
102
        jbe     @f
103
        mov     ecx, [esp+RECT.right]
104
     @@:
105
	cmp     edx, [esp+RECT.bottom]
106
        jbe     @f
107
        mov     edx, [esp+RECT.bottom]
108
     @@:
109
 
110
        push    esi
111
        movzx   esi, word [0xC400 + esi * 2]
112
        call    setscreen
113
        pop     esi
114
 
1 ha 115
      .not_wnd:
112 poddubny 116
      .out_of_bounds:
117
        inc     esi
118
        dec     ebp
119
        jnz     .new_wnd
1 ha 120
      .finish:
112 poddubny 121
 
122
	pop     eax ebx ecx edx
123
 
102 poddubny 124
        popfd
1 ha 125
        popad
126
ret
127
 
128
 
129
 
130
virtual at esp
112 poddubny 131
  ff_x     dd ?
132
  ff_y     dd ?
133
  ff_width dd ?
1 ha 134
  ff_xsz   dd ?
135
  ff_ysz   dd ?
136
  ff_scale dd ?
137
end virtual
138
 
139
align 4
140
; резервирует место под окно заданного процесса
141
setscreen:
142
;  eax  x start
143
;  ebx  y start
144
;  ecx  x end
145
;  edx  y end
146
;  esi  process number
147
pushad
148
        mov edi, esi ;;;word [esi*2+0xc400]
149
        shl   edi, 8
150
        add   edi, 0x80000+0x80  ; address of random shaped window area
151
        cmp   [edi], dword 0
152
        jne   .free_form
153
 
154
        ; get x&y size
155
        sub   ecx, eax
156
        sub   edx, ebx
157
        inc   ecx
158
        inc   edx
159
 
160
        ; get WinMap start
161
        mov   edi, [0xFE00] ; screen_sx
162
        inc   edi
163
        imul  edi, ebx
164
        add   edi, eax
165
        add   edi, WinMapAddress
166
 
167
  .new_y:
168
        push  ecx ; sx
169
        push  edx
170
 
171
        mov   edx, esi
172
        align 4
173
  .new_x:
174
        mov   byte [edi], dl
175
        inc   edi
176
        dec   ecx
177
        jnz   .new_x
178
 
179
        pop   edx
180
        pop   ecx
181
        add   edi, [0xFE00]
182
        inc   edi
183
        sub   edi, ecx
184
        dec   edx
185
        jnz   .new_y
186
 popad
187
 ret
188
  .read_byte:
189
   ;eax - address
190
   ;esi - slot
191
        push  eax
192
        push  ebx
193
        push  ecx
194
        push  edx
195
        mov   edx,eax
196
        mov   eax,esi
197
        lea   ebx,[esp+12]
198
        mov   ecx,1
199
        call  read_process_memory
200
        pop   edx
201
        pop   ecx
202
        pop   ebx
203
        pop   eax
204
        ret
205
  .free_form:
206
 
207
        ;  for (y=0; y <= x_size; y++)
208
        ;      for (x=0; x <= x_size; x++)
209
        ;          if (shape[coord(x,y,scale)]==1)
210
        ;             set_pixel(x, y, process_number);
211
 
212
        sub  ecx, eax
213
        sub  edx, ebx
214
        inc  ecx
215
        inc  edx
216
 
217
        push  dword [edi+4]  ; push scale first -> for loop
218
 
219
        ; get WinMap start  -> ebp
220
        push  eax
221
        mov   eax, [0xFE00] ; screen_sx
222
        inc   eax
112 poddubny 223
        imul  eax, ebx
224
        add   eax, [esp]
1 ha 225
        add   eax, WinMapAddress
226
        mov   ebp, eax
227
 
228
        mov   edi, [edi]
229
        pop   eax
230
 
231
        ; eax = x_start
232
        ; ebx = y_start
233
        ; ecx = x_size
234
        ; edx = y_size
235
        ; esi = process_number
236
        ; edi = &shape
237
        ;       [scale]
112 poddubny 238
        push edx ecx ; for loop - x,y size
239
 
240
        mov  ecx, esi
241
        shl  ecx, 5
114 mikedld 242
        mov  edx, [window_data+ecx+WDATA.box.top]
243
        push [window_data+ecx+WDATA.box.width]      ; for loop - width
244
        mov  ecx, [window_data+ecx+WDATA.box.left]
112 poddubny 245
        sub  ebx, edx
246
        sub  eax, ecx
247
        push ebx eax ; for loop - x,y
248
 
249
        add  [ff_xsz], eax
250
        add  [ff_ysz], ebx
251
 
252
        mov  ebx, [ff_y]
253
 
1 ha 254
      .ff_new_y:
112 poddubny 255
        mov  edx, [ff_x]
256
 
1 ha 257
      .ff_new_x:
258
        ; -- body --
259
        mov  ecx, [ff_scale]
112 poddubny 260
        mov  eax, [ff_width]
261
        inc  eax
1 ha 262
        shr  eax, cl
263
        push ebx edx
264
        shr  ebx, cl
265
        shr  edx, cl
266
        imul eax, ebx
267
        add  eax, edx
268
        pop  edx ebx
112 poddubny 269
        add  eax, edi
1 ha 270
        call .read_byte
271
        test al,al
272
        jz   @f
112 poddubny 273
        mov  eax, esi
1 ha 274
        mov  [ebp], al
275
       @@:
276
        ; -- end body --
277
        inc  ebp
278
        inc  edx
279
        cmp  edx, [ff_xsz]
280
        jb   .ff_new_x
281
        sub  ebp, [ff_xsz]
112 poddubny 282
        add  ebp, [ff_x]
1 ha 283
        add  ebp, [0xFE00]  ; screen.x
284
        inc  ebp
285
        inc  ebx
286
        cmp  ebx, [ff_ysz]
287
        jb   .ff_new_y
288
 
112 poddubny 289
        add  esp, 24
1 ha 290
popad
291
ret
292
 
293
 
294
display_settings:
295
 
296
;    eax = 0         ; DISPLAY redraw
297
;          ebx = 0   ; all
298
;
299
;    eax = 1         ; BUTTON type
300
;          ebx = 0   ; flat
301
;          ebx = 1   ; 3D
302
;    eax = 2         ; set WINDOW colours
303
;          ebx = pointer to table
304
;          ecx = number of bytes define
305
;    eax = 3         ; get WINDOW colours
306
;          ebx = pointer to table
307
;          ecx = number of bytes wanted
308
;    eax = 4         ; get skin height
309
;          input  : nothing
310
;          output : eax = skin height in pixel
41 mikedld 311
;    eax = 5         ; get screen workarea
312
;          input  : nothing
313
;          output : eax = [left]*65536+[right]
314
;                   ebx = [top]*65536+[bottom]
315
;    eax = 6         ; set screen workarea
316
;          input  : ecx = [left]*65536+[right]
317
;                   edx = [top]*65536+[bottom]
318
;          output : nothing
52 mikedld 319
;    eax = 7         ; get skin margins
320
;          input  : nothing
321
;          output : eax = [left]*65536+[right]
322
;                   ebx = [top]*65536+[bottom]
323
;    eax = 8         ; set window skin
324
;          input  : ecx = pointer to file info block
325
;          output : eax = FS error code
1 ha 326
 
327
 
328
     pushad
329
 
330
     test eax, eax      ; redraw display
331
     jnz  dspl0
332
     test ebx, ebx
333
     jnz  dspl0
334
     cmp  [windowtypechanged],dword 1
335
     jne  dspl00
336
     mov  [windowtypechanged],dword 0
41 mikedld 337
  redraw_screen_direct:
1 ha 338
     mov  [dlx],dword 0
339
     mov  [dly],dword 0
340
     mov  eax,[0xfe00]
341
     mov  [dlxe],eax
342
     mov  eax,[0xfe04]
343
     mov  [dlye],eax
344
     mov  eax,window_data
345
     call redrawscreen
346
   dspl00:
347
     popad
348
     ret
349
   dspl0:
350
 
351
     cmp  eax,1       ; button type
352
     jne  dspl1
353
     and  ebx,1
354
     cmp  ebx,[buttontype]
355
     je   dspl9
356
     mov  [buttontype],ebx
357
     mov  [windowtypechanged],dword 1
358
    dspl9:
359
     popad
360
     ret
361
   dspl1:
362
 
363
     cmp  eax,2       ; set common window colours
364
     jne  no_com_colours
365
     mov  [windowtypechanged],dword 1
366
     mov  esi,[0x3010]
54 mikedld 367
     add  esi,0x10
368
     add  ebx,[esi]
369
     mov  esi,ebx
1 ha 370
     mov  edi,common_colours
371
     and  ecx,127
372
     cld
373
     rep  movsb
374
     popad
375
     ret
376
   no_com_colours:
377
 
378
     cmp  eax,3       ; get common window colours
379
     jne  no_get_com
380
     mov  esi,[0x3010]
381
     add  esi,0x10
382
     add  ebx,[esi]
383
     mov  edi,ebx
384
     mov  esi,common_colours
385
     and  ecx,127
386
     cld
387
     rep  movsb
388
     popad
389
     ret
390
   no_get_com:
391
 
392
     cmp  eax,4       ; get skin height
393
     jne  no_skin_height
394
     popad
395
     mov  eax,[_skinh]
396
     mov  [esp+36],eax
397
     ret
398
   no_skin_height:
399
 
41 mikedld 400
        cmp     eax,5       ; get screen workarea
401
        jne     no_get_workarea
402
        popad
403
        mov     eax,[screen_workarea.left-2]
404
        mov     ax,word[screen_workarea.right]
405
        mov     [esp+36],eax
406
        mov     eax,[screen_workarea.top-2]
407
        mov     ax,word[screen_workarea.bottom]
408
        mov     [esp+24],eax
409
        ret
410
   no_get_workarea:
411
 
412
        cmp     eax,6       ; set screen workarea
413
        jne     no_set_workarea
49 mikedld 414
        movsx   eax,word[esp+16+2]
415
        movsx   ebx,word[esp+16]
41 mikedld 416
        cmp     eax,ebx
49 mikedld 417
        jge     .lp1
418
        or      eax,eax;[0xFE00]
419
        jl      @f
41 mikedld 420
        mov     [screen_workarea.left],eax
49 mikedld 421
    @@: cmp     ebx,[0xFE00]
422
        jg      .lp1
41 mikedld 423
        mov     [screen_workarea.right],ebx
49 mikedld 424
  .lp1: movsx   eax,word[esp+24+2]
425
        movsx   ebx,word[esp+24]
41 mikedld 426
        cmp     eax,ebx
49 mikedld 427
        jge     .lp2
428
        or      eax,eax;[0xFE04]
429
        jl      @f
41 mikedld 430
        mov     [screen_workarea.top],eax
49 mikedld 431
    @@: cmp     ebx,[0xFE04]
432
        jg      .lp2
41 mikedld 433
        mov     [screen_workarea.bottom],ebx
49 mikedld 434
  .lp2: call	repos_windows
112 poddubny 435
        mov     eax, 0
436
        mov     ebx, 0
437
        mov     ecx, [0xfe00]
438
        mov     edx, [0xfe04]
49 mikedld 439
	call	calculatescreen
440
;	jmp	redraw_screen_direct
441
    .exit:
442
        popad
443
        ret
444
   no_set_workarea:
41 mikedld 445
 
52 mikedld 446
        cmp     eax,7       ; get skin margins
447
        jne     no_get_skinmargins
448
        popad
449
        mov     eax,dword[_skinmargins+0]
450
        mov     [esp+36],eax
451
        mov     eax,dword[_skinmargins+4]
452
        mov     [esp+24],eax
453
        ret
454
   no_get_skinmargins:
455
 
456
        cmp     eax,8       ; set window skin
457
        jne     no_set_skin
458
        mov     eax,ebx
459
        mov     edi,[0x3010]
460
        add     ebx,[edi+0x10]        ; abs start of info block
461
        pushd   [ebx+0] [ebx+4] [ebx+8] [ebx+12]
462
        mov     dword[ebx+0],0        ; read
463
        mov     dword[ebx+4],0        ; from the beginning
464
        mov     dword[ebx+8],64       ; 32 KBytes maximum
465
        mov     ecx,skin_data+64*512
466
        sub     ecx,[edi+0x10]
467
        mov     dword[ebx+12],ecx     ; destination
468
        push	eax
469
        pushad
470
        call    file_system
471
        popad
472
        pop	eax
473
        popd    [ebx+12] [ebx+8] [ebx+4] [ebx+0]
474
        cmp     eax,ERROR_SUCCESS
475
        je      @f
476
        cmp     eax,ERROR_END_OF_FILE
477
        jne     .exit
478
    @@: cmp     [skin_data+64*512+SKIN_HEADER.ident],'SKIN'
479
        mov     eax,ERROR_UNKNOWN_FS
480
        jne     .exit
481
        mov     esi,skin_data+64*512
482
        mov     edi,skin_data
483
        mov     ecx,(64*512)/4
484
        rep     movsd
485
        call    parse_skin_data
112 poddubny 486
	pushad
487
        mov     eax, 0
488
        mov     ebx, 0
489
        mov     ecx, [0xfe00]
490
        mov     edx, [0xfe04]
52 mikedld 491
        call    calculatescreen
112 poddubny 492
	popad
52 mikedld 493
        mov     dword[esp+32+36],0
494
        jmp     redraw_screen_direct
495
  .exit:
496
        mov     [esp+32+36],eax
497
        popad
498
        ret
499
   no_set_skin:
500
 
49 mikedld 501
     popad
502
     ret
503
 
504
 
505
repos_windows:
41 mikedld 506
        mov     ecx,[0x3004]
507
        mov     esi,0x20*2
49 mikedld 508
	mov	byte[0x0000fff0],1
41 mikedld 509
        dec     ecx
49 mikedld 510
        jge	@f
511
        ret
512
    @@: mov	[esi+WDATA.fl_redraw],1
513
	test    [esi+WDATA.fl_wstate],WSTATE_MAXIMIZED
514
        jz      .lp2
41 mikedld 515
        mov     eax,[screen_workarea.left]
114 mikedld 516
        mov     [esi+WDATA.box.left],eax
41 mikedld 517
        sub     eax,[screen_workarea.right]
518
        neg     eax
114 mikedld 519
        mov     [esi+WDATA.box.width],eax
41 mikedld 520
        mov     eax,[screen_workarea.top]
114 mikedld 521
        mov     [esi+WDATA.box.top],eax
41 mikedld 522
        test    [esi+WDATA.fl_wstate],WSTATE_ROLLEDUP
523
        jnz     .lp1
524
        sub     eax,[screen_workarea.bottom]
525
        neg     eax
114 mikedld 526
        mov     [esi+WDATA.box.height],eax
41 mikedld 527
  .lp1: add     esi,0x20
528
        loop    @b
529
        ret
114 mikedld 530
  .lp2: mov     eax,[esi+WDATA.box.left]
531
        add     eax,[esi+WDATA.box.width]
49 mikedld 532
	mov	ebx,[0x0000fe00]
533
;	inc	ebx
534
	cmp	eax,ebx
535
	jle	.lp4
114 mikedld 536
        mov     eax,[esi+WDATA.box.width]
49 mikedld 537
	sub	eax,ebx
538
	jle	.lp3
114 mikedld 539
        mov     [esi+WDATA.box.width],ebx
540
  .lp3: sub     ebx,[esi+WDATA.box.width]
541
        mov     [esi+WDATA.box.left],ebx
542
  .lp4: mov     eax,[esi+WDATA.box.top]
543
        add     eax,[esi+WDATA.box.height]
49 mikedld 544
	mov	ebx,[0x0000fe04]
545
;	inc	ebx
546
	cmp	eax,ebx
547
	jle	.lp6
114 mikedld 548
        mov     eax,[esi+WDATA.box.height]
49 mikedld 549
	sub	eax,ebx
550
	jle	.lp5
114 mikedld 551
        mov     [esi+WDATA.box.height],ebx
552
  .lp5: sub     ebx,[esi+WDATA.box.height]
553
        mov     [esi+WDATA.box.top],ebx
49 mikedld 554
  .lp6: add     esi,0x20
555
        loop    @b
556
	ret
41 mikedld 557
 
1 ha 558
uglobal
559
  common_colours:
560
     times 128 db 0x0
561
endg
562
 
563
 
564
 
565
 
566
check_window_position:
567
 
568
    pushad                           ; window inside screen ?
569
 
570
    movzx eax,word [edi+0]
571
    movzx ebx,word [edi+4]
572
    movzx ecx,word [edi+8]
573
    movzx edx,word [edi+12]
574
 
575
    mov   esi,ecx             ; check x pos
576
    add   esi,eax
577
    cmp   esi,[0xfe00]
578
    jbe   x_pos_ok
579
    mov   [edi+0],dword 0
580
    xor   eax, eax
581
  x_pos_ok:
582
 
583
    mov   esi,edx             ; check y pos
584
    add   esi,ebx
585
    cmp   esi,[0xfe04]
586
    jbe   y_pos_ok
587
    mov   [edi+4],dword 0
588
    mov   ebx,0
589
  y_pos_ok:
590
 
591
    mov   esi,ecx             ; check x size
592
    add   esi,eax
593
    cmp   esi,[0xfe00]
594
    jbe   x_size_ok
595
    mov   ecx,[0xfe00]
596
    mov   [edi+8],ecx
597
  x_size_ok:
598
 
599
    mov   esi,edx             ; check y size
600
    add   esi,ebx
601
    cmp   esi,[0xfe04]
602
    jbe   y_size_ok
603
    mov   edx,[0xfe04]
604
    mov   [edi+12],edx
605
  y_size_ok:
606
 
607
    popad
608
 
609
    ret
610
 
611
 
612
uglobal
613
  new_window_starting dd 0
614
endg
615
 
616
 
617
sys_window_mouse:
618
 
619
    push  eax
620
 
621
    mov   eax,[timer_ticks] ;[0xfdf0]
622
    cmp   [new_window_starting],eax
623
    jb    swml1
624
 
625
    mov   [0xfff4],byte 0  ; no mouse background
626
    mov   [0xfff5],byte 0  ; draw mouse
627
 
628
    mov   [new_window_starting],eax
629
 
630
  swml1:
631
 
632
    pop   eax
633
 
634
    ret
635
 
636
 
637
 
638
 
114 mikedld 639
drawwindow_I_caption:
640
 
1 ha 641
        mov   ecx,[edx+20]   ; grab bar
642
        push  ecx
643
        mov   esi,edx
644
        mov   edx,[esi+04]
645
        add   edx,1
646
        mov   ebx,[esi+04]
114 mikedld 647
        add   ebx,21
1 ha 648
        mov   eax,[esi+04]
649
        add   eax,[esi+12]
650
        cmp   ebx,eax
114 mikedld 651
        jb    .wdsizeok
1 ha 652
        mov   ebx,eax
114 mikedld 653
  .wdsizeok:
1 ha 654
        push  ebx
114 mikedld 655
  .drwi:
1 ha 656
        mov   ebx,edx
657
        shl   ebx,16
658
        add   ebx,edx
659
        mov   eax,[esi+00]
660
        inc   eax
661
        shl   eax,16
662
        add   eax,[esi+00]
663
        add   eax,[esi+8]
664
        sub   eax,1
665
        push  edx
666
        mov   edx,0x80000000
667
        mov   ecx,[esi+20]
668
        and   ecx,edx
669
        cmp   ecx,edx
114 mikedld 670
        jnz   .nofa
1 ha 671
        mov   ecx,[esi+20]
672
        sub   ecx,0x00040404
673
        mov   [esi+20],ecx
674
        and   ecx,0x00ffffff
114 mikedld 675
        jmp   .faj
676
  .nofa:
1 ha 677
        mov   ecx,[esi+20]
678
        and   ecx,0x00ffffff
114 mikedld 679
  .faj:
1 ha 680
        pop   edx
681
        mov   edi,0
682
        call  [draw_line]
683
        inc   edx
684
        cmp   edx,[esp]
114 mikedld 685
        jb    .drwi
1 ha 686
        add   esp,4
687
        pop   ecx
688
        mov   [esi+20],ecx
689
 
114 mikedld 690
        ret
691
 
692
 
693
drawwindow_I:
694
 
695
        pushad
696
 
697
        mov   esi,[edx+24]   ; rectangle
698
        mov   eax,[edx+0]
699
        shl   eax,16
700
        add   eax,[edx+0]
701
        add   eax,[edx+8]
702
        mov   ebx,[edx+04]
703
        shl   ebx,16
704
        add   ebx,[edx+4]
705
        add   ebx,[edx+12]
706
        call  draw_rectangle
707
 
708
        call    drawwindow_I_caption
709
 
1 ha 710
        mov   edx,[esi+04]      ; inside work area
711
        add   edx,21+5
712
        mov   ebx,[esi+04]
713
        add   ebx,[esi+12]
714
        cmp   edx,ebx
715
        jg    noinside
716
        mov   eax,1
717
        mov   ebx,21
718
        mov   ecx,[esi+8]
719
        mov   edx,[esi+12]
720
        mov   edi,[esi+16]
721
        call  [drawbar]
722
      noinside:
723
 
724
        popad
725
 
726
        ret
727
 
728
 
729
draw_rectangle:
730
 
731
r_eax equ [esp+28]   ; x start
732
r_ax  equ [esp+30]   ; x end
733
r_ebx equ [esp+16]   ; y start
734
r_bx  equ [esp+18]   ; y end
735
;esi                 ; color
736
 
737
        pushad
738
 
739
        mov   ecx,esi          ; yb,xb -> yb,xe
740
        mov   eax, r_eax
741
        rol   eax, 16
742
        mov   ebx,r_ebx
743
        shl   ebx,16
744
        mov   bx,r_ebx
745
        xor   edi, edi
746
        call  [draw_line]
747
 
748
        mov   ebx,r_bx         ; ye,xb -> ye,xe
749
        shl   ebx,16
750
        mov   bx,r_bx
751
        call  [draw_line]
752
 
753
        mov   ecx,esi          ; ya,xa -> ye,xa
754
        mov   eax,r_eax
755
        shl   eax,16
756
        mov   ax,r_eax
757
        mov   ebx,r_ebx
758
        shl   ebx,16
759
        mov   bx,r_bx
760
        mov   edi,0
761
        call  [draw_line]
762
 
763
        mov   eax,r_ax       ; ya,xe -> ye,xe
764
        shl   eax,16
765
        mov   ax,r_ax
766
        call  [draw_line]
767
 
768
        popad
769
        ret
770
 
771
 
114 mikedld 772
drawwindow_III_caption:
1 ha 773
 
774
        mov   ecx,[edx+20]                       ; GRAB BAR
775
        push  ecx
776
        mov   esi,edx
777
        mov   edx,[esi+04]
778
        add   edx,4
779
        mov   ebx,[esi+04]
780
        add   ebx,20
781
        mov   eax,[esi+04]
782
        add   eax,[esi+12]
783
        cmp   ebx,eax
114 mikedld 784
        jb    .wdsizeok
1 ha 785
        mov   ebx,eax
114 mikedld 786
  .wdsizeok:
1 ha 787
        push  ebx
114 mikedld 788
  .drwi:
1 ha 789
        mov   ebx,edx
790
        shl   ebx,16
791
        add   ebx,edx
792
        mov   eax,[esi+00]
793
        shl   eax,16
794
        add   eax,[esi+00]
795
        add   eax,[esi+8]
796
        add   eax,4*65536-4
797
        mov   ecx,[esi+20]
798
        test  ecx,0x40000000
114 mikedld 799
        jz    .nofa
1 ha 800
        add   ecx,0x040404
114 mikedld 801
  .nofa:
1 ha 802
        test  ecx,0x80000000
114 mikedld 803
        jz    .nofa2
1 ha 804
        sub   ecx,0x040404
114 mikedld 805
  .nofa2:
1 ha 806
        mov   [esi+20],ecx
807
        and   ecx,0xffffff
808
        xor   edi, edi
809
        call  [draw_line]
810
        inc   edx
811
        cmp   edx,[esp]
114 mikedld 812
        jb    .drwi
1 ha 813
        add   esp,4
814
        pop   ecx
815
        mov   [esi+20],ecx
816
 
114 mikedld 817
        ret
818
 
819
 
820
drawwindow_III:
821
 
822
        pushad
823
 
824
        mov   edi,edx                              ; RECTANGLE
825
        mov   eax,[edi+0]
826
        shl   eax,16
827
        mov   ax,[edi+0]
828
        add   ax,[edi+8]
829
        mov   ebx,[edi+4]
830
        shl   ebx,16
831
        mov   bx,[edi+4]
832
        add   bx,[edi+12]
833
        mov   esi,[edi+24]
834
        shr   esi,1
835
        and   esi,0x007f7f7f
836
        push  esi
837
        call  draw_rectangle
838
        mov   ecx,3
839
      dw3l:
840
        add   eax,1*65536-1
841
        add   ebx,1*65536-1
842
        mov   esi,[edi+24]
843
        call  draw_rectangle
844
        dec   ecx
845
        jnz   dw3l
846
        pop   esi
847
        add   eax,1*65536-1
848
        add   ebx,1*65536-1
849
        call  draw_rectangle
850
 
851
        call    drawwindow_III_caption
852
 
1 ha 853
        mov   edx,[esi+04]                       ; WORK AREA
854
        add   edx,21+5
855
        mov   ebx,[esi+04]
856
        add   ebx,[esi+12]
857
        cmp   edx,ebx
858
        jg    noinside2
859
        mov   eax,5
860
        mov   ebx,20
861
        mov   ecx,[esi+8]
862
        mov   edx,[esi+12]
863
        sub   ecx,4
864
        sub   edx,4
865
        mov   edi,[esi+16]
866
        call  [drawbar]
867
      noinside2:
868
 
869
        popad
870
 
871
        ret
872
 
873
 
874
 
875
; activate window
876
align 4
877
windowactivate:
878
 
879
        ; esi = abs mem position in stack 0xC400+
880
 
881
        pushad
102 poddubny 882
 
883
     ; if type of current active window is 3,
884
     ; it must be redrawn
885
        mov   eax, [0x3004]
886
        movzx eax, word [0xC400 + eax*2]
887
        shl   eax, 5
888
        add   eax, window_data
889
        mov   ebx, [eax + WDATA.cl_workarea]
890
        and   ebx, 0x0f000000
891
        cmp   ebx, 0x03000000
892
        jne   @f
893
        mov   [eax + WDATA.fl_redraw], byte 1
894
     @@:
895
 
33 mario79 896
        push   esi
1 ha 897
      movzx   eax, word [esi] ; ax <- process no
898
      movzx   eax, word [0xC000+eax*2] ; ax <- position in window stack
899
 
900
        xor   esi, esi        ; drop others
901
      waloop:
902
        cmp   esi, dword [0x3004]
903
        jae   wacont
904
        inc   esi
905
        lea   edi, [0xC000 + esi*2]
906
        mov   bx, [edi] ; position of the current process
907
        cmp   bx, ax
908
        jbe   @f
909
        dec   bx       ; upper? => drop!
910
        mov   [edi], bx
911
      @@:
912
        jmp   waloop
913
      wacont:
914
                            ; set to no 1
915
        pop   esi           ;   esi = pointer at 0xC400
916
 
917
      movzx   eax, word [esi]
918
        mov   bx, [0x3004]  ; number of processes
919
        mov   [0xC000+eax*2], bx     ; this is the last (and the upper)
920
 
921
        ; update on screen -window stack
922
        xor   esi, esi
923
      waloop2:
924
        mov   edi, [0x3004]
925
        cmp   esi, edi
926
        jae   wacont2
927
        inc   esi
928
        movzx ebx, word [esi*2 + 0xC000]
929
        mov   [ebx*2 + 0xC400], si
930
        jmp   waloop2
931
      wacont2:
932
        mov   [0xf400], byte 0           ; empty keyboard buffer
933
        mov   [0xf500], byte 0           ; empty button buffer
934
        popad
935
        ret
936
 
937
 
938
; check if window is necessary to draw
939
 
940
checkwindowdraw:
941
 
942
        ; edi = position in window_data+
943
 
102 poddubny 944
        mov   eax, [edi + WDATA.cl_workarea]
945
        and   eax, 0x0f000000
946
        cmp   eax, 0x03000000
947
        je    .return_yes      ; window type 3
948
 
1 ha 949
        mov   esi, edi
950
        sub   esi, window_data
951
        shr   esi, 5
952
 
953
        ; esi = process number
954
 
955
        movzx eax, word [0xC000 + esi * 2] ; get value of the curr process
956
        lea   esi, [0xC400 + eax * 2]      ; get address of this process at 0xC400
957
 
958
        push  esi
959
 
960
      .new_check:
961
 
962
        pop   esi
963
        add   esi, 2
964
        push  esi
965
 
966
        mov   eax, [0x3004]
967
        lea   eax, word [0xC400 + eax * 2] ; number of the upper window
968
 
969
        cmp   esi, eax
970
        ja    .all_wnds_to_top
971
 
972
        movzx eax, word [esi]
973
        shl   eax, 5
102 poddubny 974
        cmp   [0x3000 + eax + 0xa], byte 9
975
        je    .new_check                    ; skip dead windows
1 ha 976
 
102 poddubny 977
        lea   esi, [eax+window_data]
978
 
979
        mov   ebx, [edi+4]  ; y0
1 ha 980
        mov   edx, [edi+12]
102 poddubny 981
        add   edx, ebx      ; y0e
1 ha 982
 
102 poddubny 983
        mov   ecx, [esi+4]  ; y  ; y check
984
        cmp   ecx, edx
985
        jae   .new_check     ; y < y0e
1 ha 986
        mov   eax, [esi+12]
102 poddubny 987
        add   ecx, eax       ; ye
988
        cmp   ebx, ecx       ; y0 >= ye
1 ha 989
        ja    .new_check
990
 
102 poddubny 991
        mov   eax, [edi+0]   ; x0
1 ha 992
        mov   ecx, [edi+8]
102 poddubny 993
        add   ecx, eax       ; x0e
1 ha 994
 
102 poddubny 995
        mov   edx, [esi+0]   ; x ; x check
1 ha 996
        cmp   edx, ecx
102 poddubny 997
        jae   .new_check     ; x < x0e
1 ha 998
        mov   ecx, [esi+8]
999
        add   edx, ecx
1000
        cmp   eax, edx
1001
        ja    .new_check
1002
 
1003
        pop   esi
102 poddubny 1004
  .return_yes:
1 ha 1005
        mov   ecx,1   ; overlap some window
1006
        ret
1007
 
1008
  .all_wnds_to_top:
1009
 
1010
        pop   esi
1011
 
1012
        xor   ecx, ecx       ; passed all windows to top
1013
        ret
1014
 
1015
 
1016
 
1017
 
1018
waredraw:     ; if redraw necessary at activate
1019
 
1020
        pushad
1021
 
1022
        call  checkwindowdraw      ; draw window on activation ?
1023
        test  ecx, ecx
1024
        jz    .do_not_draw
1025
 
1026
        popad
1027
        mov   [0xfb44], byte 1     ; do draw mouse
1028
        call  windowactivate
1029
 
1030
        ; update screen info
1031
        pushad
1032
        mov   edi, [0x3004] ; the last process (number)
1033
        movzx esi, word [0xC400 + edi * 2]
1034
        shl   esi, 5
1035
        add   esi, window_data
1036
 
1037
        ; coordinates of the upper window
1038
        mov   eax, [esi+00] ; cx
1039
        mov   ebx, [esi+04] ; cy
1040
        mov   ecx, [esi+08] ; sx
1041
        mov   edx, [esi+12] ; sy
1042
 
1043
        add   ecx, eax       ; ecx = x_end
1044
        add   edx, ebx       ; edx = y_end
1045
 
1046
        mov   edi, [0x3004]
1047
        movzx esi, word [0xC400 + edi * 2]
102 poddubny 1048
        call  setscreen
1 ha 1049
        popad
1050
 
1051
        mov   [edi+31],byte 1  ; redraw flag for app
1052
        mov   [0xfb44],byte 0  ; mouse down checks
1053
 
1054
        ret
1055
 
1056
     .do_not_draw:
1057
 
1058
        popad
1059
 
1060
        call  windowactivate
1061
        mov   [0xfb44],byte 0  ; mouse down checks
1062
        mov   [0xfff4],byte 0  ; no mouse background
1063
        mov   [0xfff5],byte 0  ; draw mouse
1064
        ret
1065
 
1066
 
105 poddubny 1067
; eax = window number on screen
1068
; corrupts registers and [dl*]
1069
minimize_window:
1070
        movzx eax, word [0xC400+eax*2]
1071
        shl   eax, 5
1072
        add   eax, window_data
1073
        test  [eax+WDATA.fl_wstate], WSTATE_MINIMIZED
1074
        jnz   .skip_redrawings
1075
        pushfd
1076
        cli
1077
        or    [eax+WDATA.fl_wstate], WSTATE_MINIMIZED
1078
        mov   edi, eax
112 poddubny 1079
        ;call  calculatescreen
114 mikedld 1080
        mov   eax, [edi+WDATA.box.left]
105 poddubny 1081
        mov   [dlx], eax
112 poddubny 1082
        mov   ecx, eax
114 mikedld 1083
        add   ecx, [edi+WDATA.box.width]
112 poddubny 1084
        mov   [dlxe], ecx
114 mikedld 1085
        mov   ebx, [edi+WDATA.box.top]
112 poddubny 1086
        mov   [dly], ebx
1087
        mov   edx, ebx
114 mikedld 1088
        add   edx, [edi+WDATA.box.height]
112 poddubny 1089
        mov   [dlye], edx
1090
        call  calculatescreen
105 poddubny 1091
        xor   esi, esi
1092
        xor   eax, eax
1093
        call  redrawscreen
1094
        popfd
1095
.skip_redrawings:
1096
        ret
1097
 
1098
; eax = window number on screen
1099
; corrupts registers and [dl*]
1100
restore_minimized_window:
1101
        pushfd
1102
        cli
1103
        movzx esi, word [0xC400+eax*2]
1104
        mov   edi, esi
1105
        shl   edi, 5
1106
        add   edi, window_data
1107
        test  [edi+WDATA.fl_wstate], WSTATE_MINIMIZED
1108
        jz    .skip_redrawings
1109
        mov   [edi+WDATA.fl_redraw], 1
1110
        and   [edi+WDATA.fl_wstate], not WSTATE_MINIMIZED
1111
        cmp   eax, [0x3004] ; the uppermost window
1112
        jnz   .no_uppermost
114 mikedld 1113
        mov   eax, [edi+WDATA.box.left]
1114
        mov   ebx, [edi+WDATA.box.top]
105 poddubny 1115
        mov   ecx, eax
1116
        mov   edx, ebx
114 mikedld 1117
        add   ecx, [edi+WDATA.box.width]
1118
        add   edx, [edi+WDATA.box.height]
105 poddubny 1119
        call  setscreen
1120
        jmp   .done
1121
.no_uppermost:
114 mikedld 1122
        mov   eax, [edi+WDATA.box.left]
1123
        mov   ebx, [edi+WDATA.box.top]
112 poddubny 1124
        mov   ecx, eax
1125
        mov   edx, ebx
114 mikedld 1126
        add   ecx, [edi+WDATA.box.width]
1127
        add   edx, [edi+WDATA.box.height]
105 poddubny 1128
        call  calculatescreen
1129
.done:
1130
        mov   [0xfff4],byte 0 ; no mouse under
1131
.skip_redrawings:
1132
        popfd
1133
        ret
1134
 
1135
 
1 ha 1136
iglobal
1137
  window_moving   db 'K : Window - move/resize',13,10,0
1138
  window_moved    db 'K : Window - done',13,10,0
1139
endg
1140
 
1141
; check window touch
1142
align 4
1143
checkwindows:
1144
        pushad
1145
 
105 poddubny 1146
        cmp   [window_minimize], 0
1147
        je    .no_minimizing
1148
        mov   eax, [0x3004]       ; the uppermost window
1149
        mov   bl, 0
1150
        xchg  [window_minimize], bl
1151
        cmp   bl, 1
1152
        jne   .restore
1153
        call  minimize_window
1154
        jmp   .continue
1155
  .restore:
1156
        call  restore_minimized_window
1157
  .continue:
1158
  .no_minimizing:
1 ha 1159
 
1160
        cmp   [0xfb40],byte 0    ; mouse buttons pressed ?
1161
        jne   .mouse_buttons_pressed
1162
        popad
1163
        ret
1164
    .mouse_buttons_pressed:
1165
 
1166
        mov   esi,[0x3004]
1167
        inc   esi
1168
 
1169
      cwloop:
1170
        cmp   esi,2
1171
        jb   .exit
105 poddubny 1172
 
1 ha 1173
        dec   esi
1174
        movzx edi, word [0xC400 + esi * 2] ; ebx
1175
        shl   edi, 5
1176
        add   edi, window_data
1177
;        mov   edi, ebx
1178
        mov   ecx, [edi+0]
1179
        mov   edx, [edi+4]
1180
 
1181
        mov   eax,ecx
1182
        mov   ebx,edx
41 mikedld 1183
        test    [edi+WDATA.fl_wstate],WSTATE_MINIMIZED
1184
        jnz     cwloop
1 ha 1185
 
1186
       movzx  eax, word [0xfb0a]
1187
       movzx  ebx, word [0xfb0c]
1188
 
1189
        cmp   ecx, eax
1190
        jae   cwloop
1191
        cmp   edx, ebx
1192
        jae   cwloop
1193
        add   ecx, [edi+8]
1194
        add   edx, [edi+12]
1195
        cmp   eax, ecx
1196
        jae   cwloop
1197
        cmp   ebx, edx
1198
        jae   cwloop
1199
 
1200
        pushad
1201
        mov   eax, esi
1202
        mov   ebx, [0x3004]
1203
        cmp   eax, ebx      ; is this window active?
1204
        jz    .move_resize_window
1205
 
1206
        ; eax = position in windowing stack
1207
        ; redraw must ?
1208
        lea   esi, [0xC400 + esi * 2]
1209
        call  waredraw
1210
        add   esp, 32
1211
 
1212
      .exit:
1213
        popad
1214
        ret
1215
 
1216
   .move_resize_window:    ; MOVE OR RESIZE WINDOW
1217
 
1218
        popad
1219
 
1220
        ; Check for user enabled fixed window
1221
        mov   edx, [edi+0x14]
1222
        and   edx, 0x0f000000
1223
        cmp   edx, 0x01000000
1224
        jne   .window_move_enabled_for_user
1225
        popad
1226
        ret
1227
      .window_move_enabled_for_user:
1228
 
41 mikedld 1229
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
1230
        jnz     .no_resize_2
1231
 
1 ha 1232
        mov   [do_resize_from_corner],byte 0   ; resize for skinned window
1233
        mov   edx, [edi+0x10]
1234
        and   edx, 0x0f000000
1235
        cmp   edx, 0x02000000
1236
        jb    .no_resize_2 ; not type 2 wnd
1237
 
1238
        mov   edx, [edi+4]
1239
        add   edx, [edi+12]
1240
        sub   edx, 6       ; edx = y_end - 6
1241
        cmp   ebx, edx     ; ebx = mouse_y
1242
        jb    .no_resize_2
1243
        mov   [do_resize_from_corner],byte 1
1244
        jmp   .continue
1245
      .no_resize_2:
1246
 
41 mikedld 1247
        push    eax
1248
        call    get_titlebar_height
1249
        add     eax,[edi+4]
1250
        cmp     ebx,eax
1251
        pop     eax
1252
        jae     .exit
1 ha 1253
 
1254
     .continue:
1255
 
1256
        push  esi
1257
        mov   esi, window_moving
1258
        call  sys_msg_board_str
1259
        pop   esi
1260
 
105 poddubny 1261
        mov   ecx, [timer_ticks]     ; double-click ?
1 ha 1262
        mov   edx, ecx
1263
        sub   edx, [latest_window_touch]
1264
        mov   [latest_window_touch], ecx
1265
        mov   [latest_window_touch_delta], edx
1266
 
1267
        mov   cl, [0xfb40]     ; save for shade check
1268
        mov   [do_resize], cl
1269
     no_emulation_righ_button:
1270
        mov   ecx, [edi+0]
1271
        mov   edx, [edi+4]
1272
 
1273
        push  eax ecx edx
1274
        mov   [dlx], ecx      ; save for drawlimits
1275
        mov   [dly], edx
1276
        mov   eax, [edi+8]
1277
        add   ecx, eax
1278
        mov   eax, [edi+12]
1279
        add   edx, eax
1280
        mov   [dlxe], ecx
1281
        mov   [dlye], edx
1282
        pop   edx ecx eax
1283
 
1284
        sub   eax, ecx
1285
        sub   ebx, edx
1286
 
1287
        mov   esi, [0xfb0a]
1288
        mov   [0xf300], esi
1289
 
1290
        pushad           ; wait for putimages to finish
1291
;        mov   eax,5
1292
;        call  delay_hs
1293
        mov   eax,[edi+0]
1294
        mov   [npx],eax
1295
        mov   eax,[edi+4]
1296
        mov   [npy],eax
1297
        popad
1298
 
1299
        push eax                  ; save old coordinates
1300
        mov   ax,[edi+00]
1301
        mov   word [oldc+00],ax
1302
        mov   ax,[edi+04]
1303
        mov   word [oldc+04],ax
1304
        mov   ax,[edi+8]
1305
        mov   word [oldc+8],ax
1306
        mov   word [npxe],ax
1307
        mov   ax,[edi+12]
1308
        mov   word [oldc+12],ax
1309
        mov   word [npye],ax
1310
        pop eax
1311
 
41 mikedld 1312
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
1313
        jnz     @f
1 ha 1314
        call  drawwindowframes
41 mikedld 1315
    @@:
1 ha 1316
 
1317
        mov   [reposition],0
1318
        mov   [0xfb44],byte 1   ; no reaction to mouse up/down
1319
 
1320
        ; move window
1321
 
1322
      newchm:
1323
 
1324
        mov   [0xfff5],byte 1
1325
 
1326
        call  checkidle
1327
 
1328
        call  checkEgaCga
1329
 
1330
        mov   [0xfff4],byte 0
1331
 
1332
        call  [draw_pointer]
1333
 
1334
        pushad
1335
        call   stack_handler
1336
        popad
1337
 
1338
        mov   esi,[0xf300]
1339
        cmp   esi,[0xfb0a]
1340
        je    cwb
1341
 
1342
        mov   cx,[0xfb0a]
1343
        mov   dx,[0xfb0c]
1344
        sub   cx,ax
1345
        sub   dx,bx
1346
 
1347
        push  ax
1348
        push  bx
1349
 
41 mikedld 1350
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
1351
        jnz     @f
1 ha 1352
        call  drawwindowframes
41 mikedld 1353
    @@:
1 ha 1354
 
1355
        mov   ax,[0xfe00]
1356
        mov   bx,[0xfe04]
1357
 
1358
        cmp   [do_resize_from_corner],1
1359
        je    no_new_position
1360
 
1361
        mov   word [npx],word 0     ; x repos ?
1362
        cmp   ax,cx
1363
        jb    noreposx
1364
        mov   [reposition],1
1365
        sub   ax,word [npxe]
1366
        mov   word [npx],ax
1367
        cmp   ax,cx
1368
        jb    noreposx
1369
        mov   word [npx],cx
1370
      noreposx:
1371
 
1372
        mov   word [npy],word 0     ; y repos ?
1373
        cmp   bx,dx
1374
        jb    noreposy
1375
        mov   [reposition],1
1376
        sub   bx,word [npye]
1377
        mov   word [npy],bx
1378
        cmp   bx,dx
1379
        jb    noreposy
1380
        mov   word [npy],dx
1381
      noreposy:
1382
 
1383
      no_new_position:
1384
 
1385
        cmp   [do_resize_from_corner],0    ; resize from right corner
1386
        je    norepos_size
1387
        pushad
1388
 
1389
        mov   edx,edi
1390
        sub   edx,window_data
1391
        shr   edx,5
1392
        shl   edx,8
1393
        add   edx,0x80000                 ; process base at 0x80000+
1394
 
1395
        movzx eax,word [0xfb0a]
1396
        cmp   eax,[edi+0]
1397
        jb    nnepx
1398
        sub   eax,[edi+0]
57 mikedld 1399
        cmp   eax,32 ; [edx+0x90+8]
1 ha 1400
        jge   nnepx2
57 mikedld 1401
        mov   eax,32 ; [edx+0x90+8]
1 ha 1402
      nnepx2:
1403
        mov   [npxe],eax
1404
      nnepx:
1405
 
57 mikedld 1406
        call    get_rolledup_height
41 mikedld 1407
        mov     ebx,eax
1 ha 1408
        movzx eax,word [0xfb0c]
1409
        cmp   eax,[edi+4]
1410
        jb    nnepy
1411
        sub   eax,[edi+4]
41 mikedld 1412
        cmp     eax,ebx ; [edx+0x90+12]
1413
        jge     nnepy2
1414
        mov     eax,ebx ; [edx+0x90+12]
1 ha 1415
      nnepy2:
1416
        mov   [npye],eax
1417
      nnepy:
1418
 
1419
        mov   [reposition],1
1420
 
1421
        popad
1422
      norepos_size:
1423
 
1424
        pop   bx
1425
        pop   ax
41 mikedld 1426
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
1427
        jnz     @f
1 ha 1428
        call  drawwindowframes
41 mikedld 1429
    @@:
1 ha 1430
 
1431
        mov   esi,[0xfb0a]
1432
        mov   [0xf300],esi
1433
 
1434
      cwb:
1435
        cmp   [0xfb40],byte 0
1436
        jne   newchm
1437
                                     ; new position done
41 mikedld 1438
        mov     [0xfff5],byte 1
1439
        mov     cl,0
1440
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
1441
        jnz     @f
1442
        mov     cl,[reposition]
1443
        call    drawwindowframes
1 ha 1444
 
1445
        mov   eax,[npx]
1446
        mov   [edi+0],eax
1447
        mov   eax,[npy]
1448
        mov   [edi+4],eax
1449
        mov   eax,[npxe]
1450
        mov   [edi+8],eax
1451
        mov   eax,[npye]
1452
        mov   [edi+12],eax
1453
 
41 mikedld 1454
    @@: mov     [reposition],cl
1455
 
52 mikedld 1456
        cmp   [reposition],1         ; save new position and size
1457
        jne   no_bounds_save
1 ha 1458
        push  esi edi ecx
1459
        mov   esi,edi
57 mikedld 1460
        mov   ecx,2
1461
        test  [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP or WSTATE_MAXIMIZED
1462
        jnz   @f
1463
        add   ecx,2
1464
    @@: sub   edi,window_data
1 ha 1465
        shr   edi,5
1466
        shl   edi,8
1467
        add   edi,0x80000+0x90
1468
        cld
1469
        rep   movsd
1470
        pop   ecx edi esi
52 mikedld 1471
      no_bounds_save:
1 ha 1472
 
1473
        pushad                             ; WINDOW SHADE/FULLSCREEN
1474
 
1475
        cmp   [reposition],1
1476
        je    no_window_sizing
1477
        mov   edx,edi
1478
        sub   edx,window_data
1479
        shr   edx,5
1480
        shl   edx,8
1481
        add   edx,0x80000                 ; process base at 0x80000+
1482
 
1483
        cmp   [do_resize],2               ; window shade ?
41 mikedld 1484
        jne   no_window_shade
1 ha 1485
        mov   [reposition],1
1486
 
41 mikedld 1487
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
1488
        jnz     wnd_rolldown
1489
  wnd_rollup:
1490
        or      [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
1491
        call    get_rolledup_height
1492
        jmp     @f
1493
  wnd_rolldown:
1494
        and     [edi+WDATA.fl_wstate],not WSTATE_ROLLEDUP
1495
        mov     eax,[edx+0x90+BOX.height]
1496
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
1497
        jz      @f
1498
        mov     eax,[screen_workarea.bottom]
1499
        sub     eax,[screen_workarea.top]
114 mikedld 1500
    @@: mov     [edi+WDATA.box.height],eax
1 ha 1501
 
1502
      no_window_shade:
1503
 
1504
        cmp   [do_resize],1               ; fullscreen/restore ?
1505
        jne   no_fullscreen_restore
1506
        cmp   [latest_window_touch_delta],dword 50
1507
        jg    no_fullscreen_restore
1508
        mov   [reposition],1
41 mikedld 1509
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
1510
        jnz     restore_from_fullscreen
1511
        or      [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
1512
        mov     eax,[screen_workarea.left]
114 mikedld 1513
        mov     [edi+WDATA.box.left],eax
41 mikedld 1514
        sub     eax,[screen_workarea.right]
1515
        neg     eax
114 mikedld 1516
        mov     [edi+WDATA.box.width],eax
41 mikedld 1517
        mov     eax,[screen_workarea.top]
114 mikedld 1518
        mov     [edi+WDATA.box.top],eax
41 mikedld 1519
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
1520
        jnz     @f
1521
        sub     eax,[screen_workarea.bottom]
1522
        neg     eax
114 mikedld 1523
        mov     [edi+WDATA.box.height],eax
41 mikedld 1524
    @@:
1 ha 1525
        jmp   no_fullscreen_restore
1526
      restore_from_fullscreen:
41 mikedld 1527
        and     [edi+WDATA.fl_wstate],not WSTATE_MAXIMIZED
114 mikedld 1528
        push    [edi+WDATA.box.height]
1 ha 1529
        push  edi                         ; restore
1530
        lea   esi, [edx + 0x90]
1531
        mov   ecx,4
1532
        cld
1533
        rep   movsd
1534
        pop   edi
41 mikedld 1535
        pop     eax
1536
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
1537
        jz      @f
114 mikedld 1538
        mov     [edi+WDATA.box.height],eax
41 mikedld 1539
    @@:
1 ha 1540
 
1541
      no_fullscreen_restore:
1542
 
1543
        mov   eax,[edi+4]                 ; check Y inside screen
1544
        add   eax,[edi+12]
1545
        cmp   eax,[0xfe04]
1546
        jbe   no_window_sizing
1547
        mov   eax,[edi+0]                 ; check X inside screen
1548
        add   eax,[edi+8]
1549
        cmp   eax,[0xfe00]
1550
        jbe   no_window_sizing
1551
        mov   eax,[0xfe00]
1552
        sub   eax,[edi+8]
1553
        mov   [edi+0],eax
1554
        mov   eax,[0xfe04]
1555
        sub   eax,[edi+12]
1556
        mov   [edi+4],eax
1557
      no_window_sizing:
1558
 
1559
        popad
1560
 
1561
        cmp   [reposition],0
1562
        je    retwm
1563
 
1564
        mov   [0xfff5],byte 1 ; no mouse
1565
 
112 poddubny 1566
 
1 ha 1567
        push  eax ebx ecx edx
112 poddubny 1568
        mov   eax,[edi+00]
1569
        mov   ebx,[edi+04]
1570
        mov   ecx,[edi+8]
1571
        mov   edx,[edi+12]
1572
        add   ecx,eax
1573
        add   edx,ebx
1574
        call  calculatescreen
1575
 
1 ha 1576
        mov   eax,[oldc+00]
1577
        mov   ebx,[oldc+04]
1578
        mov   ecx,[oldc+8]
1579
        mov   edx,[oldc+12]
1580
        add   ecx,eax
1581
        add   edx,ebx
1582
        call  calculatescreen
1583
        pop   edx ecx ebx eax
1584
 
1585
        mov   eax,edi
1586
        call  redrawscreen
1587
 
112 poddubny 1588
 
1589
        mov     [edi+WDATA.fl_redraw],1
1590
 
1 ha 1591
        mov   ecx,100         ; wait to avoid mouse residuals
1592
      waitre2:
1593
        mov   [0xfff5],byte 1
1594
        call  checkidle
41 mikedld 1595
        cmp     [edi+WDATA.fl_redraw],0
1 ha 1596
        jz    retwm
1597
        loop  waitre2
1598
 
1599
      retwm:
1600
 
1601
        mov   [0xfff5],byte 0 ; mouse pointer
1602
        mov   [0xfff4],byte 0 ; no mouse under
1603
        mov   [0xfb44],byte 0 ; react to mouse up/down
1604
 
1605
        mov    esi,window_moved
1606
        call   sys_msg_board_str
1607
 
1608
        popad
1609
 
1610
        ret
1611
 
1612
 
1613
uglobal
1614
  add_window_data            dd  0
1615
  do_resize_from_corner      db  0x0
1616
  reposition                 db  0x0
1617
  latest_window_touch        dd  0x0
1618
  latest_window_touch_delta  dd  0x0
1619
 
1620
  do_resize db 0x0
1621
 
1622
  oldc    dd 0x0,0x0,0x0,0x0
1623
 
1624
  dlx     dd 0x0
1625
  dly     dd 0x0
1626
  dlxe    dd 0x0
1627
  dlye    dd 0x0
1628
 
1629
  npx     dd 0x0
1630
  npy     dd 0x0
1631
  npxe    dd 0x0
1632
  npye    dd 0x0
1633
 
1634
  mpx     dd 0x0
1635
  mpy     dd 0x0
1636
endg
1637
 
1638
 
1639
; draw negative window frames
1640
 
1641
drawwindowframes:
1642
 
1643
        pushad
1644
 
1645
        mov   eax,[npx]
1646
        shl   eax,16
1647
        add   eax,[npx]
1648
        add   eax,[npxe]
1649
        add   eax,65536*1-1
1650
        mov   ebx,[npy]
1651
        shl   ebx,16
1652
        add   ebx,[npy]
1653
        mov   ecx,0x01000000
1654
        push  edi
1655
        mov   edi,1
1656
        call  [draw_line]
1657
        pop   edi
1658
 
1659
        mov   eax,[npx]
1660
        shl   eax,16
1661
        add   eax,[npx]
1662
        add   eax,[npxe]
1663
        add   eax,65536*1-1
1664
        mov   ebx,[npy]
1665
        add   ebx,[npye]
1666
        shl   ebx,16
1667
        add   ebx,[npy]
1668
        add   ebx,[npye]
1669
        mov   ecx,0x01000000
1670
        push  edi
1671
        mov   edi,1
1672
        call  [draw_line]
1673
        pop   edi
1674
 
1675
        mov   eax,[npx]
1676
        shl   eax,16
1677
        add   eax,[npx]
1678
        mov   ebx,[npy]
1679
        shl   ebx,16
1680
        add   ebx,[npy]
1681
        add   ebx,[npye]
1682
        mov   ecx,0x01000000
1683
        push  edi
1684
        mov   edi,1
1685
        call  [draw_line]
1686
        pop   edi
1687
 
1688
        mov   eax,[npx]
1689
        add   eax,[npxe]
1690
        shl   eax,16
1691
        add   eax,[npx]
1692
        add   eax,[npxe]
1693
        mov   ebx,[npy]
1694
        shl   ebx,16
1695
        add   ebx,[npy]
1696
        add   ebx,[npye]
1697
        mov   ecx,0x01000000
1698
        push  edi
1699
        mov   edi,1
1700
        call  [draw_line]
1701
        mov   edi,[0x3000]
1702
        shl   edi,5
1703
        add   edi,window_data
1704
        mov   [edi+30],byte 1
1705
        pop   edi
1706
 
1707
        popad
1708
 
1709
        ret
1710
 
1711
 
1712
 
1713
random_shaped_window:
1714
 
1715
;
1716
;  eax = 0    giving address of data area
1717
;      ebx    address
1718
;  ebx = 1    shape area scale
1719
;      ebx    2^ebx scale
1720
 
1721
     test eax, eax
1722
     jne  rsw_no_address
1723
     mov  eax,[0x3000]
1724
     shl  eax,8
1725
 
1726
     mov  [eax+0x80000+0x80],ebx
1727
   rsw_no_address:
1728
 
1729
     cmp  eax,1
1730
     jne  rsw_no_scale
1731
     mov  eax,[0x3000]
1732
     shl  eax,8
1733
     mov  [eax+0x80000+0x84],bl
1734
   rsw_no_scale:
1735
 
1736
     ret
1737