Example #1
0
//Clone from another context
Context* Context_new_from(Context* source_context) {

    Context* new_ctx = Context_new(source_context->width, source_context->height, source_context->buffer);
    new_ctx->finalize_handler = source_context->finalize_handler;

    return new_ctx;
}
Example #2
0
WrapWindow::WrapWindow(BRect frame, BApplication* in_app) : BWindow(frame, "Patch", B_TITLED_WINDOW, 0) {
        
    media_raw_audio_format req_format = {44100.0, 2, media_raw_audio_format::B_AUDIO_FLOAT, B_MEDIA_LITTLE_ENDIAN, 4096};    
        
    mouse_handler = (MouseCallback_handler)0;
    resize_handler = (ResizeCallback_handler)0;
    mouse_obj = (Object*)0;
    resize_obj = (Object*)0;    
    
    ah_list = List_new();
                
    draw_view = new WrapView(this, Bounds());
    AddChild(draw_view);
    
    BRect bounds = Bounds();
         	
            
    screen_buffer = new BBitmap(bounds, B_RGB32);
    context = Context_new((uint16_t)(bounds.right - bounds.left + 1), 
                          (uint16_t)(bounds.bottom - bounds.top + 1),
                          (uint32_t*)screen_buffer->Bits());                                              
    Show();

    Lock();
    draw_view->GetMouse(&mouse_point, &mouse_buttons);
    Unlock();
            
    app = in_app;
            
    draw_thread_id = spawn_thread(DrawingThread, "drawing_thread", B_NORMAL_PRIORITY, (void*)this);
    resume_thread(draw_thread_id);
    
    ah_player = new BSoundPlayer(&req_format, "ah_player", doPullSamples, NULL, ah_list);
    ah_player->Start();
    ah_player->SetHasData(true);
    
    global_win = this;
}
Example #3
0
int main(int argc, char* argv[]) {
	Context* ctx = Context_new();
	register_math(ctx);
	
	for(nextLine(); !feof(stdin); nextLine()) {
		/* Strip trailing newline */
		char* end;
		if((end = strchr(line, '\n')) != NULL) *end = '\0';
		if((end = strchr(line, '\r')) != NULL) *end = '\0';
		if((end = strchr(line, '#')) != NULL) *end = '\0';
		
		const char* p = line;
		
		/* Get verbosity level */
		int verbose = 0;
		while(p[0] == '?') {
			verbose++;
			p++;
		}
		trimSpaces(&p);
		
		if(*p == '~') {
			/* Variable deletion */
			p++;
			
			char* name = nextToken(&p);
			if(name == NULL) {
				/* '~~~' means reset interpreter */
				if(p[0] == '~' && p[1] == '~') {
					/* Wipe out context */
					Context_free(ctx);
					ctx = Context_new();
					register_math(ctx);
					continue;
				}
				
				if(*p == '\0') {
					RAISE(earlyEnd());
					continue;
				}
				
				RAISE(badChar(*p));
				continue;
			}
			
			Context_del(ctx, name);
			
			free(name);
			
			continue;
		}
		
		/* Parse the user's input */
		Expression* expr = Expression_parse(&p);
		
		/* Print expression depending on verbosity */
		Expression_print(expr, ctx, verbose);
		
		/* Error? Go to next loop iteration */
		if(Expression_didError(expr)) {
			Expression_free(expr);
			continue;
		}
		
		/* Evaluate expression */
		Value* result = Expression_eval(expr, ctx);
		Expression_free(expr);
		
		/* Print result */
		Value_print(result, ctx);
		
		Value_free(result);
	}
	
	Context_free(ctx);
	
	return 0;
}