Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-26-2007, 10:51 PM
siren siren is offline
Newbie
 
Join Date: Apr 2007
Posts: 10
Rep Power: 0
siren is on a distinguished road
Default ! Need urgent help ! Drawing program using cygwin

Hi everyone! I'm new to programming, and right now I am making a drawing program. I actually was able to make some progress, but I can't get it to work completely. It's a drawing program where 3 choices can be chosen via buttons (I didn't make buttons. I just made it so if one clicks in a certain area, that mode is chosen) So mode 1 is free drawing, where the person can draw anything, mode 2 is writing letters on the screen (starts where the mouse was last clicked), mode 3 is drawing straight lines (one click for the starting point, a second click for the other point) and last mode is quiting the program ( it can also be done by typing 'e'). I've managed to get the free drawing, line drawing, and program terminating section correct, but can't finish the letter writing, and menu selection part right. Any help is appreciated!! This is the code.

Code:
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#define Window_width 700
#define Window_height 500
#define Menu_width 60
#define Menu_height 20

Display *display;
Window window;
GC context;
int pX, pY;
int mode, ready;

void CreateResource(){
  int black,white;
  display = XOpenDisplay(NULL);
  black = BlackPixel(display, DefaultScreen(display));
  white = WhitePixel(display, DefaultScreen(display));
  window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0,
			       Window_width, Window_height, 2, black, white);
  context = XCreateGC(display, window, 0,0);
  XSelectInput(display,window,KeyPressMask|ButtonPressMask|Button1MotionMask);
  XMapWindow(display, window);
  XSetForeground(display, context, black);
  XSetBackground(display, context, white);
  XFlush(display);
}
void MakeMenu(){
  XDrawLine(display, window, context,
	    0, Menu_height, Menu_width, Menu_height);
  XDrawLine(display, window, context,
	    Menu_width, 0, Menu_width, Menu_height);
  XDrawString(display, window, context, 15, 16,"end", 3);
  XDrawLine(display, window, context,
	    0, 40, Menu_width, 40);
  XDrawLine(display, window, context,
	    Menu_width, Menu_height, Menu_width,40);            /* I am making a menu here */
  XDrawString(display, window, context, 15, 36,"free",4 );
  XDrawLine(display, window, context,
	    0, 60, Menu_width, 60);
  XDrawLine(display, window, context,
	   Menu_width,40,Menu_width,60);
  XDrawString(display, window, context, 15, 56,"word",4 );
   XDrawLine(display, window, context,
	    0, 80, Menu_width, 80);
  XDrawLine(display, window, context,
	   Menu_width,60,Menu_width,80);

  XDrawString(display, window, context, 15, 76,"line",4 );
  
}

void HitButton(XButtonEvent *event){
  if(event->x < Menu_width){
    if(event->y <Menu_height){
      XCloseDisplay(display); exit(1);
    }
    else if(event-> y>20 && event-> y<40){
      mode=1; return;}
    else if(event-> y>40 && event-> y<60){      /* This is where I declare what would happen if 	mode=2; return;}                          a button (I didn’t really make buttons, Ijust
    else if(event->y>60 && event->y<80){          made it so if a certain area is clicked, a
      mode=3; ready=0; return;}                  certain command is chosen. */
  }
  if(event->window == window){
    if(mode==1){
      XDrawLine(display, window, context, pX, pY, event->x, event->y); pX =event ->x; pY= event -> y;}
    // if(mode==2){
    // XDrawString(display, window, context, pX, pY, event->x, event->y);}
    if(mode==3){
      if(ready){ XDrawLine(display, window, context, pX, pY, event->x, event->y); ready = 0;}
      else{ ready =1;}
    }
     pX =event ->x; pY= event -> y;
  }
}
void Draw(XMotionEvent *event){
  XDrawLine(display, window, context, pX, pY, event->x, event->y);
  pX = event->x; pY = event->y;
}  
void HitKey(XKeyEvent *event){
  char ch;
  KeySym keysym;
  XLookupString(event, &ch, 1, &keysym, NULL);
  if(ch=='e'){
    XCloseDisplay(display); exit(1);
  }
}
void EventLoop(){
  XEvent event;
  while(1){
    XNextEvent(display, &event);
    switch (event.type){
    case ButtonPress:
      HitButton(&event. xbutton);
      break;
       case MotionNotify:
       Draw(&event.xmotion);
       break;
    case KeyPress:
      HitKey(&event.xkey);
      break;
    default:
      break;
    }
  }
}
int main(){
  CreateResource();
  MakeMenu();
  EventLoop();
  return 0;
}

Once again, any help is appreciated!! Thanks before hand!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent...plz help me.... Shap3r C and C++ 7 08-09-2007 10:59 AM
How do I Program another Program? ! bosco General Programming 1 06-15-2007 11:15 AM
Need help w/ word count program (ASAP) siren C and C++ 1 04-23-2007 08:14 AM
How to modify a program written in .NET 2.0? jackyjack C# Programming 7 03-27-2007 12:26 PM


All times are GMT -5. The time now is 11:28 PM.

Contest Stats

Xav ........ 162.68
Sacback ........ 120.05
alearb8 ........ 120.05
tfusion ........ 120
amr2107 ........ 120
d3s!gn ........ 120
Qoolman21 ........ 120
Pillager ........ 108
satrian ........ 100
neerlin ........ 100

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 68%

Ads