Exemple #1
0
void
HippoCanvas::onMouseDoubleClick(int button, WPARAM wParam, LPARAM lParam)
{
    if (root_ != (HippoCanvasItem*) NULL) {
        int x, y;
        getMouseCoords(lParam, &x, &y); // don't check return value - emit even if outside the area
        hippo_canvas_item_emit_button_press_event(root_,
                x, y, button,
                0, 0, 0, 2);
    }
}
Exemple #2
0
void
HippoCanvas::onHover(WPARAM wParam, LPARAM lParam)
{
    if (root_ == (HippoCanvasItem*) NULL)
        return;

    int x, y;
    if (!getMouseCoords(lParam, &x, &y))
        return;

    updateTooltip(true, x, y);
}
Exemple #3
0
void
HippoCanvas::onMouseUp(int button, WPARAM wParam, LPARAM lParam)
{
    if (root_ != (HippoCanvasItem*) NULL) {
        int x, y;
        if (getMouseCoords(lParam, &x, &y)) {
            hippo_canvas_item_emit_button_release_event(root_,
                x, y, button,
                0, 0, 0);
        }
    }
}
Exemple #4
0
int main(int argc, char *argv[]) {
	mandelPars pars;
	int i,k,x,y,level,*res,check;
	int xoff,yoff, thrCheck;
	long double reStep,imStep;
	Toolbox **Tool;
	pthread_t *thrP;
	
	printf("\n");
	printf("This program starts by drawing the default Mandelbrot region\n");
	printf("When done, you can click with the mouse on an area of interest\n");
	printf("and the program will zoom at this point\n");
	printf("\n");
	printf("Press enter to continue\n");
	getchar();
	
	pars.rePixels = WinW; /* never changes */
	pars.imPixels = WinH; /* never changes */
	
	/* default mandelbrot region */
	
	pars.reBeg = (long double) -2.0;
	pars.reEnd = (long double) 1.0;
	pars.imBeg = (long double) -1.5;
	pars.imEnd = (long double) 1.5;
	
	reStep = (pars.reEnd - pars.reBeg) / pars.rePixels;
	imStep = (pars.imEnd - pars.imBeg) / pars.imPixels;
	
	printf("enter max iterations (50): ");
	scanf("%d",&pars.maxIterations);
	printf("enter no of slices: ");
	scanf("%d",&pars.slices);
	
	/* adjust slices to divide win height */
	
	while (WinH % pars.slices != 0) { pars.slices++;}
	
	/* allocate result and ready arrays */
	
	res = (int *) malloc(sizeof(int)*pars.rePixels*pars.imPixels);
	
	
	/* open window for drawing results */
	
	openDisplay();
	openWin(argv[0], WinW, WinH);
	
	
	level = 1;
	
	if (NULL== (Tool=(Toolbox**)malloc(sizeof(Toolbox)*pars.slices))){
		perror ("Memory Error");
	}
	
	
	
	for (i=0; i<pars.slices; i++){
		
		if (NULL== (Tool[i]=(Toolbox*)malloc(sizeof(Toolbox)*pars.slices))){
			perror ("Memory Error");
		}
		
		
		
		if (NULL==(Tool[i]->mand=(mandelPars*)malloc(sizeof(mandelPars)))){
			
			perror ("Memory error");
		}
		Tool[i]->mand=&pars;
		
		
		
		
		if (NULL==(Tool[i]->res=(int*)malloc(sizeof(int)))){
			perror ("Memory error");
		}
		Tool[i]->res= res;
		Tool[i]->count=i;
		Tool[i]->rd=-1;	
		
		
		
		
		
		if (NULL== (thrP=(pthread_t*)malloc(sizeof(pthread_t)*pars.slices))){
			perror ("Memory Error");
		}
		thrCheck = pthread_create( &thrP[i], NULL,calcMandel , (void *)Tool[i]);
		if(thrCheck)
		{
			fprintf(stderr,"Error - pthread_create() return code: %d\n",thrCheck);
			exit(EXIT_FAILURE);
		}
		
	}
	
	
	while (1) {
		
		clearWin();
		
		printf("computing for level %d:\n",level);
		printf("reBeg=%Lf reEnd=%Lf reStep=%Lf\n",pars.reBeg,pars.reEnd,reStep);
		printf("imBeg=%Lf imEnd=%Lf imStep=%Lf\n",pars.imBeg,pars.imEnd,imStep);
		printf("maxIterations=%d\n",pars.maxIterations);
		
		
		for (i=0; i<pars.slices; i++) { 
			Tool[i]->level=&level;
			Tool[i]->rd=0;
			
		}
		
		
		
		/* busywait (and draw results) until all slices done */
		
		k=0;
		while (k!=pars.slices) {
			for (i=0; i<pars.slices; i++) {
				
				while (Tool[i]->rd!=1){
					if (0!=(check= sched_yield())){
						perror ("Thread");
					}
					
				}
					
					for (y=i*(pars.imPixels/pars.slices); y<(i+1)*(pars.imPixels/pars.slices); y++) {
						
						for (x=0; x<pars.rePixels; x++) {
							setColor(pickColor(res[y*pars.rePixels+x],pars.maxIterations));
							drawPoint(x,y);
							
						}
					}
					
					k++; Tool[i]->rd=2;
			}
		}
		
		
		/* get next focus/zoom point */
		
		
		
		getMouseCoords(&x,&y);
		xoff = WinW/2 - x;
		yoff = WinH/2 - (WinH-y);
		
		/* adjust focus */
		
		pars.reBeg = pars.reBeg - xoff*reStep;
		pars.reEnd = pars.reBeg + reStep*pars.rePixels;
		pars.imBeg = pars.imBeg - yoff*reStep;
		pars.imEnd = pars.imBeg + reStep*pars.imPixels;
		
		/* zoom in */
		
		reStep = reStep*ZoomStepFactor; 
		imStep = imStep*ZoomStepFactor;
		pars.reBeg = pars.reBeg + (pars.reEnd-pars.reBeg)/2 - reStep*pars.rePixels/2;
		pars.reEnd = pars.reBeg+reStep*pars.rePixels;
		pars.imBeg = pars.imBeg + (pars.imEnd-pars.imBeg)/2 - imStep*pars.imPixels/2;
		pars.imEnd = pars.imBeg+imStep*pars.imPixels;
		pars.maxIterations = pars.maxIterations*ZoomIterationFactor;
		
		level++;
		
	} 
	
	/* never reach this point; for cosmetic reasons */
	
	free(res);
	
	
	closeWin();
	closeDisplay();
	
}
Exemple #5
0
void
HippoCanvas::onMouseMove(WPARAM wParam, LPARAM lParam)
{
    int x, y;

    if (!getMouseCoords(lParam, &x, &y))
        return;

    if (x == lastMoveX_ && y == lastMoveY_) {
        // we didn't really move. I don't know why Windows does this.
        return;
    }
    lastMoveX_ = x;
    lastMoveY_ = y;

    // FIXME what we really want here is that if the mouse is still 
    // on the same logical UI component (which may or may not be
    // a separate canvas item), we update the tooltip, otherwise
    // we hide the tooltip. A case where this happens is that with
    // non-NW-gravity windows, we get a motion event on size allocate,
    // and that should not usually clear the tooltip as long as the 
    // pointer stays inside the same item. But also, just the user
    // moving within one item really shouldn't clear the tip.
    // We could just check whether the results of get_tooltip have
    // changed (for_area and the tip text), but that isn't good enough
    // since both can change when we're still inside the same item.

    //updateTooltip(false, x, y);
    tooltip_->deactivate();

    bool entered;

    entered = false;
    if (!containsMouse_) {
        // request a WM_MOUSELEAVE message
        TRACKMOUSEEVENT tme;
        tme.cbSize = sizeof(tme);
        tme.dwFlags = TME_LEAVE;
        tme.hwndTrack = window_;
        if (TrackMouseEvent(&tme) != 0) {
            containsMouse_ = true;
            entered = true;
        } else {
            g_warning("Failed to track mouse leave");
            return;
        }
    }

    g_assert(containsMouse_);

    if (root_ != (HippoCanvasItem*) NULL) {
        startTrackingHover();

        if (entered) {
            hippo_canvas_item_emit_motion_notify_event(root_,
                x, y, HIPPO_MOTION_DETAIL_ENTER);
        }
        hippo_canvas_item_emit_motion_notify_event(root_,
            x, y, HIPPO_MOTION_DETAIL_WITHIN);
    }

    updatePointer(x, y);
}
Exemple #6
0
int main(int argc, char *argv[]) {
  mandel_Pars pars;
  int i, j, x, y, k, nofslices, level, thread_status;
  int xoff,yoff;
  long double reEnd,imEnd,reCenter,imCenter;
  pthread_t *thread_workers;

  printf("\n");
  printf("This program starts by drawing the default Mandelbrot region\n");
  printf("When done, you can click with the mouse on an area of interest\n");
  printf("and the program will automatically zoom around this point\n");
  printf("\n");
  printf("Press enter to continue\n");
  getchar();

  pars.reSteps = WinW; /* never changes */
  pars.imSteps = WinH; /* never changes */

  /* default mandelbrot region */

  pars.reBeg = (long double) -2.0;
  reEnd = (long double) 1.0;
  pars.imBeg = (long double) -1.5;
  imEnd = (long double) 1.5;
  pars.reInc = (reEnd - pars.reBeg) / pars.reSteps;
  pars.imInc = (imEnd - pars.imBeg) / pars.imSteps;

  printf("enter max iterations (50): ");
  scanf("%d",&maxIterations);
  printf("enter no of slices: ");
  scanf("%d",&nofslices);

  /* adjust slices to divide win height */

  while (WinH % nofslices != 0) { nofslices++;}

  /* allocate slice parameter and result arrays */

  slices = (mandel_Pars *) malloc(sizeof(mandel_Pars)*nofslices);
  res = (int *) malloc(sizeof(int)*pars.reSteps*pars.imSteps);


  //workers init
  thread_workers = (pthread_t*)malloc(sizeof(pthread_t)*nofslices);
  work_status=(int *)malloc(sizeof(int)*nofslices);
  for(i=0;i<nofslices;i++)work_status[i]=-1;
  for(i=0;i<nofslices;i++){
      thread_status=pthread_create(&thread_workers[i], NULL, workers, (void*)(intptr_t)i);
      if(thread_status){
          perror("Fail create thread\n");
          exit(1);
      }
  }

  /* open window for drawing results */

  openDisplay();
  openWin(argv[0], WinW, WinH);

  level = 1;

  while (1) {

    clearWin();

    mandel_Slice(&pars,nofslices,slices);

    for(i=0;i<nofslices;i++)work_status[i]=0;

    i=0;
    y=0;
    while(i<nofslices){

        for(k=0;work_status[k]!=1;k++)if((k+1)==nofslices)k=-1;

        for(i++, work_status[k]=2, j=0;j<slices[k].imSteps;j++,y++){
            for(x=0;x<slices[k].reSteps;x++){
                setColor(pickColor(res[y*slices[k].reSteps+x],maxIterations));
                drawPoint(x, y);
            }
        }

        printf("thread no. %d finish draw\n", k);

    }

    /* get next focus/zoom point */

    getMouseCoords(&x,&y);
    xoff = x;
    yoff = WinH-y;

    /* adjust region and zoom factor  */

    reCenter = pars.reBeg + xoff*pars.reInc;
    imCenter = pars.imBeg + yoff*pars.imInc;
    pars.reInc = pars.reInc*ZoomStepFactor;
    pars.imInc = pars.imInc*ZoomStepFactor;
    pars.reBeg = reCenter - (WinW/2)*pars.reInc;
    pars.imBeg = imCenter - (WinH/2)*pars.imInc;

    maxIterations = maxIterations*ZoomIterationFactor;
    level++;

  }

  /* never reach this point; for cosmetic reasons */

  free(work_status);
  free(thread_workers);
  free(slices);
  free(res);

  closeWin();
  closeDisplay();

}