OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [demos/] [nanox/] [move.c] - Blame information for rev 673

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
#include <stdio.h>
2
#define MWINCLUDECOLORS
3
#include "nano-X.h"
4
/*
5
 * Demo to test child window movement and redrawing
6
 */
7
int
8
main(int ac,char **av)
9
{
10
  GR_COORD      offset_x = 0, offset_y = 0;
11
  GR_WINDOW_ID  window1, subwindow1, subsubwin1;
12
  GR_WINDOW_ID  window2, subwindow2;
13
  /*GR_WINDOW_ID        subsubwin2;*/
14
  GR_EVENT      event;
15
 
16
  fprintf(stderr,"This is a demo program.\n");
17
  fprintf(stderr,"Left-button drags window\n");
18
  fprintf(stderr,"Right-button raises window\n");
19
 
20
  GrOpen();
21
  window1 = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, 100, 60, 4, BLACK, BLUE);
22
  subwindow1 = GrNewWindow(window1, 5, 5, 90, 50, 4, WHITE, RED);
23
  subsubwin1 = GrNewWindow(subwindow1, 10, 10, 10, 10, 2, GREEN, BLUE);
24
 
25
  window2 = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 100, 100, 60, 4, BLACK, BLUE);
26
  subwindow2 = GrNewWindow(window2, 5, 5, 90, 50, 4, WHITE, RED);
27
/*    subsubwin2 = GrNewWindow(subwindow2, 10, 10, 10, 10, 2, GREEN, BLUE); */
28
 
29
  GrSelectEvents(window1,
30
                 GR_EVENT_MASK_EXPOSURE |
31
                 GR_EVENT_MASK_BUTTON_DOWN |
32
                 GR_EVENT_MASK_BUTTON_UP |
33
                 GR_EVENT_MASK_MOUSE_ENTER |
34
                 GR_EVENT_MASK_MOUSE_EXIT |
35
                 GR_EVENT_MASK_MOUSE_MOTION |
36
                 GR_EVENT_MASK_CLOSE_REQ);
37
 
38
  GrSelectEvents(window2,
39
                 GR_EVENT_MASK_EXPOSURE |
40
                 GR_EVENT_MASK_BUTTON_DOWN |
41
                 GR_EVENT_MASK_BUTTON_UP |
42
                 GR_EVENT_MASK_MOUSE_ENTER |
43
                 GR_EVENT_MASK_MOUSE_EXIT |
44
                 GR_EVENT_MASK_MOUSE_MOTION |
45
                 GR_EVENT_MASK_CLOSE_REQ);
46
 
47
  GrSelectEvents(subsubwin1,
48
                 GR_EVENT_MASK_BUTTON_DOWN |
49
                 0);
50
 
51
  GrMapWindow(subsubwin1);
52
  GrMapWindow(subwindow1);
53
  GrMapWindow(window1);
54
 
55
  /*GrMapWindow(subsubwin2);*/
56
  GrMapWindow(subwindow2);
57
  GrMapWindow(window2);
58
 
59
  while(1) {
60
    GrGetNextEvent(&event);
61
 
62
    switch (event.type) {
63
    case GR_EVENT_TYPE_NONE:
64
      break;
65
    case GR_EVENT_TYPE_BUTTON_DOWN:
66
        offset_x = event.button.x;
67
        offset_y = event.button.y;
68
 
69
      if (event.button.changebuttons & GR_BUTTON_R) {
70
        GrRaiseWindow(event.button.wid);
71
      }
72
      if (event.button.wid == subsubwin1) {
73
        GR_WINDOW_INFO winfo;
74
        GrGetWindowInfo(subsubwin1, &winfo);
75
        if (winfo.parent == subwindow1) {
76
          GrReparentWindow(subsubwin1, subwindow2, 10, 10);
77
        } else {
78
          GrReparentWindow(subsubwin1, subwindow1, 10, 10);
79
        }
80
      }
81
    case GR_EVENT_TYPE_MOUSE_MOTION:
82
      if (event.mouse.buttons == GR_BUTTON_L &&
83
          (event.mouse.wid == window1 || event.mouse.wid == window2)) {
84
        GrMoveWindow(event.mouse.wid,
85
                     event.mouse.rootx - offset_x,
86
                     event.mouse.rooty - offset_y);
87
      }
88
      if (event.mouse.buttons == GR_BUTTON_R) {
89
        GrResizeWindow(event.mouse.wid,
90
                     event.mouse.x + 1,
91
                     event.mouse.y + 1);
92
      }
93
      break;
94
    case GR_EVENT_TYPE_EXPOSURE:
95
      /*GrFillRect(event.exposure.wid, defgc,
96
        event.exposure.x, event.exposure.y,
97
        event.exposure.width, event.exposure.height);*/
98
      break;
99
    case GR_EVENT_TYPE_CLOSE_REQ:
100
      GrClose();
101
      exit(0);
102
    default:
103
      fprintf(stderr, "%d\n", event.type);
104
    }
105
  }
106
  GrClose();
107
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.