Esempio n. 1
0
void drawWindow(Node* node, char** out, int wOff, int hOff)
{
	int i;
	for(i = wOff+1; i < wOff + node->dim.w; i++)
	{
		if(out[hOff][i] == ' ') out[hOff][i] = '-';
		if(out[hOff+node->dim.h][i] == ' ') out[hOff+node->dim.h][i] = '-';
	}
	for(i = hOff+1; i < hOff + node->dim.h; i++)
	{
		if(out[i][wOff] == ' ') out[i][wOff] = '|';
		if(out[i][wOff+node->dim.w] == ' ') out[i][wOff+node->dim.w] = '|';
	}
	out[hOff][wOff] = '*';
	out[hOff+node->dim.h][wOff] = '*';
	out[hOff][wOff+node->dim.w] = '*';
	out[hOff+node->dim.h][wOff+node->dim.w] = '*';
	
	
	if(node->c == '|')
	{
		drawWindow(node->left, out, wOff, hOff);
		drawWindow(node->right, out, wOff + node->left->dim.w, hOff);
	}
	else if(node->c == '-')
	{
		drawWindow(node->left, out, wOff, hOff);
		drawWindow(node->right, out, wOff, hOff + node->left->dim.h);
	}
	else
		out[hOff][wOff] = node->c;		
}
Esempio n. 2
0
/* View the memory contents of the Flash and DDR devices. Navigate through the
   address space with ARROW UP and DOWN keys. Returns to the boot loader on
   ESC key pressed. */
void view_memories() {

   uint adr = 0;

   cls();

   drawWindow(&wFlashMemory);
   drawWindow(&wDDRMemory);

   // Show contetnts starting at address 0 at the beginning.
   show_memory_contents(0);

   while(TRUE) {
      switch(getc()->chr) {
         case KEY_ARROWD:
            adr += NUM_OF_WORDS;
            show_memory_contents(adr);
            break;

         case KEY_ARROWU:
            if(adr >= NUM_OF_WORDS) adr -= NUM_OF_WORDS;
            show_memory_contents(adr);
            break;

         case KEY_ESC:
            boot();
            break;

         default:
            break;
      }
   }
}
Esempio n. 3
0
void markWindowVisible(Window* dest_window, unsigned char is_visible) {

	unsigned char was_visible;
	Rect overlap_rect;

	was_visible = dest_window->flags & WIN_VISIBLE;

	if (!!was_visible && !!is_visible)
		return;

	if (is_visible) {

		dest_window->flags |= WIN_VISIBLE;
		drawWindow(dest_window, 0);
	}
	else {

		dest_window->flags &= ~((unsigned char)WIN_VISIBLE);
		overlap_rect.top = dest_window->y;
		overlap_rect.left = dest_window->x;
		overlap_rect.bottom = overlap_rect.top + dest_window->h - 1;
		overlap_rect.right = overlap_rect.left + dest_window->w - 1;
		updateOverlapped(&overlap_rect, dest_window); //Redraw all of the siblings that this window was covering up
	}

	return;
}
Esempio n. 4
0
/* Load Flash contents into DDR. 
   
   Input:
      start    Image start address on flash.
      size     Image size.
 */
void load(uint start, uint size) {

   uint step;           // Progress bar step size.
   uint cval;           // Current progress value.
   
   cls();

   // User Upload Menu.
   drawWindow(&wDDRUpload);

   // Upload Initialization.
   pbUpload.val = 0;   
   drawProgressBar(&wDDRUpload, &pbUpload);
   
   step = size / 64;
   cval = step;
   
   // Copy flash data to DDR2 memory.
   // NOTE: Missing bytes, if binary file is not 4 bytes aligned.
   for(uint i=0; i < (size / 4); i++) {
   
      DDR_ADDRESS[i] = flash_read(i + start);
      
      // Update status bar.
      if(i == cval) {
         pbUpload.val++;
         drawProgressBar(&wUpload, &pbUpload);
         cval += step;
      }
   }    
}
Esempio n. 5
0
void renderDemo(struct NVGcontext* vg, float mx, float my, float width, float height,
				float t, int blowup, struct DemoData* data)
{
	float x,y,popy;

	drawEyes(vg, width - 250, 50, 150, 100, mx, my, t);
	drawParagraph(vg, width - 450, 50, 150, 100, mx, my);
	drawGraph(vg, 0, height/2, width, height/2, t);
	drawColorwheel(vg, width - 300, height - 300, 250.0f, 250.0f, t);

	// Line joints
	drawLines(vg, 50, height-50, 600, 50, t);

	// Line caps
	drawWidths(vg, 10, 50, 30);

	// Line caps
	drawCaps(vg, 10, 300, 30);

	nvgSave(vg);
	if (blowup) {
		nvgRotate(vg, sinf(t*0.3f)*5.0f/180.0f*NVG_PI);
		nvgScale(vg, 2.0f, 2.0f);
	}

	// Widgets
	drawWindow(vg, "Widgets `n Stuff", 50, 50, 300, 400);
	x = 60; y = 95;
	drawSearchBox(vg, "Search", x,y,280,25);
	y += 40;
	drawDropDown(vg, "Effects", x,y,280,28);
	popy = y + 14;
	y += 45;

	// Form
	drawLabel(vg, "Login", x,y, 280,20);
	y += 25;
	drawEditBox(vg, "Email",  x,y, 280,28);
	y += 35;
	drawEditBox(vg, "Password", x,y, 280,28);
	y += 38;
	drawCheckBox(vg, "Remember me", x,y, 140,28);
	drawButton(vg, ICON_LOGIN, "Sign in", x+138, y, 140, 28, nvgRGBA(0,96,128,255));
	y += 45;

	// Slider
	drawLabel(vg, "Diameter", x,y, 280,20);
	y += 25;
	drawEditBoxNum(vg, "123.00", "px", x+180,y, 100,28);
	drawSlider(vg, 0.4f, x,y, 170,28);
	y += 55;

	drawButton(vg, ICON_TRASH, "Delete", x, y, 160, 28, nvgRGBA(128,16,8,255));
	drawButton(vg, 0, "Cancel", x+170, y, 110, 28, nvgRGBA(0,0,0,0));

	// Thumbnails box
	drawThumbnails(vg, 365, popy-30, 160, 300, data->images, 12, t);

	nvgRestore(vg);
}
Esempio n. 6
0
 void imageCb(const sensor_msgs::ImageConstPtr& msg)
  {

          cv_bridge::CvImagePtr cv_ptr;
          try
          {
             cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
          }
          catch (cv_bridge::Exception& e)
          {
                 ROS_ERROR("cv_bridge exception: %s", e.what());
                 return;
          }

         // ImageConverter im;
         vector<vector<Point> > squares;
         compare(cv_ptr->image);
         findWindow(cv_ptr->image,squares);
         drawWindow(cv_ptr->image, squares);
        // imshow(wndname,cv_ptr->image);

         // Output modified video stream
         image_pub_.publish(cv_ptr->toImageMsg());

         int c=  waitKey(30);
         if((char) c == 27 )
         {
                 destroyWindow(wndname);
                 return ;
         }
  }
Esempio n. 7
0
void changeWindowPosition(Window* dest_window, unsigned short new_x, unsigned short new_y) {

	Rect overlap_rect;

	//If a window is moved, we must ensure that it is the active window 
	markWindowVisible(dest_window, 1);
	raiseWindow(dest_window);

	//Create a rectangle covering the old location for later intersection
	overlap_rect.top = dest_window->y;
	overlap_rect.left = dest_window->x;
	overlap_rect.bottom = overlap_rect.top + dest_window->h - 1;
	overlap_rect.right = overlap_rect.left + dest_window->w - 1;

	dest_window->x = new_x;
	dest_window->y = new_y;

	//Need to update the screen if we're visible    
	if (dest_window->flags & WIN_VISIBLE) {

		//Should update this so that we don't redraw stuff that's going to
		//be under the window's new location because we're going to draw
		//over that when we draw the window at the new location anyhow     
		updateOverlapped(&overlap_rect, dest_window); //Redraw all of the siblings that this window was covering up

		//Redraw the window at its new location
		dest_window->frame_needs_redraw = 1;
		drawWindow(dest_window, 0);
	}

	return;
}
Esempio n. 8
0
	void Button::drawContents() const {
		drawWindow(IRect(int2(0, 0), size()), isMouseOver() && m_is_enabled? WindowStyle::gui_light : WindowStyle::gui_dark,
					m_mouse_press? -2 : 2);

		int2 rect_center = size() / 2;
		int2 pos = rect_center - m_text_extents.size() / 2 - m_text_extents.min - int2(1, 1);
		if(m_mouse_press)
			pos += int2(2, 2);
		m_font->draw((float2)pos, {m_is_enabled? Color::white : Color::gray, Color::black}, m_text);
	}
	void Graphics2D::drawMoneyWindow(Vector2D const& p)
	{
		model::Project& proj = getOwner().getProject();

		drawWindow(p, MONEY_WINDOW_SIZE);
		std::ostringstream ss;
		ss << std::setw(8) << proj.getLSD().getMoney();
		drawString( ss.str(), p + Vector2D(16, 10), font::FNT_NORMAL);
		drawString( proj.getLDB()[21].getArray1D()[95], p + Vector2D(16 + font::HALF_FONT_W*8, 10), font::FNT_MONEY);
	}
Esempio n. 10
0
//Redraws every window intersected by window_bounds
void updateOverlapped(Rect* window_bounds, Window* avoid_window) {

	int i = 0;
	Rect comp_rect, draw_rect;
	window* cur_window;

	//prints("[WYG] Looking for previously overlapped windows\n");

	for (i = 0; i < window_list->count; i++) {

		cur_window = (Window*)List_get_at(window_list, i);

		if (!cur_window || cur_window == avoid_window)
			continue;

		comp_rect.top = cur_window->y;
		comp_rect.left = cur_window->x;
		comp_rect.bottom = comp_rect.top + cur_window->h - 1;
		comp_rect.right = comp_rect.left + cur_window->w - 1;

		if ((cur_window->flags & WIN_VISIBLE) &&
			window_bounds->left <= comp_rect.right &&
			window_bounds->right >= comp_rect.left &&
			window_bounds->top <= comp_rect.bottom &&
			window_bounds->bottom >= comp_rect.top) {

			if (window_bounds->top < comp_rect.top)
				draw_rect.top = comp_rect.top;
			else
				draw_rect.top = window_bounds->top;

			if (window_bounds->left < comp_rect.left)
				draw_rect.left = comp_rect.left;
			else
				draw_rect.left = window_bounds->left;

			if (window_bounds->bottom > comp_rect.bottom)
				draw_rect.bottom = comp_rect.bottom;
			else
				draw_rect.bottom = window_bounds->bottom;

			if (window_bounds->right > comp_rect.right)
				draw_rect.right = comp_rect.right;
			else
				draw_rect.right = window_bounds->right;

			cur_window->context->top = draw_rect.top - cur_window->y;
			cur_window->context->left = draw_rect.left - cur_window->x;
			cur_window->context->bottom = draw_rect.bottom - cur_window->y;
			cur_window->context->right = draw_rect.right - cur_window->x;
			drawWindow(cur_window, 1);
		}
	}
}
Esempio n. 11
0
void drawScreenSurface(){
    //TODO : WindowPosition for mouse()
    glEnable(GL_TEXTURE_2D);
    for (int i = 0 ; i < myFinder->getNbWindows(); i++){
        MyWindow* currentWindow = myFinder->getAnchorWindow(i);
        currentWindow->setConfiguration(i);
        if(currentWindow!=NULL){
            currentWindow->findAllChilds();
            drawWindow(currentWindow,0);
        }
    }
}
Esempio n. 12
0
reg_t GfxPorts::kernelNewWindow(Common::Rect dims, Common::Rect restoreRect, uint16 style, int16 priority, int16 colorPen, int16 colorBack, const char *title) {
	Window *wnd = NULL;

	if (restoreRect.bottom != 0 && restoreRect.right != 0)
		wnd = addWindow(dims, &restoreRect, title, style, priority, false);
	else
		wnd = addWindow(dims, NULL, title, style, priority, false);
	wnd->penClr = colorPen;
	wnd->backClr = colorBack;
	drawWindow(wnd);

	return make_reg(0, wnd->id);
}
Esempio n. 13
0
void StageSelect::draw()
{
	drawWindow();
	drawBackground();
	drawDodai();
	card_.draw();
	post_.draw();
	exit_.draw();
	drawScrollbar();
	for (int i = 0;i < stagelavel_.size(); i++) {
		stagelavel_[i].draw();
	}
	drawMousePointer();
}
void StelQGLRenderer::renderFrame(StelRenderClient& renderClient)
{
	invariant();
	recentFrames.update();
	clearFrameStatistics();
	if(previousFrameEndTime < 0.0)
	{
		previousFrameEndTime = StelApp::getTotalRunTime();
	}

	viewport.setDefaultPainter(renderClient.getPainter(), glContext);

	makeGLContextCurrent();
	viewport.startFrame();

	// When using the GUI, try to have the best reactivity, 
	// even if we need to lower the FPS.
	const int minFps = StelApp::getInstance().getGui()->isCurrentlyUsed() ? 16 : 2;

	glClearColor(0, 0, 0, 0);
	glClear(GL_COLOR_BUFFER_BIT);
	while (true)
	{
		const bool doneDrawing = !renderClient.drawPartial();
		if(doneDrawing) 
		{
			viewport.finishFrame();
			break;
		}

		const double spentTime = StelApp::getTotalRunTime() - previousFrameEndTime;

		// We need FBOs to do partial drawing.
		if (viewport.useFBO() && 1.0 / spentTime <= minFps)
		{
			// We stop the painting operation for now
			viewport.suspendFrame();
			break;
		}
	}
	
	drawWindow(renderClient.getViewportEffect());
	viewport.setDefaultPainter(NULL, glContext);

	// Flushing GL commands helps FPS somewhat (not sure why, though)
	glFlush();
	
	previousFrameEndTime = StelApp::getTotalRunTime();
	invariant();
}
Esempio n. 15
0
//
// len is in characters, not pixels!!
//
void AgiEngine::blitTextbox(const char *p, int y, int x, int len) {
	// if x | y = -1, then center the box
	int xoff, yoff, lin, h, w;
	char *msg, *m;

	debugC(3, kDebugLevelText, "blitTextbox(): x=%d, y=%d, len=%d", x, y, len);
	if (_game.window.active)
		closeWindow();

	if (x == 0 && y == 0 && len == 0)
		x = y = -1;

	if (len <= 0)
		len = 30;

	xoff = x * CHAR_COLS;
	yoff = y * CHAR_LINES;

	m = msg = wordWrapString(agiSprintf(p), &len);

	for (lin = 1; *m; m++) {
		// Test \r for MacOS 8
		if (*m == '\n' || *m == '\r')
			lin++;
	}

	if (lin * CHAR_LINES > GFX_HEIGHT)
		lin = (GFX_HEIGHT / CHAR_LINES);

	w = (len + 2) * CHAR_COLS;
	h = (lin + 2) * CHAR_LINES;

	if (xoff < 0)
		xoff = (GFX_WIDTH - w - CHAR_COLS) / 2;
	else
		xoff -= CHAR_COLS;

	if (yoff < 0)
		yoff = (GFX_HEIGHT - 3 * CHAR_LINES - h) / 2;

	drawWindow(xoff, yoff, xoff + w - 1, yoff + h - 1);

	printText2(2, msg, 0, CHAR_COLS + xoff, CHAR_LINES + yoff,
			len + 1, MSG_BOX_TEXT, MSG_BOX_COLOR);

	free(msg);

	_gfx->doUpdate();
}
Esempio n. 16
0
int16_t
NPP_HandleEvent(NPP instance, void* event) {
  InstanceData *instanceData = (InstanceData*)(instance->pdata);
  XEvent *nativeEvent = (XEvent*)event;

  if (nativeEvent->type != GraphicsExpose)
    return 0;

  XGraphicsExposeEvent *expose = &nativeEvent->xgraphicsexpose;
  instanceData->window.window = (void*)(expose->drawable);

  GdkNativeWindow nativeWinId = (XID)(instanceData->window.window);
  GdkDrawable* gdkWindow = GDK_DRAWABLE(gdk_window_foreign_new(nativeWinId));  
  drawWindow(instanceData, gdkWindow);
  g_object_unref(gdkWindow);

  return 1;
}
Esempio n. 17
0
int sys_updateWindow()
{
	int window_id;
	int detail;
	color16* context;
	WindowLink pWindow;
	if (argint(0, &window_id) < 0)
		return -1;
	pWindow = getWindowById(window_id);
	cprintf("updateWindow called: %d\n", pWindow);
	if (pWindow == 0) return -1;
	int size = ((pWindow->window_position).right_x - (pWindow->window_position).left_x) *
		((pWindow->window_position).right_y - (pWindow->window_position).left_y);
	//cprintf("window size: %d\n", size);
	if (size < 0) return -1;
	if (argptr(1, (void*)&context, sizeof(color16) * size) < 0) return -1;
	if (argint(2, &detail) < 0)		return -1;
	drawWindow(pWindow, context, detail);
	return 0;
}
Esempio n. 18
0
void printWindows()
{
	char** out = (char**)malloc( (root.dim.h+1) * sizeof(char*) );
	int i,j;
	for(i=0; i<root.dim.h+1; i++)
	{
		out[i] = (char*)malloc( (root.dim.w+2) * sizeof(char) );
		for(j=0; j<root.dim.w+1; j++)
			out[i][j] = ' ';
		out[i][root.dim.w+1] = '\0';
	}
	
	drawWindow(&root, out, 0, 0);
	
	for(i=0; i<root.dim.h+1; i++)
	{
		printf("%s\n", out[i]);
		free(out[i]);
	}
	free(out);
}
Esempio n. 19
0
int AgiEngine::loadGameDialog() {
	int rc, slot = 0;
	int hm, vm, hp, vp;	// box margins
	int w;

	hm = 1;
	vm = 3;
	hp = hm * CHAR_COLS;
	vp = vm * CHAR_LINES;
	w = (40 - 2 * hm) - 1;

	_sprites->eraseBoth();
	_sound->stopSound();

	drawWindow(hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp);
	printText("Select a game which you wish to\nrestore:",
			0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOR);

	slot = selectSlot();

	if (slot < 0) {
		if (slot == -1) // slot = -2 when GMM was launched
			messageBox("Game NOT restored.");

		return errOK;
	}

	Common::String fileName = getSavegameFilename(_firstSlot + slot);

	if ((rc = loadGame(fileName)) == errOK) {
		messageBox("Game restored.");
		_game.exitAllLogics = 1;
		_menu->enableAll();
	} else {
		messageBox("Error restoring game.");
	}

	return rc;
}
Esempio n. 20
0
void resizeWindow(Window* win, int width, int height) {

	bitmap* new_context = newBitmap(width, height);

	if (!new_context)
		return;

	int copy_w = width < win->w ? width : win->w;
	int copy_h = height < win->h ? height : win->h;

	win->w = width;
	win->h = height;

	int x, y;
	for (y = 0; y < copy_h; y++)
	for (x = 0; x < copy_w; x++)
		new_context->data[y*new_context->width + x] = win->context->data[y*win->context->width + x];

	freeBitmap(win->context);
	win->context = new_context;

	drawWindow(win, 0);
}
Esempio n. 21
0
Window *GfxPorts::addWindow(const Common::Rect &dims, const Common::Rect *restoreRect, const char *title, uint16 style, int16 priority, bool draw) {
	// Find an unused window/port id
	uint id = PORTS_FIRSTWINDOWID;
	while (id < _windowsById.size() && _windowsById[id]) {
		if (_windowsById[id]->counterTillFree) {
			// port that is already disposed, but not freed yet
			freeWindow((Window *)_windowsById[id]);
			_freeCounter--;
			break; // reuse the handle
			// we do this especially for sq4cd. it creates and disposes the
			//  inventory window all the time, but reuses old handles as well
			//  this worked somewhat under the original interpreter, because
			//  it put the new window where the old was.
		}
		++id;
	}
	if (id == _windowsById.size())
		_windowsById.push_back(0);
	assert(0 < id && id < 0xFFFF);

	Window *pwnd = new Window(id);
	Common::Rect r;

	if (!pwnd) {
		error("Can't open window");
		return 0;
	}

	_windowsById[id] = pwnd;

	// KQ1sci, KQ4, iceman, QfG2 always add windows to the back of the list.
	// KQ5CD checks style.
	// Hoyle3-demo also always adds to the back (#3036763).
	bool forceToBack = (getSciVersion() <= SCI_VERSION_1_EGA_ONLY) ||
	                   (g_sci->getGameId() == GID_HOYLE3 && g_sci->isDemo());

	if (!forceToBack && (style & SCI_WINDOWMGR_STYLE_TOPMOST))
		_windowList.push_front(pwnd);
	else
		_windowList.push_back(pwnd);
	openPort(pwnd);

	r = dims;
	// This looks fishy, but it's exactly what Sierra did. They removed last
	// bit of the left dimension in their interpreter. It seems Sierra did it
	// for EGA byte alignment (EGA uses 1 byte for 2 pixels) and left it in
	// their interpreter even in the newer VGA games.
	r.left = r.left & 0xFFFE;

	if (r.width() > _screen->getWidth()) {
		// We get invalid dimensions at least at the end of sq3 (script bug!).
		// Same happens very often in lsl5, sierra sci didnt fix it but it looked awful.
		// Also happens frequently in the demo of GK1.
		warning("Fixing too large window, left: %d, right: %d", dims.left, dims.right);
		r.left = 0;
		r.right = _screen->getWidth() - 1;
		if ((style != _styleUser) && !(style & SCI_WINDOWMGR_STYLE_NOFRAME))
			r.right--;
	}
	pwnd->rect = r;
	if (restoreRect)
		pwnd->restoreRect = *restoreRect;

	pwnd->wndStyle = style;
	pwnd->hSaved1 = pwnd->hSaved2 = NULL_REG;
	pwnd->bDrawn = false;
	if ((style & SCI_WINDOWMGR_STYLE_TRANSPARENT) == 0)
		pwnd->saveScreenMask = (priority == -1 ? GFX_SCREEN_MASK_VISUAL : GFX_SCREEN_MASK_VISUAL | GFX_SCREEN_MASK_PRIORITY);

	if (title && (style & SCI_WINDOWMGR_STYLE_TITLE)) {
		pwnd->title = title;
	}

	r = pwnd->rect;
	if ((style != _styleUser) && !(style & SCI_WINDOWMGR_STYLE_NOFRAME)) {
		r.grow(1);
		if (style & SCI_WINDOWMGR_STYLE_TITLE) {
			r.top -= 10;
			r.bottom++;
		}
	}

	pwnd->dims = r;

	// Clip window, if needed
	Common::Rect wmprect = _wmgrPort->rect;
	// Handle a special case for Dr. Brain 1 Mac. When hovering the mouse cursor
	// over the status line on top, the game scripts try to draw the game's icon
	// bar above the current port, by specifying a negative window top, so that
	// the end result will be drawn 10 pixels above the current port. This is a
	// hack by Sierra, and is only limited to user style windows. Normally, we
	// should not clip, same as what Sierra does. However, this will result in
	// having invalid rectangles with negative coordinates. For this reason, we
	// adjust the containing rectangle instead.
	if (pwnd->dims.top < 0 && g_sci->getPlatform() == Common::kPlatformMacintosh &&
		(style & SCI_WINDOWMGR_STYLE_USER) && _wmgrPort->top + pwnd->dims.top >= 0) {
		// Offset the final rect top by the requested pixels
		wmprect.top += pwnd->dims.top;
	}

	int16 oldtop = pwnd->dims.top;
	int16 oldleft = pwnd->dims.left;

	// WORKAROUND: We also adjust the restore rect when adjusting the window
	// rect.
	// SSCI does not do this. It wasn't necessary in the original interpreter,
	// but it is needed for Freddy Pharkas CD. This version does not normally
	// have text, but we allow this by modifying the text/speech setting
	// according to what is set in the ScummVM GUI (refer to syncIngameAudioOptions()
	// in sci.cpp). Since the text used in Freddy Pharkas CD is quite large in
	// some cases, it ends up being offset in order to fit inside the screen,
	// but the associated restore rect isn't adjusted accordingly, leading to
	// artifacts being left on screen when some text boxes are removed. The
	// fact that the restore rect wasn't ever adjusted doesn't make sense, and
	// adjusting it shouldn't have any negative side-effects (it *should* be
	// adjusted, normally, but SCI doesn't do it). The big text boxes are still
	// odd-looking, because the text rect is drawn outside the text window rect,
	// but at least there aren't any leftover textbox artifacts left when the
	// boxes are removed. Adjusting the text window rect would require more
	// invasive changes than this one, thus it's not really worth the effort
	// for a feature that was not present in the original game, and its
	// implementation is buggy in the first place.
	// Adjusting the restore rect properly fixes bug #3575276.

	if (wmprect.top > pwnd->dims.top) {
		pwnd->dims.moveTo(pwnd->dims.left, wmprect.top);
		if (restoreRect)
			pwnd->restoreRect.moveTo(pwnd->restoreRect.left, wmprect.top);
	}

	if (wmprect.bottom < pwnd->dims.bottom) {
		pwnd->dims.moveTo(pwnd->dims.left, wmprect.bottom - pwnd->dims.bottom + pwnd->dims.top);
		if (restoreRect)
			pwnd->restoreRect.moveTo(pwnd->restoreRect.left, wmprect.bottom - pwnd->restoreRect.bottom + pwnd->restoreRect.top);
	}

	if (wmprect.right < pwnd->dims.right) {
		pwnd->dims.moveTo(wmprect.right + pwnd->dims.left - pwnd->dims.right, pwnd->dims.top);
		if (restoreRect)
			pwnd->restoreRect.moveTo(wmprect.right + pwnd->restoreRect.left - pwnd->restoreRect.right, pwnd->restoreRect.top);
	}

	if (wmprect.left > pwnd->dims.left) {
		pwnd->dims.moveTo(wmprect.left, pwnd->dims.top);
		if (restoreRect)
			pwnd->restoreRect.moveTo(wmprect.left, pwnd->restoreRect.top);
	}

	pwnd->rect.moveTo(pwnd->rect.left + pwnd->dims.left - oldleft, pwnd->rect.top + pwnd->dims.top - oldtop);

	if (restoreRect == 0)
		pwnd->restoreRect = pwnd->dims;

	if (pwnd->restoreRect.top < 0 && g_sci->getPlatform() == Common::kPlatformMacintosh &&
		(style & SCI_WINDOWMGR_STYLE_USER) && _wmgrPort->top + pwnd->restoreRect.top >= 0) {
		// Special case for Dr. Brain 1 Mac (check above), applied to the
		// restore rectangle.
		pwnd->restoreRect.moveTo(pwnd->restoreRect.left, wmprect.top);
	}

	if (draw)
		drawWindow(pwnd);
	setPort((Port *)pwnd);

	// All SCI0 games till kq4 .502 (not including) did not adjust against _wmgrPort, we set _wmgrPort->top to 0 in that case
	setOrigin(pwnd->rect.left, pwnd->rect.top + _wmgrPort->top);
	pwnd->rect.moveTo(0, 0);
	return pwnd;
}
Esempio n. 22
0
void do_menu(void){
	if(show_menu){ //regular xmc mode
		//xmc
		#define pos_x 0.25
		#define start_y 0.14
		INIT_FRONTEND_HELPER_TEXT();
		DRAW_FRONTEND_HELPER_TEXT("LEAVE", "INPUT_F_CANCEL", 0);
		DRAW_FRONTEND_HELPER_TEXT("CONFIRM", "INPUT_F_ACCEPT", 0);
		DRAW_FRONTEND_HELPER_TEXT("SCROLL", "PAD_DPAD_UPDOWN", 0);
	
		if(!xmc_compact){
			HIDE_HELP_TEXT_THIS_FRAME();
			pos_y = start_y;
			
			if(xmc_dim) DRAW_RECT(0.5000, 0.5000, 1.0000, 1.0000, 0, 0, 0, 110);
			
			//draw_title(0.5,0.05,0.6,0.98,s_r,s_g,s_b,255,MENU_TITLE);
			draw_title(0.5,0.05,0.6,0.98,s_r,s_g,s_b,255,footer);
			draw_title(0.5,0.109,0.4,0.50,s_r,s_g,s_b,255,MENU_AUTHOR);
			
			set_up_draw(3,0.35,0.35,255,255,255,255);
			//draw_text("STRING",0.05,0.975,footer);
			
			uint i = 1;
			for(i;i <= item_count;i++){
				r = 255;
				g = 255;
				b = 255;
				a = 255;
				pos_y = pos_y + 0.0375;
				if(item_select == i){
					r = s_r;
					g = s_g;
					b = s_b;
				}
				if(menu[i].type == 1){
					if(menu[i].value){
						set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
						draw_text("STRING",(pos_x + 0.3),pos_y,"On");
					}
					else{
						set_up_draw(3,0.35,0.35,255,255,255,a);
						draw_text("STRING",(pos_x + 0.3),pos_y,"Off");
					}
				}
				if(menu[i].type == 2){
					set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
					draw_text("STRING",(pos_x + 0.3),pos_y,"(");
					
					set_up_draw(3,0.35,0.35,255,255,255,a);				
					draw_number("NUMBR",(pos_x + 0.305),pos_y,menu[i].value);
					
					set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
					if(menu[i].value > 99)
						draw_text("STRING",(pos_x + 0.345),pos_y,")");
					else if(menu[i].value > 9)
						draw_text("STRING",(pos_x + 0.33),pos_y,")");
					else
						draw_text("STRING",(pos_x + 0.315),pos_y,")");
				}
				if(menu[i].type == 3){
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING",pos_x,pos_y,GET_STRING_FROM_TEXT_FILE(GET_DISPLAY_NAME_FROM_VEHICLE_MODEL(menu[i].value)));
				}
				if(menu[i].type == 4){
					if(item_select == i){
						r = s_r;
						g = s_g;
						b = s_b;
					}
					else GET_PLAYER_RGB_COLOUR(menu[i].value,&r,&g,&b);
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING", pos_x, pos_y, menu[i].item_name);
				}
				if(menu[i].type == 5){
					if(!COMPARE_STRING(menu[i].item_name, "")){
						set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
						draw_text("STRING", pos_x - 0.08, pos_y, "Admin");
					}
					if(item_select == i){
						r = s_r;
						g = s_g;
						b = s_b;
					}
					else if(xmc_online_col) GET_PLAYER_RGB_COLOUR(menu[i].value,&r,&g,&b);					
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING", pos_x, pos_y, menu[i].item_name);
				}
				else{
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING",pos_x,pos_y,menu[i].item_name);
				}
			}
			
			
			
			///Buttons
			if(IS_BUTTON_JUST_PRESSED(0,DPAD_UP)){
				if(item_select == 1){
					item_select = item_count;
				}
				else item_select--;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_DOWN)){
				if(item_select == item_count){
					item_select = 1;
				}
				else item_select++;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_RIGHT) && menu[item_select].type == 2){
				if(menu[item_select].value == menu[item_select].maxval)
					menu[item_select].value = 1;
				else
					menu[item_select].value += 1;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_LEFT) && menu[item_select].type == 2){
				if(menu[item_select].value == 1)
					menu[item_select].value = menu[item_select].maxval;
				else
					menu[item_select].value -= 1;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,BUTTON_A)){
				if(menu[item_select].action){
					menu_functions();
				}
				else{
					uint i = 1;
					for(i;i <= item_count;i++){
						menu[i].action = false;
						menu[i].type = 0;
					}
					last_selected[menu_level] = item_select;
					menu_level++;
					menu_setup();
					item_select = 1;
				}
			}
			else if(IS_BUTTON_JUST_PRESSED(0,BUTTON_B)){
				if(menu_level > 0){
					uint i = 1;
					for(i;i <= item_count;i++){
						menu[i].action = false;
						menu[i].type = 0;
					}
					menu_level--;
					item_select = last_selected[menu_level];
					menu_setup();
				}
				else menu_shutdown();
			}
		}
		else{ 
			#define pos_x 0.60
			#define start_y 0.25 				
			#define spacing 0.025
			pos_y = start_y;
			drawWindow();
			s_a = 255;
			set_up_draw(4,0.35,0.35,s_r,s_g,s_b,255);
			draw_text("STRING",pos_x,start_y-.02,footer);
			uint i = 1;
			for(i;i <= item_count;i++){
				r = 255;g = 255;b = 255;a = 255;
				pos_y = pos_y + spacing;
				if(item_select == i){
					r = s_r;
					g = s_g;
					b = s_b;
				}
				if(menu[i].type == 1){
					if(menu[i].value){
						set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
						draw_text("STRING",(pos_x + 0.265),pos_y,"On");
					}
				}
				if(menu[i].type == 2){
					set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
					draw_text("STRING",(pos_x + 0.19),pos_y,"(");
					set_up_draw(3,0.35,0.35,255,255,255,a);				
					draw_number("NUMBR",(pos_x + 0.205),pos_y,menu[i].value);
					set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
					if(menu[i].value > 99) draw_text("STRING",(pos_x + 0.245),pos_y,")");
					else if(menu[i].value > 9) draw_text("STRING",(pos_x + 0.23),pos_y,")");
					else draw_text("STRING",(pos_x + 0.215),pos_y,")");
				}
				if(menu[i].type == 3){
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING",pos_x,pos_y,GET_STRING_FROM_TEXT_FILE(GET_DISPLAY_NAME_FROM_VEHICLE_MODEL(menu[i].value)));
				}
				if(menu[i].type == 4){
					if(item_select == i){
						r = s_r;
						g = s_g;
						b = s_b;
					}
					else GET_PLAYER_RGB_COLOUR(menu[i].value,&r,&g,&b);
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING", pos_x, pos_y, menu[i].item_name);
				}
				else{
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING",pos_x,pos_y,menu[i].item_name);
				}
			}
			
			///Buttons
			if(IS_BUTTON_JUST_PRESSED(0,DPAD_UP)){
				if(item_select == 1){
					item_select = item_count;
				}
				else item_select--;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_DOWN)){
				if(item_select == item_count){
					item_select = 1;
				}
				else item_select++;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_RIGHT) && menu[item_select].type == 2){
				if(menu[item_select].value == menu[item_select].maxval)
					menu[item_select].value = 1;
				else
					menu[item_select].value += 1;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_LEFT) && menu[item_select].type == 2){
				if(menu[item_select].value == 1)
					menu[item_select].value = menu[item_select].maxval;
				else
					menu[item_select].value -= 1;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,BUTTON_A)){
				if(menu[item_select].action){
					menu_functions();
				}
				else{
					uint i = 1;
					for(i;i <= item_count;i++){
						menu[i].action = false;
						menu[i].type = 0;
					}
					last_selected[menu_level] = item_select;
					menu_level++;
					menu_setup();
					item_select = 1;
				}
			}
			else if(IS_BUTTON_JUST_PRESSED(0,BUTTON_B)){
				if(menu_level > 0){
					uint i = 1;
					for(i;i <= item_count;i++){
						menu[i].action = false;
						menu[i].type = 0;
					}
					menu_level--;
					item_select = last_selected[menu_level];
					menu_setup();
				}
				else menu_shutdown();
			}
		}
	}
	else if(!xmc_switch && IS_BUTTON_PRESSED(0,BUTTON_LB) && IS_BUTTON_JUST_PRESSED(0,BUTTON_RB)) menu_startup();
	else if(xmc_switch && IS_BUTTON_PRESSED(0,BUTTON_RB) && IS_BUTTON_JUST_PRESSED(0,BUTTON_LB)) menu_startup();
}
Esempio n. 23
0
void peripheralsOutputTick(void) {
	drawWindow();
	SDL_GL_SwapWindow(wnd);
}
Esempio n. 24
0
void drawWindow(MyWindow* currentWindow, float zOrder){
    DWORD winStyle = GetWindowLong(currentWindow->hwnd, GWL_STYLE);



    if(IsWindowVisible(currentWindow->hwnd)){
        BITMAP bitmap;
        HBITMAP hbmp;
        //find all childs and sort them according to z-order
        //draw all window on mainWindowpos + relative coord
        //myFinder->getAnchorWindow()->draw();

        glBindTexture(GL_TEXTURE_2D, screenTexture);

        hbmp = currentWindow->getHBitmap();
        currentWindow->convertToDib(hbmp);
        GetObject (hbmp, sizeof(BITMAP), &bitmap);
        int data_size = bitmap.bmWidth * bitmap.bmHeight * 4;

        //RGB to BGR (ou l'autre, j'en ai plus aucune idée)
        bool isFullyBlack = 1;
        for (int i=0; i<data_size; i+=4){
            // Bitmap failed to be captured
            if(bitmap.bmBits == NULL){
                return;
            }
            unsigned char tmp = ((unsigned char*)bitmap.bmBits)[i];
            ((unsigned char*)bitmap.bmBits)[i] = ((unsigned char*)bitmap.bmBits)[i+2];
            ((unsigned char*)bitmap.bmBits)[i+2] = tmp;

            unsigned char* vals = (unsigned char*) bitmap.bmBits;
            if(vals[0]!=0 && vals[1]!=0 && vals[2]!=0){
                isFullyBlack = 0;
            }
        }

        if(isFullyBlack){
            return;
        }

        glTexImage2D(GL_TEXTURE_2D,0,4,bitmap.bmWidth,bitmap.bmHeight,0,GL_RGBA, GL_UNSIGNED_BYTE, bitmap.bmBits);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

        //Draw texture
        int width = bitmap.bmWidth;
        int height = bitmap.bmHeight;

        glBegin(GL_TRIANGLE_STRIP);

        glColor4f(1,1,1,1);
        float left,right;
        float bottom,top;


        RECT position;
        GetWindowRect(currentWindow->hwnd, &position);

        float scale = 50;



        if(currentWindow->parent!=NULL){
            MapWindowPoints(HWND_DESKTOP, currentWindow->parent->hwnd, (LPPOINT) &position, 2);
            position.left += currentWindow->parent->winPos.left;
            position.top += currentWindow->parent->winPos.top;
            position.right +=  currentWindow->parent->winPos.left;
            position.bottom += currentWindow->parent->winPos.top;

        }
        else{
            position.top -= (float)GetSystemMetrics(SM_CYSCREEN)/2  ;
            position.bottom -= (float)GetSystemMetrics(SM_CYSCREEN)/2;
            position.left -= (float)GetSystemMetrics(SM_CXSCREEN)/2 ;
            position.right -= (float)GetSystemMetrics(SM_CXSCREEN)/2 ;
            currentWindow->adjustConfiguration(&position, scale);
        }



        currentWindow->winPos = position;

        left = position.left;
        right = position.right;
        top = -position.top;
        bottom = top-(float)height;



        top/=scale;
        left/=scale;
        bottom/=scale;
        right/=scale;

        glTexCoord2f(0,0);
        glVertex3f(left,bottom,currentWindow->leftZOrder);
        glTexCoord2f(1,0);
        glVertex3f(right, bottom,currentWindow->rightZOrder);
        glTexCoord2f(0,1);
        glVertex3f(left, top,currentWindow->leftZOrder);
        glTexCoord2f(1,1);
        glVertex3f(right, top,currentWindow->rightZOrder);

        glEnd();

        DeleteObject(hbmp);
        }

        for(int i = 0; i < currentWindow->childList.size();i++){
            MyWindow* child = currentWindow->childList.front();
            currentWindow->childList.pop_front();
            float deltaZOrder = (float)(currentWindow->childList.size()-i)/(currentWindow->childList.size()*10000);
            drawWindow(child,zOrder+deltaZOrder);
            currentWindow->childList.push_back(child);

        }
}
Esempio n. 25
0
/* NOTE: Automatic deduction of the number of blocks, that need to be erased 
         has not been tested extensive. */
void upload() {

   uint size;           // Image size.
   uint step;           // Progress bar step size.
   uint cval;           // Current progress value.

   // Clear screen.
   cls();

   // User Upload Menu.
   drawWindow(&wUpload);

   // Upload Initialization.
   drawMessage(&wUpload, &msgUploadWait); 
   pbUpload.val = 0;   
   drawProgressBar(&wUpload, &pbUpload);
   
   // Receive 4 bytes of size data.
   for(uchar i=0; i < 4; i++) {
      size <<= 8;
      size += rs232_receive();
   }

   // Check for image size to fit into flash.
   if(size > FLASH_BLOCK_SIZE * FLASH_BLOCKS) {
      drawErrorWindow(&errErrorFlashSize);
      return 0;
   }

   // Flash Clean Up.
   drawMessage(&wUpload, &msgUploadErase);
   pbUpload.val = 0;                         // Reset progress bar.
   drawProgressBar(&wUpload, &pbUpload);
   
   // Erase affected flash blocks.
   for(uint i=0; i < (size / FLASH_BLOCK_SIZE) + 1; i++) {
      flash_block_erase(i * FLASH_BLOCK_SIZE);

      // Update the Progress Bar.
      pbUpload.val = (i >> 1);
      drawProgressBar(&wUpload, &pbUpload);

      // Check for errors while erasing.
      if(flash_wait() & FLASH_ERASE_ERROR) {
         drawErrorWindow(&errErrorFlashErase);
         return 0;
      }
   }
   
   // Write image size at flash address 0x0.
   for(uchar i=0; i<4; i++) {
      flash_write(i, size >> ((3-i) * 8) );
      checkFlashWrite();
   }

   // Upload data.
   drawMessage(&wUpload, &msgUploadWrite);
   pbUpload.val = 0;                         // Reset progress bar.
   step = size / 64;                         // Calculate progress step size.
   cval = step;

   // Echoing received image size.
   for(uchar i=0; i<4; i++) {
      rs232_transmit( size >> ((3-i) * 8) );
   }
   
   // Write each single byte to Flash.
   for(uint i=0; i < size; i++) {
      flash_write(i + 4, rs232_receive());

      // Update status bar.
      if(i == cval) {
         pbUpload.val++;
         drawProgressBar(&wUpload, &pbUpload);
         cval += step;
      }

      checkFlashWrite();
   }

   // Go back to main menu.
   boot();
}
Esempio n. 26
0
/* Wait for completed flash initialization. Set up main menu box. */
int main() {
   
   uchar s;
   
   // Clear screen.
   cls();

   // Wait for flash hardware initialization end.
   s = flash_wait();

   // Flash not ready.
   if( !(s & FLASH_READY) ) {
      drawErrorWindow(&errFlashNotReady);
      return 0;
   }

   // Flash command error.
   if(s & FLASH_CMD_ERROR) {
      drawErrorWindow(&errFlashState);
      flash_clear_sr();
      //boot();
      return 0;
   }

   // User Main Menu.
   drawWindow(&wBoot);

   while(TRUE) {
      switch(getc()->chr) {
         case KEY_ARROWD:
            menuKeyDown(&wBoot, &menu);
            break;

         case KEY_ARROWU:
            menuKeyUp(&wBoot, &menu);
            break;

         case KEY_ENTER:
            switch(menu.index) {
               case OPTION_UPLOAD:
                  upload();
                  break;

               case OPTION_MEMORY:
                  view_memories();
                  break;

               case OPTION_START:
                  load(1, flash_read(0));
                  start();
                  break;

               default:
                  break;
            }
            break;

         default:
            break;
      }
   }
}
Esempio n. 27
0
	void FileDialog::drawContents(Renderer2D &out) const {
		drawWindow(out, IRect({0, 0}, rect().size()), WindowStyle::gui_dark, 3);
	}
Esempio n. 28
0
bool AgiEngine::predictiveDialog() {
	int key = 0, active = -1, lastactive = 0;
	bool rc = false;
	uint8 x;
	int y;
	int bx[17], by[17];
	Common::String prefix;
	char temp[MAXWORDLEN + 1], repeatcount[MAXWORDLEN];
	AgiBlock tmpwindow;
	bool navigationwithkeys = false;
	bool processkey;

	const char *buttonStr[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
	const char *buttons[] = {
		"(1)'-.&",  "(2)abc", "(3)def",
		"(4)ghi",  "(5)jkl", "(6)mno",
		"(7)pqrs", "(8)tuv", "(9)wxyz",
		"(#)next",    "add",
		"<",
		"Cancel",  "OK",
		"Pre", "(0) ", NULL
	};
	const int colors[] = {
		15, 0, 15, 0, 15, 0,
		15, 0, 15, 0, 15, 0,
		15, 0, 15, 0, 15, 0,
		15, 12, 15, 12,
		15, 0,
		15, 0, 15, 0,
		14, 0, 15, 0, 0, 0
	};
	const char *modes[] = { "(*)Pre", "(*)123", "(*)Abc" };

	// FIXME: Move this to a more appropriate place.
	if (!_predictiveDictText) {
		loadDict();
		if (!_predictiveDictText)
			return false;
	}
	_predictiveDictActLine = NULL;
	uint8 numMatchingWords = 0;

	_predictiveDialogRunning = true;
	_system->setFeatureState(OSystem::kFeatureDisableKeyFiltering, true);

	memset(repeatcount, 0, sizeof(repeatcount));

	// show the predictive dialog.
	// if another window is already in display, save its state into tmpwindow
	memset(&tmpwindow, 0, sizeof(tmpwindow));
	tmpwindow.active = false;
	if (_game.window.active)
		memcpy(&tmpwindow, &(_game.window), sizeof(AgiBlock));
	drawWindow(50, 40, 269, 159);
	_gfx->drawRectangle(62, 54, 249, 66, MSG_BOX_TEXT);
	_gfx->flushBlock(62, 54, 249, 66);

	bx[15] = 73; // Zero/space
	by[15] = 120;
	bx[9] = 110; // next
	by[9] = 120;
	bx[10] = 172; // add
	by[10] = 120;
	bx[14] = 200; // Mode
	by[14] = 120;
	bx[11] = 252; // Backspace
	by[11] = 57;
	bx[12] = 180; // Cancel
	by[12] = 140;
	bx[13] = 240; // OK
	by[13] = 140;

	x = 73;
	y = 75;
	for (int i = 0; i < 9; i++) {
		bx[i] = x;
		by[i] = y;
		x += 60;
		if (i % 3 == 2) {
			y += 15;
			x = 73;
		}
	}

	clearKeyQueue();

	prefix.clear();
	_currentCode.clear();
	_currentWord.clear();
	_wordNumber = 0;

	int mode = kModePre;

	bool needRefresh = true;

	for (;;) {
		if (needRefresh) {
			for (int i = 0; buttons[i]; i++) {
				int color1 = colors[i * 2];
				int color2 = colors[i * 2 + 1];

				if (i == 9 && !((mode != kModeAbc && _predictiveDictActLine && numMatchingWords > 1)
							|| (mode == kModeAbc && _currentWord.size() && _currentWord.lastChar() != ' '))) { // Next
					color2 = 7;
				}

				// needs fixing, or remove it!
				bool _addIsActive = false; // FIXME: word adding is not implemented
				if (i == 10 && !_addIsActive) { // Add
					color2 = 7;
				}
				if (i == 14) {
					_gfx->drawDefaultStyleButton(bx[i], by[i], modes[mode], i == active, 0, color1, color2);
				} else {
					_gfx->drawDefaultStyleButton(bx[i], by[i], buttons[i], i == active, 0, color1, color2);
				}
			}

			Common::strlcpy(temp, prefix.c_str(), sizeof(temp));
			Common::strlcat(temp, _currentWord.c_str(), sizeof(temp));

			for (int i = prefix.size() + _currentCode.size(); i < MAXWORDLEN; i++)
				temp[i] = ' ';
			temp[MAXWORDLEN] = 0;

			printText(temp, 0, 8, 7, MAXWORDLEN, 15, 0);
			_gfx->flushBlock(62, 54, 249, 66);

			if (active >= 0 && !navigationwithkeys) {
				// provide visual feedback only when not navigating with the arrows
				// so that the user can see the active button.
				active = -1;
				needRefresh = true;
			} else
				needRefresh = false;

			_gfx->doUpdate();
		}

		pollTimer();
		key = doPollKeyboard();
		processkey = false;
		switch (key) {
		case KEY_ENTER:
			if (navigationwithkeys) {
				// when the user has utilized arrow key navigation,
				// interpret enter as 'click' on the active button
				active = lastactive;
			} else {
				// else it is a shortcut for 'Ok'
				active = 13;
			}
			processkey = true;
			break;
		case KEY_ESCAPE:
			rc = false;
			goto getout;
		case BUTTON_LEFT:
			navigationwithkeys = false;
			for (int i = 0; buttons[i]; i++) {
				if (_gfx->testButton(bx[i], by[i], buttons[i])) {
					active = i;
					processkey = true;
					break;
				}
			}
			break;
		case KEY_BACKSPACE:
			active = 11;
			processkey = true;
			break;
		case '#':
			active = 9;
			processkey = true;
			break;
		case '*':
			active = 14;
			processkey = true;
			break;
		case 0x09:	// Tab
			navigationwithkeys = true;
			debugC(3, kDebugLevelText, "Focus change");
			lastactive = active = lastactive + 1;
			active %= ARRAYSIZE(buttons) - 1;
			needRefresh = true;
			break;
		case KEY_LEFT:
			navigationwithkeys = true;
			if (lastactive == 0 || lastactive == 3 || lastactive == 6)
				active = lastactive + 2;
			else if (lastactive == 9)
				active = 15;
			else if (lastactive == 11)
				active = 11;
			else if (lastactive == 12)
				active = 13;
			else if (lastactive == 14)
				active = 10;
			else
				active = lastactive - 1;
			lastactive = active;
			needRefresh = true;
			break;
		case KEY_RIGHT:
			navigationwithkeys = true;
			if (lastactive == 2 || lastactive == 5 || lastactive == 8)
				active = lastactive - 2;
			else if (lastactive == 10)
				active = 14;
			else if (lastactive == 11)
				active = 11;
			else if (lastactive == 13)
				active = 12;
			else if (lastactive == 15)
				active = 9;
			else
				active = lastactive + 1;
			lastactive = active;
			needRefresh = true;
			break;
		case KEY_UP:
			navigationwithkeys = true;
			if (lastactive <= 2)
				active = 11;
			else if (lastactive == 9 || lastactive == 10)
				active = lastactive - 2;
			else if (lastactive == 11)
				active = 13;
			else if (lastactive == 14)
				active = 8;
			else if (lastactive == 15)
				active = 6;
			else
				active = lastactive - 3;
			lastactive = active;
			needRefresh = true;
			break;
		case KEY_DOWN:
			navigationwithkeys = true;
			if (lastactive == 6)
				active = 15;
			else if (lastactive == 7 || lastactive == 8)
				active = lastactive + 2;
			else if (lastactive == 11)
				active = 0;
			else if (lastactive == 12 || lastactive == 13)
				active = 11;
			else if (lastactive == 14 || lastactive == 15)
				active = lastactive - 2;
			else
				active = lastactive + 3;
			lastactive = active;
			needRefresh = true;
			break;
		default:
			// handle numeric buttons
			if (key >= '1' && key <= '9') {
				active = key - '1';
				processkey = true;
			} else if (key == '0') {
				active = 15;
				processkey = true;
			}
			break;
		}

		if (processkey) {
			if (active >= 0) {
				needRefresh = true;
				lastactive = active;
				if (active == 15 && mode != kModeNum) { // Space
					// bring MRU word at the top of the list when changing words
					if (mode == kModePre && _predictiveDictActLine && numMatchingWords > 1 && _wordNumber != 0)
						bringWordtoTop(_predictiveDictActLine, _wordNumber);
					strncpy(temp, _currentWord.c_str(), _currentCode.size());
					temp[_currentCode.size()] = 0;
					prefix += temp;
					prefix += " ";
					_currentCode.clear();
					_currentWord.clear();
					numMatchingWords = 0;
					memset(repeatcount, 0, sizeof(repeatcount));
				} else if (active < 9 || active == 11 || active == 15) { // number or backspace
					if (active == 11) { // backspace
						if (_currentCode.size()) {
							repeatcount[_currentCode.size() - 1] = 0;
							_currentCode.deleteLastChar();
						} else {
							if (prefix.size())
								prefix.deleteLastChar();
						}
					} else if (prefix.size() + _currentCode.size() < MAXWORDLEN - 1) { // don't overflow the dialog line
						if (active == 15) { // zero
							_currentCode += buttonStr[9];
						} else {
							_currentCode += buttonStr[active];
						}
					}

					switch (mode) {
					case kModeNum:
						_currentWord = _currentCode;
						break;
					case kModePre:
						if (!matchWord() && _currentCode.size()) {
							_currentCode.deleteLastChar();
							matchWord();
						}
						numMatchingWords = countWordsInString(_predictiveDictActLine);
						break;
					case kModeAbc:
						for (x = 0; x < _currentCode.size(); x++)
							if (_currentCode[x] >= '1')
								temp[x] = buttons[_currentCode[x] - '1'][3 + repeatcount[x]];
						temp[_currentCode.size()] = 0;
						_currentWord = temp;
					}
				} else if (active == 9) { // next
					if (mode == kModePre) {
						if (_predictiveDictActLine && numMatchingWords > 1) {
							_wordNumber = (_wordNumber + 1) % numMatchingWords;
							char tmp[MAXLINELEN];
							strncpy(tmp, _predictiveDictActLine, MAXLINELEN);
							tmp[MAXLINELEN - 1] = 0;
							char *tok = strtok(tmp, " ");
							for (uint8 i = 0; i <= _wordNumber; i++)
								tok = strtok(NULL, " ");
							_currentWord = Common::String(tok, _currentCode.size());
						}
					} else if (mode == kModeAbc){
						x = _currentCode.size();
						if (x) {
							if (_currentCode.lastChar() == '1' || _currentCode.lastChar() == '7' || _currentCode.lastChar() == '9')
								repeatcount[x - 1] = (repeatcount[x - 1] + 1) % 4;
							else
								repeatcount[x - 1] = (repeatcount[x - 1] + 1) % 3;
							if (_currentCode.lastChar() >= '1')
								_currentWord.setChar(buttons[_currentCode[x - 1] - '1'][3 + repeatcount[x - 1]], x-1);
						}
					}
				} else if (active == 10) { // add
					debug(0, "add");
				} else if (active == 13) { // Ok
					// bring MRU word at the top of the list when ok'ed out of the dialog
					if (mode == kModePre && _predictiveDictActLine && numMatchingWords > 1 && _wordNumber != 0)
						bringWordtoTop(_predictiveDictActLine, _wordNumber);
					rc = true;
					goto press;
				} else if (active == 14) { // Mode
					mode++;
					if (mode > kModeAbc)
						mode = kModePre;

					// truncate current input at mode change
					strncpy(temp, _currentWord.c_str(), _currentCode.size());
					temp[_currentCode.size()] = 0;
					prefix += temp;
					_currentCode.clear();
					_currentWord.clear();
					memset(repeatcount, 0, sizeof(repeatcount));
				} else {
					goto press;
				}
			}
		}
	}

 press:
	Common::strlcpy(_predictiveResult, prefix.c_str(), sizeof(_predictiveResult));
	Common::strlcat(_predictiveResult, _currentWord.c_str(), sizeof(_predictiveResult));

 getout:
	// if another window was shown, bring it up again
	if (!tmpwindow.active)
		closeWindow();
	else {
		_gfx->restoreBlock(_game.window.x1, _game.window.y1,
				_game.window.x2, _game.window.y2, _game.window.buffer);

		free(_game.window.buffer);
		memcpy(&(_game.window), &tmpwindow, sizeof(AgiBlock));
		_gfx->doUpdate();
	}

	_system->setFeatureState(OSystem::kFeatureDisableKeyFiltering, false);
	_predictiveDialogRunning = false;

	return rc;
}
Esempio n. 29
0
Window* newWindow(unsigned int width, unsigned int height, unsigned char flags, unsigned int pid) {

	static int next_handle = 1;
	Window *new_window, *temp_window;
	unsigned int i, bufsz;

	if (!(new_window = (Window*)malloc(sizeof(window)))) {

		printf("Coudln't allocate a new window structure");
		return 0;
	}

	new_window->active = 1;
	new_window->pid = pid;
	new_window->flags = flags;
	new_window->x = 0;
	new_window->y = 0;
	new_window->w = width;
	new_window->h = height;
	new_window->title = (unsigned char*)0;
	new_window->frame_needs_redraw = 1;

	//Create a drawing context for the new window
	if (!(new_window->context = newBitmap(new_window->w, new_window->h))) {

		free((void*)new_window);
		printf("Couldn't allocate bitmap area for new window");
		return (window*)0;
	}

	bufsz = new_window->w * new_window->h;

	//Clear new window to white
	for (i = 0; i < bufsz; i++)
		new_window->context->data[i] = RGB(255, 255, 255);

	new_window->handle = next_handle++;

	if (mouse_window)
		List_pop(window_list, (void*)mouse_window);

	//De-activate the old active window
	if (temp_window = (window*)List_get_at(window_list, window_list->count - (mouse_window ? 2 : 1))) {

		temp_window->active = 0;
	}

	if (!List_add(window_list, (void*)new_window)){

		freeBitmap(new_window->context);
		free((void*)new_window);

		//re-activate the old active window
		if (temp_window)
			temp_window->active = 1;

		return (window*)0;
	}

	//Give the new window its initial decoration
	if (!(new_window->flags & WIN_UNDECORATED))
		drawFrame(new_window);

	drawWindow(new_window, 0);

	//Update the titlebar on the old active window 
	if (temp_window)
		drawTitlebar(temp_window, 1);

	if (mouse_window) {

		List_add(window_list, mouse_window);
		drawWindow(mouse_window, 0);
	}

	return new_window;
}
Esempio n. 30
0
void drawTitlebar(Window* cur_window, int do_refresh) {

	unsigned char* s;
	unsigned int tb_color, text_color;
	Rect old_ctx_rect;

	if (cur_window->flags & WIN_UNDECORATED)
		return;

	//Titlebar
	if (cur_window->active)
		tb_color = RGB(182, 0, 0);
	else
		tb_color = RGB(238, 203, 137);

	bmpFillRect(cur_window->context, 4, 4, cur_window->w - 28, 20, tb_color);

	//Window title
	if (cur_window->title) {

		int base_x, base_y, off_x, titlebar_width;

		s = cur_window->title;
		base_x = 7;
		base_y = 9;
		off_x = 0;
		titlebar_width = cur_window->w - 28;

		if (cur_window->active)
			text_color = RGB(255, 255, 255);
		else
			text_color = RGB(138, 103, 37);

		while (*s) {

			bmpDrawCharacter(cur_window->context, *(s++), base_x + off_x, base_y, text_color);
			off_x += 8;

			//Truncate the text if it's wider than the titlebar
			if (off_x >= titlebar_width)
				break;
		}
	}

	if (do_refresh) {

		old_ctx_rect.top = cur_window->context->top;
		old_ctx_rect.left = cur_window->context->left;
		old_ctx_rect.bottom = cur_window->context->bottom;
		old_ctx_rect.right = cur_window->context->right;

		cur_window->context->top = 4;
		cur_window->context->left = 4;
		cur_window->context->bottom = 23;
		cur_window->context->right = cur_window->w - 26;

		drawWindow(cur_window, 1);

		cur_window->context->top = old_ctx_rect.top;
		cur_window->context->left = old_ctx_rect.left;
		cur_window->context->bottom = old_ctx_rect.bottom;
		cur_window->context->right = old_ctx_rect.right;
	}
}