Solved

c++/cygwin

Posted on 2007-04-11
2
552 Views
Last Modified: 2013-11-15
hi..below is my program..i need help modifying it..im using XWindow on linux..i need help on:

- draw graphics on the window
- report mouse movement
- report mouse-button presses
- report keyboard presses

Draw graphic...my program can already draw graphic..the window pops up and i can draw graphic by touching my mouse and putting the cursor over the screen..my goal is not to touch the mouse and let the window pop up and pixels color the window by itself..it fills up the screen by itself without having me to touch the mouse..if i touch the mouse and press button..i should see on my screen that "you pressed the left button" like that...

 #include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include "Xwindow.h"
                                                                               
using namespace std;
                                                                               
#define  bsize       10          // The pixel size of the smiley-face image
#define  MaxXCoord   50         // Width of the window = MaxXCoord * bsize
#define  MaxYCoord   50         // Height of the window = MaxYCoord * bsize
                                                                               
                                                                               
// This is the smiley-face design.
//  0's are skipped, 1's are drawn in whatever color
const int color_array[] = {0, 0, 1, 1, 1, 1, 1, 1, 0, 0,
                           0, 1, 1, 0, 0, 0, 0, 1, 1, 0,
                           0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
                           1, 0, 0, 1, 0, 1, 0, 0, 0, 1,
                           1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
                           1, 0, 1, 0, 0, 0, 0, 1, 0, 1,
                           1, 0, 0, 1, 1, 1, 1, 0, 0, 1,
                           1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
                           0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
                           0, 0, 1, 1, 1, 1, 1, 1, 0, 0};
                                                                               
//************************************************************************
//    Random Number Generator functions
//************************************************************************
                                                                               
// Generate a random number from 0 to size-1
unsigned long rand_long(unsigned long size)
{
   float r;
  unsigned long r2;
                                                                               
   r = rand();
   r = ( r / RAND_MAX)*size;
   r2 = (unsigned long) r;
   return( r2 );
}
                                                                               
                                                                               
// Return a number that is >= lowlimit, but < highlimit.
// Work with integers
int rand_int(int lowlimit, int highlimit)
{
   int j,r,limit;
                                                                               
   j = rand();
   limit = highlimit - lowlimit;
   r = 0;
   if (limit!=0)
      r = j % limit;
  r = r + lowlimit;
   return r;
}
                                                                               
                                                                               
// Return a number that is >= lowlimit, but < highlimit.
// Work with unsigned long ints
unsigned long rand_long(unsigned long lowlimit, unsigned long highlimit)
{
   unsigned long j,r,limit;
   j = rand();
   limit = highlimit - lowlimit;
   r = 0;
   if (limit!=0)
      r = j % limit;
   r = r + lowlimit;
   return r;
}
//************************************************************************
//       Main
//************************************************************************
int main(int argc, char *argv[])
{
                                                                               
   Bool quit = false;
                                                                               
   // Initialize rnd generator
 int j = (__TIME__[6]-48) + (__TIME__[7]-48)*10;
   srand(j);
                                                                               
   Xwindow mywindow;
   Xwindow mywindow2;
                                                                               
   int x, y;
   unsigned long  TempX, TempY, TempC;
 // Set up the Xwindow.
   mywindow.Set_Background(mywindow.BLACK());
   mywindow.Set_Foreground(mywindow.WHITE());
   mywindow.Set_Name("Demo - by Michael Weeks");
   mywindow.Set_Height(MaxYCoord * bsize);
   mywindow.Set_Width(MaxXCoord * bsize);
   mywindow.Open();
                                                                               
   unsigned long Background = mywindow.Get_Background();  // background color
   unsigned long BLACK = mywindow.BLACK();          // min color value
 unsigned long WHITE = mywindow.WHITE();          // max color value
   unsigned long color;
                                                                               
   color = rand_long(WHITE+1);
  // cout << "Press the right mouse button, or q, to exit.\n";
   while ()
   {
      if (mywindow.Check_Event())
      {
         switch (mywindow.Get_Event())
 {
            case (KeyPress):
                  if (mywindow.Get_Key() == 'q')
                     quit=true;
                  break;
                                                                               
            case (ButtonPress):
                  // A button was pressed, so take care of it here.
                  switch (mywindow.Get_Button())
                  {
    case (Button1):
                           color = rand_long(WHITE+1);
                           break;
                     case (Button2):
                     default:
                           quit=true;
                  }
                  break;
                                                                               
            case (MotionNotify):
x = mywindow.Get_Cursor_X();
                  y = mywindow.Get_Cursor_Y();
                  // Draw a figure here
                 // for (int i=0; i<bsize; i++)
                 // {
                   //  for (int j=0; j<bsize; j++)
                    // {
                      //  if (color_array[i+j*bsize]==1)
                        //   mywindow.DrawPoint(x+i, y+j, color);
                       // else
          mywindow.DrawPoint(50, 50, Background);
                     }
                  }
                 // break;
            case (Expose):
                  // redraw the screen here.
                  break;
         }
      }
      // Do other stuff between events.
}
                                                                               
   // Example #2. This is a window showing a text message.
   // Open a second window to confirm quit.
   mywindow2.Open();
   mywindow2.Draw_Text("Are you sure? Press q to quit.");
   quit = false;
   cout << "win2: opening window 2   (Press q in the window to exit)" << endl;
   while (quit==false)
   {
 if (mywindow2.Check_Event())
       {
         if (mywindow2.Get_Event() == KeyPress)
         {
            if (mywindow2.Get_Key() == 'q')
               quit=true;
         }
         // Redraw window if needed.
         else if (mywindow2.Get_Event() == Expose)
            mywindow2.Draw_Text("Are you sure? Press q to quit.");
}
   }
   cout << "win2: closing window 2" << endl;
   mywindow2.Close();
                                                                               
   mywindow.Close();
                                                                               
                                                                               
   // Example #3. This is a window showing a text message.
   // Open a third window, wait, then quit.
 Xwindow mywindow3;
   mywindow3.Set_Background(mywindow3.BLACK());
   mywindow3.Set_Foreground(mywindow3.WHITE());
   mywindow3.Open();
   mywindow3.Draw_Text("Goodbye.");
   if (mywindow3.Check_Event()) {}  // Needed or text will not display
   system("sleep 1");    // wait a second
   mywindow3.Close();
                                                                               
   return 0;
}


0
Comment
Question by:shahrine99
2 Comments
 

Author Comment

by:shahrine99
ID: 18900844
hello?
0
 
LVL 6

Accepted Solution

by:
Sanktwo earned 500 total points
ID: 18920381
Shahrine, which topic did you post this to? I am reading it in software/cygwin which is primarily for help in getting *nix utilities running in MS Windows.

I think it is probably not an appropriate list to get help on X-Window programming.

This may be an example of the new EE posting wizard "helping" you to post to the inappropriate list ;-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Any free software for printscreens 7 65
Magic Software info 18 105
Dentrix G4 1 32
Win 7 OS unable to install Win updates 3 88
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now