Define Cs Currentselection

Define Cs Currentselection

<p>//caption_resize041106.cctmp: - RJL041106 - (approx 25+125+90=150lines) //Functions: caption_resize, do_caption_resize{_begin,_move,_end} // #define abbrevs for states, events, predicates; 3 actions now are function calls // New 041106: more abbrevs,macros; merged similar guard/action/next-state triples // Some incomplete actions identified and completed when merged. // Some comments and dprint calls removed #define cs currentselection #define sc selected_caption #define SCR SCaptionResize #define SCCR SCaptionConfirmResize #define BD BUTTON_DOWN_EVENT #define BM BUTTON_MOVED_EVENT #define BU BUTTON_UP_EVENT #define ccc changeCanvasCursor #define csHasTypeCG (hasType((id=(hcg_key)cs->getid()),CG)) #define SCRBUG1 ((cs!= 0) && csHasTypeCG) #define SCCRBDG1 (sc!=0 && cs==sc && csHasTypeCG) #define SCCRBDG2 (sc!=0 && (cs==0 || !csHasTypeCG)) #define SCCRBDG3 (sc!=0 && cs!=0 && cs!=sc && csHasTypeCG ) #define SCCRBDA1 do_caption_resize_begin() #define SCCRBMA1 do_caption_resize((int)event->x, (int)event->y); #define SCCRBUA4 do_caption_resize_end() static hcg_key id; // added static - RJL041029 static float savedx, savedy; float sx, sy; //char *curr_shape[20]; float center_x, center_y, radius; float temp_x, temp_y, tempr; /*, temp_radius*/; float diff_x, diff_y; static graphobject *sc = NULL; static graphobject *cs = NULL; void caption_resize ( XButtonEvent *even, int state, /* Canvas State */ caption_attributes *attribute, int button_op) /* BUTTON_UP, BUTTON_DOWN,BUTTON_MOVED */ { EP; switch (state) // states: SCR=102, SCCR=103 { case SCR: //%%SCR DP;dprintdd("case SCR:SCR = %x; ==? state = %x\n", SCR, state); assert(state == SCR); switch (button_op) { case BD: //%%SCRBDA1 DP; reselect(event, &sx, &sy);//530:new curr..sel- RJL041028 break; // wait for BUTTON_UP case BM: //%%SCRBMA1:no-op DP;break; case BU://%%SCRBU if (SCRBUG1) { //%%SCRBUG1/A1 -line540: not reached 041029 -RJL DP;sc = cs;//540:got here selected.changeAttribState( SCCR);//change-State ccc(movehand); DP;break;//Never reached here! RJL041029.0045 } //end %%SCRBUA1 else { DP;break; // %%SCRBUA2: no-op, same state - retry } default: PostErrorMsg(SCR); DP;break; }; // end sw button_op break; // added 041029 - this bug took hours to find! // end %%SCR - case SCR case SCCR: //%%SCCR DP;dprintdd( /* 558:*/ "[case SCCR:SCCR = %x; ==?, state = %x]\n", SCCR, state); assert(state==SCCR);//SCCR:561: switch (button_op) { case BD: //%%SCCRBD DP; if (SCCRBDG1) { //%%SCCRBDG1:selection confirmed;begin resize DP; SCCRBDA1; //do_caption_resize_begin(); //%%SCCRBDA1 break; //else old selection not confirmed; may be new CG else if (SCCRBDG2) { //%%SCCRBDA2 DP; unselect(); sc = 0; // RJL041028 ccc(arrow); displayMessage("Invalid selection; select a Caption\n"); selected.changeAttribState(SCR); break;//%%end SCCRBDA2 } else { //%%SCCRBDG3: curr_sel != 0 && new && hasType(id, CG) DP; displayMessage( "SCCR: new Caption;must re-confirm\n"); sc = cs; //RJL041024 break; //%%end SCCRBDA3 } // end else (new CG saved in sc) //%%end SCCRBD (BUTTON_DOWN) case BM: //%%SCCRBM DP; //%%SCCRBMA1 do_caption_resize((int)event->x, (int)event->y);//xorGC break; //end %%SCCRBMA1 case BU://%%SCCRBU if (SCCRBUG1orG3) //%%((!sc||!cs)||(sc && cs && !csHasTypeCG )) { //%%SCCRBUA1=A3 DP;ccc(arrow); sc = cs = 0; selected.changeAttribState(SCR); break; } //end %%SCCRBUG1A1, %%SCCRBUG3A3</p><p> else { //%%SCCRBUG4 : cs!=0 && csHasTypeCG //if (cs != 0 && csHasTypeCG ) do_caption_resize_end(); DP;break; }//end %%SCCRBUA4 // end %%SCCRBU - BU in SCCR default: /* illegal value for button_op variable */ fprintf(stderr, "Out of State in function caption_resize.\n"); fprintf(stderr,"switch on state\n"); fprintf(stderr,"Report this to Professor Lechner.\n"); DP;break; }//end switch(button_op) // end %%SCCR = case SCCR default: DP;assert(0); } // end switch(state) } // end caption_resize ///////////////////////////////////////////////////// //do_caption_resize_begin was case block SCCRBDA1, made a function - RJL041105 ///////////////////////////////////////////////// void do_caption_resize_begin(void) //%%SCCRBDA1 { float curr_x,curr_y, center_x,center_y; float temp_x,temp_y, diff_x,diff_y; hcg_key id; // local non-static? CGcurr = (struct CG*)cs->getcurr(); selectedx = sx; selectedy = sy; savedx = cs->getcenterx(); savedy = cs->getcentery(); displayMessage("Drag the mouse button to resize\n"); center_x = cs->getcenterx(); center_y = cs->getcentery(); radius = cs->getradius(); last_width = cs->getwidth(); //initialize for do_caption_resize_move last_height = cs->getheight(); return; } // end do_caption_resize_begin - exit if selection reconfirmed; //First try: call cs->Draw - but need to use moverect not drawrect /*************************************************************************** * Name: do_caption_resize_move * Description: * This routine resizes a graph caption box on the drawing canvas * Client: caption_resize * Inputs: * x (int): new x coordinate location of button move * y (int): new y coordinate location of button move * Outputs: NONE * Returns: * none * Client: state SCCR, in event BUTTON_MOVED * pre-condition: cs != 0 and hasType(id, CG) * ***************************************************************************/ void do_caption_resize_move(int x, int y) { float curr_x,curr_y, center_x,center_y; float temp_x,temp_y, diff_x,diff_y; hcg_key tmpid; // local non-static? assert(cs != 0); tmpid = (hcg_key)cs->getid(); if (!hasType(tmpid, CG)) return; CGcurr = (struct CG*) cs->getcurr(); assert (CGcurr != NULL); assert(CGcurr->CGid == tmpid); /* RJL 040328 */ curr_x = (float)x; //new mouse pos curr_y = (float)y; temp_x = cs->getcenterx();//old center temp_y = cs->getcentery(); center_x = cs->getcenterx();//old center center_y = cs->getcentery(); redrawrectangular( center_x, center_y, last_width*2.0, last_height*2.0); // init in client? last_width = new_width = diff_x = fabs(curr_x - temp_x); last_height = new_width = diff_y = fabs(curr_y - temp_y); redrawrectangular(center_x,center_y, new_width*2.0, new_height*2.0);// repeat; return; } // end do_caption_resize_move (client: BUTTON_MOVED in SCCaptionConfirmResize ///////////////////////////////////////////////////// //do_caption_resize_end was case block SCCRBUA4, now a function - RJL041105 ///////////////////////////////////////////////// void do_caption_resize_end(void) //%%SCCRBUA4 { center_x = cs->getcenterx(); center_y = cs->getcentery(); temp_x = event->x;//no need if assert succeeds temp_y = event->y; diff_x = fabs(temp_x - center_x); diff_y = fabs(temp_y - center_y); tempr = (diff_x>diff_y)?diff_x:diff_y; //(radius = max) cs->setradius(tempr,tempr);</p><p>ReDraw();//On exit, redraw entire diagram? RJL041022</p><p>} //end do_caption_resize_end</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us