def fx(): width = bge.render.getWindowWidth() height = bge.render.getWindowHeight() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() bgl.gluOrtho2D(0, width, 0, height) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glLoadIdentity() bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.8, 0.0, 0.0, 0.1) bgl.glRecti(0, 0, width, height) # bgl.glBegin(bgl.GL_QUADS) # bgl.glVertex2i(0, 0) # bgl.glVertex2i(width, 0) # bgl.glVertex2i(width, height) # bgl.glVertex2i(0, height) # bgl.glVertex2f(0.0, 0.0) # bgl.glVertex2f(1.0, 0.0) # bgl.glVertex2f(1.0, 1.0) # bgl.glVertex2f(0.0, 1.0) # bgl.glEnd() bgl.glDisable(bgl.GL_BLEND)
def draw(self): """a multiline output drawn""" # super(Text,self).draw() #PKHG 7jul12 drawn by this draw tmp = self.bounds x = self.bounds.origin.x y = self.bounds.origin.y xx = self.bounds.corner.x yy = self.bounds.corner.y hei = yy - y nr = len(self.lines) lineHei = -1 + hei // nr # PKHG force a list?? background_color wat not changed it is OK bgcol = self.background_color # PKHG no transparency!(strange behavior if allowed) bgcol[3] = 1.0 bgl.glColor4f(*bgcol) dime = self.get_extent().as_list() bgl.glRecti( self.get_position().x, self.get_position().y, self.get_position().x + dime[0], self.get_position().y + dime[1], ) # PKHG white color forced for el in range(nr): Morph.draw_string_to_viewport( self.lines[el], self, 24, (1, 1, 1, 1), self.font, x, yy - lineHei - el * lineHei ) return
def draw_callback(self, context): region = context.region if region and region == self.region: bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(*self.color) bgl.glRecti(0, 0, region.width, region.height) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, 1.0) # 初期値ってこれだっけ?
def draw_callback(self, context): region = context.region if region and region == self.mouseovered_region: bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 0.0, 0.0, 0.3) bgl.glRecti(0, 0, region.width, region.height) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
def draw_bg(region): # Enable Opengl alpha bgl.glEnable(bgl.GL_BLEND) # set color: red, green, blue, alpha bgl.glColor4f(1.0, 0.0, 0.0, 0.1) # draw rectangle # x0, y0, x1, y1 bgl.glRecti(1, 100, region.width, 0)
def draw_callback_mode(self, context): # draw mode_title mode_title(True, "Object Assembler Mode") bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.img.bindcode) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST) bgl.glLineWidth(1) # draw frame for icon in self.menu: bgl.glColor3f(0.1, 0.1, 0.1) bgl.glRecti( icon[2][0],icon[2][1],icon[2][2],icon[2][3] ) # icon zeichnen for icon in self.menu: bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glTexEnvf(bgl.GL_TEXTURE_ENV,bgl.GL_TEXTURE_ENV_MODE, bgl.GL_REPLACE) bgl.glBegin(bgl.GL_QUADS) bgl.glTexCoord2f(icon[4][0][0], icon[4][0][1]) bgl.glVertex2f(icon[1][0], icon[1][1]) bgl.glTexCoord2f(icon[4][1][0], icon[4][1][1]) bgl.glVertex2f(icon[1][0], icon[1][3]) bgl.glTexCoord2f(icon[4][2][0], icon[4][2][1]) bgl.glVertex2f(icon[1][2], icon[1][3]) bgl.glTexCoord2f(icon[4][3][0], icon[4][3][1]) bgl.glVertex2f(icon[1][2], icon[1][1]) bgl.glEnd() bgl.glDisable(bgl.GL_TEXTURE_2D) # draw hover effekt for icon in self.menu: # mouse hover icon if mouse_hover_icon(icon[1], self.mouse): bgl.glColor3f(0.4, 0.4, 0.4) bgl.glLineWidth(2) rect_round_corners(icon[3][0], icon[3][1], icon[3][2], icon[3][3]) # restore opengl defaults bgl.glLineWidth(1) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_untextured(self): """ call this draw function only if morph does not use texture""" global debug_color # print("morph", self, "visibility = ", self.is_visible) # if not self.is_visible: # return # print(">>>>>>>>>>> self and color = ",self, self.color) bgl.glColor4f(*self.color) dimensions = self.get_extent().as_list() if self.rounded: Morph.draw_rounded_morph(self, 0.3, self.color, rectangle = False) else: bgl.glRecti(self.get_position().x, self.get_position().y, self.get_position().x+dimensions[0], self.get_position().y+dimensions[1]) #PKHG.TODO font stuff # font_id = blf.load("c:/Windows/Fonts/arialbd.ttf") font_id = self.font_id size = 16 blf.size(font_id, size, 72) dims_x,dims_y = blf.dimensions(font_id, self.name) #PKHG should be done elsewhere! self.my_name_size = int(dims_x) + 2 x = self.bounds.origin.x xx = self.bounds.corner.x difx = xx - x if dims_x > difx: quot = difx/dims_x size = int(size * quot) y = self.bounds.corner.y - size #PKHG. bounds should include name of morph #PKHG 040612 does not work???! self.bounds = Rectangle(self.bounds.origin,Point(int(dims_x) + 2,\ # self.bounds.corner.y)) #PKHG.1jun12 the foregoing line causes strange behavior! if self.with_name: Morph.draw_string_to_viewport(self.name, self, size , (1,1,1,1), font_id, x , y) if debug_color and self.name == "toggle editing: LM-click!": tmp = [self] tmp.extend(self.children[:]) print(">....color debug draw in morph\nself and chidren",tmp) tmpcol = [el.color for el in tmp] print("their color = ", tmpcol) print(debug_color) debug_color -=1
def open(self, x, y): if len(self.items) == 0: return width = self.max * self.width # menu background bgl.glColor4f(self.color[0], self.color[1], self.color[2], self.color[3]) bgl.glRecti( x - self.margin, y - (self.height + self.margin) * (len(self.items) - 1) - self.margin, x + width + self.margin, y + self.height + self.margin - self.shift, ) if self.highlighted != "": ir = self.itemRects[self.highlighted] bgl.glColor4f(self.hColor[0], self.hColor[1], self.hColor[2], self.hColor[3]) bgl.glRecti(ir[0], ir[1] - self.shift, ir[2], ir[3] - 2 * self.shift) # bgl.glColor4f(0.0, 0.0, 0.0, 1.0) font_id = 0 # XXX, need to find out how best to get this. bgl.glColor4f(self.textColor[0], self.textColor[1], self.textColor[2], self.textColor[3]) for it in self.items: rect = self.itemRects[it] # if it == self.highlighted: # bgl.glColor4f(self.color[0], self.color[1], self.color[2], self.color[3]) blf.position(font_id, float(rect[0] + self.margin), float(rect[1]), 0) # check for boundaries ? blf.size(font_id, self.height, 72) blf.draw(font_id, it) # if it == self.highlighted: # bgl.glColor4f(self.textColor[0], self.textColor[1], self.textColor[2], self.textColor[3]) # restore opengl defaults bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_mode(self, context): settings = context.scene.OASettings if self.ctrl and not settings.shift: mode_title(context, "Replace") bgl.glLineWidth(1) tool_shelf_width = get_tool_shelf_width(bpy.context) # add the offset-width and offset-height for the first time if self.menu_offset['first_iteration']: for icon in self.menu: # iterate over icon, frame and hover for i in (1, 2, 3): # iterate over lower left and upper right corner for j in (0, 2): icon[i][0 + j] += tool_shelf_width icon[i][1 + j] += bpy.context.region.height self.menu_offset['first_iteration'] = False # add current offset-region-height and offset-tool-shelf-width # when the user altered the size of the 3d-view or toggled region_overlap elif any(( self.menu_offset['width'] != tool_shelf_width, self.menu_offset['height'] != bpy.context.region.height, self.menu_offset['region_overlap'] != bool( bpy.context.user_preferences.system.use_region_overlap), )): for icon in self.menu: # iterate over icon, frame and hover for i in (1, 2, 3): # iterate over lower left and upper right corner for j in (0, 2): icon[i][0 + j] += (tool_shelf_width - self.menu_offset['width']) icon[i][1 + j] += (bpy.context.region.height - self.menu_offset['height']) self.menu_offset['width'] = tool_shelf_width self.menu_offset['height'] = bpy.context.region.height self.menu_offset['region_overlap'] = bool( bpy.context.user_preferences.system.use_region_overlap) # draw frame bgl.glColor3f(0.1, 0.1, 0.1) for icon in self.menu: bgl.glRecti(icon[2][0], icon[2][1], icon[2][2], icon[2][3]) # draw icons if settings.valid_icon_file: bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.img.bindcode) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST) for icon in self.menu: bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_REPLACE) bgl.glBegin(bgl.GL_QUADS) bgl.glTexCoord2f(icon[4][0][0], icon[4][0][1]) bgl.glVertex2f(icon[1][0], icon[1][1]) bgl.glTexCoord2f(icon[4][1][0], icon[4][1][1]) bgl.glVertex2f(icon[1][0], icon[1][3]) bgl.glTexCoord2f(icon[4][2][0], icon[4][2][1]) bgl.glVertex2f(icon[1][2], icon[1][3]) bgl.glTexCoord2f(icon[4][3][0], icon[4][3][1]) bgl.glVertex2f(icon[1][2], icon[1][1]) bgl.glEnd() bgl.glDisable(bgl.GL_TEXTURE_2D) else: # draw category and model_id if no icon file is provided # draw background bgl.glColor3f(0.2, 0.2, 0.2) for icon in self.menu: bgl.glRecti(icon[2][0] + 2, icon[2][1] + 2, icon[2][2] - 2, icon[2][3] - 2) font_id = 0 bgl.glColor4f(1, 1, 1, 1) for icon in self.menu: blf.position(font_id, icon[1][0] + 1, icon[1][1] + 8, 0) blf.size(font_id, int(settings.menu_icon_display_size / 3), 72) blf.draw( font_id, "{0: >2}".format(icon[0][1]) + "," + "{0: >2}".format(icon[0][2])) # draw hover effekt for icon in self.menu: # mouse hover icon if mouse_over_icon(icon[1], self.mouse): bgl.glColor3f(0.6, 0.6, 0.6) bgl.glLineWidth(2) rect_round_corners(icon[3][0], icon[3][1], icon[3][2], icon[3][3]) # restore opengl defaults bgl.glLineWidth(1) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def on_draw(self): bgl.glColor4f(1.0, 1.0, 1.0, 0.5*self.a) #draw button backgrounds if self.lmb == True: #bgl.glColor4f(1.0, 0.5, 0.5, 0.5*self.a) bgl.glRecti( self.left(), self.top()-self.bdy, self.left() + self.bdx, self.top()) if self.mmb == True: #bgl.glColor4f(0.5, 0.5, 1.0, 0.5*self.a) bgl.glRecti( self.ox + self.bdx, self.oy + self.dy - self.bdy, self.ox + self.dx - self.bdx, self.oy + self.dy) if self.rmb == True: #bgl.glColor4f(0.5, 1.0, 0.5, 0.5*self.a) bgl.glRecti( self.ox + self.dx-self.bdx, self.oy + self.dy - self.bdy, self.ox + self.dx, self.oy + self.dy) #draw button dividers bgl.glColor4f(1.0, 1.0, 1.0, 0.5*self.a) if self._scroll!='': mx=self.left() + int(self.bdx*1.5) my=self.top() - int(self.bdy*0.5) dx=4 dy=0 #flip if self._scroll=='WHEELUPMOUSE': dy+=4 elif self._scroll=='WHEELDOWNMOUSE': dy-=4 #line bgl.glLineWidth(3) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2i(mx, my) bgl.glVertex2i(mx, my - dy) bgl.glEnd() # arrow bgl.glLineWidth(1) bgl.glBegin(bgl.GL_TRIANGLES) bgl.glVertex2i(mx - dx, my) bgl.glVertex2i(mx, my + dy) bgl.glVertex2i(mx + dx, my) bgl.glEnd() bgl.glLineWidth(1) bgl.glBegin(bgl.GL_LINES) #left-middle bgl.glVertex2i(self.ox+self.bdx, self.oy+self.dy) bgl.glVertex2i(self.ox+self.bdx, self.oy+self.dy-self.bdy) #middle-right bgl.glVertex2i(self.ox+self.dx-self.bdx, self.oy+self.dy) bgl.glVertex2i(self.ox+self.dx-self.bdx, self.oy+self.dy-self.bdy) #bottom bgl.glVertex2i(self.ox, self.oy+self.dy-self.bdy) bgl.glVertex2i(self.ox+self.dx, self.oy+self.dy-self.bdy) bgl.glEnd() pass
def draw_background(self): # background 50% alpha, black self.on_set_background() bgl.glRecti(self.ox, self.oy, self.ox + self.dx, self.oy + self.dy)