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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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